]> xmof Git - DeDRM.git/commitdiff
Updated to inept.pdf for PC
authorApprentice Harper <apprenticeharper@gmail.com>
Sun, 3 Jan 2021 16:01:14 +0000 (16:01 +0000)
committerApprentice Harper <apprenticeharper@gmail.com>
Sun, 3 Jan 2021 16:01:14 +0000 (16:01 +0000)
Contributed changes for PC compatibility. Thanks, Aldo.

Update main version to 7.0.2

DeDRM_plugin/__init__.py
DeDRM_plugin/ineptpdf.py

index 47c5ee36286a88e907a6447301950c0de804962e..1e9c2e5f8e33b5ca337cb823658d4f947037feb9 100644 (file)
@@ -5,7 +5,7 @@
 # Copyright © 2008-2020 Apprentice Harper et al.
 
 __license__   = 'GPL v3'
-__version__ = '7.0.0'
+__version__ = '7.0.2'
 __docformat__ = 'restructuredtext en'
 
 
@@ -72,6 +72,7 @@ __docformat__ = 'restructuredtext en'
 #   6.8.1 - Kindle key fix for Mac OS X Big Sur
 #   7.0.0 - Switched to Python 3 for calibre 5.0. Thanks to all who contributed
 #   7.0.1 - More Python 3 changes. Adobe PDF decryption should now work in some cases
+#   7.0.2 - More Python 3 changes. Adobe PDF decryption should now work on PC too.
 
 """
 Decrypt DRMed ebooks.
index 7b53058304d9e00e1d6cfcbf5fbab776d314a09f..f0ebbc824fd6627b0bdca202c24681e84b5c9d9f 100755 (executable)
@@ -260,7 +260,8 @@ def _load_crypto_pycrypto():
     from Crypto.PublicKey import RSA as _RSA
     from Crypto.Cipher import ARC4 as _ARC4
     from Crypto.Cipher import AES as _AES
-
+    from Crypto.Cipher import PKCS1_v1_5 as _PKCS1_v1_5
+    
     # ASN.1 parsing code from tlslite
     class ASN1Error(Exception):
         pass
@@ -374,7 +375,7 @@ def _load_crypto_pycrypto():
 
     class RSA(object):
         def __init__(self, der):
-            key = ASN1Parser([ord(x) for x in der])
+            key = ASN1Parser([x for x in der])
             key = [key.getChild(x).value for x in range(1, 4)]
             key = [self.bytesToNumber(v) for v in key]
             self._rsa = _RSA.construct(key)
@@ -386,7 +387,7 @@ def _load_crypto_pycrypto():
             return total
 
         def decrypt(self, data):
-            return self._rsa.decrypt(data)
+            return _PKCS1_v1_5.new(self._rsa).decrypt(data, 172)
 
     return (ARC4, RSA, AES)
 
@@ -1596,10 +1597,13 @@ class PDFDocument(object):
         expr = './/{http://ns.adobe.com/adept}encryptedKey'
         bookkey = codecs.decode(''.join(rights.findtext(expr)).encode('utf-8'),'base64')
         bookkey = rsa.decrypt(bookkey)
-        if bookkey[0] != 2:
-            raise ADEPTError('error decrypting book session key')
-        index = bookkey.index(b'\0') + 1
-        bookkey = bookkey[index:]
+        #if bookkey[0] != 2:
+        #    raise ADEPTError('error decrypting book session key')
+        try:
+               index = bookkey.index(b'\0') + 1
+               bookkey = bookkey[index:]
+        except ValueError:
+               pass
         ebx_V = int_value(param.get('V', 4))
         ebx_type = int_value(param.get('EBX_ENCRYPTIONTYPE', 6))
         # added because of improper booktype / decryption book session key errors