Avoid mismtaching cryptography configuration in both extremes of a tunnel.
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 9 Nov 2012 12:36:39 +0000 (13:36 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 9 Nov 2012 12:36:39 +0000 (13:36 +0100)
DEPENDENCIES
src/nepi/util/proxy.py
src/nepi/util/tunchannel.py

index 1c83aa4..c66fd9c 100644 (file)
@@ -1,2 +1,3 @@
 * ipaddr-2.1.7 : http://ipaddr-py.googlecode.com/files/ipaddr-2.1.7.tar.gz
-* sleekxmpp-1.0.1dev: 
+* sleekxmpp-1.0.1dev:
+* python-crypto
index 04f3655..4226bac 100644 (file)
@@ -759,7 +759,7 @@ class TestbedControllerServer(BaseServer):
                 broadcast)
 
     @Marshalling.handles(ADD_ROUTE)
-    @Marshalling.args(int, str, int, str, int)
+    @Marshalling.args(int, str, int, str, int, str)
     @Marshalling.retvoid
     def defer_add_route(self, guid, destination, netprefix, nexthop, 
             metric, device):
index 78176d6..a5c3960 100644 (file)
@@ -180,7 +180,7 @@ def decrypt(packet, crypter, ord=ord):
         padding = ord(packet[-1])
         if not (0 < padding <= crypter.block_size):
             # wrong padding
-            raise RuntimeError, "Truncated packet"
+            raise RuntimeError, "Truncated packet %s"
         packet = packet[:-padding]
     
     return packet
@@ -216,18 +216,27 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN
             ciphername = cipher
             cipher = getattr(Crypto.Cipher, cipher)
             hashed_key = hashlib.sha256(cipher_key).digest()
-            if getattr(cipher, 'key_size'):
-                hashed_key = hashed_key[:cipher.key_size]
+
+            if ciphername == 'AES':
+                hashed_key = hashed_key[:16]
+            elif ciphername == 'Blowfish':
+                hashed_key = hashed_key[:24]
+            elif ciphername == 'DES':
+                hashed_key = hashed_key[:8]
             elif ciphername == 'DES3':
                 hashed_key = hashed_key[:24]
+
             crypter = cipher.new(
                 hashed_key, 
                 cipher.MODE_ECB)
             crypto_mode = True
     except:
+        # We don't want decription to work only on one side,
+        # This could break things really bad
+        #crypto_mode = False
+        #crypter = None
         traceback.print_exc(file=sys.stderr)
-        crypto_mode = False
-        crypter = None
+        raise
 
     if stderr is not None:
         if crypto_mode: