Adding Authentication to ControlPort

This commit is contained in:
Sarah Jamie Lewis 2020-10-15 15:29:54 -07:00
parent 4bf58a3c21
commit 5b9bdf108a
2 changed files with 12 additions and 0 deletions

View File

@ -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 {

View File

@ -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