@@ -74,49 +74,48 @@ public OkHttpClient getOkHttpClient() {
74
74
try {
75
75
final X509TrustManager trustManager = new AdvancedX509TrustManager (
76
76
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
+
78
83
// Automatic cookie handling, NOT PERSISTENT
79
84
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());
83
85
mOkHttpClient = buildNewOkHttpClient (sslSocketFactory , trustManager , cookieJar );
84
86
87
+ } catch (NoSuchAlgorithmException nsae ){
88
+ Timber .e (nsae , "Could not setup SSL system." );
89
+ throw new RuntimeException ("Could not setup okHttp client." , nsae );
85
90
} 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 );
87
93
}
88
94
}
89
95
return mOkHttpClient ;
90
96
}
91
97
92
- private static SSLContext getSslContext () throws NoSuchAlgorithmException {
98
+ private SSLContext buildSSLContext () throws NoSuchAlgorithmException {
93
99
try {
94
- return SSLContext .getInstance (TlsVersion . TLS_1_3 . javaName () );
100
+ return SSLContext .getInstance ("TLSv1.3" );
95
101
} catch (NoSuchAlgorithmException tlsv13Exception ) {
96
102
try {
97
103
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" );
99
105
} catch (NoSuchAlgorithmException tlsv12Exception ) {
100
106
try {
101
107
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" );
103
109
} catch (NoSuchAlgorithmException tlsv11Exception ) {
104
110
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" );
106
112
// should be available in any device; see reference of supported protocols in
107
113
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
108
114
}
109
115
}
110
116
}
111
117
}
112
118
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
-
120
119
private OkHttpClient buildNewOkHttpClient (SSLSocketFactory sslSocketFactory , X509TrustManager trustManager ,
121
120
CookieJar cookieJar ) {
122
121
return new OkHttpClient .Builder ()
0 commit comments