]> xmof Git - DeDRM.git/commitdiff
Add useful error message for the new, uncracked ADEPT DRM
authorNoDRM <no_drm123@protonmail.com>
Mon, 15 Nov 2021 18:51:36 +0000 (19:51 +0100)
committerNoDRM <no_drm123@protonmail.com>
Mon, 15 Nov 2021 18:51:36 +0000 (19:51 +0100)
DeDRM_plugin/__init__.py
DeDRM_plugin/ineptepub.py
DeDRM_plugin/ineptpdf.py

index 892e46451ac8a9510765e609157a2be5f7b8249c..8bdf1d2eb280233868771d04d758eef2dcc1d9ec 100644 (file)
@@ -373,6 +373,10 @@ class DeDRM(FileTypePlugin):
                         if result == 0:
                             print("{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname,time.time()-self.starttime))
                             return self.checkFonts(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))
+                        return path_to_ebook
+
                     except:
                         print("{0} v{1}: Exception when decrypting after {2:.1f} seconds - trying other keys".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
                         traceback.print_exc()
@@ -387,6 +391,9 @@ class DeDRM(FileTypePlugin):
                 # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                 try:
                     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))
+                    return path_to_ebook
                 except:
                     print("{0} v{1}: Exception when decrypting after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
                     traceback.print_exc()
@@ -521,6 +528,10 @@ class DeDRM(FileTypePlugin):
                     if result == 0:
                         print("{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname,time.time()-self.starttime))
                         return of.name
+                       
+                except ineptpdf.ADEPTNewVersionError:
+                    print("{0} v{1}: Book uses unsupported (too new) Adobe DRM.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
+                    return path_to_ebook
                 except:
                     print("{0} v{1}: Exception when decrypting after {2:.1f} seconds - trying other keys".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
                     traceback.print_exc()
@@ -537,6 +548,9 @@ class DeDRM(FileTypePlugin):
             # Give the user key, ebook and TemporaryPersistent file to the decryption function.
             try:
                 result = ineptpdf.decryptBook(userkey, path_to_ebook, of.name)
+            except ineptpdf.ADEPTNewVersionError:
+                print("{0} v{1}: Book uses unsupported (too new) Adobe DRM.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
+                return path_to_ebook
             except:
                 print("{0} v{1}: Exception when decrypting after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
                 traceback.print_exc()
index ad745d860e9e60070ef3bded77273a5d764493db..3f01a7cc7cf76544d8f97dff0cbb2a6ff13940b4 100644 (file)
@@ -110,6 +110,9 @@ def unicode_argv():
 class ADEPTError(Exception):
     pass
 
+class ADEPTNewVersionError(Exception):
+    pass
+
 def _load_crypto_libcrypto():
     from ctypes import CDLL, POINTER, c_void_p, c_char_p, c_int, c_long, \
         Structure, c_ulong, create_string_buffer, cast
@@ -468,6 +471,12 @@ def decryptBook(userkey, inpath, outpath):
             adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
             expr = './/%s' % (adept('encryptedKey'),)
             bookkey = ''.join(rights.findtext(expr))
+            if len(bookkey) == 192:
+                print("{0:s} seems to be an Adobe ADEPT ePub with Adobe's new DRM".format(os.path.basename(inpath)))
+                print("This DRM cannot be removed yet. ")
+                print("Try getting your distributor to give you a new ACSM file, then open that in an old version of ADE (2.0).")
+                print("If your book distributor is not enforcing the new DRM yet, this will give you a copy with the old DRM.")
+                raise ADEPTNewVersionError("Book uses new ADEPT encryption")
             if len(bookkey) != 172:
                 print("{0:s} is not a secure Adobe Adept ePub.".format(os.path.basename(inpath)))
                 return 1
index 2be0fbfde09aa5d5f7e6625dc4b5e34f64be0f9d..7dc6e8372cb7b56d1ae5053cfeba1da9a3ad7581 100755 (executable)
@@ -125,6 +125,9 @@ def unicode_argv():
 class ADEPTError(Exception):
     pass
 
+class ADEPTNewVersionError(Exception):
+    pass
+
 
 import hashlib
 
@@ -1615,7 +1618,16 @@ class PDFDocument(object):
         rights = zlib.decompress(rights, -15)
         rights = etree.fromstring(rights)
         expr = './/{http://ns.adobe.com/adept}encryptedKey'
-        bookkey = codecs.decode(''.join(rights.findtext(expr)).encode('utf-8'),'base64')
+        bookkey = ''.join(rights.findtext(expr))
+
+        if len(bookkey) == 192:
+            print("This seems to be an Adobe ADEPT PDF with Adobe's new DRM")
+            print("This DRM cannot be removed yet. ")
+            print("Try getting your distributor to give you a new ACSM file, then open that in an old version of ADE (2.0).")
+            print("If your book distributor is not enforcing the new DRM yet, this will give you a copy with the old DRM.")
+            raise ADEPTNewVersionError("Book uses new ADEPT encryption")
+
+        bookkey = codecs.decode(bookkey.encode('utf-8'),'base64')
         bookkey = rsa.decrypt(bookkey)
 
         if len(bookkey) > 16: