From 92494597ce18e21ca8db4d0cd7ba1be3ba05e735 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Sun, 25 May 2014 09:14:14 +0000 Subject: Wire in go.net/proxy, enabling SOCKS5 via TOR_PT_PROXY. With tor patched to support 8402, obfs4 bootstraps via a SOCKSv5 proxy now. Other schemes will bail with a PROXY-ERROR, as the go.net/proxy package does not support them, and I have not gotten around to writing dialers for them yet (next on my TODO list). Part of issue #7. --- obfs4.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'obfs4.go') diff --git a/obfs4.go b/obfs4.go index 6978a97..e4c22f8 100644 --- a/obfs4.go +++ b/obfs4.go @@ -533,10 +533,21 @@ func (c *Obfs4Conn) SetWriteDeadline(t time.Time) error { return syscall.ENOTSUP } +// DialFn is a function pointer to a dial routine that matches the +// net.Dialer.Dial routine. +type DialFn func(string, string) (net.Conn, error) + // DialObfs4 connects to the remote address on the network, and handshakes with // the peer's obfs4 Node ID and Identity Public Key. nodeID and publicKey are // expected as strings containing the Base64 encoded values. func DialObfs4(network, address, nodeID, publicKey string, iatObfuscation bool) (*Obfs4Conn, error) { + + return DialObfs4DialFn(net.Dial, network, address, nodeID, publicKey, iatObfuscation) +} + +// DialObfs4DialFn connects to the remote address on the network via DialFn, +// and handshakes with the peers' obfs4 Node ID and Identity Public Key. +func DialObfs4DialFn(dialFn DialFn, network, address, nodeID, publicKey string, iatObfuscation bool) (*Obfs4Conn, error) { // Decode the node_id/public_key. pub, err := ntor.PublicKeyFromBase64(publicKey) if err != nil { @@ -553,13 +564,13 @@ func DialObfs4(network, address, nodeID, publicKey string, iatObfuscation bool) return nil, err } - // Connect to the peer. + // Generate the Obfs4Conn. c := new(Obfs4Conn) c.lenProbDist = newWDist(seed, 0, framing.MaximumSegmentLength) if iatObfuscation { c.iatProbDist = newWDist(seed, 0, maxIatDelay) } - c.conn, err = net.Dial(network, address) + c.conn, err = dialFn(network, address) if err != nil { return nil, err } -- cgit v1.2.3