Skip to content

Commit

Permalink
Tor can do SOCKS over Unix sockets; sweet!
Browse files Browse the repository at this point in the history
  • Loading branch information
meejah committed Apr 15, 2016
1 parent 9408a71 commit 4b7e2df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/check_pypi2.py
Expand Up @@ -52,7 +52,7 @@ def main(reactor):
print("State:", state)

fac = AgentEndpointFactoryUsingTor(
reactor, TCP4ClientEndpoint(reactor, '127.0.0.1', int(tor.config.SOCKSPort[0]))
reactor, UNIXClientEndpoint(reactor, '/tmp/torsocks/socks'),
)
agent = Agent.usingEndpointFactory(reactor, fac)
#uri = 'https://www.torproject.org:80'
Expand Down
5 changes: 4 additions & 1 deletion txtorcon/socks.py
Expand Up @@ -173,7 +173,8 @@ def _is_valid_response(self, msg):
# print("_is_valid_response", msg)
try:
(version, reply, _, typ) = struct.unpack('BBBB', msg[:4])
return version == 5 and reply == 0 and typ in [0x01, 0x03]
# print(version, reply, _, typ)
return version == 5 and reply == 0 and typ in [0x01, 0x03, 0x04]
except Exception as e:
print("error", e)
return False
Expand All @@ -185,6 +186,8 @@ def _parse_response(self, msg):
elif typ == 0x03: # DOMAINNAME
addrlen = struct.unpack('B', msg[4:5])[0]
addr = msg[5:5 + addrlen]
elif typ == 0x04: # IPv6
addr = msg[4:20]
else:
raise Exception("logic error")
port = struct.unpack('H', msg[-2:])[0]
Expand Down

0 comments on commit 4b7e2df

Please sign in to comment.