https://github.com/crackcomm/onion
https://github.com/crackcomm/onion
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/crackcomm/onion
- Owner: crackcomm
- License: apache-2.0
- Created: 2021-09-28T00:08:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-28T00:09:23.000Z (over 4 years ago)
- Last Synced: 2024-06-20T03:31:24.026Z (almost 2 years ago)
- Language: Go
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# onion
[](https://godoc.org/github.com/crackcomm/onion)
Make an onion made of net and crypto layers.
```Go
o := onion.New(
net.NewLayer(),
tor.NewLayer(
tor.WithPort(80), // Hidden service port
tor.WithBin("/usr/bin/tor"),
tor.WithVerbose(true),
),
sch.NewLayer(
sch.WithPubKey(readPubKey()),
sch.WithPrivKey(readPrivKey()),
),
tls.NewLayer(
tls.WithCertKeyFile("ca.pem", "ca.key"),
),
sch.NewLayer(
sch.WithPubKey(readPubKey()),
sch.WithPrivKey(readPrivKey()),
),
sch.NewLayer(
sch.WithPubKey(readPubKey()),
sch.WithPrivKey(readPrivKey()),
),
)
```
## TOR Hidden service
To create a tor hidden service, all You need to do is create an Onion:
```Go
o := onion.New(
net.NewLayer(),
tor.NewLayer(
tor.WithPort(80), // Hidden service port
tor.WithBin("/usr/bin/tor"),
),
)
```
Then you can start listening through TOR:
```Go
listener, err := o.Listener(nil)
if err != nil {
glog.Fatal(err)
}
// Will output {address}.onion
glog.Infof("Listening on %s", listener.Addr())
for {
c, err := listener.Accept()
if err != nil {
glog.Warning(err)
continue
}
go serve(c)
}
```
You can also dial to TOR `.onion` services using this Onion:
```Go
conn, err := o.Connect("{address}.onion", time.Minute)
if err != nil {
glog.Fatal(err)
}
conn.Write([]byte("Hello world!\n"))
```