Package javax.xml.crypto.dsig

Examples of javax.xml.crypto.dsig.XMLSignature


           
            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");
                    boolean sv = signature.getSignatureValue().validate(validationContext);
                    logger.log(Level.FINEST,"Signature validation status: " + sv);
                    // check the validation status of each Reference
                    Iterator i = signature.getSignedInfo().getReferences().iterator();
                    for (int j=0; i.hasNext(); j++) {
                        Reference ref = (Reference) i.next();
                        logger.log(Level.FINEST,"Reference ID "+ref.getId());
                        logger.log(Level.FINEST,"Reference URI "+ref.getURI());
                        boolean refValid =
View Full Code Here


        dsc.putNamespacePrefix(XML_DIGSIG_NS, "ns2");

        // Create the XMLSignature, but don't sign it yet.
        try {
            SignedInfo si = initSignedInfo(fac);
            XMLSignature signature = fac.newXMLSignature(si, ki);

            // Marshal, generate, and sign the enveloped signature.
            signature.sign(dsc);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

                        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");
                                boolean sv = signature.getSignatureValue().validate(valContext);
                                logger.debug("signature validation status: " + sv);
                                OutReadableErrorMessage.set("signature validation failed: " + sv + "." + OutReadableErrorMessage.get());
                                // Check the validation status of each Reference.
                                @SuppressWarnings("unchecked")
                                Iterator<Reference> i = signature.getSignedInfo().getReferences().iterator();
                                //System.out.println("---------------------------------------------");
                                for (int j = 0; i.hasNext(); j++) {
                                        Reference ref = (Reference) i.next();
                                        boolean refValid = ref.validate(valContext);
                                        logger.debug(j);
View Full Code Here

                dsc.putNamespacePrefix(XML_DIGSIG_NS, "ns2");

                // Create the XMLSignature, but don't sign it yet.
                try {
                        SignedInfo si = initSignedInfo(fac);
                        XMLSignature signature = fac.newXMLSignature(si, ki);

                        // Marshal, generate, and sign the enveloped signature.
                        signature.sign(dsc);
                } catch (Exception e) {
                        throw new RuntimeException(e);
                }
        }
View Full Code Here

                parent = XmlSignatureHelper.newDocumentBuilder(Boolean.TRUE).newDocument();
            }

            DOMSignContext dsc = createAndConfigureSignContext(parent, keySelector);

            XMLSignature signature = fac.newXMLSignature(si, keyInfo, objects, signatureId, null);
            // generate the signature
            signature.sign(dsc);

            return XmlSignatureHelper.getDocument(parent);

        } catch (XMLSignatureException se) {
            if (se.getCause() instanceof InvalidKeyException) {
View Full Code Here

        }
        setUriDereferencerAndBaseUri(valContext);

        setCryptoContextProperties(valContext);

        final XMLSignature signature = fac.unmarshalXMLSignature(valContext);

        executeApplicationCheck(out, doc, signature);

        boolean coreValidity;
        try {
            coreValidity = signature.validate(valContext);
        } catch (XMLSignatureException se) {
            throw getConfiguration().getValidationFailedHandler().onXMLSignatureException(se);
        }
        // Check core validation status
        boolean goon = coreValidity;
View Full Code Here

        webElem.appendChild(text);
        XMLObject obj = fac.newXMLObject(Collections.singletonList
                                         (new DOMStructure(webElem)), "DSig.Object_1", "text/xml", null);

        // create XMLSignature
        XMLSignature sig = fac.newXMLSignature
        (si, ki, Collections.singletonList(obj), null, null);

        DOMSignContext dsc = new DOMSignContext(signingKey, doc);
        dsc.setDefaultNamespacePrefix("dsig");

        sig.sign(dsc);
        TestUtils.validateSecurityOrEncryptionElement(doc.getDocumentElement());
       
        // XMLUtils.outputDOM(doc.getDocumentElement(), System.out);

        DOMValidateContext dvc = new DOMValidateContext
        (ks, doc.getDocumentElement());
        XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);

        assertTrue(sig.equals(sig2));
        assertTrue(sig2.validate(dvc));
    }
View Full Code Here

                }
                lastParent = parent;

                DOMSignContext dsc = createAndConfigureSignContext(parent, keySelector);

                XMLSignature signature = fac.newXMLSignature(si, keyInfo, objects, signatureId, null);
                // generate the signature
                signature.sign(dsc);
            }

            return XmlSignatureHelper.getDocument(lastParent);

        } catch (XMLSignatureException se) {
View Full Code Here

        for (int i = 0; i < totalCount; i++) {

            Element signatureNode = (Element) signatureNodes.item(i);

            valContext.setNode(signatureNode);
            final XMLSignature signature = fac.unmarshalXMLSignature(valContext);

            if (getConfiguration().getXmlSignatureChecker() != null) {
                XmlSignatureChecker.Input checkerInput = new CheckerInputBuilder().message(out).messageBodyDocument(doc)
                        .keyInfo(signature.getKeyInfo()).currentCountOfSignatures(i + 1).currentSignatureElement(signatureNode)
                        .objects(signature.getObjects()).signatureValue(signature.getSignatureValue())
                        .signedInfo(signature.getSignedInfo()).totalCountOfSignatures(totalCount)
                        .xmlSchemaValidationExecuted(getSchemaResourceUri(out) != null).build();
                getConfiguration().getXmlSignatureChecker().checkBeforeCoreValidation(checkerInput);
            }

            boolean coreValidity;
            try {
                coreValidity = signature.validate(valContext);
            } catch (XMLSignatureException se) {
                throw getConfiguration().getValidationFailedHandler().onXMLSignatureException(se);
            }
            // Check core validation status
            boolean goon = coreValidity;
            if (!coreValidity) {
                goon = handleSignatureValidationFailed(valContext, signature);
            }
            if (goon) {
                LOG.debug("XML signature {} verified", i + 1);
            } else {
                throw new XmlSignatureInvalidException("XML signature validation failed");
            }
            collectedObjects.addAll((List<XMLObject>) signature.getObjects());
            collectedReferences.addAll((List<Reference>) signature.getSignedInfo().getReferences());
        }
        map2Message(collectedReferences, collectedObjects, out, doc);
    }
View Full Code Here

            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 XWSSecurityException(ex);
        }
    }
View Full Code Here

TOP

Related Classes of javax.xml.crypto.dsig.XMLSignature

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.