Fix for key decryption failure
This commit is contained in:
parent
f6b14efc5a
commit
1c8b6531e6
|
@ -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,13 +529,13 @@ 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 len(bookkey) > 16:
|
if verify_book_key(bookkey):
|
||||||
# Padded as per RSAES-PKCS1-v1_5
|
if len(bookkey) > 16:
|
||||||
if verify_book_key(bookkey):
|
# Padded as per RSAES-PKCS1-v1_5
|
||||||
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)))
|
||||||
return 2
|
return 2
|
||||||
else:
|
else:
|
||||||
# Adobe PassHash / B&N
|
# Adobe PassHash / B&N
|
||||||
key = base64.b64decode(userkey)[:16]
|
key = base64.b64decode(userkey)[:16]
|
||||||
|
|
Loading…
Reference in New Issue