Search in sources :

Example 1 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class DSAKeyValue method getPublicKey.

/** @inheritDoc */
public PublicKey getPublicKey() throws XMLSecurityException {
    try {
        DSAPublicKeySpec pkspec = new DSAPublicKeySpec(this.getBigIntegerFromChildElement(Constants._TAG_Y, Constants.SignatureSpecNS), this.getBigIntegerFromChildElement(Constants._TAG_P, Constants.SignatureSpecNS), this.getBigIntegerFromChildElement(Constants._TAG_Q, Constants.SignatureSpecNS), this.getBigIntegerFromChildElement(Constants._TAG_G, Constants.SignatureSpecNS));
        KeyFactory dsaFactory = KeyFactory.getInstance("DSA");
        PublicKey pk = dsaFactory.generatePublic(pkspec);
        return pk;
    } catch (NoSuchAlgorithmException ex) {
        throw new XMLSecurityException("empty", ex);
    } catch (InvalidKeySpecException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
Also used : PublicKey(java.security.PublicKey) DSAPublicKey(java.security.interfaces.DSAPublicKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyFactory(java.security.KeyFactory) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) DSAPublicKeySpec(java.security.spec.DSAPublicKeySpec)

Example 2 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class RSAKeyValue method getPublicKey.

/** @inheritDoc */
public PublicKey getPublicKey() throws XMLSecurityException {
    try {
        KeyFactory rsaFactory = KeyFactory.getInstance("RSA");
        RSAPublicKeySpec rsaKeyspec = new RSAPublicKeySpec(this.getBigIntegerFromChildElement(Constants._TAG_MODULUS, Constants.SignatureSpecNS), this.getBigIntegerFromChildElement(Constants._TAG_EXPONENT, Constants.SignatureSpecNS));
        PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);
        return pk;
    } catch (NoSuchAlgorithmException ex) {
        throw new XMLSecurityException("empty", ex);
    } catch (InvalidKeySpecException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
Also used : PublicKey(java.security.PublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) RSAPublicKeySpec(java.security.spec.RSAPublicKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyFactory(java.security.KeyFactory) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 3 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class XMLX509Certificate method getX509Certificate.

/**
     * Method getX509Certificate
     *
     * @return the x509 certificate
     * @throws XMLSecurityException
     */
public X509Certificate getX509Certificate() throws XMLSecurityException {
    try {
        byte[] certbytes = this.getCertificateBytes();
        CertificateFactory certFact = CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
        X509Certificate cert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(certbytes));
        if (cert != null) {
            return cert;
        }
        return null;
    } catch (CertificateException ex) {
        throw new XMLSecurityException("empty", ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 4 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class DEREncodedKeyValue method getEncodedDER.

/**
     * Method getEncodedDER
     *
     * @return the public key
     * @throws XMLSecurityException
     */
protected byte[] getEncodedDER(PublicKey publicKey) throws XMLSecurityException {
    try {
        KeyFactory keyFactory = KeyFactory.getInstance(publicKey.getAlgorithm());
        X509EncodedKeySpec keySpec = keyFactory.getKeySpec(publicKey, X509EncodedKeySpec.class);
        return keySpec.getEncoded();
    } catch (NoSuchAlgorithmException e) {
        Object[] exArgs = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
        throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
    } catch (InvalidKeySpecException e) {
        Object[] exArgs = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
        throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
    }
}
Also used : X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyFactory(java.security.KeyFactory) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)

Example 5 with XMLSecurityException

use of com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException in project jdk8u_jdk by JetBrains.

the class X509SKIResolver method engineLookupResolveX509Certificate.

/**
     * Method engineResolveX509Certificate
     * @inheritDoc
     * @param element
     * @param baseURI
     * @param storage
     *
     * @throws KeyResolverException
     */
public X509Certificate engineLookupResolveX509Certificate(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_X509DATA)) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "I can't");
        }
        return null;
    }
    /** Field _x509childObject[] */
    XMLX509SKI[] x509childObject = null;
    Element[] x509childNodes = null;
    x509childNodes = XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509SKI);
    if (!((x509childNodes != null) && (x509childNodes.length > 0))) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "I can't");
        }
        return null;
    }
    try {
        if (storage == null) {
            Object[] exArgs = { Constants._TAG_X509SKI };
            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;
        }
        x509childObject = new XMLX509SKI[x509childNodes.length];
        for (int i = 0; i < x509childNodes.length; i++) {
            x509childObject[i] = new XMLX509SKI(x509childNodes[i], baseURI);
        }
        Iterator<Certificate> storageIterator = storage.getIterator();
        while (storageIterator.hasNext()) {
            X509Certificate cert = (X509Certificate) storageIterator.next();
            XMLX509SKI certSKI = new XMLX509SKI(element.getOwnerDocument(), cert);
            for (int i = 0; i < x509childObject.length; i++) {
                if (certSKI.equals(x509childObject[i])) {
                    if (log.isLoggable(java.util.logging.Level.FINE)) {
                        log.log(java.util.logging.Level.FINE, "Return PublicKey from " + cert.getSubjectX500Principal().getName());
                    }
                    return cert;
                }
            }
        }
    } catch (XMLSecurityException ex) {
        throw new KeyResolverException("empty", ex);
    }
    return null;
}
Also used : XMLX509SKI(com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI) Element(org.w3c.dom.Element) KeyResolverException(com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException) X509Certificate(java.security.cert.X509Certificate) XMLSecurityException(com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

XMLSecurityException (com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException)32 Element (org.w3c.dom.Element)15 IOException (java.io.IOException)11 X509Certificate (java.security.cert.X509Certificate)9 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)8 KeyResolverException (com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException)8 PublicKey (java.security.PublicKey)7 XMLSignatureInput (com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput)6 Certificate (java.security.cert.Certificate)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 SAXException (org.xml.sax.SAXException)6 InvalidCanonicalizerException (com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException)5 XMLX509Certificate (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate)5 TransformationException (com.sun.org.apache.xml.internal.security.transforms.TransformationException)5 Transforms (com.sun.org.apache.xml.internal.security.transforms.Transforms)4 InclusiveNamespaces (com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces)4 XMLX509SKI (com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI)3 UnsyncBufferedOutputStream (com.sun.org.apache.xml.internal.security.utils.UnsyncBufferedOutputStream)3 OutputStream (java.io.OutputStream)3 KeyFactory (java.security.KeyFactory)3