From 1c8b6531e6bbe23637dcfb153a38145e2d1033a2 Mon Sep 17 00:00:00 2001 From: Aldo Bleeker <2095835+ableeker@users.noreply.github.com> Date: Sun, 20 Feb 2022 18:00:12 +0100 Subject: [PATCH] Fix for key decryption failure --- DeDRM_plugin/ineptepub.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/DeDRM_plugin/ineptepub.py b/DeDRM_plugin/ineptepub.py index 7f34357..7e866b9 100644 --- a/DeDRM_plugin/ineptepub.py +++ b/DeDRM_plugin/ineptepub.py @@ -329,7 +329,7 @@ def _load_crypto_pycrypto(): return total 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) @@ -466,6 +466,12 @@ def adeptGetUserUUID(inpath): return None 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: # Byte not null, invalid result return False @@ -523,13 +529,13 @@ def decryptBook(userkey, inpath, outpath): bookkey = rsa.decrypt(base64.b64decode(bookkey.encode('ascii'))) # Verify key: - if len(bookkey) > 16: - # Padded as per RSAES-PKCS1-v1_5 - if verify_book_key(bookkey): + if verify_book_key(bookkey): + if len(bookkey) > 16: + # Padded as per RSAES-PKCS1-v1_5 bookkey = bookkey[-16:] - else: - print("Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath))) - return 2 + else: + print("Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath))) + return 2 else: # Adobe PassHash / B&N key = base64.b64decode(userkey)[:16]