Search in sources :

Example 51 with CertificateException

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

the class CertificateFactoryTest method test_generateCertificate_InputStream_InvalidStart_Failure.

private void test_generateCertificate_InputStream_InvalidStart_Failure(CertificateFactory cf) throws Exception {
    try {
        Certificate c = cf.generateCertificate(new ByteArrayInputStream("-----BEGIN CERTIFICATE-----".getBytes()));
        if (!"BC".equals(cf.getProvider().getName())) {
            fail("should throw CertificateException: " + cf.getProvider().getName());
        }
        assertNull(c);
    } catch (CertificateException expected) {
        if ("BC".equals(cf.getProvider().getName())) {
            fail("should return null: " + cf.getProvider().getName());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 52 with CertificateException

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

the class CertificateFactoryTest method test_generateCertificate_InputStream_Empty.

private void test_generateCertificate_InputStream_Empty(CertificateFactory cf) throws Exception {
    try {
        Certificate c = cf.generateCertificate(new ByteArrayInputStream(new byte[0]));
        if (!"BC".equals(cf.getProvider().getName())) {
            fail("should throw CertificateException: " + cf.getProvider().getName());
        }
        assertNull(c);
    } catch (CertificateException e) {
        if ("BC".equals(cf.getProvider().getName())) {
            fail("should return null: " + cf.getProvider().getName());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 53 with CertificateException

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

the class SSLSocketTest method test_SSLSocket_untrustedServer.

public void test_SSLSocket_untrustedServer() throws Exception {
    TestSSLContext c = TestSSLContext.create(TestKeyStore.getClientCA2(), TestKeyStore.getServer());
    SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
    final SSLSocket server = (SSLSocket) c.serverSocket.accept();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<Void> future = executor.submit(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try {
                server.startHandshake();
                assertFalse(StandardNames.IS_RI);
            } catch (SSLHandshakeException expected) {
                assertTrue(StandardNames.IS_RI);
            }
            return null;
        }
    });
    executor.shutdown();
    try {
        client.startHandshake();
        fail();
    } catch (SSLHandshakeException expected) {
        assertTrue(expected.getCause() instanceof CertificateException);
    }
    client.close();
    server.close();
    future.get();
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) ExecutorService(java.util.concurrent.ExecutorService) CertificateException(java.security.cert.CertificateException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) SSLProtocolException(javax.net.ssl.SSLProtocolException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SSLException(javax.net.ssl.SSLException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 54 with CertificateException

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

the class CertificateFactory method engineGenerateCertPath.

public CertPath engineGenerateCertPath(List certificates) throws CertificateException {
    Iterator iter = certificates.iterator();
    Object obj;
    while (iter.hasNext()) {
        obj = iter.next();
        if (obj != null) {
            if (!(obj instanceof X509Certificate)) {
                throw new CertificateException("list contains non X509Certificate object while creating CertPath\n" + obj.toString());
            }
        }
    }
    return new PKIXCertPath(certificates);
}
Also used : Iterator(java.util.Iterator) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Example 55 with CertificateException

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

the class CertificateFactory method engineGenerateCertificate.

/**
     * Generates a certificate object and initializes it with the data
     * read from the input stream inStream.
     */
public java.security.cert.Certificate engineGenerateCertificate(InputStream in) throws CertificateException {
    if (currentStream == null) {
        currentStream = in;
        sData = null;
        sDataObjectCount = 0;
    } else if (// reset if input stream has changed
    currentStream != in) {
        currentStream = in;
        sData = null;
        sDataObjectCount = 0;
    }
    try {
        if (sData != null) {
            if (sDataObjectCount != sData.size()) {
                return getCertificate();
            } else {
                sData = null;
                sDataObjectCount = 0;
                return null;
            }
        }
        PushbackInputStream pis = new PushbackInputStream(in);
        int tag = pis.read();
        if (tag == -1) {
            return null;
        }
        pis.unread(tag);
        if (// assume ascii PEM encoded.
        tag != 0x30) {
            return readPEMCertificate(pis);
        } else {
            return readDERCertificate(new ASN1InputStream(pis));
        }
    } catch (Exception e) {
        throw new ExCertificateException(e);
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PushbackInputStream(java.io.PushbackInputStream) CertificateParsingException(java.security.cert.CertificateParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CRLException(java.security.cert.CRLException)

Aggregations

CertificateException (java.security.cert.CertificateException)456 IOException (java.io.IOException)221 X509Certificate (java.security.cert.X509Certificate)215 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)141 KeyStoreException (java.security.KeyStoreException)123 CertificateFactory (java.security.cert.CertificateFactory)103 ByteArrayInputStream (java.io.ByteArrayInputStream)97 Certificate (java.security.cert.Certificate)75 KeyStore (java.security.KeyStore)58 InputStream (java.io.InputStream)55 UnrecoverableKeyException (java.security.UnrecoverableKeyException)53 ArrayList (java.util.ArrayList)49 InvalidKeyException (java.security.InvalidKeyException)44 X509TrustManager (javax.net.ssl.X509TrustManager)41 SSLContext (javax.net.ssl.SSLContext)36 FileInputStream (java.io.FileInputStream)34 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)34 RemoteException (android.os.RemoteException)33 FileNotFoundException (java.io.FileNotFoundException)30 KeyManagementException (java.security.KeyManagementException)30