[Pkg-privacy-commits] [obfsproxy] 252/353: Send more appropriate SOCKS error codes on connect failures

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:02:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository obfsproxy.

commit c990b7212227c2e4c36d4dbe415b3d37c97be316
Author: Yawning Angel <yawning at schwanenlied.me>
Date:   Mon Mar 3 19:57:22 2014 +0000

    Send more appropriate SOCKS error codes on connect failures
---
 obfsproxy/network/socks.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/obfsproxy/network/socks.py b/obfsproxy/network/socks.py
index c19bc67..41f73b2 100644
--- a/obfsproxy/network/socks.py
+++ b/obfsproxy/network/socks.py
@@ -1,4 +1,4 @@
-from twisted.internet import reactor, protocol
+from twisted.internet import reactor, protocol, error
 
 import obfsproxy.common.log as logging
 import obfsproxy.network.network as network
@@ -354,8 +354,18 @@ class SOCKSv5Protocol(network.GenericProtocol):
 
     def _handle_connect_failure(self, failure):
         log.warning("%s: Failed to connect to peer: %s" % (self.name, failure))
-        # XXX: Send a better error code based on reply
-        self.send_reply(_SOCKS_REP_GENERAL_FAILURE)
+
+        # Map common twisted errors to SOCKS error codes
+        if failure.type == error.NoRouteError:
+            self.send_reply(_SOCKS_REP_NETWORK_UNREACHABLE)
+        elif failure.type == error.ConnectionRefusedError:
+            self.send_reply(_SOCKS_REP_CONNECTION_REFUSED)
+        elif failure.type == error.TCPTimedOutError:
+            self.send_reply(_SOCKS_REP_TTL_EXPIRED)
+        elif failure.type == error.UnsupportedAddressFamily:
+            self.send_reply(_SOCKS_REP_ADDRESS_TYPE_NOT_SUPPORTED)
+        else:
+            self.send_reply(_SOCKS_REP_GENERAL_FAILURE)
 
     def setup_circuit(self):
         assert self._other_conn

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git



More information about the Pkg-privacy-commits mailing list