Skip to content

Commit

Permalink
feat: allow the Compression element in the encryption file
Browse files Browse the repository at this point in the history
  - update the `ocf-encryption-30.rnc` schema to allow the `Compression`
    element as a child of `EncryptionProperty`
  - add tests

Fix #904
  • Loading branch information
mattgarrish authored and rdeltour committed Feb 25, 2019
1 parent 365e6e6 commit ed6f1c4
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
default namespace = "urn:oasis:names:tc:opendocument:xmlns:container"
start = element encryption {
grammar {
include "mod/security/Lenient-Encryption11-ghc.rnc" {
start = xenc_EncryptedData | xenc_EncryptedKey
}
xenc_EncryptionMethodOtherParams |=
attribute Algorithm { xsd:anyURI "http://www.idpf.org/2008/embedding" }
xenc_EncryptionAlgorithms |=
xsd:anyURI "http://www.idpf.org/2008/embedding"
}+
}
default namespace = "urn:oasis:names:tc:opendocument:xmlns:container"
namespace epub_xenc_compress = "http://www.idpf.org/2016/encryption#compression"
namespace xenc = "http://www.w3.org/2001/04/xmlenc#"

start =
element encryption {
grammar {
include "mod/security/Lenient-Encryption11-ghc.rnc" {
start = xenc_EncryptedData | xenc_EncryptedKey
xenc_EncryptionPropertyType =
mixed {
attribute Target { xsd:anyURI }?,
attribute Id { xenc_IdType }?,
attribute xml:* { text }*,
xenc_EncryptionPropertyContent
}
xenc_anyForeignElement =
element * - (xenc:* | epub_xenc_compress:*) {
mixed { security_anyAttribute*, security_anyElement* }
}
}
xenc_EncryptionMethodOtherParams |= attribute Algorithm { xsd:anyURI "http://www.idpf.org/2008/embedding" }
xenc_EncryptionAlgorithms |= xsd:anyURI "http://www.idpf.org/2008/embedding"
xenc_EncryptionPropertyContent = (epub_xenc_Compression & xenc_anyForeignElement*) | xenc_anyForeignElement+
epub_xenc_Compression = element epub_xenc_compress:Compression { epub_xenc_CompressionType }
epub_xenc_CompressionType =
attribute Method { "0" | "8" },
attribute OriginalLength { xsd:nonNegativeInteger }
}+
}
37 changes: 37 additions & 0 deletions src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ public void testLoremMultipleRenditions30()
assertTrue(testReport.hasInfoMessage("[EPUB renditions count] 2"));
}

@Test
public void testValidCompression()
{
ValidationReport testReport = testOcfPackage("/30/expanded/valid/ocf-compression/",
EPUBVersion.VERSION_3);

if (0 != testReport.getErrorCount() || 0 != testReport.getWarningCount())
{
outWriter.println(testReport);
}
assertEquals(0, testReport.getErrorCount());
assertEquals(0, testReport.getWarningCount());
}

@Test
public void testInvalidLoremForeign30()
{
Expand Down Expand Up @@ -384,4 +398,27 @@ public void testInvalidLoremSCH30()

assertTrue(testReport.hasInfoMessage(VERSION_STRING));
}

@Test
public void testInvalidCompressionMethod()
{
ValidationReport testReport = testOcfPackage("/30/expanded/invalid/ocf-compression/",
EPUBVersion.VERSION_3);

if (2 != testReport.getErrorCount() || 0 != testReport.getWarningCount())
{
outWriter.println(testReport);
}
List<MessageId> errors = new ArrayList<MessageId>();
Collections.addAll(errors, MessageId.RSC_005, MessageId.RSC_005);
assertEquals(errors, testReport.getErrorIds());
assertEquals(0, testReport.getWarningCount());
if (testReport.errorList.size() >= 2)
{
assertTrue(testReport.errorList.get(0).message
.contains("value of attribute \"Method\" is invalid; must be equal to \"0\" or \"8\""));
assertTrue(testReport.errorList.get(1).message
.contains("value of attribute \"OriginalLength\" is invalid; must be an integer"));
}
}
}
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="EK">
<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="ED1">
<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="3" OriginalLength=""/>
</enc:EncryptionProperty>
</enc:EncryptionProperties>
</enc:EncryptedData>
</encryption>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
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="EK">
<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="ED1">
<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 ed6f1c4

Please sign in to comment.