]> xmof Git - DeDRM.git/commitdiff
Fix plugin crash with invalid ADE key
authorNoDRM <no_drm123@protonmail.com>
Wed, 3 Aug 2022 17:49:20 +0000 (19:49 +0200)
committerNoDRM <no_drm123@protonmail.com>
Wed, 3 Aug 2022 17:49:20 +0000 (19:49 +0200)
CHANGELOG.md
DeDRM_plugin/__init__.py

index feb8a84a1424e6ecc39cb112346b52d1c0870d91..8f3c7f20283e2fd804b50cba3a817c96e10fe62e 100644 (file)
@@ -71,3 +71,4 @@ List of changes since the fork of Apprentice Harper's repository:
 
 - Fix a bug introduced with #48 that breaks DeDRM'ing on Calibre 4 (fixes #101).
 - Fix some more Calibre-6 bugs in the Obok plugin (should fix #114).
+- Fix a bug where invalid Adobe keys could cause the plugin to stop trying subsequent keys (partially fixes #109).
\ No newline at end of file
index ad68ab41f4a8ef19c59e46c40338f4e47cd8189e..ba9e2ec27468f48a8ef095c0c5781bccd37a5bda 100644 (file)
@@ -511,10 +511,10 @@ class DeDRM(FileTypePlugin):
                             continue
 
                         # Found matching key
-                        userkey = codecs.decode(userkeyhex, 'hex')
                         print("{0} v{1}: Trying UUID-matched encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname))
                         of = self.temporary_file(".epub")
                         try: 
+                            userkey = codecs.decode(userkeyhex, 'hex')
                             result = ineptepub.decryptBook(userkey, inf.name, of.name)
                             of.close()
                             if result == 0:
@@ -531,12 +531,13 @@ class DeDRM(FileTypePlugin):
 
                 # Attempt to decrypt epub with each encryption key (generated or provided).
                 for keyname, userkeyhex in dedrmprefs['adeptkeys'].items():
-                    userkey = codecs.decode(userkeyhex, 'hex')
+                    
                     print("{0} v{1}: Trying Encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname))
                     of = self.temporary_file(".epub")
 
                     # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                     try:
+                        userkey = codecs.decode(userkeyhex, 'hex')
                         result = ineptepub.decryptBook(userkey, inf.name, of.name)
                     except ineptepub.ADEPTNewVersionError:
                         print("{0} v{1}: Book uses unsupported (too new) Adobe DRM.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
@@ -673,11 +674,11 @@ class DeDRM(FileTypePlugin):
                     continue
             
                 # Found matching key
-                userkey = codecs.decode(userkeyhex, 'hex')
                 print("{0} v{1}: Trying UUID-matched encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname))
                 of = self.temporary_file(".pdf")
 
                 try: 
+                    userkey = codecs.decode(userkeyhex, 'hex')
                     result = ineptpdf.decryptBook(userkey, path_to_ebook, of.name)
                     of.close()
                     if result == 0: