Detect Kobo & Apple DRM in epubtest.py
This commit is contained in:
parent
3eb4eab18d
commit
a16e66a023
|
@ -175,15 +175,13 @@ def getfiledata(file, zi):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def encryption(infile):
|
def encryption(infile):
|
||||||
# returns encryption: one of Unencrypted, Adobe, B&N and Unknown
|
# Supports Adobe (old & new), B&N, Kobo, Apple, Readium LCP.
|
||||||
encryption = "Error When Checking."
|
encryption = "Error"
|
||||||
try:
|
try:
|
||||||
with open(infile,'rb') as infileobject:
|
with open(infile,'rb') as infileobject:
|
||||||
bookdata = infileobject.read(58)
|
bookdata = infileobject.read(58)
|
||||||
# Check for Zip
|
# Check for Zip
|
||||||
if bookdata[0:0+2] == b"PK":
|
if bookdata[0:0+2] == b"PK":
|
||||||
foundrights = False
|
|
||||||
foundencryption = False
|
|
||||||
inzip = zipfile.ZipFile(infile,'r')
|
inzip = zipfile.ZipFile(infile,'r')
|
||||||
namelist = set(inzip.namelist())
|
namelist = set(inzip.namelist())
|
||||||
if (
|
if (
|
||||||
|
@ -192,20 +190,31 @@ def encryption(infile):
|
||||||
b"EncryptedContentKey" in inzip.read("META-INF/encryption.xml")):
|
b"EncryptedContentKey" in inzip.read("META-INF/encryption.xml")):
|
||||||
encryption = "Readium LCP"
|
encryption = "Readium LCP"
|
||||||
|
|
||||||
|
elif 'META-INF/sinf.xml' in namelist and b"fairplay" in inzip.read("META-INF/sinf.xml"):
|
||||||
|
# Untested, just found this info on Google
|
||||||
|
encryption = "Apple"
|
||||||
|
|
||||||
|
elif 'META-INF/rights.xml' in namelist and b"<kdrm>" in inzip.read("META-INF/rights.xml"):
|
||||||
|
# Untested, just found this info on Google
|
||||||
|
encryption = "Kobo"
|
||||||
|
|
||||||
elif 'META-INF/rights.xml' not in namelist or 'META-INF/encryption.xml' not in namelist:
|
elif 'META-INF/rights.xml' not in namelist or 'META-INF/encryption.xml' not in namelist:
|
||||||
encryption = "Unencrypted"
|
encryption = "Unencrypted"
|
||||||
else:
|
else:
|
||||||
rights = etree.fromstring(inzip.read('META-INF/rights.xml'))
|
try:
|
||||||
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
|
rights = etree.fromstring(inzip.read('META-INF/rights.xml'))
|
||||||
expr = './/%s' % (adept('encryptedKey'),)
|
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
|
||||||
bookkey = ''.join(rights.findtext(expr))
|
expr = './/%s' % (adept('encryptedKey'),)
|
||||||
if len(bookkey) == 172:
|
bookkey = ''.join(rights.findtext(expr))
|
||||||
encryption = "Adobe (old)"
|
if len(bookkey) == 172:
|
||||||
if len(bookkey) == 192:
|
encryption = "Adobe (old)"
|
||||||
encryption = "Adobe (new)"
|
if len(bookkey) == 192:
|
||||||
elif len(bookkey) == 64:
|
encryption = "Adobe (new)"
|
||||||
encryption = "B&N"
|
elif len(bookkey) == 64:
|
||||||
else:
|
encryption = "B&N"
|
||||||
|
else:
|
||||||
|
encryption = "Unknown (key len " + str(len(bookkey)) + ")"
|
||||||
|
except:
|
||||||
encryption = "Unknown"
|
encryption = "Unknown"
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
Loading…
Reference in New Issue