ineptpdf 6.1

This commit is contained in:
Anonymous 2010-02-18 15:59:10 +00:00 committed by Apprentice Alf
parent 26a54dd3d6
commit f027848bff

View File

@ -1,6 +1,6 @@
#! /usr/bin/python #! /usr/bin/python
# ineptpdf.pyw, version 6 # ineptpdf.pyw, version 6.1
# To run this program install Python 2.6 from http://www.python.org/download/ # To run this program install Python 2.6 from http://www.python.org/download/
# and PyCrypto from http://www.voidspace.org.uk/python/modules.shtml#pycrypto # and PyCrypto from http://www.voidspace.org.uk/python/modules.shtml#pycrypto
@ -14,6 +14,7 @@
# 4 - Removal of ciando's personal ID (anon) # 4 - Removal of ciando's personal ID (anon)
# 5 - removing small bug with V3 ebooks (anon) # 5 - removing small bug with V3 ebooks (anon)
# 6 - changed to adeptkey4.der format for 1.7.2 support (anon) # 6 - changed to adeptkey4.der format for 1.7.2 support (anon)
# 6.1 - backward compatibility for 1.7.1 and old adeptkey.der
""" """
Decrypt Adobe ADEPT-encrypted PDF files. Decrypt Adobe ADEPT-encrypted PDF files.
""" """
@ -34,7 +35,6 @@ import Tkinter
import Tkconstants import Tkconstants
import tkFileDialog import tkFileDialog
import tkMessageBox import tkMessageBox
import pickle
try: try:
from Crypto.Cipher import ARC4 from Crypto.Cipher import ARC4
@ -1171,53 +1171,40 @@ class PDFDocument(object):
def initialize_ebx(self, password, docid, param): def initialize_ebx(self, password, docid, param):
self.is_printable = self.is_modifiable = self.is_extractable = True self.is_printable = self.is_modifiable = self.is_extractable = True
with open(password, 'r') as f: with open(password, 'rb') as f:
keyderlist = pickle.load(f) keyder = f.read()
keynotfound = 1 key = ASN1Parser([ord(x) for x in keyder])
for keyder in keyderlist: key = [bytesToNumber(key.getChild(x).value) for x in xrange(1, 4)]
key = ASN1Parser([ord(x) for x in keyder]) rsa = RSA.construct(key)
key = [bytesToNumber(key.getChild(x).value) for x in xrange(1, 4)] length = int_value(param.get('Length', 0)) / 8
try: rights = str_value(param.get('ADEPT_LICENSE')).decode('base64')
rsa = RSA.construct(key) rights = zlib.decompress(rights, -15)
except Exception: rights = etree.fromstring(rights)
continue expr = './/{http://ns.adobe.com/adept}encryptedKey'
length = int_value(param.get('Length', 0)) / 8 bookkey = ''.join(rights.findtext(expr)).decode('base64')
rights = str_value(param.get('ADEPT_LICENSE')).decode('base64') bookkey = rsa.decrypt(bookkey)
rights = zlib.decompress(rights, -15) if bookkey[0] != '\x02':
rights = etree.fromstring(rights) raise ADEPTError('error decrypting book session key')
expr = './/{http://ns.adobe.com/adept}encryptedKey' index = bookkey.index('\0') + 1
bookkey = ''.join(rights.findtext(expr)).decode('base64') bookkey = bookkey[index:]
try: ebx_V = int_value(param.get('V', 4))
bookkey = rsa.decrypt(bookkey) ebx_type = int_value(param.get('EBX_ENCRYPTIONTYPE', 6))
except Exception: # added because of the booktype / decryption book session key error
continue if ebx_V == 3:
if bookkey[0] != '\x02': V = 3
keynotfound = 1 elif ebx_V < 4 or ebx_type < 6:
continue V = ord(bookkey[0])
else: bookkey = bookkey[1:]
keynotfound = 0 else:
index = bookkey.index('\0') + 1 V = 2
bookkey = bookkey[index:] if length and len(bookkey) != length:
ebx_V = int_value(param.get('V', 4)) raise ADEPTError('error decrypting book session key')
ebx_type = int_value(param.get('EBX_ENCRYPTIONTYPE', 6)) self.decrypt_key = bookkey
# added because of the booktype / decryption book session key error self.genkey = self.genkey_v3 if V == 3 else self.genkey_v2
if ebx_V == 3: self.decipher = self.decrypt_rc4
V = 3 self.ready = True
elif ebx_V < 4 or ebx_type < 6:
V = ord(bookkey[0])
bookkey = bookkey[1:]
else:
V = 2
if length and len(bookkey) != length:
raise ADEPTError('error decrypting book session key')
self.decrypt_key = bookkey
self.genkey = self.genkey_v3 if V == 3 else self.genkey_v2
self.decipher = self.decrypt_rc4
self.ready = True
break
if keynotfound == 1:
raise ADEPTError('problem decrypting session key')
return return
PASSWORD_PADDING = '(\xbfN^Nu\x8aAd\x00NV\xff\xfa\x01\x08..' \ PASSWORD_PADDING = '(\xbfN^Nu\x8aAd\x00NV\xff\xfa\x01\x08..' \
'\x00\xb6\xd0h>\x80/\x0c\xa9\xfedSiz' '\x00\xb6\xd0h>\x80/\x0c\xa9\xfedSiz'
@ -1672,8 +1659,8 @@ class DecryptionDialog(Tkinter.Frame):
Tkinter.Label(body, text='Key file').grid(row=0) Tkinter.Label(body, text='Key file').grid(row=0)
self.keypath = Tkinter.Entry(body, width=30) self.keypath = Tkinter.Entry(body, width=30)
self.keypath.grid(row=0, column=1, sticky=sticky) self.keypath.grid(row=0, column=1, sticky=sticky)
if os.path.exists('adeptkey4.der'): if os.path.exists('adeptkey.der'):
self.keypath.insert(0, 'adeptkey4.der') self.keypath.insert(0, 'adeptkey.der')
button = Tkinter.Button(body, text="...", command=self.get_keypath) button = Tkinter.Button(body, text="...", command=self.get_keypath)
button.grid(row=0, column=2) button.grid(row=0, column=2)
Tkinter.Label(body, text='Input file').grid(row=1) Tkinter.Label(body, text='Input file').grid(row=1)