Package javax.xml.crypto.dsig.dom

Examples of javax.xml.crypto.dsig.dom.DOMValidateContext


  {
    NodeList nodeList = document.getElementsByTagNameNS(XMLSignature.XMLNS,"Signature");
    if (nodeList.getLength() > 0)
    {
      XMLSignatureFactory signFactory = XMLSignatureFactory.getInstance();
      DOMValidateContext validateContext = new DOMValidateContext(new XMLDSigKeySelector(),nodeList.item(0));
      URIDereferencer dereferencer = new EbMSDataSourceURIDereferencer(dataSources);
      validateContext.setURIDereferencer(dereferencer);
      XMLSignature signature = signFactory.unmarshalXMLSignature(validateContext);
      return signature.validate(validateContext);
    }
    return true;
  }
View Full Code Here


            //verify the signature inside the SAML assertion
            if (nl.getLength() == 0) {
                throw new SAMLException("Unsigned SAML Assertion encountered while verifying the SAML signature");
            }
            Element signElement = (Element) nl.item(0);
            DOMValidateContext validationContext = new DOMValidateContext(pubKey, signElement);
            XMLSignatureFactory signatureFactory = WSSPolicyConsumerImpl.getInstance().getSignatureFactory();
            // unmarshal the XMLSignature
            XMLSignature xmlSignature = signatureFactory.unmarshalXMLSignature(validationContext);           
            validationContext.setURIDereferencer(new DSigResolver(map, samlAssertion));
            boolean coreValidity = xmlSignature.validate(validationContext);
            return coreValidity;
        } catch (Exception ex) {
            throw new SAMLException(ex);
        }
View Full Code Here

            key = publicKey;
        } else {
            key = WSSecurityUtil.prepareSecretKey(signatureMethod, secretKey);
        }
       
        XMLValidateContext context = new DOMValidateContext(key, elem);
        context.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
        context.setProperty(STRTransform.TRANSFORM_WS_DOC_INFO, wsDocInfo);
       
        try {
            XMLSignature xmlSignature = signatureFactory.unmarshalXMLSignature(context);
            setElementsOnContext(xmlSignature, (DOMValidateContext)context, wsDocInfo, elem.getOwnerDocument());
            boolean signatureOk = xmlSignature.validate(context);
View Full Code Here

    NodeList nl = doc.getElementsByTagNameNS( XMLSignature.XMLNS, "Signature" );
    if ( nl.getLength() == 0 ) {
      throw new IllegalStateException( "Cannot find Signature element!" );
    }

    DOMValidateContext valContext = new DOMValidateContext( x509Support.getCertificate().getPublicKey(), nl.item( 0 ) );
    XMLSignature signature = SIGNATURE_FACTORY.unmarshalXMLSignature( valContext );
    return signature.validate( valContext );

    //    if ( signature.validate( valContext ) ) {
    //      System.out.println( "Signature passed core validation!" );
View Full Code Here

      throw new Exception("Cannot find Signature element!");
    }

    // Step 4: Create a DOMValidateContext instance (extract public key from
    // the "KeyInfo" bloc using overrided KeySelector impl.)
    DOMValidateContext valContext = new DOMValidateContext(new KeyValueKeySelector(), nl.item(0));

    // Step 5: Unmarshal the Signature node into an XMLSiganture object.
    XMLSignature signature = fac.unmarshalXMLSignature(valContext);

    // Step 6 : Validate signature
View Full Code Here

                        "Expected Signature Element as per receiver requirements, found  "+
                        localName));
                context.isPrimaryPolicyViolation(true);
                return 0;
            }
            DOMValidateContext validationContext = new DOMValidateContext(KeySelectorImpl.getInstance(), signElement);
            XMLSignatureFactory signatureFactory = WSSPolicyConsumerImpl.getInstance().getSignatureFactory();
            // unmarshal the XMLSignature
            XMLSignature signature = signatureFactory.unmarshalXMLSignature(validationContext);
            verifySignatureAlgorithm(signature);
           
            //For SignatureConfirmation
            List scList = (ArrayList)context.getExtraneousProperty("receivedSignValues");
            if(scList != null){
                scList.add(Base64.encode(signature.getSignatureValue().getValue()));
            }
            //End SignatureConfirmation specific code
           
            validationContext.setURIDereferencer(DSigResolver.getInstance());
            // Validate the XMLSignature (generated above)
            validationContext.put(MessageConstants.WSS_PROCESSING_CONTEXT, context);
            SignaturePolicy currentMessagePolicy = null;
            if(context.getMode() == FilterProcessingContext.ADHOC ||
                    context.getMode() == FilterProcessingContext.POSTHOC){
                currentMessagePolicy = new SignaturePolicy();
                context.setInferredPolicy(currentMessagePolicy);
View Full Code Here

    public static boolean verifySignature(Element signElement, FilterProcessingContext context)
    throws XWSSecurityException {
        try {
           
           
            DOMValidateContext validationContext =
                    new DOMValidateContext(KeySelectorImpl.getInstance(), signElement);
            XMLSignatureFactory signatureFactory = WSSPolicyConsumerImpl.getInstance().getSignatureFactory();
            // unmarshal the XMLSignature
            XMLSignature signature = signatureFactory.unmarshalXMLSignature(validationContext);
            validationContext.setURIDereferencer(DSigResolver.getInstance());
            // Validate the XMLSignature (generated above)
            validationContext.put(MessageConstants.WSS_PROCESSING_CONTEXT, context);
            boolean coreValidity = signature.validate(validationContext);
            if (coreValidity == false){
               
                if(logger.isLoggable(Level.FINEST)){
                    logger.log(Level.FINEST,"Signature failed core validation");
View Full Code Here

                XMLSignatureFactory fac = initXMLSigFactory();
                NodeList nl = element.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
                if (nl.getLength() == 0) {
                        throw new RuntimeException("Cannot find Signature element");
                }
                DOMValidateContext valContext = new DOMValidateContext(validatingKey, nl.item(0));
                try {
                        valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
                        XMLSignature signature = fac.unmarshalXMLSignature(valContext);
                        boolean coreValidity = signature.validate(valContext);
                        // Check core validation status.
                        if (coreValidity == false) {
                                logger.warn("Signature failed core validation");
View Full Code Here

        KeySelector selector = getConfiguration().getKeySelector();
        if (selector == null) {
            throw new IllegalStateException("Wrong configuration. Key selector is missing.");
        }

        DOMValidateContext valContext = new DOMValidateContext(selector, signatureNode);
        valContext.setProperty("javax.xml.crypto.dsig.cacheReference", Boolean.TRUE);
        valContext.setProperty("org.jcp.xml.dsig.validateManifests", Boolean.TRUE);
       
        if (getConfiguration().getSecureValidation() == Boolean.TRUE) {
            valContext.setProperty("org.apache.jcp.xml.dsig.secureValidation", Boolean.TRUE);
            valContext.setProperty("org.jcp.xml.dsig.secureValidation", Boolean.TRUE);
        }
        setUriDereferencerAndBaseUri(valContext);

        setCryptoContextProperties(valContext);
View Full Code Here

        KEYS[1] = TestUtils.getPublicKey("RSA");
        KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");

        // set up the default XMLValidateContext
        SecretKey sk = new SecretKeySpec(new byte[8], "DES");
        defContext = new DOMValidateContext(sk, TestUtils.newDocument());

        // set up the key selectors
        KEY_SELECTORS = new KeySelector[1];
        KEY_SELECTORS[0] = KeySelector.singletonKeySelector(sk);
    }
View Full Code Here

TOP

Related Classes of javax.xml.crypto.dsig.dom.DOMValidateContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.