From 880880a374e960a05515e63ec4a2ee84475b4db5 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 28 Dec 2011 11:58:50 +0100 Subject: [PATCH] We convert the given password to a string to avoid errors with the crypto module. fix #193 --- auth/lib.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/auth/lib.py b/auth/lib.py index 8592cad86..160cd67e7 100644 --- a/auth/lib.py +++ b/auth/lib.py @@ -8,10 +8,11 @@ import base64 from modoboa.lib import parameters def encrypt(clear): - obj = AES.new(parameters.get_admin("SECRET_KEY"), - AES.MODE_ECB) + key = parameters.get_admin("SECRET_KEY") + obj = AES.new(key, AES.MODE_ECB) + clear = str(clear) if len(clear) % AES.block_size: - clear += "\0" * (AES.block_size - len(clear) % AES.block_size) + clear += " " * (AES.block_size - len(clear) % AES.block_size) ciph = obj.encrypt(clear) ciph = base64.b64encode(ciph) return ciph @@ -20,7 +21,7 @@ def decrypt(ciph): obj = AES.new(parameters.get_admin("SECRET_KEY"), AES.MODE_ECB) ciph = base64.b64decode(ciph) clear = obj.decrypt(ciph) - return clear.rstrip('\0') + return clear.rstrip(' ') def get_password(request): return decrypt(request.session["password"])