mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
8e3c1c7425
commit
0dcf925b8d
@ -3,7 +3,7 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os, re
|
||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||||
@ -37,9 +37,10 @@ class EPUBInput(InputFormatPlugin):
|
|||||||
def process_encryption(self, encfile, opf, log):
|
def process_encryption(self, encfile, opf, log):
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import uuid, hashlib
|
import uuid, hashlib
|
||||||
idpf_key = opf.unique_identifier
|
idpf_key = opf.raw_unique_identifier
|
||||||
if idpf_key:
|
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
|
key = None
|
||||||
for item in opf.identifier_iter():
|
for item in opf.identifier_iter():
|
||||||
scheme = None
|
scheme = None
|
||||||
|
@ -940,7 +940,7 @@ class EpubContainer(Container):
|
|||||||
if not fonts:
|
if not fonts:
|
||||||
return
|
return
|
||||||
|
|
||||||
package_id = unique_identifier = idpf_key = None
|
package_id = raw_unique_identifier = idpf_key = None
|
||||||
for attrib, val in self.opf.attrib.iteritems():
|
for attrib, val in self.opf.attrib.iteritems():
|
||||||
if attrib.endswith('unique-identifier'):
|
if attrib.endswith('unique-identifier'):
|
||||||
package_id = val
|
package_id = val
|
||||||
@ -948,10 +948,12 @@ class EpubContainer(Container):
|
|||||||
if package_id is not None:
|
if package_id is not None:
|
||||||
for elem in self.opf_xpath('//*[@id=%r]'%package_id):
|
for elem in self.opf_xpath('//*[@id=%r]'%package_id):
|
||||||
if elem.text:
|
if elem.text:
|
||||||
unique_identifier = elem.text.rpartition(':')[-1]
|
raw_unique_identifier = elem.text
|
||||||
break
|
break
|
||||||
if unique_identifier is not None:
|
if raw_unique_identifier is not None:
|
||||||
idpf_key = hashlib.sha1(unique_identifier).digest()
|
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
|
key = None
|
||||||
for item in self.opf_xpath('//*[local-name()="metadata"]/*'
|
for item in self.opf_xpath('//*[local-name()="metadata"]/*'
|
||||||
'[local-name()="identifier"]'):
|
'[local-name()="identifier"]'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user