]> xmof Git - DeDRM.git/commitdiff
decoding from base64 in a portable way
authorRémi Vanicat <vanicat@debian.org>
Fri, 8 May 2020 15:51:40 +0000 (17:51 +0200)
committerRémi Vanicat <vanicat@debian.org>
Fri, 8 May 2020 16:09:27 +0000 (18:09 +0200)
DeDRM_plugin/ineptepub.py

index 6d48905ef9995789af352888907aad6666f9315a..e3815e772f99be2cc499a48deab9bca3c228690a 100644 (file)
@@ -63,6 +63,7 @@ import zipfile
 from zipfile import ZipInfo, ZipFile, ZIP_STORED, ZIP_DEFLATED
 from contextlib import closing
 import xml.etree.ElementTree as etree
+import base64
 
 # Wrap a stream so that output gets flushed immediately
 # and also make sure that any unicode strings get
@@ -421,9 +422,11 @@ def decryptBook(userkey, inpath, outpath):
             if len(bookkey) != 172:
                 print(u"{0:s} is not a secure Adobe Adept ePub.".format(os.path.basename(inpath)))
                 return 1
-            bookkey = rsa.decrypt(bookkey.decode('base64'))
+            bookkey = bookkey.encode('ascii')
+            bookkey = base64.b64decode(bookkey)
+            bookkey = rsa.decrypt(bookkey)
             # Padded as per RSAES-PKCS1-v1_5
-            if bookkey[-17] != '\x00':
+            if bookkey[-17] != '\x00' and bookkey[-17] != 0:
                 print(u"Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath)))
                 return 2
             encryption = inf.read('META-INF/encryption.xml')