Search in sources :

Example 26 with XMLSignature

use of javax.xml.crypto.dsig.XMLSignature in project simba-os by cegeka.

the class Utils method validateSign.

/**
 * Validate signature (Message or Assertion).
 *
 * @param signatureElement The element we should validate
 * @param cert             The pubic cert
 * @param fingerprint      The fingerprint of the public cert
 * @return True if the sign is valid, false otherwise.
 */
public static boolean validateSign(Node signatureElement, Certificate cert, String... fingerprint) throws Exception {
    boolean res;
    DOMValidateContext ctx = new DOMValidateContext(cert.getPublicKey(), signatureElement);
    XMLSignatureFactory sigF = XMLSignatureFactory.getInstance("DOM");
    try {
        XMLSignature xmlSignature = sigF.unmarshalXMLSignature(ctx);
        res = xmlSignature.validate(ctx);
    } catch (MarshalException e) {
        log.error("Cannot locate Signature Node " + e.getMessage(), e);
        throw e;
    } catch (NullPointerException e) {
        log.error("Context can't be validated", e);
        throw e;
    }
    return res;
}
Also used : XMLSignatureFactory(javax.xml.crypto.dsig.XMLSignatureFactory) MarshalException(javax.xml.crypto.MarshalException) XMLSignature(javax.xml.crypto.dsig.XMLSignature) DOMValidateContext(javax.xml.crypto.dsig.dom.DOMValidateContext)

Aggregations

XMLSignature (javax.xml.crypto.dsig.XMLSignature)26 Reference (javax.xml.crypto.dsig.Reference)21 XMLSignatureFactory (javax.xml.crypto.dsig.XMLSignatureFactory)18 DOMValidateContext (javax.xml.crypto.dsig.dom.DOMValidateContext)16 Document (org.w3c.dom.Document)16 SignedInfo (javax.xml.crypto.dsig.SignedInfo)14 DOMSignContext (javax.xml.crypto.dsig.dom.DOMSignContext)13 NodeList (org.w3c.dom.NodeList)13 URIReference (javax.xml.crypto.URIReference)10 ArrayList (java.util.ArrayList)8 CanonicalizationMethod (javax.xml.crypto.dsig.CanonicalizationMethod)8 Transform (javax.xml.crypto.dsig.Transform)8 KeyInfo (javax.xml.crypto.dsig.keyinfo.KeyInfo)8 Element (org.w3c.dom.Element)8 KeyInfoFactory (javax.xml.crypto.dsig.keyinfo.KeyInfoFactory)7 X509Data (javax.xml.crypto.dsig.keyinfo.X509Data)7 Node (org.w3c.dom.Node)7 XMLObject (javax.xml.crypto.dsig.XMLObject)6 DOMStructure (javax.xml.crypto.dom.DOMStructure)4 SignatureMethod (javax.xml.crypto.dsig.SignatureMethod)4