Skip to content

Commit 274c1c1

Browse files
pskopekbaranowb
authored andcommitted
[BZ1296797] validate mix signed assertions properly
(cherry picked from commit 71b87f3)
1 parent 20e6b42 commit 274c1c1

File tree

4 files changed

+474
-3
lines changed

4 files changed

+474
-3
lines changed

modules/federation/src/main/java/org/picketlink/identity/federation/core/util/XMLSignatureUtil.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.picketlink.common.PicketLinkLogger;
2121
import org.picketlink.common.PicketLinkLoggerFactory;
22+
import org.picketlink.common.constants.JBossSAMLConstants;
2223
import org.picketlink.common.constants.JBossSAMLURIConstants;
2324
import org.picketlink.common.constants.WSTrustConstants;
2425
import org.picketlink.common.exceptions.ParsingException;
@@ -500,9 +501,18 @@ public static boolean validate(Document signedDoc, Key publicKey) throws Marshal
500501

501502
if (publicKey == null)
502503
throw logger.nullValueError("Public Key");
503-
504+
int signedAssertions = 0;
505+
String assertionNameSpaceUri = null;
504506
for (int i = 0; i < nl.getLength(); i++) {
505-
DOMValidateContext valContext = new DOMValidateContext(publicKey, nl.item(i));
507+
Node signatureNode = nl.item(i);
508+
Node parent = signatureNode.getParentNode();
509+
if (parent != null && JBossSAMLConstants.ASSERTION.get().equals(parent.getLocalName())) {
510+
++signedAssertions;
511+
if (assertionNameSpaceUri == null) {
512+
assertionNameSpaceUri = parent.getNamespaceURI();
513+
}
514+
}
515+
DOMValidateContext valContext = new DOMValidateContext(publicKey, signatureNode);
506516
XMLSignature signature = fac.unmarshalXMLSignature(valContext);
507517

508518
boolean coreValidity = signature.validate(valContext);
@@ -521,7 +531,11 @@ public static boolean validate(Document signedDoc, Key publicKey) throws Marshal
521531
return false;
522532
}
523533
}
524-
534+
NodeList assertions = signedDoc.getElementsByTagNameNS(assertionNameSpaceUri, JBossSAMLConstants.ASSERTION.get());
535+
if (signedAssertions > 0 && assertions != null && assertions.getLength() != signedAssertions) {
536+
// there are unsigned assertions mixed with signed ones
537+
return false;
538+
}
525539
return true;
526540
}
527541

modules/federation/src/main/java/org/picketlink/identity/federation/saml/v2/protocol/ResponseType.java

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public void addAssertion(RTChoiceType choice) {
6868
assertions.add(choice);
6969
}
7070

71+
public void addAssertion(int index, RTChoiceType choice) {
72+
assertions.add(index, choice);
73+
}
74+
7175
/**
7276
* Remove an assertion
7377
*

0 commit comments

Comments
 (0)