Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 79e4287

Browse files
theScrabiabelgardep
authored andcommitted
clean up http client
1 parent 0313c1e commit 79e4287

File tree

1 file changed

+16
-17
lines changed
  • owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http

1 file changed

+16
-17
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,49 +74,48 @@ public OkHttpClient getOkHttpClient() {
7474
try {
7575
final X509TrustManager trustManager = new AdvancedX509TrustManager(
7676
NetworkUtils.getKnownServersStore(sContext));
77-
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
77+
78+
79+
final SSLContext sslContext = buildSSLContext();
80+
sslContext.init(null, new TrustManager[]{trustManager}, null);
81+
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
82+
7883
// Automatic cookie handling, NOT PERSISTENT
7984
final CookieJar cookieJar = new CookieJarImpl(mCookieStore);
80-
81-
// TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok.
82-
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
8385
mOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
8486

87+
} catch(NoSuchAlgorithmException nsae){
88+
Timber.e(nsae, "Could not setup SSL system.");
89+
throw new RuntimeException("Could not setup okHttp client.", nsae);
8590
} catch (Exception e) {
86-
Timber.e(e, "Could not setup SSL system.");
91+
Timber.e(e, "Could not setup okHttp client.");
92+
throw new RuntimeException("Could not setup okHttp client.", e);
8793
}
8894
}
8995
return mOkHttpClient;
9096
}
9197

92-
private static SSLContext getSslContext() throws NoSuchAlgorithmException {
98+
private SSLContext buildSSLContext() throws NoSuchAlgorithmException {
9399
try {
94-
return SSLContext.getInstance(TlsVersion.TLS_1_3.javaName());
100+
return SSLContext.getInstance("TLSv1.3");
95101
} catch (NoSuchAlgorithmException tlsv13Exception) {
96102
try {
97103
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
98-
return SSLContext.getInstance(TlsVersion.TLS_1_2.javaName());
104+
return SSLContext.getInstance("TLSv1.2");
99105
} catch (NoSuchAlgorithmException tlsv12Exception) {
100106
try {
101107
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
102-
return SSLContext.getInstance(TlsVersion.TLS_1_1.javaName());
108+
return SSLContext.getInstance("TLSv1.1");
103109
} catch (NoSuchAlgorithmException tlsv11Exception) {
104110
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
105-
return SSLContext.getInstance(TlsVersion.TLS_1_0.javaName());
111+
return SSLContext.getInstance("TLSv1");
106112
// should be available in any device; see reference of supported protocols in
107113
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
108114
}
109115
}
110116
}
111117
}
112118

113-
private static SSLSocketFactory getNewSslSocketFactory(X509TrustManager trustManager)
114-
throws NoSuchAlgorithmException, KeyManagementException {
115-
final SSLContext sslContext = getSslContext();
116-
sslContext.init(null, new TrustManager[]{trustManager}, null);
117-
return sslContext.getSocketFactory();
118-
}
119-
120119
private OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
121120
CookieJar cookieJar) {
122121
return new OkHttpClient.Builder()

0 commit comments

Comments
 (0)