Search in sources :

Example 31 with SSLSocketFactory

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

the class SSLSocketTest method test_SSLSocket_setSSLParameters.

public void test_SSLSocket_setSSLParameters() throws Exception {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket ssl = (SSLSocket) sf.createSocket();
    String[] defaultCipherSuites = ssl.getEnabledCipherSuites();
    String[] defaultProtocols = ssl.getEnabledProtocols();
    String[] supportedCipherSuites = ssl.getSupportedCipherSuites();
    String[] supportedProtocols = ssl.getSupportedProtocols();
    {
        SSLParameters p = new SSLParameters();
        ssl.setSSLParameters(p);
        assertEquals(Arrays.asList(defaultCipherSuites), Arrays.asList(ssl.getEnabledCipherSuites()));
        assertEquals(Arrays.asList(defaultProtocols), Arrays.asList(ssl.getEnabledProtocols()));
    }
    {
        SSLParameters p = new SSLParameters(supportedCipherSuites, supportedProtocols);
        ssl.setSSLParameters(p);
        assertEquals(Arrays.asList(supportedCipherSuites), Arrays.asList(ssl.getEnabledCipherSuites()));
        assertEquals(Arrays.asList(supportedProtocols), Arrays.asList(ssl.getEnabledProtocols()));
    }
    {
        SSLParameters p = new SSLParameters();
        p.setNeedClientAuth(true);
        assertFalse(ssl.getNeedClientAuth());
        assertFalse(ssl.getWantClientAuth());
        ssl.setSSLParameters(p);
        assertTrue(ssl.getNeedClientAuth());
        assertFalse(ssl.getWantClientAuth());
        p.setWantClientAuth(true);
        assertTrue(ssl.getNeedClientAuth());
        assertFalse(ssl.getWantClientAuth());
        ssl.setSSLParameters(p);
        assertFalse(ssl.getNeedClientAuth());
        assertTrue(ssl.getWantClientAuth());
        p.setWantClientAuth(false);
        assertFalse(ssl.getNeedClientAuth());
        assertTrue(ssl.getWantClientAuth());
        ssl.setSSLParameters(p);
        assertFalse(ssl.getNeedClientAuth());
        assertFalse(ssl.getWantClientAuth());
    }
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) SSLSocket(javax.net.ssl.SSLSocket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 32 with SSLSocketFactory

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

the class SSLSocketTest method test_SSLSocket_getSupportedCipherSuites_names.

public void test_SSLSocket_getSupportedCipherSuites_names() throws Exception {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket ssl = (SSLSocket) sf.createSocket();
    String[] cipherSuites = ssl.getSupportedCipherSuites();
    StandardNames.assertSupportedCipherSuites(StandardNames.CIPHER_SUITES, cipherSuites);
    assertNotSame(cipherSuites, ssl.getSupportedCipherSuites());
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 33 with SSLSocketFactory

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

the class SSLSocketFactoryTest method test_SSLSocketFactory_getDefaultCipherSuites.

public void test_SSLSocketFactory_getDefaultCipherSuites() {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    String[] cipherSuites = sf.getDefaultCipherSuites();
    StandardNames.assertDefaultCipherSuites(cipherSuites);
    assertNotSame(cipherSuites, sf.getDefaultCipherSuites());
}
Also used : SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 34 with SSLSocketFactory

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

the class SSLSocketTest method test_SSLSocket_setSoTimeout_basic.

public void test_SSLSocket_setSoTimeout_basic() throws Exception {
    ServerSocket listening = new ServerSocket(0);
    Socket underlying = new Socket(listening.getInetAddress(), listening.getLocalPort());
    assertEquals(0, underlying.getSoTimeout());
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    Socket wrapping = sf.createSocket(underlying, null, -1, false);
    assertEquals(0, wrapping.getSoTimeout());
    // setting wrapper sets underlying and ...
    // 10 was too small because it was affected by rounding
    int expectedTimeoutMillis = 1000;
    wrapping.setSoTimeout(expectedTimeoutMillis);
    assertEquals(expectedTimeoutMillis, wrapping.getSoTimeout());
    assertEquals(expectedTimeoutMillis, underlying.getSoTimeout());
    // ... getting wrapper inspects underlying
    underlying.setSoTimeout(0);
    assertEquals(0, wrapping.getSoTimeout());
    assertEquals(0, underlying.getSoTimeout());
}
Also used : ServerSocket(java.net.ServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) ServerSocket(java.net.ServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 35 with SSLSocketFactory

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

the class SSLSocketTest method test_SSLSocket_getSession.

public void test_SSLSocket_getSession() throws Exception {
    SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket ssl = (SSLSocket) sf.createSocket();
    SSLSession session = ssl.getSession();
    assertNotNull(session);
    assertFalse(session.isValid());
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) SSLSession(javax.net.ssl.SSLSession) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Aggregations

SSLSocketFactory (javax.net.ssl.SSLSocketFactory)191 SSLSocket (javax.net.ssl.SSLSocket)69 SSLContext (javax.net.ssl.SSLContext)57 IOException (java.io.IOException)45 Socket (java.net.Socket)37 Test (org.junit.Test)33 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)29 HostnameVerifier (javax.net.ssl.HostnameVerifier)27 URL (java.net.URL)23 KeyManagementException (java.security.KeyManagementException)20 OutputStream (java.io.OutputStream)19 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)19 InputStream (java.io.InputStream)18 CertificateException (java.security.cert.CertificateException)17 HttpURLConnection (java.net.HttpURLConnection)15 InetSocketAddress (java.net.InetSocketAddress)15 X509TrustManager (javax.net.ssl.X509TrustManager)15 OkHttpClient (okhttp3.OkHttpClient)14 SSLParameters (javax.net.ssl.SSLParameters)13 TrustManager (javax.net.ssl.TrustManager)13