Search in sources :

Example 71 with SSLHandshakeException

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

the class HandshakeIODataStream method append.

private void append(byte[] src, int from, int length) {
    if (read_pos == read_pos_end) {
        // start reading state after writing
        if (write_pos_beg != write_pos) {
            // but inbound handshake data has been received.
            throw new AlertException(AlertProtocol.UNEXPECTED_MESSAGE, new SSLHandshakeException("Handshake message has been received before " + "the last oubound message had been sent."));
        }
        if (read_pos < write_pos) {
            read_pos = write_pos;
            read_pos_end = read_pos;
        }
    }
    if (read_pos_end + length > buff_size) {
        enlargeBuffer(read_pos_end + length - buff_size);
    }
    System.arraycopy(src, from, buffer, read_pos_end, length);
    read_pos_end += length;
}
Also used : SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 72 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method getLatestVersionInfo.

protected AddOnCollection getLatestVersionInfo(final CheckForUpdateCallback callback) {
    if (latestVersionInfo == null) {
        if (this.remoteCallThread == null || !this.remoteCallThread.isAlive()) {
            this.remoteCallThread = new Thread() {

                @Override
                public void run() {
                    // Using a thread as the first call could timeout
                    // and we dont want the ui to hang in the meantime
                    this.setName("ZAP-cfu");
                    String shortUrl;
                    String longUrl;
                    if (Constant.isDevBuild()) {
                        shortUrl = ZAP_VERSIONS_DEV_XML_SHORT;
                        longUrl = ZAP_VERSIONS_DEV_XML_FULL;
                    } else if (Constant.isDailyBuild()) {
                        shortUrl = ZAP_VERSIONS_WEEKLY_XML_SHORT;
                        longUrl = ZAP_VERSIONS_DEV_XML_FULL;
                    } else {
                        shortUrl = ZAP_VERSIONS_REL_XML_SHORT;
                        longUrl = ZAP_VERSIONS_REL_XML_FULL;
                    }
                    logger.debug("Getting latest version info from " + shortUrl);
                    try {
                        latestVersionInfo = new AddOnCollection(getRemoteConfigurationUrl(shortUrl), getPlatform(), false);
                    } catch (Exception e1) {
                        logger.debug("Failed to access " + shortUrl, e1);
                        logger.debug("Getting latest version info from " + longUrl);
                        try {
                            latestVersionInfo = new AddOnCollection(getRemoteConfigurationUrl(longUrl), getPlatform(), false);
                        } catch (SSLHandshakeException e2) {
                            if (callback != null) {
                                callback.insecureUrl(longUrl, e2);
                            }
                        } catch (InvalidCfuUrlException e2) {
                            if (callback != null) {
                                callback.insecureUrl(longUrl, e2);
                            }
                        } catch (Exception e2) {
                            logger.debug("Failed to access " + longUrl, e2);
                        }
                    }
                    if (callback != null && latestVersionInfo != null) {
                        logger.debug("Calling callback with  " + latestVersionInfo);
                        callback.gotLatestData(latestVersionInfo);
                    }
                    logger.debug("Done");
                }
            };
            this.remoteCallThread.start();
        }
        if (callback == null) {
            // Synchronous, but include a 30 sec max anyway
            int i = 0;
            while (latestVersionInfo == null && this.remoteCallThread.isAlive() && i < 30) {
                try {
                    Thread.sleep(1000);
                    i++;
                } catch (InterruptedException e) {
                // Ignore
                }
            }
        }
    }
    return latestVersionInfo;
}
Also used : AddOnCollection(org.zaproxy.zap.control.AddOnCollection) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 73 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project GNS by MobilityFirst.

the class AuthTestClient method testIt.

private void testIt(String jksFile) {
    try {
        String https_url = "https://localhost:24803/";
        URL url;
        url = new URL(https_url);
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
        conn.setSSLSocketFactory(getSSLFactory(jksFile));
        conn.setRequestMethod("GET");
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        try (BufferedReader bir = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
            String line;
            while ((line = bir.readLine()) != null) {
                System.out.println(line);
            }
        }
        conn.disconnect();
    } catch (SSLHandshakeException | SocketException e) {
        System.out.println(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SocketException(java.net.SocketException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SocketException(java.net.SocketException)

Example 74 with SSLHandshakeException

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

the class SSLSocketTest method test_SSLSocket_clientAuth_bogusAlias.

public void test_SSLSocket_clientAuth_bogusAlias() throws Exception {
    TestSSLContext c = TestSSLContext.create();
    SSLContext clientContext = SSLContext.getInstance("TLS");
    X509KeyManager keyManager = new X509KeyManager() {

        @Override
        public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
            return "bogus";
        }

        @Override
        public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
            throw new AssertionError();
        }

        @Override
        public X509Certificate[] getCertificateChain(String alias) {
            // return null for "bogus" alias
            return null;
        }

        @Override
        public String[] getClientAliases(String keyType, Principal[] issuers) {
            throw new AssertionError();
        }

        @Override
        public String[] getServerAliases(String keyType, Principal[] issuers) {
            throw new AssertionError();
        }

        @Override
        public PrivateKey getPrivateKey(String alias) {
            // return null for "bogus" alias
            return null;
        }
    };
    clientContext.init(new KeyManager[] { keyManager }, new TrustManager[] { c.clientTrustManager }, null);
    SSLSocket client = (SSLSocket) 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.setNeedClientAuth(true);
                server.startHandshake();
                fail();
            } catch (SSLHandshakeException expected) {
            }
            return null;
        }
    });
    executor.shutdown();
    try {
        client.startHandshake();
        fail();
    } catch (SSLHandshakeException expected) {
    // before we would get a NullPointerException from passing
    // due to the null PrivateKey return by the X509KeyManager.
    }
    future.get();
    client.close();
    server.close();
    c.close();
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) 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) X509KeyManager(javax.net.ssl.X509KeyManager) ExecutorService(java.util.concurrent.ExecutorService) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) ServerSocket(java.net.ServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 75 with SSLHandshakeException

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

the class SSLHandshakeExceptionTest method test_Constructor01.

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

Aggregations

SSLHandshakeException (javax.net.ssl.SSLHandshakeException)90 IOException (java.io.IOException)29 Test (org.junit.Test)22 CertificateException (java.security.cert.CertificateException)18 URL (java.net.URL)15 SSLException (javax.net.ssl.SSLException)15 SocketException (java.net.SocketException)13 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)12 SSLProtocolException (javax.net.ssl.SSLProtocolException)10 Socket (java.net.Socket)9 SSLSocket (javax.net.ssl.SSLSocket)9 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)8 SocketTimeoutException (java.net.SocketTimeoutException)7 SSLSession (javax.net.ssl.SSLSession)7 InputStream (java.io.InputStream)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 Channel (io.netty.channel.Channel)5 InetSocketAddress (java.net.InetSocketAddress)5 MalformedURLException (java.net.MalformedURLException)5 ClosedChannelException (java.nio.channels.ClosedChannelException)5