Search in sources :

Example 71 with SSLPeerUnverifiedException

use of javax.net.ssl.SSLPeerUnverifiedException in project XobotOS by xamarin.

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 72 with SSLPeerUnverifiedException

use of javax.net.ssl.SSLPeerUnverifiedException in project Asqatasun by Asqatasun.

the class DownloaderImpl method download.

private String download(String url) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    httpclient.getParams().setParameter("http.socket.timeout", Integer.valueOf(10000));
    httpclient.getParams().setParameter("http.connection.timeout", Integer.valueOf(10000));
    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody;
    try {
        responseBody = httpclient.execute(httpget, responseHandler);
    } catch (HttpResponseException ex) {
        LOGGER.warn(ex.getMessage() + " " + url);
        return "";
    } catch (UnknownHostException ex) {
        LOGGER.warn(ex.getMessage() + " " + url);
        return "";
    } catch (SSLPeerUnverifiedException ex) {
        LOGGER.warn(ex.getMessage() + " " + url);
        return "";
    } catch (IOException ex) {
        LOGGER.warn(ex.getMessage() + " " + url);
        return "";
    }
    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
    return responseBody;
}
Also used : UnknownHostException(java.net.UnknownHostException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 73 with SSLPeerUnverifiedException

use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.

the class SSLSocketTest method test_SSLSocket_startHandshake.

public void test_SSLSocket_startHandshake() throws Exception {
    final TestSSLContext c = TestSSLContext.create();
    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 {
            server.startHandshake();
            assertNotNull(server.getSession());
            try {
                server.getSession().getPeerCertificates();
                fail();
            } catch (SSLPeerUnverifiedException expected) {
            }
            Certificate[] localCertificates = server.getSession().getLocalCertificates();
            assertNotNull(localCertificates);
            TestKeyStore.assertChainLength(localCertificates);
            assertNotNull(localCertificates[0]);
            TestSSLContext.assertServerCertificateChain(c.serverTrustManager, localCertificates);
            TestSSLContext.assertCertificateInKeyStore(localCertificates[0], c.serverKeyStore);
            return null;
        }
    });
    executor.shutdown();
    client.startHandshake();
    assertNotNull(client.getSession());
    assertNull(client.getSession().getLocalCertificates());
    Certificate[] peerCertificates = client.getSession().getPeerCertificates();
    assertNotNull(peerCertificates);
    TestKeyStore.assertChainLength(peerCertificates);
    assertNotNull(peerCertificates[0]);
    TestSSLContext.assertServerCertificateChain(c.clientTrustManager, peerCertificates);
    TestSSLContext.assertCertificateInKeyStore(peerCertificates[0], c.serverKeyStore);
    future.get();
    client.close();
    server.close();
    c.close();
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) ExecutorService(java.util.concurrent.ExecutorService) 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) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 74 with SSLPeerUnverifiedException

use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.

the class SSLPeerUnverifiedExceptionTest method test_Constructor01.

/**
     * Test for <code>SSLPeerUnverifiedException(String)</code> constructor Assertion:
     * constructs SSLPeerUnverifiedException with detail message msg. Parameter
     * <code>msg</code> is not null.
     */
public void test_Constructor01() {
    SSLPeerUnverifiedException sslE;
    for (int i = 0; i < msgs.length; i++) {
        sslE = new SSLPeerUnverifiedException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), sslE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", sslE.getCause());
    }
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Example 75 with SSLPeerUnverifiedException

use of javax.net.ssl.SSLPeerUnverifiedException 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)

Aggregations

SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)112 X509Certificate (java.security.cert.X509Certificate)40 Certificate (java.security.cert.Certificate)39 SSLSession (javax.net.ssl.SSLSession)27 SSLSocket (javax.net.ssl.SSLSocket)23 IOException (java.io.IOException)21 SSLException (javax.net.ssl.SSLException)15 CertificateException (java.security.cert.CertificateException)14 X509Certificate (javax.security.cert.X509Certificate)12 Principal (java.security.Principal)11 Test (org.junit.jupiter.api.Test)11 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)10 InetSocketAddress (java.net.InetSocketAddress)8 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)8 Test (org.junit.Test)8 UnknownHostException (java.net.UnknownHostException)7 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)6 SSLProtocolException (javax.net.ssl.SSLProtocolException)6 MockResponse (mockwebserver3.MockResponse)6