Skip to content

Commit 9a11f48

Browse files
committed
Fix plugin crash with invalid ADE key
1 parent 59839ae commit 9a11f48

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ List of changes since the fork of Apprentice Harper's repository:
7171

7272
- Fix a bug introduced with #48 that breaks DeDRM'ing on Calibre 4 (fixes #101).
7373
- Fix some more Calibre-6 bugs in the Obok plugin (should fix #114).
74+
- Fix a bug where invalid Adobe keys could cause the plugin to stop trying subsequent keys (partially fixes #109).

Diff for: DeDRM_plugin/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ def ePubDecrypt(self,path_to_ebook):
511511
continue
512512

513513
# Found matching key
514-
userkey = codecs.decode(userkeyhex, 'hex')
515514
print("{0} v{1}: Trying UUID-matched encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname))
516515
of = self.temporary_file(".epub")
517516
try:
517+
userkey = codecs.decode(userkeyhex, 'hex')
518518
result = ineptepub.decryptBook(userkey, inf.name, of.name)
519519
of.close()
520520
if result == 0:
@@ -531,12 +531,13 @@ def ePubDecrypt(self,path_to_ebook):
531531

532532
# Attempt to decrypt epub with each encryption key (generated or provided).
533533
for keyname, userkeyhex in dedrmprefs['adeptkeys'].items():
534-
userkey = codecs.decode(userkeyhex, 'hex')
534+
535535
print("{0} v{1}: Trying Encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname))
536536
of = self.temporary_file(".epub")
537537

538538
# Give the user key, ebook and TemporaryPersistent file to the decryption function.
539539
try:
540+
userkey = codecs.decode(userkeyhex, 'hex')
540541
result = ineptepub.decryptBook(userkey, inf.name, of.name)
541542
except ineptepub.ADEPTNewVersionError:
542543
print("{0} v{1}: Book uses unsupported (too new) Adobe DRM.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
@@ -673,11 +674,11 @@ def PDFIneptDecrypt(self, path_to_ebook):
673674
continue
674675

675676
# Found matching key
676-
userkey = codecs.decode(userkeyhex, 'hex')
677677
print("{0} v{1}: Trying UUID-matched encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname))
678678
of = self.temporary_file(".pdf")
679679

680680
try:
681+
userkey = codecs.decode(userkeyhex, 'hex')
681682
result = ineptpdf.decryptBook(userkey, path_to_ebook, of.name)
682683
of.close()
683684
if result == 0:

0 commit comments

Comments
 (0)