Skip to content

Commit

Permalink
Support for Adobe's 'aes128-cbc-uncompressed' encryption (see noDRM#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
noDRM committed Jan 6, 2023
1 parent 3c12806 commit fb8b003
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ List of changes since the fork of Apprentice Harper's repository:
- Obok: Fix where changing the Calibre UI language to some languages would cause the "duplicate book" setting to reset.
- Fix Python3 bug in stylexml2css.php script, fixes #232.
- PDF: Ignore invalid PDF objids unless the script is running in strict mode. Fixes some PDFs, apparently. Fixes #233.
- Bugfix: EPUBs with remaining content in the encryption.xml after decryption weren't written correctly.
- Support for Adobe's 'aes128-cbc-uncompressed' encryption method (fixes #242).
11 changes: 9 additions & 2 deletions DeDRM_plugin/ineptepub.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, bookkey, encryption):
self._aes = AES.new(bookkey, AES.MODE_CBC, b'\x00'*16)
self._encryption = etree.fromstring(encryption)
self._encrypted = encrypted = set()
self._encryptedForceNoDecomp = encryptedForceNoDecomp = set()
self._otherData = otherData = set()

self._json_elements_to_remove = json_elements_to_remove = set()
Expand All @@ -106,6 +107,11 @@ def __init__(self, bookkey, encryption):
path = path.encode('utf-8')
encrypted.add(path)
json_elements_to_remove.add(elem.getparent().getparent())
elif (encryption_type_url == "http://ns.adobe.com/adept/xmlenc#aes128-cbc-uncompressed"):
# Adobe uncompressed, for stuff like video files
path = path.encode('utf-8')
encryptedForceNoDecomp.add(path)
json_elements_to_remove.add(elem.getparent().getparent())
else:
path = path.encode('utf-8')
otherData.add(path)
Expand Down Expand Up @@ -134,14 +140,15 @@ def decompress(self, bytes):
return decompressed_bytes

def decrypt(self, path, data):
if path.encode('utf-8') in self._encrypted:
if path.encode('utf-8') in self._encrypted or path.encode('utf-8') in self._encryptedForceNoDecomp:
data = self._aes.decrypt(data)[16:]
if type(data[-1]) != int:
place = ord(data[-1])
else:
place = data[-1]
data = data[:-place]
data = self.decompress(data)
if not path.encode('utf-8') in self._encryptedForceNoDecomp:
data = self.decompress(data)
return data

# check file to make check whether it's probably an Adobe Adept encrypted ePub
Expand Down

0 comments on commit fb8b003

Please sign in to comment.