[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [obfsproxy/master] Catch some exceptions in scramblesuit's setup() and fail gracefully.



commit 879181dd50980a329f345b5784fc37cf1abecf6a
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Fri May 9 15:39:58 2014 +0100

    Catch some exceptions in scramblesuit's setup() and fail gracefully.
    
    Conflicts:
    	obfsproxy/transports/scramblesuit/scramblesuit.py
---
 obfsproxy/managed/client.py                       |    8 +++++++-
 obfsproxy/managed/server.py                       |    8 +++++++-
 obfsproxy/transports/base.py                      |    3 +++
 obfsproxy/transports/scramblesuit/scramblesuit.py |   18 +++++++++++-------
 4 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/obfsproxy/managed/client.py b/obfsproxy/managed/client.py
index f819e1a..8210a27 100644
--- a/obfsproxy/managed/client.py
+++ b/obfsproxy/managed/client.py
@@ -6,6 +6,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.transports.base as base
 import obfsproxy.common.log as logging
 import obfsproxy.common.transport_config as transport_config
 
@@ -53,7 +54,12 @@ def do_managed_client():
 
         # Call setup() method for this transport.
         transport_class = transports.get_transport_class(transport, 'socks')
-        transport_class.setup(pt_config)
+        try:
+            transport_class.setup(pt_config)
+        except base.TransportSetupFailed, err:
+            log.warning("Transport '%s' failed during setup()." % transport)
+            ptclient.reportMethodError(transport, "setup() failed: %s." % (err))
+            continue
 
         try:
             addrport = launch_transport.launch_transport_listener(transport, None, 'socks', None, pt_config)
diff --git a/obfsproxy/managed/server.py b/obfsproxy/managed/server.py
index eeca339..66c7fb5 100644
--- a/obfsproxy/managed/server.py
+++ b/obfsproxy/managed/server.py
@@ -7,6 +7,7 @@ from pyptlib.server import ServerTransportPlugin
 from pyptlib.config import EnvError
 
 import obfsproxy.transports.transports as transports
+import obfsproxy.transports.base as base
 import obfsproxy.network.launch_transport as launch_transport
 import obfsproxy.common.log as logging
 import obfsproxy.common.transport_config as transport_config
@@ -52,7 +53,12 @@ def do_managed_server():
 
         # Call setup() method for this tranpsort.
         transport_class = transports.get_transport_class(transport, 'server')
-        transport_class.setup(pt_config)
+        try:
+            transport_class.setup(pt_config)
+        except base.TransportSetupFailed, err:
+            log.warning("Transport '%s' failed during setup()." % transport)
+            ptserver.reportMethodError(transport, "setup() failed: %s." % (err))
+            continue
 
         try:
             if ext_orport:
diff --git a/obfsproxy/transports/base.py b/obfsproxy/transports/base.py
index b9140c0..a2b78f1 100644
--- a/obfsproxy/transports/base.py
+++ b/obfsproxy/transports/base.py
@@ -48,6 +48,8 @@ class BaseTransport(object):
         Receive Pluggable Transport Config, perform setup task
         and save state in class attributes.
         Called at obfsproxy startup.
+
+        Raise TransportSetupFailed if something goes wrong.
         """
 
     @classmethod
@@ -153,3 +155,4 @@ class BaseTransport(object):
 
 class PluggableTransportError(Exception): pass
 class SOCKSArgsError(Exception): pass
+class TransportSetupFailed(Exception): pass
diff --git a/obfsproxy/transports/scramblesuit/scramblesuit.py b/obfsproxy/transports/scramblesuit/scramblesuit.py
index 9f5daf5..1479f12 100644
--- a/obfsproxy/transports/scramblesuit/scramblesuit.py
+++ b/obfsproxy/transports/scramblesuit/scramblesuit.py
@@ -125,13 +125,12 @@ class ScrambleSuitTransport( base.BaseTransport ):
             if cfg and "password" in cfg:
                 try:
                     cls.uniformDHSecret = base64.b32decode(util.sanitiseBase32(
-                            cfg["password"]))
-                except TypeError as error:
-                    log.error(error.message)
-                    raise base.PluggableTransportError("Given password '%s' " \
-                            "is not valid Base32!  Run " \
-                            "'generate_password.py' to generate a good " \
-                            "password." % cfg["password"])
+                        cfg["password"]))
+                except (TypeError, AttributeError) as error:
+                    raise base.TransportSetupFailed(
+                        "Password could not be base32 decoded (%s)" % error)
+
+                cls.uniformDHSecret = cls.uniformDHSecret.strip()
 
         if cls.weAreServer:
             if not hasattr(cls, "uniformDHSecret"):
@@ -144,6 +143,11 @@ class ScrambleSuitTransport( base.BaseTransport ):
                     "Wrong password length (%d instead of %d)"
                     % len(cls.uniformDHSecret), const.SHARED_SECRET_LENGTH)
 
+            if not const.STATE_LOCATION:
+                raise base.TransportSetupFailed(
+                    "No state location set. If you are using external mode, " \
+                    "please set it using the --data-dir switch.")
+
             state.writeServerPassword(cls.uniformDHSecret)
 
     @classmethod



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits