##// END OF EJS Templates
fix(encryption): don't be strict on enc format when no enc headers are missing....
super-admin -
r5381:0a39631e default
parent child Browse files
Show More
@@ -43,6 +43,7 b' class InvalidDecryptedValue(str):'
43 43 content = f'<{cls.__name__}({content[:16]}...)>'
44 44 return str.__new__(cls, content)
45 45
46
46 47 KEY_FORMAT = b'enc$aes_hmac${1}'
47 48
48 49
@@ -29,12 +29,16 b' class Encryptor(object):'
29 29 @classmethod
30 30 def detect_enc_algo(cls, enc_data: bytes):
31 31 parts = enc_data.split(b'$', 3)
32 if len(parts) != 3:
33 raise ValueError(f'Encrypted Data has invalid format, expected {cls.key_format}, got {parts}')
34 32
35 33 if b'enc$aes_hmac$' in enc_data:
34 # we expect this data is encrypted, so validate the header
35 if len(parts) != 3:
36 raise ValueError(f'Encrypted Data has invalid format, expected {cls.key_format}, got `{parts}`')
36 37 return 'aes'
37 38 elif b'enc2$salt' in enc_data:
39 # we expect this data is encrypted, so validate the header
40 if len(parts) != 3:
41 raise ValueError(f'Encrypted Data has invalid format, expected {cls.key_format}, got `{parts}`')
38 42 return 'fernet'
39 43 return None
40 44
@@ -65,7 +69,7 b' class Encryptor(object):'
65 69 def _get_parts(self, enc_data):
66 70 parts = enc_data.split(b'$', 3)
67 71 if len(parts) != 3:
68 raise ValueError(f'Encrypted Data has invalid format, expected {self.key_format}, got {parts}')
72 raise ValueError(f'Encrypted Data has invalid format, expected {self.key_format}, got `{parts}`')
69 73 prefix, salt, enc_data = parts
70 74
71 75 try:
General Comments 0
You need to be logged in to leave comments. Login now