Search in sources :

Example 76 with SSLSession

use of javax.net.ssl.SSLSession in project jdk8u_jdk by JetBrains.

the class X509TrustManagerImpl method getRequestedServerNames.

// Also used by X509KeyManagerImpl
static List<SNIServerName> getRequestedServerNames(Socket socket) {
    if (socket != null && socket.isConnected() && socket instanceof SSLSocket) {
        SSLSocket sslSocket = (SSLSocket) socket;
        SSLSession session = sslSocket.getHandshakeSession();
        if (session != null && (session instanceof ExtendedSSLSession)) {
            ExtendedSSLSession extSession = (ExtendedSSLSession) session;
            return extSession.getRequestedServerNames();
        }
    }
    return Collections.<SNIServerName>emptyList();
}
Also used : SSLSession(javax.net.ssl.SSLSession)

Example 77 with SSLSession

use of javax.net.ssl.SSLSession in project BBS-Android by bdpqchen.

the class CollectionClient method getUnSaveBuilder.

private static OkHttpClient.Builder getUnSaveBuilder() {
    try {
        // Create a trust manager that does not validate certificate chains
        final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

            @Override
            public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
            }

            @Override
            public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[] {};
            }
        } };
        // Install the all-trusting trust manager
        final SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
        // Create an ssl socket factory with our all-trusting manager
        final javax.net.ssl.SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.sslSocketFactory(sslSocketFactory);
        builder.hostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
        return builder;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 78 with SSLSession

use of javax.net.ssl.SSLSession in project webpieces by deanhiller.

the class TestSSLEngine method testRawSSLEngine.

//private static final Logger log = LoggerFactory.getLogger(TestSSLEngine.class);
/**
	 * Sunny day scenaior of normal two normal SSLEngines...no split packets,
	 * no failures, etc.
	 * @throws Exception
	 */
public void testRawSSLEngine() throws Exception {
    SSLEngine server = getServerEngine();
    SSLEngine client = getClientEngine();
    SSLSession s = client.getSession();
    ByteBuffer unencrPacket = ByteBuffer.allocate(s.getApplicationBufferSize());
    ByteBuffer encPacket = ByteBuffer.allocate(s.getPacketBufferSize());
    encPacket.clear();
    unencrPacket.clear();
    doHandshakeAndVerify(client, server, unencrPacket, encPacket);
    doRehandshake();
    //connection is now established....
    encPacket.clear();
    client.closeOutbound();
    SSLEngineResult result = client.wrap(unencrPacket, encPacket);
    assertEquals(HandshakeStatus.NEED_UNWRAP, result.getHandshakeStatus());
    assertEquals(Status.CLOSED, result.getStatus());
    encPacket.flip();
    result = server.unwrap(encPacket, unencrPacket);
    assertEquals(HandshakeStatus.NEED_WRAP, result.getHandshakeStatus());
    assertEquals(Status.CLOSED, result.getStatus());
    encPacket.clear();
    result = server.wrap(unencrPacket, encPacket);
    assertEquals(HandshakeStatus.NOT_HANDSHAKING, result.getHandshakeStatus());
    assertEquals(Status.CLOSED, result.getStatus());
    encPacket.flip();
    result = client.unwrap(encPacket, unencrPacket);
    assertEquals(HandshakeStatus.NOT_HANDSHAKING, result.getHandshakeStatus());
    assertEquals(Status.CLOSED, result.getStatus());
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult) SSLEngine(javax.net.ssl.SSLEngine) SSLSession(javax.net.ssl.SSLSession) ByteBuffer(java.nio.ByteBuffer)

Example 79 with SSLSession

use of javax.net.ssl.SSLSession in project bnd by bndtools.

the class HttpsUtil method disableServerVerification.

static void disableServerVerification(URLConnection connection) throws GeneralSecurityException {
    if (!(connection instanceof HttpsURLConnection))
        return;
    HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }

        public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
        }

        public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
        }
    } };
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustAllCerts, new SecureRandom());
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
    httpsConnection.setSSLSocketFactory(sslSocketFactory);
    HostnameVerifier trustAnyHost = new HostnameVerifier() {

        public boolean verify(String string, SSLSession session) {
            return true;
        }
    };
    httpsConnection.setHostnameVerifier(trustAnyHost);
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) SSLSession(javax.net.ssl.SSLSession) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) X509Certificate(java.security.cert.X509Certificate) X509TrustManager(javax.net.ssl.X509TrustManager) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 80 with SSLSession

use of javax.net.ssl.SSLSession in project opennms by OpenNMS.

the class VmwareViJavaAccess method relax.

/**
 * This method is used to "relax" the policies concerning self-signed certificates.
 */
protected void relax() {
    TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
    try {
        SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    } catch (Exception exception) {
        logger.warn("Error setting relaxed SSL policy", exception);
    }
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    });
}
Also used : SSLSession(javax.net.ssl.SSLSession) SecureRandom(java.security.SecureRandom) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) SSLContext(javax.net.ssl.SSLContext) CIMException(org.sblim.wbem.cim.CIMException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) TrustManager(javax.net.ssl.TrustManager) AnyServerX509TrustManager(org.opennms.core.utils.AnyServerX509TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

SSLSession (javax.net.ssl.SSLSession)187 HostnameVerifier (javax.net.ssl.HostnameVerifier)50 SSLSocket (javax.net.ssl.SSLSocket)34 X509Certificate (java.security.cert.X509Certificate)32 IOException (java.io.IOException)31 SSLContext (javax.net.ssl.SSLContext)30 Test (org.junit.Test)29 CertificateException (java.security.cert.CertificateException)27 Certificate (java.security.cert.Certificate)20 SSLException (javax.net.ssl.SSLException)17 X509TrustManager (javax.net.ssl.X509TrustManager)16 URL (java.net.URL)14 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)14 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)14 TrustManager (javax.net.ssl.TrustManager)14 SecureRandom (java.security.SecureRandom)13 FakeSSLSession (okhttp3.FakeSSLSession)13 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)12 InputStream (java.io.InputStream)11 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11