Search in sources :

Example 11 with SSLException

use of javax.net.ssl.SSLException in project geode by apache.

the class LauncherLifecycleCommands method doAutoConnect.

private boolean doAutoConnect(final String locatorHostname, final int locatorPort, final String gemfirePropertiesPathname, final String gemfireSecurityPropertiesPathname, final InfoResultData infoResultData) {
    boolean connectSuccess = false;
    boolean jmxManagerAuthEnabled = false;
    boolean jmxManagerSslEnabled = false;
    Map<String, String> configurationProperties = loadConfigurationProperties(gemfireSecurityPropertiesPathname, loadConfigurationProperties(gemfirePropertiesPathname));
    Map<String, String> locatorConfigurationProperties = new HashMap<>(configurationProperties);
    String responseFailureMessage = null;
    for (int attempts = 0; (attempts < 10 && !connectSuccess); attempts++) {
        try {
            ConnectToLocatorResult connectToLocatorResult = ShellCommands.connectToLocator(locatorHostname, locatorPort, ShellCommands.getConnectLocatorTimeoutInMS() / 4, locatorConfigurationProperties);
            ConnectionEndpoint memberEndpoint = connectToLocatorResult.getMemberEndpoint();
            jmxManagerSslEnabled = connectToLocatorResult.isJmxManagerSslEnabled();
            if (!jmxManagerSslEnabled) {
                configurationProperties.clear();
            }
            getGfsh().setOperationInvoker(new JmxOperationInvoker(memberEndpoint.getHost(), memberEndpoint.getPort(), null, null, configurationProperties, null));
            String shellAndLogMessage = CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, "JMX Manager " + memberEndpoint.toString(false));
            infoResultData.addLine("\n");
            infoResultData.addLine(shellAndLogMessage);
            getGfsh().logToFile(shellAndLogMessage, null);
            connectSuccess = true;
            responseFailureMessage = null;
        } catch (IllegalStateException unexpected) {
            if (CauseFinder.indexOfCause(unexpected, ClassCastException.class, false) != -1) {
                responseFailureMessage = "The Locator might require SSL Configuration.";
            }
        } catch (SecurityException ignore) {
            getGfsh().logToFile(ignore.getMessage(), ignore);
            jmxManagerAuthEnabled = true;
            // no need to continue after SecurityException
            break;
        } catch (AuthenticationFailedException ignore) {
            getGfsh().logToFile(ignore.getMessage(), ignore);
            jmxManagerAuthEnabled = true;
            // no need to continue after AuthenticationFailedException
            break;
        } catch (SSLException ignore) {
            if (ignore instanceof SSLHandshakeException) {
                // try to connect again without SSL since the SSL handshake failed implying a plain text
                // connection...
                locatorConfigurationProperties.clear();
            } else {
                // another type of SSL error occurred (possibly a configuration issue); pass the buck...
                getGfsh().logToFile(ignore.getMessage(), ignore);
                responseFailureMessage = "Check your SSL configuration and try again.";
                break;
            }
        } catch (Exception ignore) {
            getGfsh().logToFile(ignore.getMessage(), ignore);
            responseFailureMessage = "Failed to connect; unknown cause: " + ignore.getMessage();
        }
    }
    if (!connectSuccess) {
        doOnConnectionFailure(locatorHostname, locatorPort, jmxManagerAuthEnabled, jmxManagerSslEnabled, infoResultData);
    }
    if (StringUtils.isNotBlank(responseFailureMessage)) {
        infoResultData.addLine("\n");
        infoResultData.addLine(responseFailureMessage);
    }
    return connectSuccess;
}
Also used : HashMap(java.util.HashMap) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) ConnectToLocatorResult(org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult) JmxOperationInvoker(org.apache.geode.management.internal.cli.shell.JmxOperationInvoker) SSLException(javax.net.ssl.SSLException) ConnectionEndpoint(org.apache.geode.management.internal.cli.util.ConnectionEndpoint) ConverterHint(org.apache.geode.management.cli.ConverterHint) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MalformedObjectNameException(javax.management.MalformedObjectNameException) SSLException(javax.net.ssl.SSLException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) ClusterConfigurationNotAvailableException(org.apache.geode.internal.process.ClusterConfigurationNotAvailableException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConnectionEndpoint(org.apache.geode.management.internal.cli.util.ConnectionEndpoint)

Example 12 with SSLException

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

the class SSLEngineTest method test_unwrap_ByteBuffer$ByteBuffer_01.

/**
     * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
     * SSLException should be thrown.
     */
public void test_unwrap_ByteBuffer$ByteBuffer_01() throws IOException, InterruptedException {
    prepareEngines();
    doHandshake();
    ByteBuffer bbs = ByteBuffer.allocate(100);
    ByteBuffer bbd = ByteBuffer.allocate(100);
    try {
        clientEngine.engine.unwrap(bbs, new ByteBuffer[] { bbd });
        fail("SSLException wasn't thrown");
    } catch (SSLException ex) {
    //expected
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) SSLException(javax.net.ssl.SSLException)

Example 13 with SSLException

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

the class SSLEngineTest method test_wrap_ByteBuffer$ByteBuffer_01.

/**
     * @throws IOException
     * @throws InterruptedException
     * javax.net.ssl.SSLEngine#wrap(ByteBuffer[] srcs, ByteBuffer dst)
     * SSLException should be thrown.
     */
public void test_wrap_ByteBuffer$ByteBuffer_01() throws IOException, InterruptedException {
    prepareEngines();
    doHandshake();
    ByteBuffer bbs = ByteBuffer.allocate(100);
    ByteBuffer bbd = ByteBuffer.allocate(20000);
    try {
        clientEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd);
        serverEngine.engine.wrap(new ByteBuffer[] { bbs }, bbd);
    //fail("SSLException wasn't thrown");
    } catch (SSLException ex) {
    //expected
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) SSLException(javax.net.ssl.SSLException)

Example 14 with SSLException

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

the class SSLEngineTest method test_unwrap_ByteBuffer_ByteBuffer_01.

/**
     * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer dst)
     * SSLException should be thrown.
     */
public void test_unwrap_ByteBuffer_ByteBuffer_01() throws InterruptedException, IOException {
    prepareEngines();
    doHandshake();
    ByteBuffer bbs = ByteBuffer.allocate(100);
    ByteBuffer bbd = ByteBuffer.allocate(100);
    try {
        SSLEngineResult unwrap = clientEngine.engine.unwrap(bbs, bbd);
        fail("SSLException wasn't thrown");
    } catch (SSLException ex) {
    //expected
    }
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult) ByteBuffer(java.nio.ByteBuffer) SSLException(javax.net.ssl.SSLException)

Example 15 with SSLException

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

the class SSLExceptionTest method testSSLException06.

/**
     * Test for <code>SSLException(String, Throwable)</code> constructor
     * Assertion: constructs SSLException when <code>cause</code> is null
     * <code>msg</code> is not null
     */
public void testSSLException06() {
    SSLException sE;
    for (int i = 0; i < msgs.length; i++) {
        sE = new SSLException(msgs[i], null);
        assertEquals("getMessage() must return: ".concat(msgs[i]), sE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", sE.getCause());
    }
}
Also used : SSLException(javax.net.ssl.SSLException)

Aggregations

SSLException (javax.net.ssl.SSLException)326 IOException (java.io.IOException)106 CertificateException (java.security.cert.CertificateException)54 X509Certificate (java.security.cert.X509Certificate)43 SslContext (io.netty.handler.ssl.SslContext)37 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)37 InetSocketAddress (java.net.InetSocketAddress)35 SSLEngineResult (javax.net.ssl.SSLEngineResult)34 SocketException (java.net.SocketException)33 Test (org.junit.Test)33 ByteBuffer (java.nio.ByteBuffer)32 SSLEngine (javax.net.ssl.SSLEngine)30 KeyStore (java.security.KeyStore)29 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)29 SSLSocket (javax.net.ssl.SSLSocket)29 InputStream (java.io.InputStream)26 SSLContext (javax.net.ssl.SSLContext)25 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)24 Bootstrap (io.netty.bootstrap.Bootstrap)23 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)22