Search in sources :

Example 31 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method tlsBuilder_explicitCiphers.

@Test
public void tlsBuilder_explicitCiphers() throws Exception {
    ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true).cipherSuites(CipherSuite.TLS_RSA_WITH_RC4_128_MD5).tlsVersions(TlsVersion.TLS_1_2).supportsTlsExtensions(true).build();
    assertThat(tlsSpec.cipherSuites()).containsExactly(CipherSuite.TLS_RSA_WITH_RC4_128_MD5);
    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 32 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class ConnectionSpecTest method tls_explicitCiphers.

@Test
public void tls_explicitCiphers() 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.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, true);
    assertThat(socket.getEnabledProtocols()).containsExactly(TlsVersion.TLS_1_2.javaName());
    List<String> expectedCipherSuites = new ArrayList<>();
    expectedCipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256.javaName());
    if (asList(socket.getSupportedCipherSuites()).contains("TLS_FALLBACK_SCSV")) {
        expectedCipherSuites.add("TLS_FALLBACK_SCSV");
    }
    assertThat(socket.getEnabledCipherSuites()).containsExactlyElementsOf(expectedCipherSuites);
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) SSLSocket(javax.net.ssl.SSLSocket) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 33 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class CipherSuiteTest method applyIntersectionRetainsSslPrefixes.

@Test
public void applyIntersectionRetainsSslPrefixes() throws Exception {
    FakeSslSocket socket = new FakeSslSocket();
    socket.setEnabledProtocols(new String[] { "TLSv1" });
    socket.setSupportedCipherSuites(new String[] { "SSL_A", "SSL_B", "SSL_C", "SSL_D", "SSL_E" });
    socket.setEnabledCipherSuites(new String[] { "SSL_A", "SSL_B", "SSL_C" });
    ConnectionSpec connectionSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_0).cipherSuites("TLS_A", "TLS_C", "TLS_E").build();
    applyConnectionSpec(connectionSpec, socket, false);
    assertArrayEquals(new String[] { "SSL_A", "SSL_C" }, socket.enabledCipherSuites);
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) Test(org.junit.jupiter.api.Test)

Example 34 with ConnectionSpec

use of okhttp3.ConnectionSpec in project okhttp by square.

the class CipherSuiteTest method applyIntersectionToProtocolVersion.

@Test
public void applyIntersectionToProtocolVersion() throws Exception {
    FakeSslSocket socket = new FakeSslSocket();
    socket.setEnabledProtocols(new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" });
    socket.setSupportedCipherSuites(new String[] { "TLS_A" });
    socket.setEnabledCipherSuites(new String[] { "TLS_A" });
    ConnectionSpec connectionSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_1, TlsVersion.TLS_1_2, TlsVersion.TLS_1_3).cipherSuites("TLS_A").build();
    applyConnectionSpec(connectionSpec, socket, false);
    assertArrayEquals(new String[] { "TLSv1.1", "TLSv1.2" }, socket.enabledProtocols);
}
Also used : Internal.applyConnectionSpec(okhttp3.internal.Internal.applyConnectionSpec) Test(org.junit.jupiter.api.Test)

Example 35 with ConnectionSpec

use of okhttp3.ConnectionSpec in project uCrop by Yalantis.

the class SampleApp method setUcropHttpClient.

private void setUcropHttpClient() {
    ConnectionSpec cs = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).allEnabledCipherSuites().allEnabledTlsVersions().build();
    OkHttpClient client = new OkHttpClient.Builder().connectionSpecs(Collections.singletonList(cs)).build();
    UCropHttpClientStore.INSTANCE.setClient(client);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ConnectionSpec(okhttp3.ConnectionSpec)

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