Fix for key decryption failure

This commit is contained in:
Aldo Bleeker 2022-02-20 18:00:12 +01:00
parent f6b14efc5a
commit 1c8b6531e6

View File

@ -329,7 +329,7 @@ def _load_crypto_pycrypto():
return total return total
def decrypt(self, data): def decrypt(self, data):
return _PKCS1_v1_5.new(self._rsa).decrypt(data, 172) return _PKCS1_v1_5.new(self._rsa).decrypt(data, b'')
return (AES, RSA) return (AES, RSA)
@ -466,6 +466,12 @@ def adeptGetUserUUID(inpath):
return None return None
def verify_book_key(bookkey): def verify_book_key(bookkey):
if len(bookkey) < 16:
return False
if len(bookkey) == 16:
return True
if bookkey[-17] != '\x00' and bookkey[-17] != 0: if bookkey[-17] != '\x00' and bookkey[-17] != 0:
# Byte not null, invalid result # Byte not null, invalid result
return False return False
@ -523,9 +529,9 @@ def decryptBook(userkey, inpath, outpath):
bookkey = rsa.decrypt(base64.b64decode(bookkey.encode('ascii'))) bookkey = rsa.decrypt(base64.b64decode(bookkey.encode('ascii')))
# Verify key: # Verify key:
if verify_book_key(bookkey):
if len(bookkey) > 16: if len(bookkey) > 16:
# Padded as per RSAES-PKCS1-v1_5 # Padded as per RSAES-PKCS1-v1_5
if verify_book_key(bookkey):
bookkey = bookkey[-16:] bookkey = bookkey[-16:]
else: else:
print("Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath))) print("Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath)))