[tor-commits] [obfsproxy/master] Proxy support: Ensure we have txsocksx and a recent enough Twisted.

asn at torproject.org asn at torproject.org
Fri Apr 25 19:24:50 UTC 2014


commit 1106ec14c98207cf8cfdb1e660efbaee4293fe1d
Author: George Kadianakis <desnacked at riseup.net>
Date:   Fri Apr 25 20:11:23 2014 +0100

    Proxy support: Ensure we have txsocksx and a recent enough Twisted.
    
    From now on, obfsproxy when configured to connect to a proxy (either
    using --proxy or TOR_PT_PROXY) will refuse to run if it doesn't have
    txsocksx or its Twisted is too old (< 13.2.0).
---
 obfsproxy/managed/client.py  |    8 ++++++++
 obfsproxy/network/network.py |   21 +++++++++++++++++++++
 obfsproxy/pyobfsproxy.py     |    5 +++++
 3 files changed, 34 insertions(+)

diff --git a/obfsproxy/managed/client.py b/obfsproxy/managed/client.py
index 1a49074..f819e1a 100644
--- a/obfsproxy/managed/client.py
+++ b/obfsproxy/managed/client.py
@@ -4,6 +4,7 @@
 from twisted.internet import reactor, error
 
 import obfsproxy.network.launch_transport as launch_transport
+import obfsproxy.network.network as network
 import obfsproxy.transports.transports as transports
 import obfsproxy.common.log as logging
 import obfsproxy.common.transport_config as transport_config
@@ -32,6 +33,13 @@ def do_managed_client():
     # Apply the proxy settings if any
     proxy = ptclient.config.getProxy()
     if proxy:
+        # Make sure that we have all the necessary dependencies
+        try:
+            network.ensure_outgoing_proxy_dependencies()
+        except network.OutgoingProxyDepsFailure, err:
+            ptclient.reportProxyError(str(err))
+            return
+
         ptclient.reportProxySuccess()
 
     for transport in ptclient.getTransports():
diff --git a/obfsproxy/network/network.py b/obfsproxy/network/network.py
index 958728e..2715ae9 100644
--- a/obfsproxy/network/network.py
+++ b/obfsproxy/network/network.py
@@ -435,3 +435,24 @@ def create_proxy_client(host, port, proxy_spec, instance):
     else:
         # Should *NEVER* happen
         raise RuntimeError("Invalid proxy scheme %s" % proxy_spec.scheme)
+
+def ensure_outgoing_proxy_dependencies():
+    """Make sure that we have the necessary dependencies to connect to
+    outgoing HTTP/SOCKS proxies.
+
+    Raises OutgoingProxyDepsFailure in case of error.
+    """
+
+    # We can't connect to outgoing proxies without txsocksx.
+    try:
+        import txsocksx
+    except ImportError:
+        raise OutgoingProxyDepsFailure("We don't have txsocksx. Can't do proxy. Please install txsocksx.")
+
+    # We also need a recent version of twisted ( >= twisted-13.2.0)
+    import twisted
+    from twisted.python import versions
+    if twisted.version < versions.Version('twisted', 13, 2, 0):
+        raise OutgoingProxyDepsFailure("Outdated version of twisted (%s). Please upgrade to >= twisted-13.2.0" % twisted.version.short())
+
+class OutgoingProxyDepsFailure(Exception): pass
diff --git a/obfsproxy/pyobfsproxy.py b/obfsproxy/pyobfsproxy.py
index f6f7bdb..ac07c65 100755
--- a/obfsproxy/pyobfsproxy.py
+++ b/obfsproxy/pyobfsproxy.py
@@ -10,6 +10,7 @@ Currently, not all of the obfsproxy command line options have been implemented.
 import sys
 
 import obfsproxy.network.launch_transport as launch_transport
+import obfsproxy.network.network as network
 import obfsproxy.transports.transports as transports
 import obfsproxy.common.log as logging
 import obfsproxy.common.argparser as argparser
@@ -127,6 +128,10 @@ def consider_cli_args(args):
                       "Use the managed-proxy configuration protocol instead!")
             sys.exit(1)
 
+        # Check if we have the necessary dependencies
+        # (the function will raise an exception if not)
+        network.ensure_outgoing_proxy_dependencies()
+
         # Make sure that the proxy URI parses smoothly.
         try:
             proxy = parseProxyURI(args.proxy)





More information about the tor-commits mailing list