Skip to content

Commit

Permalink
feat: check duplicate IDs in the OCF encryption file
Browse files Browse the repository at this point in the history
Fix #306
  • Loading branch information
rdeltour committed Mar 13, 2019
1 parent 2427253 commit 0898061
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ public class OCFChecker
private static final ValidatorMap validatorMap = ValidatorMap.builder()
.put(Predicates.and(path(OCFData.containerEntry), version(EPUBVersion.VERSION_2)),
XMLValidators.CONTAINER_20_RNG)
.put(Predicates.and(path(OCFData.containerEntry), version(EPUBVersion.VERSION_3)),
XMLValidators.CONTAINER_30_RNC)
.put(Predicates.and(path(OCFData.containerEntry), version(EPUBVersion.VERSION_3)),
XMLValidators.CONTAINER_30_RENDITIONS_SCH)
.put(Predicates.and(path(OCFData.encryptionEntry), version(EPUBVersion.VERSION_3)),
XMLValidators.ENC_30_RNC)
.putAll(Predicates.and(path(OCFData.containerEntry), version(EPUBVersion.VERSION_3)),
XMLValidators.CONTAINER_30_RNC, XMLValidators.CONTAINER_30_RENDITIONS_SCH)
.putAll(Predicates.and(path(OCFData.encryptionEntry), version(EPUBVersion.VERSION_3)),
XMLValidators.ENC_30_RNC, XMLValidators.ENC_30_SCH)
.put(Predicates.and(path(OCFData.encryptionEntry), version(EPUBVersion.VERSION_2)),
XMLValidators.ENC_20_RNG)
.put(Predicates.and(path(OCFData.signatureEntry), version(EPUBVersion.VERSION_2)),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/adobe/epubcheck/xml/XMLValidators.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum XMLValidators
DTBOOK_RNG("schema/20/rng/dtbook-2005-2.rng"),
ENC_20_RNG("schema/20/rng/encryption.rng"),
ENC_30_RNC("schema/30/ocf-encryption-30.rnc"),
ENC_30_SCH("schema/30/ocf-encryption-30.sch"),
IDUNIQUE_20_SCH("schema/20/sch/id-unique.sch"),
META_30_RNC("schema/30/ocf-metadata-30.rnc"),
META_30_SCH("schema/30/ocf-metadata-30.sch"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">

<pattern id="id-unique">
<let name="id-set" value="//*[@Id]"/>
<rule context="*[@Id]">
<assert test="count($id-set[normalize-space(@Id) = normalize-space(current()/@Id)]) = 1"
>Duplicate '<value-of select="normalize-space(current()/@Id)"/>'</assert>
</rule>
</pattern>

</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -1340,4 +1340,11 @@ public void testBaseURI()
{
testValidateDocument("valid/base-uri");
}

@Test
public void testEncryption_DuplicateIDs()
{
Collections.addAll(expectedErrors, MessageId.RSC_005, MessageId.RSC_005);
testValidateDocument("invalid/encryption-duplicate-ids");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body epub:type="bodymatter">
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
<nav epub:type="landmarks">
<ol>
<li><a href="content_001.xhtml" epub:type="bodymatter">Start Reading</a></li>
</ol>
</nav>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="q">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="q">NOID</dc:identifier>
<meta property="dcterms:modified">2017-06-14T00:00:01Z</meta>
</metadata>
<manifest>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<encryption xmlns="urn:oasis:names:tc:opendocument:xmlns:container" xmlns:enc="http://www.w3.org/2001/04/xmlenc#"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<enc:EncryptedKey Id="ID">
<enc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<ds:KeyInfo>
<ds:KeyName>John Smith</ds:KeyName>
</ds:KeyInfo>
<enc:CipherData>
<enc:CipherValue>d2hhdCBkaWQgeW91IHRoaW5rIHlvdSdkIGZpbmQ/</enc:CipherValue>
</enc:CipherData>
</enc:EncryptedKey>
<enc:EncryptedData Id="ID">
<enc:CipherData>
<enc:CipherReference URI="OEPBS/video.mp4"/>
</enc:CipherData>
<enc:EncryptionProperties>
<enc:EncryptionProperty xmlns:ns="http://www.idpf.org/2016/encryption#compression">
<ns:Compression Method="8" OriginalLength="3500000"/>
</enc:EncryptionProperty>
</enc:EncryptionProperties>
</enc:EncryptedData>
</encryption>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit 0898061

Please sign in to comment.