Search in sources :

Example 11 with CertificateException

use of javax.security.cert.CertificateException in project j2objc by google.

the class X509CertificateTest method testGetInstance2.

/**
     * getInstance(byte[] certData) method testing.
     * @throws CertificateEncodingException
     * @throws java.security.cert.CertificateEncodingException
     */
public void testGetInstance2() throws java.security.cert.CertificateEncodingException, CertificateEncodingException {
    boolean certificateException = false;
    X509Certificate c = null;
    if (this.cert == null) {
        // Test can not be applied.
        return;
    }
    try {
        c = X509Certificate.getInstance(cert.getEncoded());
    } catch (java.security.cert.CertificateEncodingException e) {
        fail("Unexpected CertificateEncodingException was thrown.");
    } catch (CertificateException e) {
        // The requested certificate type is not available.
        // Test pass..
        certificateException = true;
    }
    if (!certificateException) {
        assertNotNull(c);
        assertTrue(Arrays.equals(c.getEncoded(), cert.getEncoded()));
    }
    try {
        X509Certificate.getInstance(new byte[] { (byte) 1 });
    } catch (CertificateException e) {
    //ok
    }
    // Regression for HARMONY-756
    try {
        X509Certificate.getInstance((byte[]) null);
        fail("No expected CertificateException");
    } catch (CertificateException e) {
    // expected;
    }
}
Also used : CertificateException(javax.security.cert.CertificateException) X509Certificate(javax.security.cert.X509Certificate)

Example 12 with CertificateException

use of javax.security.cert.CertificateException in project robovm by robovm.

the class OpenSSLSessionImpl method createPeerCertificateChain.

/**
     * Provide a value to initialize the volatile peerCertificateChain
     * field based on the native SSL_SESSION
     */
private javax.security.cert.X509Certificate[] createPeerCertificateChain() throws SSLPeerUnverifiedException {
    try {
        javax.security.cert.X509Certificate[] chain = new javax.security.cert.X509Certificate[peerCertificates.length];
        for (int i = 0; i < peerCertificates.length; i++) {
            byte[] encoded = peerCertificates[i].getEncoded();
            chain[i] = javax.security.cert.X509Certificate.getInstance(encoded);
        }
        return chain;
    } catch (CertificateEncodingException e) {
        SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage());
        exception.initCause(exception);
        throw exception;
    } catch (CertificateException e) {
        SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage());
        exception.initCause(exception);
        throw exception;
    }
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) CertificateEncodingException(java.security.cert.CertificateEncodingException) CertificateException(javax.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Example 13 with CertificateException

use of javax.security.cert.CertificateException in project robovm by robovm.

the class X509CertificateTest method testGetInstance2.

/**
     * getInstance(byte[] certData) method testing.
     * @throws CertificateEncodingException
     * @throws java.security.cert.CertificateEncodingException
     */
public void testGetInstance2() throws java.security.cert.CertificateEncodingException, CertificateEncodingException {
    boolean certificateException = false;
    X509Certificate c = null;
    if (this.cert == null) {
        // Test can not be applied.
        return;
    }
    try {
        c = X509Certificate.getInstance(cert.getEncoded());
    } catch (java.security.cert.CertificateEncodingException e) {
        fail("Unexpected CertificateEncodingException was thrown.");
    } catch (CertificateException e) {
        // The requested certificate type is not available.
        // Test pass..
        certificateException = true;
    }
    if (!certificateException) {
        assertNotNull(c);
        assertTrue(Arrays.equals(c.getEncoded(), cert.getEncoded()));
    }
    try {
        X509Certificate.getInstance(new byte[] { (byte) 1 });
    } catch (CertificateException e) {
    //ok
    }
    // Regression for HARMONY-756
    try {
        X509Certificate.getInstance((byte[]) null);
        fail("No expected CertificateException");
    } catch (CertificateException e) {
    // expected;
    }
}
Also used : CertificateException(javax.security.cert.CertificateException) X509Certificate(javax.security.cert.X509Certificate)

Example 14 with CertificateException

use of javax.security.cert.CertificateException in project robovm by robovm.

the class X509CertificateTest method testGetInstance1.

/**
     * getInstance(InputStream inStream) method testing.
     */
public void testGetInstance1() {
    if (this.cert == null) {
        // Test can not be applied.
        return;
    }
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(cert.getEncoded());
        X509Certificate.getInstance(bais);
    } catch (java.security.cert.CertificateEncodingException e) {
        fail("Unexpected CertificateEncodingException was thrown.");
    } catch (CertificateEncodingException e) {
        fail("Unexpected CertificateEncodingException was thrown.");
    } catch (CertificateException e) {
    // The requested certificate type is not available.
    // Test pass..
    }
    // Regression for HARMONY-756
    try {
        X509Certificate.getInstance((InputStream) null);
        fail("No expected CertificateException");
    } catch (CertificateException e) {
    // expected;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateEncodingException(javax.security.cert.CertificateEncodingException) CertificateException(javax.security.cert.CertificateException)

Example 15 with CertificateException

use of javax.security.cert.CertificateException in project undertow by undertow-io.

the class SSLHeaderHandler method handleRequest.

@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    HeaderMap requestHeaders = exchange.getRequestHeaders();
    final String sessionId = requestHeaders.getFirst(SSL_SESSION_ID);
    final String cipher = requestHeaders.getFirst(SSL_CIPHER);
    String clientCert = requestHeaders.getFirst(SSL_CLIENT_CERT);
    //the proxy client replaces \n with ' '
    if (clientCert != null && clientCert.length() > 28) {
        StringBuilder sb = new StringBuilder(clientCert.length() + 1);
        sb.append(Certificates.BEGIN_CERT);
        sb.append('\n');
        //core certificate data
        sb.append(clientCert.replace(' ', '\n').substring(28, clientCert.length() - 26));
        sb.append('\n');
        sb.append(Certificates.END_CERT);
        clientCert = sb.toString();
    }
    if (clientCert != null || sessionId != null || cipher != null) {
        try {
            SSLSessionInfo info = new BasicSSLSessionInfo(sessionId, cipher, clientCert);
            exchange.setRequestScheme(HTTPS);
            exchange.getConnection().setSslSessionInfo(info);
            exchange.addExchangeCompleteListener(CLEAR_SSL_LISTENER);
        } catch (java.security.cert.CertificateException | CertificateException e) {
            UndertowLogger.REQUEST_LOGGER.debugf(e, "Could not create certificate from header %s", clientCert);
        }
    }
    next.handleRequest(exchange);
}
Also used : HeaderMap(io.undertow.util.HeaderMap) BasicSSLSessionInfo(io.undertow.server.BasicSSLSessionInfo) SSLSessionInfo(io.undertow.server.SSLSessionInfo) BasicSSLSessionInfo(io.undertow.server.BasicSSLSessionInfo) CertificateException(javax.security.cert.CertificateException)

Aggregations

CertificateException (javax.security.cert.CertificateException)17 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 X509Certificate (java.security.cert.X509Certificate)3 CertificateEncodingException (javax.security.cert.CertificateEncodingException)3 X509Certificate (javax.security.cert.X509Certificate)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 PublicKey (java.security.PublicKey)2 LinkedHashMap (java.util.LinkedHashMap)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 SideEffect (dalvik.annotation.SideEffect)1 TpmModuleException (gov.niarl.his.privacyca.TpmModule.TpmModuleException)1 IHisPrivacyCAWebService2 (gov.niarl.his.webservices.hisPrivacyCAWebService2.IHisPrivacyCAWebService2)1 BasicSSLSessionInfo (io.undertow.server.BasicSSLSessionInfo)1