Examples of XMLSignature


Examples of org.apache.xml.security.signature.XMLSignature

    protected void doDOMSignatureOutbound(File file, int tagCount) throws Exception {

        DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
        Document document = builder.parse(file);

        XMLSignature sig = new XMLSignature(document, "", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
        Element root = document.getDocumentElement();
        root.insertBefore(sig.getElement(), root.getFirstChild());

        Transforms transforms = new Transforms(document);
        transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
        transforms.addTransform(Transforms.TRANSFORM_C14N_OMIT_COMMENTS);
        sig.addDocument("", transforms, "http://www.w3.org/2000/09/xmldsig#sha1");

        sig.sign(key);
        sig.addKeyInfo(cert);

        XMLUtils.outputDOM(document, new BufferedOutputStream(new FileOutputStream(new File(getTmpFilePath(), "signature-dom-" + tagCount + ".xml"))));
    }
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

        DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
        Document document = builder.parse(file);

        Element signatureElement = (Element) document.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature").item(0);
        ((Element) signatureElement.getParentNode()).setIdAttributeNS(null, "Id", true);
        XMLSignature xmlSignature = new XMLSignature(signatureElement, "", true);
        xmlSignature.checkSignatureValue(cert);
    }
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

        List<String> localNames = new ArrayList<String>();
        localNames.add("PaymentInfo");
       
        String digestAlgorithm = "http://www.w3.org/2007/05/xmldsig-more#sha3-256";
       
        XMLSignature sig = signUsingDOM(
                "http://www.w3.org/2000/09/xmldsig#rsa-sha1", document, localNames, key,
                "http://www.w3.org/2001/10/xml-exc-c14n#", digestAlgorithm
        );
       
        // Add KeyInfo
        sig.addKeyInfo(cert);

        // Convert Document to a Stream Reader
        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        transformer.transform(new DOMSource(document), new StreamResult(baos));
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

        List<String> localNames = new ArrayList<String>();
        localNames.add("PaymentInfo");
       
        String digestAlgorithm = "http://www.w3.org/2007/05/xmldsig-more#sha3-384";
       
        XMLSignature sig = signUsingDOM(
                "http://www.w3.org/2000/09/xmldsig#rsa-sha1", document, localNames, key,
                "http://www.w3.org/2001/10/xml-exc-c14n#", digestAlgorithm
        );
       
        // Add KeyInfo
        sig.addKeyInfo(cert);

        // Convert Document to a Stream Reader
        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        transformer.transform(new DOMSource(document), new StreamResult(baos));
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

        List<String> localNames = new ArrayList<String>();
        localNames.add("PaymentInfo");
       
        String digestAlgorithm = "http://www.w3.org/2007/05/xmldsig-more#sha3-512";
       
        XMLSignature sig = signUsingDOM(
                "http://www.w3.org/2000/09/xmldsig#rsa-sha1", document, localNames, key,
                "http://www.w3.org/2001/10/xml-exc-c14n#", digestAlgorithm
        );
       
        // Add KeyInfo
        sig.addKeyInfo(cert);

        // Convert Document to a Stream Reader
        javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        transformer.transform(new DOMSource(document), new StreamResult(baos));
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

    org.w3c.dom.Element dom = fomToDom((Element)element.clone(), options);
    org.w3c.dom.Document domdoc = dom.getOwnerDocument();
    PrivateKey signingKey = options.getSigningKey();
    X509Certificate cert = options.getCertificate();
    IRI baseUri = element.getResolvedBaseUri();
    XMLSignature sig = new XMLSignature(
      domdoc,
      (baseUri != null) ? baseUri.toString() : "",
      XMLSignature.ALGO_ID_SIGNATURE_DSA);
    dom.appendChild(sig.getElement());
    Transforms transforms = new Transforms(domdoc);
    transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
    transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
    sig.addDocument("", transforms, org.apache.xml.security.utils.Constants.ALGO_ID_DIGEST_SHA1);
    String[] refs = options.getReferences();
    for (String ref : refs) sig.addDocument(ref);
    sig.addKeyInfo(cert);
    sig.addKeyInfo(cert.getPublicKey());
    sig.sign(signingKey);   
    return (T)domToFom(dom, options);
  }
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

        if (node.getNodeType() == Node.ELEMENT_NODE) {
          org.w3c.dom.Element el = (org.w3c.dom.Element) node;
          if (Constants.DSIG_NS.equals(el.getNamespaceURI()) &&
              Constants.LN_SIGNATURE.equals(el.getLocalName())) {
            IRI baseUri = element.getResolvedBaseUri();
            XMLSignature sig =
              new XMLSignature(
                el, (baseUri != null) ? baseUri.toString() : "");
            if (is_valid_signature(sig)) {
              KeyInfo ki = sig.getKeyInfo();
              if (ki != null) {
                X509Certificate cert = ki.getX509Certificate();
                if (cert != null) certs.add(cert);
              }
            }
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

      if (node.getNodeType() == Node.ELEMENT_NODE) {
        org.w3c.dom.Element el = (org.w3c.dom.Element) node;
        if (Constants.DSIG_NS.equals(el.getNamespaceURI()) &&
            Constants.LN_SIGNATURE.equals(el.getLocalName())) {
          IRI baseUri = element.getResolvedBaseUri();
          XMLSignature sig =
            new XMLSignature(
              el, (baseUri != null) ? baseUri.toString() : "");
          answer = is_valid_signature(sig);
        }
      }
    }
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

           
            String userName = (String)message.getContextualProperty(SecurityConstants.ENCRYPT_USERNAME);
            if (userName != null
                && SecurityUtils.USE_REQUEST_SIGNATURE_CERT.equals(userName)
                && !MessageUtils.isRequestor(message)) {
                XMLSignature sig = message.getExchange().getInMessage().getContent(XMLSignature.class);
                if (sig != null) {
                    receiverCert = sig.getKeyInfo().getX509Certificate();
                }
            } else {
                CryptoLoader loader = new CryptoLoader();
                Crypto crypto = loader.getCrypto(message,
                                          SecurityConstants.ENCRYPT_CRYPTO,
View Full Code Here

Examples of org.apache.xml.security.signature.XMLSignature

            throwFault("Crypto can not be loaded", ex);
        }
        boolean valid = false;
        Reference ref = null;
        try {
            XMLSignature signature = new XMLSignature(signatureElement, "", true);
           
            if (sigProps != null) {
                SignedInfo sInfo = signature.getSignedInfo();
                if (sigProps.getSignatureAlgo() != null
                    && !sigProps.getSignatureAlgo().equals(sInfo.getSignatureMethodURI())) {
                    throwFault("Signature Algorithm is not supported", null);
                }
                if (sigProps.getSignatureC14Method() != null
                    && !sigProps.getSignatureC14Method().equals(sInfo.getCanonicalizationMethodURI())) {
                    throwFault("Signature Algorithm is not supported", null);
                }
            }
           
            ref = getReference(signature);
            Element signedElement = validateReference(root, ref);
            if (signedElement.hasAttributeNS(null, "ID")) {
                signedElement.setIdAttributeNS(null, "ID", true);
            }
            if (signedElement.hasAttributeNS(null, "Id")) {
                signedElement.setIdAttributeNS(null, "Id", true);
            }
           
            // See also WSS4J SAMLUtil.getCredentialFromKeyInfo
            KeyInfo keyInfo = signature.getKeyInfo();
           
            X509Certificate cert = keyInfo.getX509Certificate();
            if (cert != null) {
                valid = signature.checkSignatureValue(cert);
            } else {
                PublicKey pk = keyInfo.getPublicKey();
                if (pk != null) {
                    valid = signature.checkSignatureValue(pk);
                }
            }
           
            // validate trust
            new TrustValidator().validateTrust(crypto, cert, keyInfo.getPublicKey());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.