From 88dd1350c0e626626dd37e4a1264d2e13194794c Mon Sep 17 00:00:00 2001 From: NoDRM Date: Mon, 15 Nov 2021 19:51:36 +0100 Subject: [PATCH] Add useful error message for the new, uncracked ADEPT DRM --- DeDRM_plugin/__init__.py | 14 ++++++++++++++ DeDRM_plugin/ineptepub.py | 9 +++++++++ DeDRM_plugin/ineptpdf.py | 14 +++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/DeDRM_plugin/__init__.py b/DeDRM_plugin/__init__.py index 892e464..8bdf1d2 100644 --- a/DeDRM_plugin/__init__.py +++ b/DeDRM_plugin/__init__.py @@ -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() diff --git a/DeDRM_plugin/ineptepub.py b/DeDRM_plugin/ineptepub.py index ad745d8..3f01a7c 100644 --- a/DeDRM_plugin/ineptepub.py +++ b/DeDRM_plugin/ineptepub.py @@ -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 diff --git a/DeDRM_plugin/ineptpdf.py b/DeDRM_plugin/ineptpdf.py index 2be0fbf..7dc6e83 100755 --- a/DeDRM_plugin/ineptpdf.py +++ b/DeDRM_plugin/ineptpdf.py @@ -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: