com.sun.org.apache.xml.internal.security.utils.Constants Java Examples

The following examples show how to use com.sun.org.apache.xml.internal.security.utils.Constants. 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: TransformEnvelopedSignature.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param signatureElement
 * @return the node that is the signature
 * @throws TransformationException
 */
private static Node searchSignatureElement(Node signatureElement)
    throws TransformationException {
    boolean found = false;

    while (true) {
        if (signatureElement == null
            || signatureElement.getNodeType() == Node.DOCUMENT_NODE) {
            break;
        }
        Element el = (Element) signatureElement;
        if (el.getNamespaceURI().equals(Constants.SignatureSpecNS)
            && el.getLocalName().equals(Constants._TAG_SIGNATURE)) {
            found = true;
            break;
        }

        signatureElement = signatureElement.getParentNode();
    }

    if (!found) {
        throw new TransformationException(
            "transform.envelopedSignatureTransformNotInSignatureElement");
    }
    return signatureElement;
}
 
Example #2
Source File: KeyInfo.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Method lengthUnknownElement
 * NOTE possibly buggy.
 * @return the number of the UnknownElement tags
 */
public int lengthUnknownElement() {
    int res = 0;
    NodeList nl = this.constructionElement.getChildNodes();

    for (int i = 0; i < nl.getLength(); i++) {
        Node current = nl.item(i);

        /**
         * $todo$ using this method, we don't see unknown Elements
         *  from Signature NS; revisit
         */
        if ((current.getNodeType() == Node.ELEMENT_NODE)
            && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
            res++;
        }
    }

    return res;
}
 
Example #3
Source File: X509Data.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor X509Data
 *
 * @param element
 * @param baseURI
 * @throws XMLSecurityException
 */
public X509Data(Element element, String baseURI) throws XMLSecurityException {
    super(element, baseURI);

    Node sibling = this.constructionElement.getFirstChild();
    while (sibling != null) {
        if (sibling.getNodeType() != Node.ELEMENT_NODE) {
            sibling = sibling.getNextSibling();
            continue;
        }
        return;
    }
    /* No Elements found */
    Object exArgs[] = { "Elements", Constants._TAG_X509DATA };
    throw new XMLSecurityException("xml.WrongContent", exArgs);
}
 
Example #4
Source File: SecretKeyResolver.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolveSecretKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
 *
 * @throws KeyResolverException
 */
public SecretKey engineResolveSecretKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String keyName = element.getFirstChild().getNodeValue();
        try {
            Key key = keyStore.getKey(keyName, password);
            if (key instanceof SecretKey) {
                return (SecretKey) key;
            }
        } catch (Exception e) {
            log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #5
Source File: SingleKeyResolver.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolveSecretKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
 *
 * @throws KeyResolverException
 */
public SecretKey engineResolveSecretKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (secretKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return secretKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #6
Source File: Reference.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
 * @return the XMLSignatureInput of the source of this reference
 * @throws ReferenceNotInitializedException If the resolver found any
 * problem resolving the reference
 */
public XMLSignatureInput getContentsBeforeTransformation()
    throws ReferenceNotInitializedException {
    try {
        Attr uriAttr =
            this.constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);

        ResourceResolver resolver =
            ResourceResolver.getInstance(
                uriAttr, this.baseURI, this.manifest.getPerManifestResolvers(), secureValidation
            );
        resolver.addProperties(this.manifest.getResolverProperties());

        return resolver.resolve(uriAttr, this.baseURI, secureValidation);
    }  catch (ResourceResolverException ex) {
        throw new ReferenceNotInitializedException("empty", ex);
    }
}
 
Example #7
Source File: KeyInfo.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method lengthUnknownElement
 * NOTE possibly buggy.
 * @return the number of the UnknownElement tags
 */
public int lengthUnknownElement() {
    int res = 0;
    NodeList nl = this.constructionElement.getChildNodes();

    for (int i = 0; i < nl.getLength(); i++) {
        Node current = nl.item(i);

        /**
         * $todo$ using this method, we don't see unknown Elements
         *  from Signature NS; revisit
         */
        if ((current.getNodeType() == Node.ELEMENT_NODE)
            && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
            res++;
        }
    }

    return res;
}
 
Example #8
Source File: SingleKeyResolver.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineResolveSecretKey
 *
 * @param element
 * @param baseURI
 * @param storage
 * @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
 *
 * @throws KeyResolverException
 */
public SecretKey engineResolveSecretKey(
    Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
    }

    if (secretKey != null
        && XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
        String name = element.getFirstChild().getNodeValue();
        if (keyName.equals(name)) {
            return secretKey;
        }
    }

    log.log(java.util.logging.Level.FINE, "I can't");
    return null;
}
 
Example #9
Source File: SignedInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor SignedInfo
 *
 * @param doc <code>SignedInfo</code> is placed in this document
 * @param signatureMethodURI URI representation of the Digest and
 *    Signature algorithm
 * @param hMACOutputLength
 * @param canonicalizationMethodURI URI representation of the
 *    Canonicalization method
 * @throws XMLSecurityException
 */
public SignedInfo(
    Document doc, String signatureMethodURI,
    int hMACOutputLength, String canonicalizationMethodURI
) throws XMLSecurityException {
    super(doc);

    c14nMethod =
        XMLUtils.createElementInSignatureSpace(this.doc, Constants._TAG_CANONICALIZATIONMETHOD);

    c14nMethod.setAttributeNS(null, Constants._ATT_ALGORITHM, canonicalizationMethodURI);
    this.constructionElement.appendChild(c14nMethod);
    XMLUtils.addReturnToElement(this.constructionElement);

    if (hMACOutputLength > 0) {
        this.signatureAlgorithm =
            new SignatureAlgorithm(this.doc, signatureMethodURI, hMACOutputLength);
    } else {
        this.signatureAlgorithm = new SignatureAlgorithm(this.doc, signatureMethodURI);
    }

    signatureMethod = this.signatureAlgorithm.getElement();
    this.constructionElement.appendChild(signatureMethod);
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example #10
Source File: X509Data.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor X509Data
 *
 * @param element
 * @param baseURI
 * @throws XMLSecurityException
 */
public X509Data(Element element, String baseURI) throws XMLSecurityException {
    super(element, baseURI);

    Node sibling = this.constructionElement.getFirstChild();
    while (sibling != null) {
        if (sibling.getNodeType() != Node.ELEMENT_NODE) {
            sibling = sibling.getNextSibling();
            continue;
        }
        return;
    }
    /* No Elements found */
    Object exArgs[] = { "Elements", Constants._TAG_X509DATA };
    throw new XMLSecurityException("xml.WrongContent", exArgs);
}
 
Example #11
Source File: IntegrityHmac.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Method engineAddContextToElement
 *
 * @param element
 */
public void engineAddContextToElement(Element element) {
    if (element == null) {
        throw new IllegalArgumentException("null element");
    }

    if (this.HMACOutputLengthSet) {
        Document doc = element.getOwnerDocument();
        Element HMElem =
            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
        Text HMText =
            doc.createTextNode(Integer.valueOf(this.HMACOutputLength).toString());

        HMElem.appendChild(HMText);
        XMLUtils.addReturnToElement(element);
        element.appendChild(HMElem);
        XMLUtils.addReturnToElement(element);
    }
}
 
Example #12
Source File: SignedInfo.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public String getInclusiveNamespaces() {
    String c14nMethodURI = c14nMethod.getAttributeNS(null, Constants._ATT_ALGORITHM);
    if (!(c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#") ||
        c14nMethodURI.equals("http://www.w3.org/2001/10/xml-exc-c14n#WithComments"))) {
        return null;
    }

    Element inclusiveElement = XMLUtils.getNextElement(c14nMethod.getFirstChild());

    if (inclusiveElement != null) {
        try {
            String inclusiveNamespaces =
                new InclusiveNamespaces(
                    inclusiveElement,
                    InclusiveNamespaces.ExclusiveCanonicalizationNamespace
                ).getInclusiveNamespaces();
            return inclusiveNamespaces;
        } catch (XMLSecurityException e) {
            return null;
        }
    }
    return null;
}
 
Example #13
Source File: Algorithm.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the algorithm's URI as used in the signature.
 *
 * @param algorithmURI is the URI of the algorithm as String
 */
protected void setAlgorithmURI(String algorithmURI) {
    if (algorithmURI != null) {
        this.constructionElement.setAttributeNS(
            null, Constants._ATT_ALGORITHM, algorithmURI
        );
    }
}
 
Example #14
Source File: XMLX509IssuerSerial.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getSerialNumber
 *
 * @return the serial number
 */
public BigInteger getSerialNumber() {
    String text =
        this.getTextFromChildElement(Constants._TAG_X509SERIALNUMBER, Constants.SignatureSpecNS);
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "X509SerialNumber text: " + text);
    }

    return new BigInteger(text);
}
 
Example #15
Source File: KeyInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemMgmtData
 *
 * @param i
 * @return the asked MgmtData element, null if the index is too big
 * @throws XMLSecurityException
 */
public MgmtData itemMgmtData(int i) throws XMLSecurityException {
    Element e =
        XMLUtils.selectDsNode(
            this.constructionElement.getFirstChild(), Constants._TAG_MGMTDATA, i);

    if (e != null) {
        return new MgmtData(e, this.baseURI);
    }
    return null;
}
 
Example #16
Source File: X509CertificateResolver.java    From JDKSourceCode1.8 with MIT License 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: X509Data.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method itemCRL
 *
 * @param i
 * @return the X509CRL, null if not present
 * @throws XMLSecurityException
 */
public XMLX509CRL itemCRL(int i) throws XMLSecurityException {

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

    if (e != null) {
        return new XMLX509CRL(e, this.baseURI);
    }
    return null;
}
 
Example #18
Source File: XMLSignature.java    From openjdk-jdk9 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 #19
Source File: X509DigestResolver.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method checkSrorage
 *
 * @param storage
 * @throws KeyResolverException
 */
private void checkStorage(StorageResolver storage) throws KeyResolverException {
    if (storage == null) {
        Object exArgs[] = { Constants._TAG_X509DIGEST };
        KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "", ex);
        }
        throw ex;
    }
}
 
Example #20
Source File: X509CertificateResolver.java    From openjdk-jdk8u-backup 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 #21
Source File: XMLSignature.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor XMLSignature
 *
 * @param doc
 * @param baseURI
 * @param signatureMethodURI
 * @param hmacOutputLength
 * @param canonicalizationMethodURI
 * @throws XMLSecurityException
 */
public XMLSignature(
    Document doc,
    String baseURI,
    String signatureMethodURI,
    int hmacOutputLength,
    String canonicalizationMethodURI
) throws XMLSecurityException {
    super(doc);

    String xmlnsDsPrefix = getDefaultPrefix(Constants.SignatureSpecNS);
    if (xmlnsDsPrefix == null || xmlnsDsPrefix.length() == 0) {
        this.constructionElement.setAttributeNS(
            Constants.NamespaceSpecNS, "xmlns", Constants.SignatureSpecNS
        );
    } else {
        this.constructionElement.setAttributeNS(
            Constants.NamespaceSpecNS, "xmlns:" + xmlnsDsPrefix, Constants.SignatureSpecNS
        );
    }
    XMLUtils.addReturnToElement(this.constructionElement);

    this.baseURI = baseURI;
    this.signedInfo =
        new SignedInfo(
            this.doc, signatureMethodURI, hmacOutputLength, canonicalizationMethodURI
        );

    this.constructionElement.appendChild(this.signedInfo.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);

    // create an empty SignatureValue; this is filled by setSignatureValueElement
    signatureValueElement =
        XMLUtils.createElementInSignatureSpace(this.doc, Constants._TAG_SIGNATUREVALUE);

    this.constructionElement.appendChild(signatureValueElement);
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example #22
Source File: ObjectContainer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the <code>Id</code> attribute
 *
 * @param Id <code>Id</code> attribute
 */
public void setId(String Id) {
    if (Id != null) {
        this.constructionElement.setAttributeNS(null, Constants._ATT_ID, Id);
        this.constructionElement.setIdAttributeNS(null, Constants._ATT_ID, true);
    }
}
 
Example #23
Source File: X509CertificateResolver.java    From jdk8u60 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 #24
Source File: Manifest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the <code>Id</code> attribute
 *
 * @param Id the <code>Id</code> attribute in <code>ds:Manifest</code>
 */
public void setId(String Id) {
    if (Id != null) {
        this.constructionElement.setAttributeNS(null, Constants._ATT_ID, Id);
        this.constructionElement.setIdAttributeNS(null, Constants._ATT_ID, true);
    }
}
 
Example #25
Source File: XMLSignature.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor XMLSignature
 *
 * @param doc
 * @param baseURI
 * @param signatureMethodURI
 * @param hmacOutputLength
 * @param canonicalizationMethodURI
 * @throws XMLSecurityException
 */
public XMLSignature(
    Document doc,
    String baseURI,
    String signatureMethodURI,
    int hmacOutputLength,
    String canonicalizationMethodURI
) throws XMLSecurityException {
    super(doc);

    String xmlnsDsPrefix = getDefaultPrefix(Constants.SignatureSpecNS);
    if (xmlnsDsPrefix == null || xmlnsDsPrefix.length() == 0) {
        this.constructionElement.setAttributeNS(
            Constants.NamespaceSpecNS, "xmlns", Constants.SignatureSpecNS
        );
    } else {
        this.constructionElement.setAttributeNS(
            Constants.NamespaceSpecNS, "xmlns:" + xmlnsDsPrefix, Constants.SignatureSpecNS
        );
    }
    XMLUtils.addReturnToElement(this.constructionElement);

    this.baseURI = baseURI;
    this.signedInfo =
        new SignedInfo(
            this.doc, signatureMethodURI, hmacOutputLength, canonicalizationMethodURI
        );

    this.constructionElement.appendChild(this.signedInfo.getElement());
    XMLUtils.addReturnToElement(this.constructionElement);

    // create an empty SignatureValue; this is filled by setSignatureValueElement
    signatureValueElement =
        XMLUtils.createElementInSignatureSpace(this.doc, Constants._TAG_SIGNATUREVALUE);

    this.constructionElement.appendChild(signatureValueElement);
    XMLUtils.addReturnToElement(this.constructionElement);
}
 
Example #26
Source File: RSAKeyValueResolver.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
    Element element, String BaseURI, StorageResolver storage
) {
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
    }
    if (element == null) {
        return null;
    }

    boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
    Element rsaKeyElement = null;
    if (isKeyValue) {
        rsaKeyElement =
            XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
    } else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RSAKEYVALUE)) {
        // this trick is needed to allow the RetrievalMethodResolver to eat a
        // ds:RSAKeyValue directly (without KeyValue)
        rsaKeyElement = element;
    }

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

    try {
        RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement, BaseURI);

        return rsaKeyValue.getPublicKey();
    } catch (XMLSecurityException ex) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
        }
    }

    return null;
}
 
Example #27
Source File: X509Data.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Method itemCRL
 *
 * @param i
 * @return the X509CRL, null if not present
 * @throws XMLSecurityException
 */
public XMLX509CRL itemCRL(int i) throws XMLSecurityException {

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

    if (e != null) {
        return new XMLX509CRL(e, this.baseURI);
    }
    return null;
}
 
Example #28
Source File: Transforms.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs {@link Transforms} from {@link Element} which is
 * <code>Transforms</code> Element
 *
 * @param element  is <code>Transforms</code> element
 * @param BaseURI the URI where the XML instance was stored
 * @throws DOMException
 * @throws InvalidTransformException
 * @throws TransformationException
 * @throws XMLSecurityException
 * @throws XMLSignatureException
 */
public Transforms(Element element, String BaseURI)
    throws DOMException, XMLSignatureException, InvalidTransformException,
        TransformationException, XMLSecurityException {
    super(element, BaseURI);

    int numberOfTransformElems = this.getLength();

    if (numberOfTransformElems == 0) {
        // At least one Transform element must be present. Bad.
        Object exArgs[] = { Constants._TAG_TRANSFORM, Constants._TAG_TRANSFORMS };

        throw new TransformationException("xml.WrongContent", exArgs);
    }
}
 
Example #29
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 #30
Source File: XMLX509IssuerSerial.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method getSerialNumber
 *
 * @return the serial number
 */
public BigInteger getSerialNumber() {
    String text =
        this.getTextFromChildElement(Constants._TAG_X509SERIALNUMBER, Constants.SignatureSpecNS);
    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "X509SerialNumber text: " + text);
    }

    return new BigInteger(text);
}