• Stars
    star
    719
  • Rank 60,511 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go library for accessing and embedding Tor clients and servers

GoDoc

Bine is a Go API for using and controlling Tor. It is similar to Stem.

Features:

  • Full support for the Tor controller API
  • Support for net.Conn and net.Listen style APIs
  • Supports statically compiled Tor to embed Tor into the binary
  • Supports v3 onion services
  • Support for embedded control socket in Tor >= 0.3.5 (non-Windows)

See info below, the API docs, and the examples. The project is MIT licensed. The Tor docs/specs and https://github.com/yawning/bulb were great helps when building this.

Example

It is really easy to create an onion service. For example, assuming tor is on the PATH, this bit of code will show a directory server of the current directory:

package main

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

	"github.com/cretz/bine/tor"
)

func main() {
	// Start tor with default config (can set start conf's DebugWriter to os.Stdout for debug logs)
	fmt.Println("Starting and registering onion service, please wait a couple of minutes...")
	t, err := tor.Start(nil, nil)
	if err != nil {
		log.Panicf("Unable to start Tor: %v", err)
	}
	defer t.Close()
	// Wait at most a few minutes to publish the service
	listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute)
	defer listenCancel()
	// Create a v3 onion service to listen on any port but show as 80
	onion, err := t.Listen(listenCtx, &tor.ListenConf{RemotePorts: []int{80}})
	if err != nil {
		log.Panicf("Unable to create onion service: %v", err)
	}
	defer onion.Close()
	fmt.Printf("Open Tor browser and navigate to http://%v.onion\n", onion.ID)
	fmt.Println("Press enter to exit")
	// Serve the current folder from HTTP
	errCh := make(chan error, 1)
	go func() { errCh <- http.Serve(onion, http.FileServer(http.Dir("."))) }()
	// End when enter is pressed
	go func() {
		fmt.Scanln()
		errCh <- nil
	}()
	if err = <-errCh; err != nil {
		log.Panicf("Failed serving: %v", err)
	}
}

If in main.go it can simply be run with go run main.go. Of course this uses a separate tor process. To embed Tor statically in the binary, follow the embedded package docs which will require building Tor statically. Then with github.com/cretz/bine/process/embedded imported, change the start line above to:

t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: embedded.NewCreator()})

This defaults to Tor 0.3.5.x versions but others can be used from different packages. In non-Windows environments, the UseEmbeddedControlConn field in StartConf can be set to true to use an embedded socket that does not open a control port.

Tested on Windows, the original exe file is ~7MB. With Tor statically linked it comes to ~24MB, but Tor does not have to be distributed separately. Of course take notice of all licenses in accompanying projects.

Testing

To test, a simple go test ./... from the base of the repository will work (add in a -v in there to see the tests). The integration tests in tests however will be skipped. To execute those tests, -tor must be passed to the test. Also, tor must be on the PATH or -tor.path must be set to the path of the tor executable. Even with those flags, only the integration tests that do not connect to the Tor network are run. To also include the tests that use the Tor network, add the -tor.network flag. For details Tor logs during any of the integration tests, use the -tor.verbose flag.

More Repositories

1

asmble

Compile WebAssembly to JVM and other WASM tools
Kotlin
599
star
2

doogie

A Chromium-based web browser with tree-style pages
C++
278
star
3

kastree

Simple Kotlin Source AST and Syntax Parsing, Editing, and Writing
Kotlin
225
star
4

pb-and-k

Kotlin Code Generator and Runtime for Protocol Buffers
Kotlin
139
star
5

stackparam

JVM agent to add method parameters to Java stack traces
Rust
116
star
6

node-tds

Pure JS implementation of TDS protocol for Microsoft SQL Server
CoffeeScript
104
star
7

gwt-node

GWT implementation of standard the node.js library
Java
87
star
8

software-ideas

85
star
9

myscreen.live

P2P Screen Sharing with WebRTC
TypeScript
84
star
10

go-scrap

Go library to capture screen pixels for screenshots or screen recording
Go
76
star
11

tor-static

Helpers to build Tor statically
Go
74
star
12

dust-php

Powerful PHP templating engine based off of Dust JS
PHP
67
star
13

pgnio

Asynchronous PostgreSQL client for Java and the JVM
Java
62
star
14

gopaque

Go implementation of OPAQUE (hidden password user registration and auth)
Go
58
star
15

prost-twirp

Code generator and library for calling/serving Twirp services in Rust using prost and hyper
Rust
57
star
16

webrtc-ipfs-signaling

Tech demo using JS-IPFS to do signaling for WebRTC
HTML
56
star
17

javan-warty-pig

AFL-like fuzzer for the Java Virtual Machine
Java
49
star
18

scala-web-ideal

Akka HTTP + Scala.js + ScalaTags + ScalaCSS + Autowire + Prickle + akka-sse + Gradle + etc... (outdated/stale)
Scala
49
star
19

tor-dht-poc

Anonymous DHT Accessible from Executable or Tor-Enabled Browser
Go
48
star
20

pratphall

A typed language targeting PHP (abandoned)
JavaScript
45
star
21

qt_cef_poc

Proof of concept of simple browser w/ CEF and Qt
Go
26
star
22

kotlin-native-sample-agent

Sample JVMTI Agent Using Kotlin Native
Kotlin
23
star
23

chrome-screen-rec-poc

C++
21
star
24

go-sqleet

Encrypted SQLite for Go using go-sqlite3 and sqleet
C
17
star
25

goahead

A JVM AOT
Scala
16
star
26

msplit

Simple algorithm to split a JVM ASM method into two
Java
16
star
27

temporal-sdk-go-advanced

Go
15
star
28

go-mental-poker

Mental Poker Demonstration in Go
Go
12
star
29

go-wasm-bake

Experimenting with eager evaluation of Go WASM code
Kotlin
12
star
30

rtsw-poc

Rust + Tor (embedded) + Static (compile) + Windows + Proof of Concept
Rust
12
star
31

esgopeta

Go implementation of the Gun distributed graph database
Go
11
star
32

owncast-old

Go
11
star
33

superpose

Go library for compile-time code transformation
Go
10
star
34

SqlChop

Read the Transaction Log from SQL Server
C#
10
star
35

temporal-debug-go

Go
10
star
36

safeclient.js

JS Client to the SAFE Launcher API
TypeScript
9
star
37

imedge

Imedge - Image Manipulation in Edge Service Workers
Rust
8
star
38

rust-qt_cef_poc

Rust
8
star
39

temporal-protoc-gen-go-activity

Go
7
star
40

takecast

Go
7
star
41

go2k

Kotlin
5
star
42

rwtxt-crypt

The minimalist rwtxt CMS using encrypted SQLite and Tor
Go
5
star
43

rust-qthello

Rust
5
star
44

go-safeclient

CLI and Go library for accessing SAFE network
Go
4
star
45

statmantis

Java based baseball stat analyzer/parser
Java
4
star
46

gulliver

Scala
4
star
47

capnp-scala

Scala
3
star
48

ffembedpoc

Go
3
star
49

nexus-poc-old

Go
3
star
50

javan-warty-pig-kotlin

Kotlin
2
star
51

temporal-wasm

Go
2
star
52

teleworker

Go
2
star
53

temporal-determinist

Go
2
star
54

badads

JavaScript
2
star
55

systrument

Go
2
star
56

safe-poc-browser

Simple Proof-of-Concept Browser for SAFE Network
JavaScript
2
star
57

forsook

Java
2
star
58

smail

Scala
2
star
59

go-dump

Go
1
star
60

gwtson

GWT emulation layer for Gson
Java
1
star
61

irnie

1
star
62

mlbdash

HTML, client-side only live MLB dashboard
Java
1
star
63

clicknkick

Go
1
star
64

shrewd-old

TypeScript
1
star
65

monitoral

Go
1
star
66

distinct

JS diffing utility
CoffeeScript
1
star
67

yocalist

Java
1
star
68

fusty

Network Device Backup Tool/System
Go
1
star
69

narrow

1
star
70

gat-cdc

Trigger based Change Data Capture (CDC)
C#
1
star
71

yocalist-coffee

CoffeeScript
1
star
72

one-left

Go
1
star
73

sbn-stat

Generate posting statistics for SBN sites
Java
1
star
74

ripoata

1
star
75

elixoral

Elixir
1
star
76

rusty-zipper

Bindings and wrapper for libzip (incomplete)
Rust
1
star
77

caddy-tlsconsul

Go
1
star