Search in sources :

Example 11 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method tlsBuilder_defaultCiphers.

@Test
public void tlsBuilder_defaultCiphers() throws Exception {
    ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_2).supportsTlsExtensions(true).build();
    assertThat(tlsSpec.cipherSuites()).isNull();
    assertThat(tlsSpec.tlsVersions()).containsExactly(TlsVersion.TLS_1_2);
    assertThat(tlsSpec.supportsTlsExtensions()).isTrue();
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) Test(org.junit.jupiter.api.Test)

Example 12 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method cleartextBuilder.

@Test
public void cleartextBuilder() {
    ConnectionSpec cleartextSpec = new ConnectionSpec.Builder(false).build();
    assertThat(cleartextSpec.isTls()).isFalse();
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) Test(org.junit.jupiter.api.Test)

Example 13 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method tls_missingRequiredCipher.

@Test
public void tls_missingRequiredCipher() throws Exception {
    platform.assumeNotConscrypt();
    platform.assumeNotBouncyCastle();
    ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true).cipherSuites(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256).tlsVersions(TlsVersion.TLS_1_2).supportsTlsExtensions(false).build();
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    socket.setEnabledProtocols(new String[] { TlsVersion.TLS_1_2.javaName(), TlsVersion.TLS_1_1.javaName() });
    socket.setEnabledCipherSuites(new String[] { CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName(), CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA.javaName() });
    assertThat(tlsSpec.isCompatible(socket)).isTrue();
    socket.setEnabledCipherSuites(new String[] { CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA.javaName() });
    assertThat(tlsSpec.isCompatible(socket)).isFalse();
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) SSLSocket(javax.net.ssl.SSLSocket) Test(org.junit.jupiter.api.Test)

Example 14 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method simpleToString.

@Test
public void simpleToString() throws Exception {
    ConnectionSpec connectionSpec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).tlsVersions(TlsVersion.TLS_1_2).cipherSuites(CipherSuite.TLS_RSA_WITH_RC4_128_MD5).build();
    assertThat(connectionSpec.toString()).isEqualTo(("ConnectionSpec(cipherSuites=[SSL_RSA_WITH_RC4_128_MD5], tlsVersions=[TLS_1_2], " + "supportsTlsExtensions=true)"));
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) Test(org.junit.jupiter.api.Test)

Example 15 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method tls_defaultCiphers_noFallbackIndicator.

@Test
public void tls_defaultCiphers_noFallbackIndicator() throws Exception {
    platform.assumeNotConscrypt();
    platform.assumeNotBouncyCastle();
    ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_2).supportsTlsExtensions(false).build();
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    socket.setEnabledCipherSuites(new String[] { CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName(), CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA.javaName() });
    socket.setEnabledProtocols(new String[] { TlsVersion.TLS_1_2.javaName(), TlsVersion.TLS_1_1.javaName() });
    assertThat(tlsSpec.isCompatible(socket)).isTrue();
    applyConnectionSpec(tlsSpec, socket, false);
    assertThat(socket.getEnabledProtocols()).containsExactly(TlsVersion.TLS_1_2.javaName());
    assertThat(socket.getEnabledCipherSuites()).containsExactlyInAnyOrder(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName(), CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA.javaName());
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) SSLSocket(javax.net.ssl.SSLSocket) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionSpec (okhttp3.ConnectionSpec)18 Internal.applyConnectionSpec (okhttp3.internal.Internal.applyConnectionSpec)18 Test (org.junit.jupiter.api.Test)18 ArrayList (java.util.ArrayList)11 SSLSocket (javax.net.ssl.SSLSocket)9 X509TrustManager (javax.net.ssl.X509TrustManager)9 OkHttpClient (okhttp3.OkHttpClient)7 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 SSLContext (javax.net.ssl.SSLContext)5 TrustManager (javax.net.ssl.TrustManager)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 NonNull (android.support.annotation.NonNull)2 UnknownServiceException (java.net.UnknownServiceException)2 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)2 GsonBuilder (com.google.gson.GsonBuilder)1 FileNotFoundException (java.io.FileNotFoundException)1