naruto-lgtm commented on code in PR #1581:
URL: https://github.com/apache/poi/pull/1581#discussion_r4651346552
##########
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java:
##########
@@ -146,7 +147,7 @@ public boolean validate() {
XMLSignatureFactory xmlSignatureFactory =
signatureInfo.getSignatureFactory();
XMLSignature xmlSignature =
xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);
- boolean valid = xmlSignature.validate(domValidateContext) &&
hasSignedRelationships(doc, xmlSignature);
+ boolean valid = xmlSignature.validate(domValidateContext) &&
hasValidatedManifests(doc) && hasSignedRelationships(doc, xmlSignature);
Review Comment:
Switched to that. `hasValidatedManifests` now walks the SignedInfo
references and requires a same-document one to resolve to an Id in
`xmlSignature.getObjects()`, or to a `Manifest` which is the content of one.
One deviation: I gated it on "the referenced element carries a ds:Manifest"
rather than on the reference Type, so a reference which omits the Type
attribute can't skip the check, and so the XAdES SignedProperties references,
which point inside an Object rather than at it, keep passing.
##########
poi-ooxml/src/main/java/org/apache/poi/poifs/crypt/dsig/SignaturePart.java:
##########
@@ -184,6 +185,24 @@ public boolean validate() {
}
}
+ /**
+ * Checks that each ds:Manifest is the content of a ds:Object of the
signature, as only those
+ * manifests are validated - a signed object moved into another element
keeps its digest,
+ * but the references of its manifest, i.e. of the package parts, would
not be checked
+ */
+ private static boolean hasValidatedManifests(Document doc) {
+ Element signature = doc.getDocumentElement();
+ NodeList manifests = doc.getElementsByTagNameNS(XML_DIGSIG_NS,
"Manifest");
Review Comment:
Good point, the document-wide scan was too broad. Driving the check off the
references fixes it: a ds:Manifest the SignedInfo never references, whether in
unsigned XAdES properties or as literal transform content, isn't looked at at
all now. Only a manifest POI actually relies on has to sit where
`validateManifests` will check it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]