Removed Crypto library remmanents. Old 2.2 RSA keys are no longer supported on 3.5

This commit is contained in:
Adolfo Gómez García 2021-04-28 10:42:45 +02:00
parent 451b8f6fb9
commit 47ef12ef6a
2 changed files with 6 additions and 25 deletions

View File

@ -47,13 +47,6 @@ from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
# Deprecating these. On future versions will only use
# cryptography libraries. Keep here for backwards compat with
# 1.x 2.x encriptions methods
from Crypto.PublicKey import RSA
from Crypto.Random import atfork # type: ignore
from django.conf import settings from django.conf import settings
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -66,7 +59,6 @@ class CryptoManager:
self._rsa = serialization.load_pem_private_key( self._rsa = serialization.load_pem_private_key(
settings.RSA_KEY.encode(), password=None, backend=default_backend() settings.RSA_KEY.encode(), password=None, backend=default_backend()
) )
self._oldRsa = RSA.importKey(settings.RSA_KEY)
self._namespace = uuid.UUID('627a37a5-e8db-431a-b783-73f7d20b4934') self._namespace = uuid.UUID('627a37a5-e8db-431a-b783-73f7d20b4934')
self._counter = 0 self._counter = 0
@ -106,9 +98,6 @@ class CryptoManager:
'base64', 'base64',
).decode() ).decode()
# atfork()
# return typing.cast(str, encoders.encode((self._rsa.encrypt(value, b'')[0]), 'base64', asText=True))
def decrypt(self, value: str) -> str: def decrypt(self, value: str) -> str:
data: bytes = codecs.decode(value.encode(), 'base64') data: bytes = codecs.decode(value.encode(), 'base64')
@ -123,16 +112,8 @@ class CryptoManager:
), ),
) )
except Exception: # If fails, try old method except Exception: # If fails, try old method
try: logger.exception('Decripting: %s', value)
atfork() return 'decript error'
decrypted = self._oldRsa.decrypt(
codecs.decode(value.encode(), 'base64')
)
return decrypted.decode()
except Exception:
logger.exception('Decripting: %s', value)
# logger.error(inspect.stack())
return 'decript error'
# logger.debug('Decripted: %s %s', data, decrypted) # logger.debug('Decripted: %s %s', data, decrypted)
return decrypted.decode() return decrypted.decode()
@ -215,10 +196,11 @@ class CryptoManager:
def loadPrivateKey(self, rsaKey: str): def loadPrivateKey(self, rsaKey: str):
try: try:
pk = RSA.importKey(rsaKey) return serialization.load_pem_private_key(
settings.RSA_KEY.encode(), password=None, backend=default_backend()
)
except Exception as e: except Exception as e:
raise e raise e
return pk
def loadCertificate(self, certificate: typing.Union[str, bytes]): def loadCertificate(self, certificate: typing.Union[str, bytes]):
if isinstance(certificate, str): if isinstance(certificate, str):

View File

@ -83,7 +83,7 @@ class CalendarChecker:
r_end = ( r_end = (
datetime.datetime.combine(rule.end, datetime.datetime.max.time()) datetime.datetime.combine(rule.end, datetime.datetime.max.time())
if rule.end is not None if rule.end
else None else None
) )
@ -94,7 +94,6 @@ class CalendarChecker:
if ruleDurationMinutes == 0 or ruleFrequencyMinutes == 0: if ruleDurationMinutes == 0 or ruleFrequencyMinutes == 0:
continue continue
# ruleDurationMinutes = ruleDurationMinutes
# Relative start, rrule can "spawn" the days, so we get the start at least the ruleDurationMinutes of rule to see if it "matches" # Relative start, rrule can "spawn" the days, so we get the start at least the ruleDurationMinutes of rule to see if it "matches"
# This means, we need the previous matching day to be "executed" so we can get the "actives" correctly # This means, we need the previous matching day to be "executed" so we can get the "actives" correctly
diff = ( diff = (