Adding Authentication to ControlPort
This commit is contained in:
parent
4bf58a3c21
commit
5b9bdf108a
|
@ -3,6 +3,7 @@ package tor
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.openprivacy.ca/openprivacy/bine/control"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -14,6 +15,11 @@ type Dialer struct {
|
||||||
proxy.Dialer
|
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.
|
// DialConf is the configuration used for Dialer.
|
||||||
type DialConf struct {
|
type DialConf struct {
|
||||||
// ProxyAddress is the address for the SOCKS5 proxy. If empty, it is looked
|
// 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 is the dialer to forward to. If nil, just uses normal net dialer.
|
||||||
Forward proxy.Dialer
|
Forward proxy.Dialer
|
||||||
|
|
||||||
|
Authenticator Authenticator
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dialer creates a new Dialer for the given configuration. Context can be nil.
|
// 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 {
|
if conf == nil {
|
||||||
conf = &DialConf{}
|
conf = &DialConf{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conf.Authenticator.Authenticate(t.Control)
|
||||||
|
|
||||||
// Enable the network if requested
|
// Enable the network if requested
|
||||||
if !conf.SkipEnableNetwork {
|
if !conf.SkipEnableNetwork {
|
||||||
if err := t.EnableNetwork(ctx, true); err != nil {
|
if err := t.EnableNetwork(ctx, true); err != nil {
|
||||||
|
|
|
@ -364,6 +364,7 @@ func (t *Tor) EnableNetwork(ctx context.Context, wait bool) error {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only enable if DisableNetwork is 1
|
// Only enable if DisableNetwork is 1
|
||||||
if vals, err := t.Control.GetConf("DisableNetwork"); err != nil {
|
if vals, err := t.Control.GetConf("DisableNetwork"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue