EPUB Input: Fix incorrect handling of obfuscated fonts using the IDPF obfuscation algorithm when the epub unique identifier starts with urn:uuid:. Fixes #1311650 [ebook-edit should properly handle Adobe and IDPF method font encryption (mangling)](https://bugs.launchpad.net/calibre/+bug/1311650)

This commit is contained in:
Kovid Goyal 2014-04-24 09:19:40 +05:30
parent 8e3c1c7425
commit 0dcf925b8d
2 changed files with 10 additions and 7 deletions

View File

@ -3,7 +3,7 @@ __license__ = 'GPL 3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os
import os, re
from itertools import cycle
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
@ -37,9 +37,10 @@ class EPUBInput(InputFormatPlugin):
def process_encryption(self, encfile, opf, log):
from lxml import etree
import uuid, hashlib
idpf_key = opf.unique_identifier
idpf_key = opf.raw_unique_identifier
if idpf_key:
idpf_key = hashlib.sha1(idpf_key).digest()
idpf_key = re.sub(u'\u0020\u0009\u000d\u000a', u'', idpf_key)
idpf_key = hashlib.sha1(idpf_key.encode('utf-8')).digest()
key = None
for item in opf.identifier_iter():
scheme = None

View File

@ -940,7 +940,7 @@ class EpubContainer(Container):
if not fonts:
return
package_id = unique_identifier = idpf_key = None
package_id = raw_unique_identifier = idpf_key = None
for attrib, val in self.opf.attrib.iteritems():
if attrib.endswith('unique-identifier'):
package_id = val
@ -948,10 +948,12 @@ class EpubContainer(Container):
if package_id is not None:
for elem in self.opf_xpath('//*[@id=%r]'%package_id):
if elem.text:
unique_identifier = elem.text.rpartition(':')[-1]
raw_unique_identifier = elem.text
break
if unique_identifier is not None:
idpf_key = hashlib.sha1(unique_identifier).digest()
if raw_unique_identifier is not None:
idpf_key = raw_unique_identifier
idpf_key = re.sub(u'\u0020\u0009\u000d\u000a', u'', idpf_key)
idpf_key = hashlib.sha1(idpf_key.encode('utf-8')).digest()
key = None
for item in self.opf_xpath('//*[local-name()="metadata"]/*'
'[local-name()="identifier"]'):