Java Code Examples for com.sun.org.apache.xml.internal.security.utils.XMLUtils#selectDsNode()

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.XMLUtils#selectDsNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RetrievalMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method getTransforms
 *
 * @throws XMLSecurityException
 * @return the transformations
 */
public Transforms getTransforms() throws XMLSecurityException {
    try {
        Element transformsElem =
            XMLUtils.selectDsNode(
                this.constructionElement.getFirstChild(), Constants._TAG_TRANSFORMS, 0);

        if (transformsElem != null) {
            return new Transforms(transformsElem, this.baseURI);
        }

        return null;
    } catch (XMLSignatureException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
 
Example 2
Source File: RetrievalMethod.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method getTransforms
 *
 * @throws XMLSecurityException
 * @return the transformations
 */
public Transforms getTransforms() throws XMLSecurityException {
    try {
        Element transformsElem =
            XMLUtils.selectDsNode(
                this.constructionElement.getFirstChild(), Constants._TAG_TRANSFORMS, 0);

        if (transformsElem != null) {
            return new Transforms(transformsElem, this.baseURI);
        }

        return null;
    } catch (XMLSignatureException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
 
Example 3
Source File: RetrievalMethod.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method getTransforms
 *
 * @throws XMLSecurityException
 * @return the transformations
 */
public Transforms getTransforms() throws XMLSecurityException {
    try {
        Element transformsElem =
            XMLUtils.selectDsNode(
                this.constructionElement.getFirstChild(), Constants._TAG_TRANSFORMS, 0);

        if (transformsElem != null) {
            return new Transforms(transformsElem, this.baseURI);
        }

        return null;
    } catch (XMLSignatureException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
 
Example 4
Source File: X509Data.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemIssuerSerial
 *
 * @param i
 * @return the X509IssuerSerial, null if not present
 * @throws XMLSecurityException
 */
public XMLX509IssuerSerial itemIssuerSerial(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_X509ISSUERSERIAL, i);

    if (e != null) {
        return new XMLX509IssuerSerial(e, this.baseURI);
    }
    return null;
}
 
Example 5
Source File: KeyInfo.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemKeyValue
 *
 * @param i
 * @return the asked KeyValue element, null if the index is too big
 * @throws XMLSecurityException
 */
public KeyValue itemKeyValue(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_KEYVALUE, i);

    if (e != null) {
        return new KeyValue(e, this.baseURI);
    }
    return null;
}
 
Example 6
Source File: X509Data.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemCertificate
 *
 * @param i
 * @return the X509Certifacte, null if not present
 * @throws XMLSecurityException
 */
public XMLX509Certificate itemCertificate(int i) throws XMLSecurityException {

    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_X509CERTIFICATE, i);

    if (e != null) {
        return new XMLX509Certificate(e, this.baseURI);
    }
    return null;
}
 
Example 7
Source File: DSAKeyValueResolver.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method engineResolvePublicKey
 *
 * @param element
 * @param BaseURI
 * @param storage
 * @return null if no {@link PublicKey} could be obtained
 */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String BaseURI, StorageResolver storage
) {
    if (element == null) {
        return null;
    }
    Element dsaKeyElement = null;
    boolean isKeyValue =
        XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
    if (isKeyValue) {
        dsaKeyElement =
            XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_DSAKEYVALUE)) {
        // this trick is needed to allow the RetrievalMethodResolver to eat a
        // ds:DSAKeyValue directly (without KeyValue)
        dsaKeyElement = element;
    }

    if (dsaKeyElement == null) {
        return null;
    }

    try {
        DSAKeyValue dsaKeyValue = new DSAKeyValue(dsaKeyElement, BaseURI);
        PublicKey pk = dsaKeyValue.getPublicKey();

        return pk;
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, ex.getMessage(), ex);
        }
        //do nothing
    }

    return null;
}
 
Example 8
Source File: XMLSignature.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the KeyInfo child. If we are in signing mode and the KeyInfo
 * does not exist yet, it is created on demand and added to the Signature.
 * <br>
 * This allows to add arbitrary content to the KeyInfo during signing.
 *
 * @return the KeyInfo object
 */
public KeyInfo getKeyInfo() {
    // check to see if we are signing and if we have to create a keyinfo
    if (this.state == MODE_SIGN && this.keyInfo == null) {

        // create the KeyInfo
        this.keyInfo = new KeyInfo(this.doc);

        // get the Element from KeyInfo
        Element keyInfoElement = this.keyInfo.getElement();
        Element firstObject =
            XMLUtils.selectDsNode(
                this.constructionElement.getFirstChild(), Constants._TAG_OBJECT, 0
            );

        if (firstObject != null) {
            // add it before the object
            this.constructionElement.insertBefore(keyInfoElement, firstObject);
            XMLUtils.addReturnBeforeChild(this.constructionElement, firstObject);
        } else {
            // add it as the last element to the signature
            this.constructionElement.appendChild(keyInfoElement);
            XMLUtils.addReturnToElement(this.constructionElement);
        }
    }

    return this.keyInfo;
}
 
Example 9
Source File: XMLSignature.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the KeyInfo child. If we are in signing mode and the KeyInfo
 * does not exist yet, it is created on demand and added to the Signature.
 * <br>
 * This allows to add arbitrary content to the KeyInfo during signing.
 *
 * @return the KeyInfo object
 */
public KeyInfo getKeyInfo() {
    // check to see if we are signing and if we have to create a keyinfo
    if (this.state == MODE_SIGN && this.keyInfo == null) {

        // create the KeyInfo
        this.keyInfo = new KeyInfo(this.doc);

        // get the Element from KeyInfo
        Element keyInfoElement = this.keyInfo.getElement();
        Element firstObject =
            XMLUtils.selectDsNode(
                this.constructionElement.getFirstChild(), Constants._TAG_OBJECT, 0
            );

        if (firstObject != null) {
            // add it before the object
            this.constructionElement.insertBefore(keyInfoElement, firstObject);
            XMLUtils.addReturnBeforeChild(this.constructionElement, firstObject);
        } else {
            // add it as the last element to the signature
            this.constructionElement.appendChild(keyInfoElement);
            XMLUtils.addReturnToElement(this.constructionElement);
        }
    }

    return this.keyInfo;
}
 
Example 10
Source File: KeyInfo.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemSPKIData
 *
 * @param i
 * @return the asked SPKIData element, null if the index is too big
 * @throws XMLSecurityException
 */
public SPKIData itemSPKIData(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_SPKIDATA, i);

    if (e != null) {
        return new SPKIData(e, this.baseURI);
    }
    return null;
}
 
Example 11
Source File: KeyInfo.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemKeyName
 *
 * @param i
 * @return the asked KeyName element, null if the index is too big
 * @throws XMLSecurityException
 */
public KeyName itemKeyName(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_KEYNAME, i);

    if (e != null) {
        return new KeyName(e, this.baseURI);
    }
    return null;
}
 
Example 12
Source File: KeyInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemRetrievalMethod
 *
 * @param i
 *@return the asked RetrievalMethod element, null if the index is too big
 * @throws XMLSecurityException
 */
public RetrievalMethod itemRetrievalMethod(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_RETRIEVALMETHOD, i);

    if (e != null) {
        return new RetrievalMethod(e, this.baseURI);
    }
    return null;
}
 
Example 13
Source File: KeyInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemKeyValue
 *
 * @param i
 * @return the asked KeyValue element, null if the index is too big
 * @throws XMLSecurityException
 */
public KeyValue itemKeyValue(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_KEYVALUE, i);

    if (e != null) {
        return new KeyValue(e, this.baseURI);
    }
    return null;
}
 
Example 14
Source File: X509CertificateResolver.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method engineResolveX509Certificate
 * @inheritDoc
 * @param element
 * @param BaseURI
 * @param storage
 *
 * @throws KeyResolverException
 */
public X509Certificate engineLookupResolveX509Certificate(
    Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {

    try {
        Element[] els =
            XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509CERTIFICATE);
        if ((els == null) || (els.length == 0)) {
            Element el =
                XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_X509DATA, 0);
            if (el != null) {
                return engineLookupResolveX509Certificate(el, BaseURI, storage);
            }
            return null;
        }

        // populate Object array
        for (int i = 0; i < els.length; i++) {
            XMLX509Certificate xmlCert = new XMLX509Certificate(els[i], BaseURI);
            X509Certificate cert = xmlCert.getX509Certificate();
            if (cert != null) {
                return cert;
            }
        }
        return null;
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
        throw new KeyResolverException("generic.EmptyMessage", ex);
    }
}
 
Example 15
Source File: SignatureProperties.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the <it>i</it><sup>th</sup> SignatureProperty. Valid <code>i</code>
 * values are 0 to <code>{link@ getSize}-1</code>.
 *
 * @param i Index of the requested {@link SignatureProperty}
 * @return the <it>i</it><sup>th</sup> SignatureProperty
 * @throws XMLSignatureException
 */
public SignatureProperty item(int i) throws XMLSignatureException {
    try {
        Element propertyElem =
            XMLUtils.selectDsNode(this.constructionElement, Constants._TAG_SIGNATUREPROPERTY, i);

        if (propertyElem == null) {
            return null;
        }
        return new SignatureProperty(propertyElem, this.baseURI);
    } catch (XMLSecurityException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 16
Source File: X509CertificateResolver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method engineResolveX509Certificate
 * @inheritDoc
 * @param element
 * @param BaseURI
 * @param storage
 *
 * @throws KeyResolverException
 */
public X509Certificate engineLookupResolveX509Certificate(
    Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {

    try {
        Element[] els =
            XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509CERTIFICATE);
        if ((els == null) || (els.length == 0)) {
            Element el =
                XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_X509DATA, 0);
            if (el != null) {
                return engineLookupResolveX509Certificate(el, BaseURI, storage);
            }
            return null;
        }

        // populate Object array
        for (int i = 0; i < els.length; i++) {
            XMLX509Certificate xmlCert = new XMLX509Certificate(els[i], BaseURI);
            X509Certificate cert = xmlCert.getX509Certificate();
            if (cert != null) {
                return cert;
            }
        }
        return null;
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
        throw new KeyResolverException("generic.EmptyMessage", ex);
    }
}
 
Example 17
Source File: KeyInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemKeyName
 *
 * @param i
 * @return the asked KeyName element, null if the index is too big
 * @throws XMLSecurityException
 */
public KeyName itemKeyName(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_KEYNAME, i);

    if (e != null) {
        return new KeyName(e, this.baseURI);
    }
    return null;
}
 
Example 18
Source File: SignatureProperties.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Return the <it>i</it><sup>th</sup> SignatureProperty. Valid <code>i</code>
 * values are 0 to <code>{link@ getSize}-1</code>.
 *
 * @param i Index of the requested {@link SignatureProperty}
 * @return the <it>i</it><sup>th</sup> SignatureProperty
 * @throws XMLSignatureException
 */
public SignatureProperty item(int i) throws XMLSignatureException {
    try {
        Element propertyElem =
            XMLUtils.selectDsNode(this.constructionElement, Constants._TAG_SIGNATUREPROPERTY, i);

        if (propertyElem == null) {
            return null;
        }
        return new SignatureProperty(propertyElem, this.baseURI);
    } catch (XMLSecurityException ex) {
        throw new XMLSignatureException("empty", ex);
    }
}
 
Example 19
Source File: TransformXPath.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
 
Example 20
Source File: TransformXPath.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}