From 5b9bdf108a2603cf7807be8c7b97a168bb0db621 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 15 Oct 2020 15:29:54 -0700 Subject: [PATCH] Adding Authentication to ControlPort --- tor/dialer.go | 11 +++++++++++ tor/tor.go | 1 + 2 files changed, 12 insertions(+) diff --git a/tor/dialer.go b/tor/dialer.go index 9ef211e..522955b 100644 --- a/tor/dialer.go +++ b/tor/dialer.go @@ -3,6 +3,7 @@ package tor import ( "context" "fmt" + "git.openprivacy.ca/openprivacy/bine/control" "net" "strings" @@ -14,6 +15,11 @@ type Dialer struct { proxy.Dialer } +// Authenticator provides a facade over various Tor control port authentication methods. +type Authenticator interface { + Authenticate(controlport *control.Conn) error +} + // DialConf is the configuration used for Dialer. type DialConf struct { // ProxyAddress is the address for the SOCKS5 proxy. If empty, it is looked @@ -39,6 +45,8 @@ type DialConf struct { // Forward is the dialer to forward to. If nil, just uses normal net dialer. Forward proxy.Dialer + + Authenticator Authenticator } // Dialer creates a new Dialer for the given configuration. Context can be nil. @@ -50,6 +58,9 @@ func (t *Tor) Dialer(ctx context.Context, conf *DialConf) (*Dialer, error) { if conf == nil { conf = &DialConf{} } + + conf.Authenticator.Authenticate(t.Control) + // Enable the network if requested if !conf.SkipEnableNetwork { if err := t.EnableNetwork(ctx, true); err != nil { diff --git a/tor/tor.go b/tor/tor.go index a0a5a76..f7c35c9 100644 --- a/tor/tor.go +++ b/tor/tor.go @@ -364,6 +364,7 @@ func (t *Tor) EnableNetwork(ctx context.Context, wait bool) error { if ctx == nil { ctx = context.Background() } + // Only enable if DisableNetwork is 1 if vals, err := t.Control.GetConf("DisableNetwork"); err != nil { return err