Search in sources :

Example 1 with SSLKeyException

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

the class SSLKeyExceptionTest method test_Constructor01.

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

Example 2 with SSLKeyException

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

the class SSLKeyExceptionTest method test_Constructor02.

/**
     * Test for <code>SSLPeerUnverifiedException(String)</code> constructor Assertion:
     * constructs SSLPeerUnverifiedException with detail message msg. Parameter
     * <code>msg</code> is null.
     */
public void test_Constructor02() {
    String msg = null;
    SSLKeyException skE = new SSLKeyException(msg);
    assertNull("getMessage() must return null.", skE.getMessage());
    assertNull("getCause() must return null", skE.getCause());
}
Also used : SSLKeyException(javax.net.ssl.SSLKeyException)

Example 3 with SSLKeyException

use of javax.net.ssl.SSLKeyException in project fabric8 by fabric8io.

the class KubernetesHelper method isServiceSsl.

public static boolean isServiceSsl(String host, int port, boolean trustAllCerts) {
    try {
        LOG.info("Checking if a service is SSL on " + host + ":" + port);
        SSLSocketFactory sslsocketfactory;
        if (trustAllCerts) {
            sslsocketfactory = TrustEverythingSSLTrustManager.getTrustingSSLSocketFactory();
        } else {
            sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        }
        Socket socket = sslsocketfactory.createSocket();
        // Connect, with an explicit timeout value
        socket.connect(new InetSocketAddress(host, port), 1 * 1000);
        try {
            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();
            // Write a test byte to get a reaction :)
            out.write(1);
            while (in.available() > 0) {
                System.out.print(in.read());
            }
            return true;
        } finally {
            LOG.info("Checked if a service is SSL on " + host + ":" + port);
            socket.close();
        }
    } catch (SSLHandshakeException e) {
        LOG.error("SSL handshake failed - this probably means that you need to trust the kubernetes root SSL certificate or set the environment variable " + Utils.convertSystemPropertyNameToEnvVar(io.fabric8.kubernetes.client.Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY), e);
    } catch (SSLProtocolException e) {
        LOG.error("SSL protocol error", e);
    } catch (SSLKeyException e) {
        LOG.error("Bad SSL key", e);
    } catch (SSLPeerUnverifiedException e) {
        LOG.error("Could not verify server", e);
    } catch (SSLException e) {
        LOG.debug("Address does not appear to be SSL-enabled - falling back to http", e);
    } catch (IOException e) {
        LOG.debug("Failed to validate service", e);
    }
    return false;
}
Also used : SSLProtocolException(javax.net.ssl.SSLProtocolException) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) IOException(java.io.IOException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SSLKeyException(javax.net.ssl.SSLKeyException) SSLException(javax.net.ssl.SSLException) Socket(java.net.Socket) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Aggregations

SSLKeyException (javax.net.ssl.SSLKeyException)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 SSLException (javax.net.ssl.SSLException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 SSLProtocolException (javax.net.ssl.SSLProtocolException)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1