Package org.apache.xml.security.transforms.params

Examples of org.apache.xml.security.transforms.params.XPathContainer


        Element signatureElement = signature.getElement();
        rootElement.appendChild(signatureElement);

        Transforms transforms = new Transforms(testDocument);
        XPathContainer xpath = new XPathContainer(testDocument);
        xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
        xpath.setXPath("not(ancestor-or-self::ds:Signature)");
        transforms.addTransform(Transforms.TRANSFORM_XPATH, xpath.getElementPlusReturns());
        transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
        signature.addDocument("", transforms, MessageDigestAlgorithm.ALGO_ID_DIGEST_SHA1);

        if (cert) {
            signature.addKeyInfo(signingCert);
View Full Code Here


        {
            String rootnamespace = signedResourceElement.getNamespaceURI();
            boolean rootprefixed = (rootnamespace != null) && (rootnamespace.length() > 0);
            String rootlocalname = signedResourceElement.getNodeName();
            Transforms transforms = new Transforms(doc);
            XPathContainer xpath = new XPathContainer(doc);

            xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);

            if (rootprefixed) {
                xpath.setXPathNamespaceContext("root", rootnamespace);
            }

            String xpathStr = "\n"
                + "count(                                                                 " + "\n"
                + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n"
                + " |                                                                     " + "\n"
                + " here()/ancestor::" + (rootprefixed ? "root:" : "") + rootlocalname + "[1] " + "\n"
                + ") <= count(                                                             " + "\n"
                + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n"
                + ")                                                                      " + "\n"
                + " and                                                                   " + "\n"
                + "count(                                                                 " + "\n"
                + " ancestor-or-self::ds:Signature                                        " + "\n"
                + " |                                                                     " + "\n"
                + " here()/ancestor::ds:Signature[1]                                      " + "\n"
                + ") > count(                                                             " + "\n"
                + " ancestor-or-self::ds:Signature                                        " + "\n"
                + ")                                                                      " + "\n"



                ;
            xpath.setXPath(xpathStr);
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpath.getElementPlusReturns());
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            sig.getKeyInfo().add(new KeyName(doc, CreateCollectableSignature.passphrase));
View Full Code Here

                            transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPath("self::text()");
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpathC.getElementPlusReturns());
            sig.addDocument("#object-1", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
            sig.addDocument("#object-2", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Manifest");
        sig.addDocument("#signature-properties-1", null,
                        Constants.ALGO_ID_DIGEST_SHA1, null,
        "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                            null, "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#object-3", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#xpointer(id('object-3'))", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(id('object-3'))", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#manifest-reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-2", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        /*
         * Add KeyInfo and sign()
         */
        {
            Transforms retrievalTransforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpathC.setXPath("ancestor-or-self::ds:X509Data");
            retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH, xpathC.getElement());
            sig.getKeyInfo().add(
                new RetrievalMethod(
                    doc, "#object-4", retrievalTransforms, "http://www.w3.org/2000/09/xmldsig#X509Data"));

            System.out.println("Start signing");
View Full Code Here

            c.setAttributeNS(null, "name", "val");
            ob1.appendChild(c);
            sig.appendObject(ob1);

            Transforms transforms = new Transforms(doc);
            XPathContainer xc = new XPathContainer(doc);
            xc.setXPathNamespaceContext("prof", Constants.SignatureSpecNS);

            String xpath = "\n"
                + "count(" + "\n"
                + " ancestor-or-self::prof:Object " + "\n"
                + " | " + "\n"
                + " here()/ancestor::prof:Signature[1]/child::prof:Object[@Id='object-1']" + "\n"
                + ") <= count(" + "\n"
                + " ancestor-or-self::prof:Object" + "\n"
                + ") " + "\n";

            xc.setXPath(xpath);
            HelperNodeList nl = new HelperNodeList();
            nl.appendChild(doc.createTextNode("\n"));
            nl.appendChild(xc.getElement());
            nl.appendChild(doc.createTextNode("\n"));

            transforms.addTransform(Transforms.TRANSFORM_XPATH, nl);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
View Full Code Here

            ed.getCipherData().getCipherReference().setTransforms(xencTransforms);
            org.apache.xml.security.transforms.Transforms dsTransforms =
                xencTransforms.getDSTransforms();

            // An XPath transform
            XPathContainer xpc = new XPathContainer(d);
            xpc.setXPath("self::text()[parent::CipherText[@Id=\"CipherTextId\"]]");
            dsTransforms.addTransform(
                org.apache.xml.security.transforms.Transforms.TRANSFORM_XPATH,
                xpc.getElementPlusReturns()
            );

            // Add a Base64 Transforms
            dsTransforms.addTransform(
                org.apache.xml.security.transforms.Transforms.TRANSFORM_BASE64_DECODE
View Full Code Here

                            transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPath("self::text()");
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpathC.getElementPlusReturns());
            sig.addDocument("#object-1", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
            sig.addDocument("#object-2", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
        "http://www.w3.org/2000/09/xmldsig#Manifest");
        sig.addDocument("#signature-properties-1", null,
                        Constants.ALGO_ID_DIGEST_SHA1, null,
                        "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                            null, "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#object-3", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#xpointer(id('object-3'))", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(id('object-3'))", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#manifest-reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-2", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        /*
         * Add KeyInfo and sign()
         */
        {
            Transforms retrievalTransforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpathC.setXPath("ancestor-or-self::ds:X509Data");
            retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH,
                                             xpathC.getElement());
            sig.getKeyInfo().add(
                new RetrievalMethod(
                    doc, "#object-4", retrievalTransforms, "http://www.w3.org/2000/09/xmldsig#X509Data"));

            System.out.println("Start signing");
View Full Code Here

            String rootnamespace = contract.getNamespaceURI();
            boolean rootprefixed = (rootnamespace != null) && (rootnamespace.length() > 0);
            String rootlocalname = contract.getNodeName();
            Transforms transforms = new Transforms(doc);
            XPathContainer xpath = new XPathContainer(doc);

            xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpath.setXPath("\n" + xp1 + "\n");
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpath.getElementPlusReturns());
            firstSigner.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);

            {
                // not really secure ///////////////////
                firstSigner.getKeyInfo().add(new KeyName(doc, "First signer key"));

                ////////////////////////////////////////////////
                System.out.println("First signer: Start signing");
                firstSigner.sign(
                    firstSigner.createSecretKey("First signer key".getBytes()));
                System.out.println("First signer: Finished signing");
            }

            SignedInfo s = firstSigner.getSignedInfo();

            for (int i = 0; i < s.getSignedContentLength(); i++) {
                System.out.println("################ Signed Resource " + i
                                   + " ################");
                System.out.println(new String(s.getSignedContentItem(i)));
                System.out.println();
            }
        }

        //////////////////////////////////////////////////////////////////
        // second signer /////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////
        {
            XMLSignature secondSigner =
                new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_MAC_HMAC_SHA1);

            secondSigner.setId(id2);
            contract.appendChild(secondSigner.getElement());

            Transforms transforms2 = new Transforms(doc);
            XPathContainer xpath2 = new XPathContainer(doc);

            xpath2.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpath2.setXPath("\n" + xp2 + "\n");
            transforms2.addTransform(Transforms.TRANSFORM_XPATH,
                                     xpath2.getElementPlusReturns());
            secondSigner.addDocument("", transforms2, Constants.ALGO_ID_DIGEST_SHA1);

            {
                secondSigner.getKeyInfo().add(new KeyName(doc,
                "Second signer key"));
                System.out.println("Second signer: Start signing");
                secondSigner.sign(
                    secondSigner.createSecretKey("Second signer key".getBytes()));
                System.out.println("Second signer: Finished signing");
            }

            SignedInfo s2 = secondSigner.getSignedInfo();

            for (int i = 0; i < s2.getSignedContentLength(); i++) {
                System.out.println("################ Signed Resource " + i
                                   + " ################");
                System.out.println(new String(s2.getSignedContentItem(i)));
                System.out.println();
            }
        }

        //////////////////////////////////////////////////////////////////
        // third signer //////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////
        {
            XMLSignature thirdSigner =
                new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_MAC_HMAC_SHA1);

            thirdSigner.setId(id3);
            contract.appendChild(thirdSigner.getElement());

            Transforms transforms3 = new Transforms(doc);
            XPathContainer xpath3 = new XPathContainer(doc);

            xpath3.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpath3.setXPath("\n" + xp3 + "\n");
            transforms3.addTransform(Transforms.TRANSFORM_XPATH,
                                     xpath3.getElementPlusReturns());
            thirdSigner.addDocument("", transforms3, Constants.ALGO_ID_DIGEST_SHA1);

            {
                thirdSigner.getKeyInfo().add(new KeyName(doc, "Third signer key"));
                System.out.println("Third signer: Start signing");
                thirdSigner.sign(
                    thirdSigner.createSecretKey("Third signer key".getBytes()));
                System.out.println("Third signer: Finished signing");
            }

            SignedInfo s3 = thirdSigner.getSignedInfo();

            for (int i = 0; i < s3.getSignedContentLength(); i++) {
                System.out.println("################ Signed Resource " + i
                                   + " ################");
                System.out.println(new String(s3.getSignedContentItem(i)));
                System.out.println();
            }
        }

        //////////////////////////////////////////////////////////////////
        // forth signer //////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////
        {
            XMLSignature forthSigner =
                new XMLSignature(doc, BaseURI, XMLSignature.ALGO_ID_MAC_HMAC_SHA1);

            forthSigner.setId("sig4");
            contract.appendChild(forthSigner.getElement());

            {
                // first of all, add the basic document without signatures
                Transforms transforms4 = new Transforms(doc);
                XPathContainer xpath4 = new XPathContainer(doc);

                xpath4.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
                xpath4.setXPath("\n" + "not(ancestor-or-self::ds:Signature)"
                                + "\n");
                transforms4.addTransform(Transforms.TRANSFORM_XPATH,
                                         xpath4.getElementPlusReturns());
                forthSigner.addDocument("", transforms4,
                                        Constants.ALGO_ID_DIGEST_SHA1);
            }

            {
View Full Code Here

                            transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPath("self::text()");
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpathC.getElementPlusReturns());
            sig.addDocument("#object-1", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
            sig.addDocument("#object-2", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
            "http://www.w3.org/2000/09/xmldsig#Manifest");
        sig.addDocument("#signature-properties-1", null,
                        Constants.ALGO_ID_DIGEST_SHA1, null,
        "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                            null, "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#object-3", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#xpointer(id('object-3'))", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(id('object-3'))", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#manifest-reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-2", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        /*
         * Add KeyInfo and sign()
         */
        {
            Transforms retrievalTransforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpathC.setXPath("ancestor-or-self::ds:X509Data");
            retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH, xpathC.getElement());
            sig.getKeyInfo().add(
                new RetrievalMethod(
                    doc, "#object-4", retrievalTransforms, "http://www.w3.org/2000/09/xmldsig#X509Data"));

            System.out.println("Start signing");
View Full Code Here

                            transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPath("self::text()");
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpathC.getElementPlusReturns());
            sig.addDocument("#object-1", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_BASE64_DECODE);
            sig.addDocument("#object-2", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        sig.addDocument("#manifest-1", null, Constants.ALGO_ID_DIGEST_SHA1, null,
        "http://www.w3.org/2000/09/xmldsig#Manifest");
        sig.addDocument("#signature-properties-1", null,
                        Constants.ALGO_ID_DIGEST_SHA1, null,
                        "http://www.w3.org/2000/09/xmldsig#SignatureProperties");

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_ENVELOPED_SIGNATURE);
            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(/)", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            sig.addDocument("#object-3", null, Constants.ALGO_ID_DIGEST_SHA1,
                            null, "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#object-3", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#xpointer(id('object-3'))", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            Transforms transforms = new Transforms(doc);

            transforms.addTransform(Transforms.TRANSFORM_C14N_WITH_COMMENTS);
            sig.addDocument("#xpointer(id('object-3'))", transforms,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Object");
        }

        {
            sig.addDocument("#manifest-reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-1",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-1", null,
                            Constants.ALGO_ID_DIGEST_SHA1, "reference-2",
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        {
            sig.addDocument("#reference-2", null,
                            Constants.ALGO_ID_DIGEST_SHA1, null,
                            "http://www.w3.org/2000/09/xmldsig#Reference");
        }

        /*
         * Add KeyInfo and sign()
         */
        {
            Transforms retrievalTransforms = new Transforms(doc);
            XPathContainer xpathC = new XPathContainer(doc);

            xpathC.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);
            xpathC.setXPath("ancestor-or-self::ds:X509Data");
            retrievalTransforms.addTransform(Transforms.TRANSFORM_XPATH,
                                             xpathC.getElement());
            sig.getKeyInfo().add(
                new RetrievalMethod(
                    doc, "#object-4", retrievalTransforms, "http://www.w3.org/2000/09/xmldsig#X509Data"));

            System.out.println("Start signing");
View Full Code Here

        {
            String rootnamespace = signedResourceElement.getNamespaceURI();
            boolean rootprefixed = (rootnamespace != null) && (rootnamespace.length() > 0);
            String rootlocalname = signedResourceElement.getNodeName();
            Transforms transforms = new Transforms(doc);
            XPathContainer xpath = new XPathContainer(doc);

            xpath.setXPathNamespaceContext("ds", Constants.SignatureSpecNS);

            if (rootprefixed) {
                xpath.setXPathNamespaceContext("root", rootnamespace);
            }

            String xpathStr = "\n"
                + "count(                                                                 " + "\n"
                + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n"
                + " |                                                                     " + "\n"
                + " here()/ancestor::" + (rootprefixed ? "root:" : "") + rootlocalname + "[1] " + "\n"
                + ") <= count(                                                             " + "\n"
                + " ancestor-or-self::" + (rootprefixed ? "root:" : "") + rootlocalname + "" + "\n"
                + ")                                                                      " + "\n"
                + " and                                                                   " + "\n"
                + "count(                                                                 " + "\n"
                + " ancestor-or-self::ds:Signature                                        " + "\n"
                + " |                                                                     " + "\n"
                + " here()/ancestor::ds:Signature[1]                                      " + "\n"
                + ") > count(                                                             " + "\n"
                + " ancestor-or-self::ds:Signature                                        " + "\n"
                + ")                                                                      " + "\n"



                ;
            xpath.setXPath(xpathStr);
            transforms.addTransform(Transforms.TRANSFORM_XPATH,
                                    xpath.getElementPlusReturns());
            sig.addDocument("", transforms, Constants.ALGO_ID_DIGEST_SHA1);
        }

        {
            sig.getKeyInfo().add(new KeyName(doc, CreateCollectableSignature.passphrase));
View Full Code Here

TOP

Related Classes of org.apache.xml.security.transforms.params.XPathContainer

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.