Allow Custom Tor Config
This commit is contained in:
parent
b36f6dc33f
commit
d3398bd074
|
@ -4,3 +4,5 @@ tor/tor/
|
||||||
vendor/
|
vendor/
|
||||||
*.cover.out
|
*.cover.out
|
||||||
tmp/
|
tmp/
|
||||||
|
testing/tor/torrc
|
||||||
|
testing/tor/*
|
|
@ -1,4 +0,0 @@
|
||||||
SOCKSPort 9050
|
|
||||||
ControlPort 9051
|
|
||||||
# "examplehashedpassword" - used for testing
|
|
||||||
HashedControlPassword 16:C15305F97789414B601259E3EC5E76B8E55FC56A9F562B713F3D2BA257
|
|
|
@ -55,9 +55,9 @@ func (l *logWriter) Write(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type onionListenService struct {
|
type onionListenService struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
os *tor.OnionService
|
os *tor.OnionService
|
||||||
tp *torProvider
|
tp *torProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
type torProvider struct {
|
type torProvider struct {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package tor
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/openprivacy/log"
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
"path"
|
path "path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@ func TestTorProvider(t *testing.T) {
|
||||||
progChan := make(chan int)
|
progChan := make(chan int)
|
||||||
log.SetLevel(log.LevelDebug)
|
log.SetLevel(log.LevelDebug)
|
||||||
torpath := path.Join("..", "tmp/tor")
|
torpath := path.Join("..", "tmp/tor")
|
||||||
|
|
||||||
|
NewTorrc().WithControlPort(9051).WithHashedPassword("examplehashedpassword").Build(path.Join("..", "testing", "tor", "torrc"))
|
||||||
|
|
||||||
log.Debugf("setting tor path %v", torpath)
|
log.Debugf("setting tor path %v", torpath)
|
||||||
acn, err := NewTorACNWithAuth(path.Join("../testing/"), torpath, 9051, HashedPasswordAuthenticator{"examplehashedpassword"})
|
acn, err := NewTorACNWithAuth(path.Join("../testing/"), torpath, 9051, HashedPasswordAuthenticator{"examplehashedpassword"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -98,3 +98,11 @@ func TestGenerateTorrc(t *testing.T) {
|
||||||
}
|
}
|
||||||
os.Remove(path)
|
os.Remove(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPreviewTorrc(t *testing.T) {
|
||||||
|
expected := "SocksPort 9050 OnionTrafficOnly\nControlPort 9061"
|
||||||
|
torrc := NewTorrc().WithCustom([]string{"SocksPort 9050"}).WithControlPort(9061).WithOnionTrafficOnly().Preview()
|
||||||
|
if torrc != expected {
|
||||||
|
t.Fatalf("unexpected torrc generated: [%v] [%v]", expected, torrc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,6 +34,13 @@ func (tb *TorrcBuilder) WithControlPort(port int) *TorrcBuilder {
|
||||||
return tb
|
return tb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithCustom clobbers the torrc builder and allows the client to set any option they want, while benefiting
|
||||||
|
// from other configuration options.
|
||||||
|
func (tb *TorrcBuilder) WithCustom(lines []string) *TorrcBuilder {
|
||||||
|
tb.lines = lines
|
||||||
|
return tb
|
||||||
|
}
|
||||||
|
|
||||||
// WithOnionTrafficOnly ensures that the tor process only routes tor onion traffic.
|
// WithOnionTrafficOnly ensures that the tor process only routes tor onion traffic.
|
||||||
func (tb *TorrcBuilder) WithOnionTrafficOnly() *TorrcBuilder {
|
func (tb *TorrcBuilder) WithOnionTrafficOnly() *TorrcBuilder {
|
||||||
for i, line := range tb.lines {
|
for i, line := range tb.lines {
|
||||||
|
@ -61,6 +68,11 @@ func (tb *TorrcBuilder) Build(path string) error {
|
||||||
return ioutil.WriteFile(path, []byte(strings.Join(tb.lines, "\n")), 0600)
|
return ioutil.WriteFile(path, []byte(strings.Join(tb.lines, "\n")), 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preview provides a string representation of the torrc file without writing it to a file location.
|
||||||
|
func (tb *TorrcBuilder) Preview() string {
|
||||||
|
return strings.Join(tb.lines, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
// GenerateHashedPassword calculates a hash in the same way tha tor --hash-password does
|
// GenerateHashedPassword calculates a hash in the same way tha tor --hash-password does
|
||||||
// this function takes a salt as input which is not great from an api-misuse perspective, but
|
// this function takes a salt as input which is not great from an api-misuse perspective, but
|
||||||
// we make it private.
|
// we make it private.
|
||||||
|
|
Loading…
Reference in New Issue