All Projects → ipsn → Go Libtor

ipsn / Go Libtor

Licence: bsd-3-clause
Self-contained Tor from Go

Programming Languages

c
50402 projects - #5 most used programming language
go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Libtor

Tinytor
A tiny Tor client implementation (in pure python).
Stars: ✭ 80 (-78.26%)
Mutual labels:  tor, privacy, anonymity
Coyim
coyim - a safe and secure chat client
Stars: ✭ 513 (+39.4%)
Mutual labels:  tor, privacy, anonymity
Nipe
An engine to make Tor network your default gateway
Stars: ✭ 1,032 (+180.43%)
Mutual labels:  tor, privacy, anonymity
Onionr
Private Decentralized Communication Network 🎭 🧅
Stars: ✭ 84 (-77.17%)
Mutual labels:  tor, privacy, anonymity
Thgtoa
The Hitchhiker’s Guide to Online Anonymity
Stars: ✭ 326 (-11.41%)
Mutual labels:  tor, privacy, anonymity
Digital Rights
Promote digital rights in China
Stars: ✭ 186 (-49.46%)
Mutual labels:  tor, privacy, anonymity
Onionbrowser
An open-source, privacy-enhancing web browser for iOS, utilizing the Tor anonymity network
Stars: ✭ 1,702 (+362.5%)
Mutual labels:  tor, privacy, anonymity
Tor Android
Tor binary and library for Android
Stars: ✭ 90 (-75.54%)
Mutual labels:  library, tor, anonymity
dystopia
Anonymity on the Internet by Transparent way.
Stars: ✭ 97 (-73.64%)
Mutual labels:  tor, anonymity
orjail
a more secure way to force programs to exclusively use tor network
Stars: ✭ 136 (-63.04%)
Mutual labels:  tor, anonymity
elza
Private, fast and minimal web browser based on electron with built-in tor.
Stars: ✭ 45 (-87.77%)
Mutual labels:  privacy, tor
soxy-driver
A docker networking driver that transparently tunnels docker containers TCP traffic through a proxy
Stars: ✭ 25 (-93.21%)
Mutual labels:  tor, anonymity
alternative-frontends
🔐🌐 Privacy-respecting web frontends for popular services
Stars: ✭ 821 (+123.1%)
Mutual labels:  tor, anonymity
youtube rss
A YouTube-client for managing subscriptions and watching videos anonymously over Tor without a Google account.
Stars: ✭ 49 (-86.68%)
Mutual labels:  tor, anonymity
tordam
A library for peer discovery inside the Tor network
Stars: ✭ 13 (-96.47%)
Mutual labels:  tor, anonymity
Chaincase
The only privacy preserving bitcoin app on iOS
Stars: ✭ 55 (-85.05%)
Mutual labels:  privacy, tor
Ricochet
Anonymous peer-to-peer instant messaging
Stars: ✭ 3,570 (+870.11%)
Mutual labels:  tor, privacy
kali-whoami
Whoami provides enhanced privacy, anonymity for Debian and Arch based linux distributions
Stars: ✭ 1,424 (+286.96%)
Mutual labels:  tor, anonymity
darknet.py
darknet.py is a network application with no dependencies other than Python and Tor, useful to anonymize the traffic of linux servers and workstations.
Stars: ✭ 71 (-80.71%)
Mutual labels:  tor, anonymity
Nex
Nex™️ : The 🌐 incognito browser of the 30th Century with built-in Tor 🧅
Stars: ✭ 12 (-96.74%)
Mutual labels:  privacy, tor

go-libtor - Self-contained Tor from Go

GoDoc Travis

The go-libtor project is a self-contained, fully statically linked Tor library for Go. It consists of an elaborate suite of Go/CGO wrappers around the original C/C++ Tor library and its dependencies (zlib, libevent and openssl).

Library Version Commit
zlib 1.2.11 cacf7f1d4e3d44d871b605da3b647f07d718623f
libevent 2.2.0-alpha-dev 00b92f42b69af29a820b46049fd00be9cd3fb7d4
openssl 1.1.1-stable 081a7061f3da07318c4b0f5de67b82285630bf6b
tor 0.3.5.14-dev 1693b6151e1369ce0938761cac95e7a0a524f5f3

The library is currently supported on:

  • Linux amd64, 386, arm64 and arm; both with libc and musl.
  • Android amd64, 386, arm64 and arm; specifically via gomobile.

Installation (GOPATH)

The goal of this library is to be a self-contained Tor package for Go. As such, it plays nice with the usual go get workflow. That said, building Tor and all its dependencies locally can take quite a while, so it's recommended to run go get in verbose mode.

$ go get -u -v -x github.com/ipsn/go-libtor

You'll also need the bine bindings to interface with the library:

go get -u github.com/cretz/bine/tor

Installation (Go modules)

This library is compatible with Go modules. All you should need is to import github.com/ipsn/go-libtor and wait out the build. We suggest running go build -v -x the first time after adding the go-libtor dependency to avoid frustration, otherwise Go will build the 1000+ C files without any progress report.

Usage

The go-libtor project does not contain a full Go API to interface Tor with, rather only the smallest building block to start up an embedded instance. The reason is because there is already a solid Go project out there (github.com/cretz/bine) which focuses on interfacing.

Using both projects in combination however is straightforward:

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"

	"github.com/cretz/bine/tor"
	"github.com/ipsn/go-libtor"
)

func main() {
	// Start tor with some defaults + elevated verbosity
	fmt.Println("Starting and registering onion service, please wait a bit...")
	t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: libtor.Creator, DebugWriter: os.Stderr})
	if err != nil {
		log.Panicf("Failed to start tor: %v", err)
	}
	defer t.Close()

	// Wait at most a few minutes to publish the service
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
	defer cancel()

	// Create an onion service to listen on any port but show as 80
	onion, err := t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}})
	if err != nil {
		log.Panicf("Failed to create onion service: %v", err)
	}
	defer onion.Close()

	fmt.Printf("Please open a Tor capable browser and navigate to http://%v.onion\n", onion.ID)

	// Run a Hello-World HTTP service until terminated
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, Tor!")
	})
	http.Serve(onion, nil)
}

The above code will:

  • Start up a new Tor process from within your statically linked binary
  • Register a new anonymous onion TCP endpoint for remote clients
  • Start an HTTP server using the Tor network as its transport layer
$ go run main.go

Starting and registering onion service, please wait a bit...
[...]
Enabling network before waiting for publication
[...]
Waiting for publication
[...]
Please open a Tor capable browser and navigate to http://s7t3iy76h54cjacg.onion

Demo

Well, that was easy. With a few lines of Go code we've created a hidden TCP service inside the Tor network. The browser used to test the server with above was Brave, which among others has built in experimental support for Tor.

Mobile devices

The advantage of go-libtor starts to show when building to more exotic platforms, since it's composed of simple CGO Go files. As it doesn't require custom build steps or tooling, it plays nice with the Go ecosystem, gomobile included:

Let's see how much effort would it be to deploy onto Android:

package demo

import (
	"context"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"

	"github.com/cretz/bine/tor"
	"github.com/ipsn/go-libtor"
)

// Run starts up an embedded Tor process, starts a hidden onion service on a new
// goroutine and returns the onion address. We're cheating here and not caring
// about actually cleaning up after ourselves.
func Run(datadir string) string {
	// Start tor with some defaults + elevated verbosity
	fmt.Println("Starting and registering onion service, please wait a bit...")
	t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: libtor.Creator, DebugWriter: os.Stderr, DataDir: datadir})
	if err != nil {
		log.Panicf("Failed to start tor: %v", err)
	}
	// Wait at most a few minutes to publish the service
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
	defer cancel()

	// Create an onion service to listen on any port but show as 80
	onion, err := t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}})
	if err != nil {
		log.Panicf("Failed to create onion service: %v", err)
	}
	fmt.Printf("Please open a Tor capable browser and navigate to http://%v.onion\n", onion.ID)

	// Run a Hello-World HTTP service until terminated
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, Tor! This is Android!!!")
	})
	go http.Serve(onion, nil)

	return fmt.Sprintf("http://%v.onion", onion.ID)
}

The above code does approximately the same thing as the one before, just in its own package with a trivial API since we want to make an Android archive, not an entire .apk. We can invoke gomobile to bind it:

$ gomobile bind -v -x .
[...many logs, much wow...]
$ ls -al demo*
-rw-r--r-- 1 karalabe 38976071 Jul 19 18:46 demo.aar
-rw-r--r-- 1 karalabe     6162 Jul 19 18:46 demo-sources.jar
$ unzip -l demo.aar
Archive:  demo.aar
  Length      Date    Time    Name
---------  ---------- -----   ----
      143  1980-00-00 00:00   AndroidManifest.xml
       25  1980-00-00 00:00   proguard.txt
    11044  1980-00-00 00:00   classes.jar
 26102356  1980-00-00 00:00   jni/armeabi-v7a/libgojni.so
 27085856  1980-00-00 00:00   jni/arm64-v8a/libgojni.so
 26327236  1980-00-00 00:00   jni/x86/libgojni.so
 27757968  1980-00-00 00:00   jni/x86_64/libgojni.so
        0  1980-00-00 00:00   R.txt
        0  1980-00-00 00:00   res/
---------                     -------
107284628                     9 files

Explaining how to load an .aar into an Android project is beyond the scope of this article, but you can load the archive with Android Studio as a module and edit your Gradle build config to add it as a dependency. An overly crude app would just start the server and drop the onion URL into an Android label:

Android

That's actually it! We've managed to get a Tor hidden service running from an Android phone and access it from another device through the Tor network, all through 40 lines of Go- and 3 lines of Java code.

Credits

This repository is maintained by Péter Szilágyi (@karalabe), but authorship of all code contained inside belongs to the individual upstream projects.

License

3-Clause BSD.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].