core (memory/crypto): replaced PyCrypto by cryptography:

`PyCrypto` is unmaintained for years but was used in SàT for password hashing. This patch
fixes that by replacing `PyCrypto` by the reference `cryptography` module which is well
maintained.

The behaviour stays the same (except that previously async `hash`, `encrypt` and `decrypt`
methods are now synchronous, as they are quick and using a deferToThread may actually be
more resource intensive than using blocking methods).

It is planed to improve `memory.crypto` by using more up-to-date cryptography/hashing
algorithms in the future.

PyCrypto is no more a dependency of SàT
This commit is contained in:
Goffi 2020-02-09 23:50:26 +01:00
commit d0741de2ad

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python3
# SAT: a jabber client
# SàT: a XMPP client
# Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
# This program is free software: you can redistribute it and/or modify
@ -521,18 +520,11 @@ class Params(object):
raise exceptions.ProfileNotSetError(
"The profile is needed to decrypt a password"
)
d = self.host.memory.decryptValue(value, profile)
password = self.host.memory.decryptValue(value, profile)
def gotPlainPassword(password):
if (
password is None
): # empty value means empty password, None means decryption failure
raise exceptions.InternalError(
_("The stored password could not be decrypted!")
)
return password
return d.addCallback(gotPlainPassword)
if password is None:
raise exceptions.InternalError("password should never be None")
return defer.succeed(password)
def _type_to_str(self, result):
"""Convert result to string, according to its type """
@ -1056,7 +1048,7 @@ class Params(object):
lambda __: PasswordHasher.hash(value)
) # profile password is hashed (empty value stays empty)
elif value: # other non empty passwords are encrypted with the personal key
d = BlockCipher.encrypt(personal_key, value)
d = defer.succeed(BlockCipher.encrypt(personal_key, value))
else:
d = defer.succeed(value)
else: