Search in sources :

Example 71 with SSLSession

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

the class SSLSessionTest method test_invalidate.

/**
     * javax.net.ssl.SSLSession#invalidate()
     * javax.net.ssl.SSLSession#isValid()
     */
public void test_invalidate() {
    SSLSession s = clientSession;
    assertTrue(s.isValid());
    s.invalidate();
    assertFalse(s.isValid());
}
Also used : SSLSession(javax.net.ssl.SSLSession)

Example 72 with SSLSession

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

the class HandshakeCompletedEventTest method test_getSession.

/**
     * @throws IOException
     * javax.net.ssl.HandshakeCompletedEvent#getSession()
     */
public final void test_getSession() throws IOException {
    mySSLSession session = new mySSLSession("localhost", 1080, null);
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
    SSLSession ss = event.getSession();
    assertNotNull(ss);
    assertEquals(session, ss);
}
Also used : HandshakeCompletedEvent(javax.net.ssl.HandshakeCompletedEvent) SSLSocket(javax.net.ssl.SSLSocket) SSLSession(javax.net.ssl.SSLSession) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession)

Example 73 with SSLSession

use of javax.net.ssl.SSLSession in project android_frameworks_base by crdroidandroid.

the class RootTrustManager method checkServerTrusted.

@Override
public void checkServerTrusted(X509Certificate[] certs, String authType, SSLEngine engine) throws CertificateException {
    SSLSession session = engine.getHandshakeSession();
    if (session == null) {
        throw new CertificateException("Not in handshake; no session available");
    }
    String host = session.getPeerHost();
    NetworkSecurityConfig config = mConfig.getConfigForHostname(host);
    config.getTrustManager().checkServerTrusted(certs, authType, engine);
}
Also used : SSLSession(javax.net.ssl.SSLSession) CertificateException(java.security.cert.CertificateException)

Example 74 with SSLSession

use of javax.net.ssl.SSLSession in project Gargoyle by callakrsos.

the class HostNameVertifierInitializer method initialize.

@Override
public void initialize() throws Exception {
    LOGGER.debug(getClass().getName() + "  initialize.");
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

        @Override
        public boolean verify(String arg0, SSLSession arg1) {
            LOGGER.debug(arg0);
            return true;
        }
    });
}
Also used : SSLSession(javax.net.ssl.SSLSession) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 75 with SSLSession

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

the class X509TrustManagerImpl method checkTrusted.

private void checkTrusted(X509Certificate[] chain, String authType, Socket socket, boolean isClient) throws CertificateException {
    Validator v = checkTrustedInit(chain, authType, isClient);
    AlgorithmConstraints constraints = null;
    if ((socket != null) && socket.isConnected() && (socket instanceof SSLSocket)) {
        SSLSocket sslSocket = (SSLSocket) socket;
        SSLSession session = sslSocket.getHandshakeSession();
        if (session == null) {
            throw new CertificateException("No handshake session");
        }
        // check endpoint identity
        String identityAlg = sslSocket.getSSLParameters().getEndpointIdentificationAlgorithm();
        if (identityAlg != null && identityAlg.length() != 0) {
            checkIdentity(session, chain[0], identityAlg, isClient, getRequestedServerNames(socket));
        }
        // create the algorithm constraints
        ProtocolVersion protocolVersion = ProtocolVersion.valueOf(session.getProtocol());
        if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
            if (session instanceof ExtendedSSLSession) {
                ExtendedSSLSession extSession = (ExtendedSSLSession) session;
                String[] localSupportedSignAlgs = extSession.getLocalSupportedSignatureAlgorithms();
                constraints = new SSLAlgorithmConstraints(sslSocket, localSupportedSignAlgs, false);
            } else {
                constraints = new SSLAlgorithmConstraints(sslSocket, false);
            }
        } else {
            constraints = new SSLAlgorithmConstraints(sslSocket, false);
        }
    }
    X509Certificate[] trustedChain = null;
    if (isClient) {
        trustedChain = validate(v, chain, constraints, null);
    } else {
        trustedChain = validate(v, chain, constraints, authType);
    }
    if (debug != null && Debug.isOn("trustmanager")) {
        System.out.println("Found trusted certificate:");
        System.out.println(trustedChain[trustedChain.length - 1]);
    }
}
Also used : SSLSession(javax.net.ssl.SSLSession)

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