final String expectedSignatureMethod = binding.getAlgorithmSuite().getAsymmetricSignature();
final String expectedDigestAlgorithm = binding.getAlgorithmSuite().getDigest();
final String expectedCanonAlgorithm = binding.getAlgorithmSuite().getInclusiveC14n();
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
final NamespaceContext nsContext = this.getNamespaceContext();
xpath.setNamespaceContext(nsContext);
// Signature Algorithm
final XPathExpression sigAlgoExpr =
xpath.compile("/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo"
+ "/ds:SignatureMethod/@Algorithm");
final String sigMethod = (String) sigAlgoExpr.evaluate(signedDoc, XPathConstants.STRING);
assertEquals(expectedSignatureMethod, sigMethod);
// Digest Method Algorithm
final XPathExpression digestAlgoExpr = xpath.compile(
"/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestMethod");
final NodeList digestMethodNodes =
(NodeList) digestAlgoExpr.evaluate(signedDoc, XPathConstants.NODESET);
for (int i = 0; i < digestMethodNodes.getLength(); i++) {
Node node = (Node)digestMethodNodes.item(i);
String digestAlgorithm = node.getAttributes().getNamedItem("Algorithm").getNodeValue();
assertEquals(expectedDigestAlgorithm, digestAlgorithm);
}
// Canonicalization Algorithm
final XPathExpression canonAlgoExpr =
xpath.compile("/s:Envelope/s:Header/wsse:Security/ds:Signature/ds:SignedInfo"
+ "/ds:CanonicalizationMethod/@Algorithm");
final String canonMethod = (String) canonAlgoExpr.evaluate(signedDoc, XPathConstants.STRING);
assertEquals(expectedCanonAlgorithm, canonMethod);
}