use of okhttp3.ConnectionSpec in project caronae-android by caronae.
the class CaronaeAPI method enableTls12OnPreLollipop.
private static OkHttpClient.Builder enableTls12OnPreLollipop(OkHttpClient.Builder client) {
if (Build.VERSION.SDK_INT >= 15 && Build.VERSION.SDK_INT <= 21) {
try {
SSLContext tlsContext = SSLContext.getInstance("TLSv1.2");
tlsContext.init(null, null, null);
client.sslSocketFactory(new Tls12SocketFactory(tlsContext.getSocketFactory()));
ConnectionSpec tlsSpec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).tlsVersions(TlsVersion.TLS_1_2).build();
List<ConnectionSpec> specs = Arrays.asList(tlsSpec);
client.connectionSpecs(specs);
} catch (Exception e) {
Log.e("OkHttpTLSCompat", "Error while setting TLS 1.2", e);
}
}
return client;
}
use of okhttp3.ConnectionSpec in project AntennaPod by AntennaPod.
the class SslClientSetup method installCertificates.
public static void installCertificates(OkHttpClient.Builder builder) {
if (BuildConfig.FLAVOR.equals("free")) {
// The Free flavor bundles a modern conscrypt (security provider), so CustomSslSocketFactory
// is only used to make sure that modern protocols (TLSv1.3 and TLSv1.2) are enabled and
// that old, deprecated, protocols (like SSLv3, TLSv1.0 and TLSv1.1) are disabled.
X509TrustManager trustManager = BackportTrustManager.create();
builder.sslSocketFactory(new NoV1SslSocketFactory(trustManager), trustManager);
} else if (Build.VERSION.SDK_INT < 21) {
X509TrustManager trustManager = BackportTrustManager.create();
builder.sslSocketFactory(new NoV1SslSocketFactory(trustManager), trustManager);
// workaround for Android 4.x for certain web sites.
// see: https://github.com/square/okhttp/issues/4053#issuecomment-402579554
List<CipherSuite> cipherSuites = new ArrayList<>(ConnectionSpec.MODERN_TLS.cipherSuites());
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
ConnectionSpec legacyTls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).cipherSuites(cipherSuites.toArray(new CipherSuite[0])).build();
builder.connectionSpecs(Arrays.asList(legacyTls, ConnectionSpec.CLEARTEXT));
}
}
Aggregations