Skip to content

Commit

Permalink
feat: downgrade RSC-004 (cannot decrypt resource) to INFO (#1136)
Browse files Browse the repository at this point in the history
feat: downgrade RSC-004 (cannot decrypt resource) to INFO

An INFO better describes EPUBCheck’s inability to decrypt or de-obfuscate
a resource. RSC-004 does not necessarily means the content is invalid,
but it means EPUBCheck is unable to process it.

- All the incomplete `EncryptionFilter` implementations now accurately
report they cannot decrypt related content.
- Validation will abort early for encrypted (or obfuscated) files,
reporting RSC-004 as an INFO message.

Fixes 1077, caused by an attempt to parse an obfuscated SVG document
which was falsely assumed decryptable by the lying `EncryptionFilter`
(boo).
  • Loading branch information
rdeltour authored May 1, 2020
1 parent 2083f05 commit e732068
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void initialize()
severities.put(MessageId.RSC_001, Severity.ERROR);
severities.put(MessageId.RSC_002, Severity.FATAL);
severities.put(MessageId.RSC_003, Severity.ERROR);
severities.put(MessageId.RSC_004, Severity.ERROR);
severities.put(MessageId.RSC_004, Severity.INFO);
severities.put(MessageId.RSC_005, Severity.ERROR);
severities.put(MessageId.RSC_006, Severity.ERROR);
severities.put(MessageId.RSC_006b, Severity.USAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public AdobeFontManglingFilter(String Uid)

public boolean canDecrypt()
{
//FIXME we force return true to not issue a false-positive warning (see Issue 220)
// ultimately, we need to pass the concatenated publication IDs (encryption key)
//TODO we need to pass the concatenated publication IDs (encryption key)
// and implement de-obfuscation.
return true;
return false;
// return uniqueIdentifier != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public IDPFFontManglingFilter(String Uid)

public boolean canDecrypt()
{
//FIXME we force return true to not issue a false-positive warning (see Issue 220)
// ultimately, we need to pass the concatenated publication IDs (encryption key)
// TODO we need to pass the concatenated publication IDs (encryption key)
// and implement de-obfuscation.
return true;
return false;
// return uniqueIdentifier != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ public void testDuplicateResources()

@Test
public void testEncryption_Unknown(){
expectedErrors.add(MessageId.RSC_004);
expectedInfos.add(MessageId.RSC_004);
testValidateDocument("invalid/encryption-unknown");
}

Expand Down Expand Up @@ -1472,4 +1472,11 @@ public void testEncryption_DuplicateIDs()
Collections.addAll(expectedErrors, MessageId.RSC_005, MessageId.RSC_005);
testValidateDocument("invalid/encryption-duplicate-ids");
}

@Test
public void testObfuscatedSVG()
{
expectedInfos.add(MessageId.RSC_004);
testValidateDocument("valid/container-obfuscation-svg-valid");
}
}
1 change: 1 addition & 0 deletions src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public void testValidateEPUB30Issue289()
@Test
public void testValidateEPUB30FontObfuscation()
{
Collections.addAll(expectedInfos, MessageId.RSC_004);
testValidateDocument("valid/font-obfuscation.epub");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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>
<img src="emoji.svg" alt="a smiling emoji" />
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,17 @@
<?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"/>
<item id="emoji" href="emoji.svg" media-type="image/svg+xml"/>
</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,10 @@
<?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#">
<enc:EncryptedData>
<enc:EncryptionMethod Algorithm="http://www.idpf.org/2008/embedding"/>
<enc:CipherData>
<enc:CipherReference URI="EPUB/emoji.svg"/>
</enc:CipherData>
</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
Expand Up @@ -320,5 +320,17 @@
"context" : null
} ],
"suggestion" : null
}, {
"ID" : "RSC-004",
"severity" : "INFO",
"message" : "File \"OEBPS/fonts/ChaparralPro-Regular.otf\" could not be decrypted.",
"additionalLocations" : 0,
"locations" : [ {
"path" : "font_encryption_adobe.epub",
"line" : -1,
"column" : -1,
"context" : null
} ],
"suggestion" : null
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"checkDate" : "09-05-2014 03:17:17",
"elapsedTime" : 25,
"nFatal" : 0,
"nError" : 2,
"nError" : 1,
"nWarning" : 0,
"nUsage" : 6
},
Expand Down Expand Up @@ -322,7 +322,7 @@
"suggestion" : null
}, {
"ID" : "RSC-004",
"severity" : "ERROR",
"severity" : "INFO",
"message" : "File \"OEBPS/fonts/ChaparralPro-Regular.otf\" could not be decrypted.",
"additionalLocations" : 0,
"locations" : [ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<version>2.0.1</version>
<status>Not well-formed</status>
<messages>
<message severity="error" subMessage="RSC-004">RSC-004, ERROR, [File 'OEBPS/Text/pdfMigration.html' could not be decrypted.], epub20_encryption_binary_content.epub</message>
<message severity="error" subMessage="RSC-012">RSC-012, ERROR, [Fragment identifier is not defined.], OEBPS/toc.ncx (24-67)</message>
<message severity="error" subMessage="RSC-012">RSC-012, ERROR, [Fragment identifier is not defined.], OEBPS/toc.ncx (30-82)</message>
<message severity="error" subMessage="RSC-012">RSC-012, ERROR, [Fragment identifier is not defined.], OEBPS/toc.ncx (36-81)</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<version>2.0.1</version>
<status>Not well-formed</status>
<messages>
<message severity="error" subMessage="RSC-004">RSC-004, ERROR, [File 'OEBPS/Text/pdfMigration.html' could not be decrypted.], epub20_minimal_encryption.epub</message>
<message severity="error" subMessage="RSC-012">RSC-012, ERROR, [Fragment identifier is not defined.], OEBPS/toc.ncx (24-67)</message>
<message severity="error" subMessage="RSC-012">RSC-012, ERROR, [Fragment identifier is not defined.], OEBPS/toc.ncx (30-82)</message>
<message severity="error" subMessage="RSC-012">RSC-012, ERROR, [Fragment identifier is not defined.], OEBPS/toc.ncx (36-81)</message>
Expand Down

0 comments on commit e732068

Please sign in to comment.