use of okhttp3.ConnectionSpec in project kripton by xcesco.
the class NetworkClient method instance.
public static OkHttpClient instance() {
if (client == null) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
/* ConnectionSpec spec = new
ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.cipherSuites(
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
.build();*/
client = (new OkHttpClient.Builder()).readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS).addInterceptor(logging).build();
}
return client;
}
use of okhttp3.ConnectionSpec in project opacclient by opacapp.
the class HttpClientFactory method getOkHttpClientBuilder.
protected OkHttpClient.Builder getOkHttpClientBuilder(boolean customssl, boolean tls_only, boolean allCipherSuites) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
builder.cookieJar(new JavaNetCookieJar(cookieManager));
builder.addNetworkInterceptor(new CustomRedirectInterceptor());
builder.connectTimeout(60, TimeUnit.SECONDS);
builder.readTimeout(60, TimeUnit.SECONDS);
builder.writeTimeout(60, TimeUnit.SECONDS);
if (customssl && ssl_store_path != null) {
try {
if (trust_store == null) {
trust_store = getKeyStore();
}
X509TrustManager trustManager = new AdditionalKeyStoresSSLSocketFactory.AdditionalKeyStoresTrustManager(trust_store);
SSLSocketFactory sf = AdditionalKeyStoresSSLSocketFactory.createForOkHttp(trustManager);
if (allCipherSuites) {
sf = new AllCiphersProxySocketFactory(sf);
}
sf = new TLS12ProxySocketFactory(sf);
builder.sslSocketFactory(sf, trustManager);
List<ConnectionSpec> connectionSpecs = new ArrayList<ConnectionSpec>();
connectionSpecs.add(ConnectionSpec.MODERN_TLS);
connectionSpecs.add(new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS).allEnabledCipherSuites().build());
if (!tls_only) {
connectionSpecs.add(new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS).tlsVersions(TlsVersion.SSL_3_0, TlsVersion.TLS_1_0).allEnabledCipherSuites().build());
} else if (allCipherSuites) {
connectionSpecs.add(new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS).allEnabledCipherSuites().build());
}
connectionSpecs.add(ConnectionSpec.CLEARTEXT);
builder.connectionSpecs(connectionSpecs);
return builder;
} catch (Exception e) {
e.printStackTrace();
return builder;
}
} else {
try {
X509TrustManager trustManager = getSystemDefaultTrustManager();
SSLSocketFactory socketFactory = getSystemDefaultSSLSocketFactory(trustManager);
builder.sslSocketFactory(new TLS12ProxySocketFactory(socketFactory), trustManager);
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ignored) {
}
return builder;
}
}
use of okhttp3.ConnectionSpec in project okhttp by square.
the class CipherSuiteTest method applyIntersectionRetainsTlsPrefixes.
@Test
public void applyIntersectionRetainsTlsPrefixes() throws Exception {
FakeSslSocket socket = new FakeSslSocket();
socket.setEnabledProtocols(new String[] { "TLSv1" });
socket.setSupportedCipherSuites(new String[] { "TLS_A", "TLS_B", "TLS_C", "TLS_D", "TLS_E" });
socket.setEnabledCipherSuites(new String[] { "TLS_A", "TLS_B", "TLS_C" });
ConnectionSpec connectionSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_0).cipherSuites("SSL_A", "SSL_C", "SSL_E").build();
applyConnectionSpec(connectionSpec, socket, false);
assertArrayEquals(new String[] { "TLS_A", "TLS_C" }, socket.enabledCipherSuites);
}
use of okhttp3.ConnectionSpec in project okhttp by square.
the class CipherSuiteTest method applyIntersectionAddsSslScsvForFallback.
@Test
public void applyIntersectionAddsSslScsvForFallback() throws Exception {
FakeSslSocket socket = new FakeSslSocket();
socket.setEnabledProtocols(new String[] { "TLSv1" });
socket.setSupportedCipherSuites(new String[] { "SSL_A", "SSL_FALLBACK_SCSV" });
socket.setEnabledCipherSuites(new String[] { "SSL_A" });
ConnectionSpec connectionSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_0).cipherSuites("SSL_A").build();
applyConnectionSpec(connectionSpec, socket, true);
assertArrayEquals(new String[] { "SSL_A", "SSL_FALLBACK_SCSV" }, socket.enabledCipherSuites);
}
use of okhttp3.ConnectionSpec in project okhttp by square.
the class CipherSuiteTest method applyIntersectionAddsTlsScsvForFallback.
@Test
public void applyIntersectionAddsTlsScsvForFallback() throws Exception {
FakeSslSocket socket = new FakeSslSocket();
socket.setEnabledProtocols(new String[] { "TLSv1" });
socket.setSupportedCipherSuites(new String[] { "TLS_A", "TLS_FALLBACK_SCSV" });
socket.setEnabledCipherSuites(new String[] { "TLS_A" });
ConnectionSpec connectionSpec = new ConnectionSpec.Builder(true).tlsVersions(TlsVersion.TLS_1_0).cipherSuites("TLS_A").build();
applyConnectionSpec(connectionSpec, socket, true);
assertArrayEquals(new String[] { "TLS_A", "TLS_FALLBACK_SCSV" }, socket.enabledCipherSuites);
}
Aggregations