use of org.apache.xml.security.signature.Reference in project santuario-java by apache.
the class ExclusiveC14NInteropTest method t.
private String t(String directory, String file, boolean secureValidation) throws Exception {
String basedir = System.getProperty("basedir");
if (basedir != null && !"".equals(basedir)) {
directory = basedir + "/" + directory;
}
File f = new File(directory + "/" + file);
javax.xml.parsers.DocumentBuilder db = XMLUtils.createDocumentBuilder(false, false);
org.w3c.dom.Document doc = db.parse(f);
Element sigElement = (Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE).item(0);
XMLSignature signature = new XMLSignature(sigElement, f.toURI().toURL().toString(), secureValidation);
boolean verify = signature.checkSignatureValue(signature.getKeyInfo().getPublicKey());
LOG.debug(" signature.checkSignatureValue finished: " + verify);
// if (!verify) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < signature.getSignedInfo().getLength(); i++) {
boolean refVerify = signature.getSignedInfo().getVerificationResult(i);
if (refVerify) {
LOG.debug("Reference " + i + " was OK");
} else {
sb.append(i);
sb.append(" ");
// JavaUtils.writeBytesToFilename(directory + "/c14n-" + i + ".apache.txt", signature.getSignedInfo().item(i).getContentsAfterTransformation().getBytes());
// JavaUtils.writeBytesToFilename(directory + "/c14n-" + i + ".apache.html", signature.getSignedInfo().item(i).getHTMLRepresentation().getBytes());
Reference reference = signature.getSignedInfo().item(i);
int length = reference.getTransforms().getLength();
String algo = reference.getTransforms().item(length - 1).getURI();
LOG.debug("Reference " + i + " failed: " + algo);
}
}
String r = sb.toString().trim();
if (r.length() == 0) {
return null;
} else {
return r;
}
}
Aggregations