mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
We convert the given password to a string to avoid errors with the crypto module.
fix #193
This commit is contained in:
+5
-4
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user