-
Notifications
You must be signed in to change notification settings - Fork 1
/
tor.go
50 lines (44 loc) · 1.33 KB
/
tor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Ecca Authentication Proxy
//
// Handles Eccentric Authentication in a web proxy for browsers.
//
// Copyright 2017, Guido Witmond <[email protected]>
// Licensed under AGPL v3 or later. See LICENSE
// Motto: Long live the connections
package main
import (
"fmt"
"log"
"github.com/gwitmond/goControlTor"
)
func createTorHiddenService(torPort, endpoint string) (string, string) {
tc := &goControlTor.TorControl{}
err := tc.Dial("tcp", *torControlPort)
check(err)
err = tc.PasswordAuthenticate(*torControlPassword)
check(err)
log.Printf("Logged into Tor, creating hidden service")
onion, onionPrivKey, err := tc.CreateEphemeralHiddenService(torPort, endpoint)
check(err)
log.Printf("Created onion address: %v", onion)
onionAddress := fmt.Sprintf("%s.onion:443", onion)
log.Printf("Created Listener at %v for %v", endpoint, onionAddress)
return onionAddress, onionPrivKey
}
func restartTorHiddenService(onionPrivKey []byte, torPort, endpoint, dest string) error {
tc := &goControlTor.TorControl{}
err := tc.Dial("tcp", *torControlPort)
if err != nil {
return err
}
err = tc.PasswordAuthenticate(*torControlPassword)
if err != nil {
return err
}
log.Printf("Logged into Tor, restarting hidden service")
err = tc.RestartEphemeralHiddenService(onionPrivKey, torPort, endpoint, dest)
if err != nil {
return err
}
return nil
}