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

Commit 76a808c

Browse files
committed
Use TLSv1.3 if available
1 parent 7710db7 commit 76a808c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,21 @@ public static OkHttpClient getOkHttpClient() {
7171
SSLContext sslContext;
7272

7373
try {
74-
sslContext = SSLContext.getInstance("TLSv1.2");
75-
} catch (NoSuchAlgorithmException tlsv12Exception) {
74+
sslContext = SSLContext.getInstance("TLSv1.3");
75+
} catch (NoSuchAlgorithmException tlsv13Exception) {
7676
try {
77-
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
78-
sslContext = SSLContext.getInstance("TLSv1.1");
79-
} catch (NoSuchAlgorithmException tlsv11Exception) {
80-
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
81-
sslContext = SSLContext.getInstance("TLSv1");
82-
// should be available in any device; see reference of supported protocols in
83-
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
77+
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
78+
sslContext = SSLContext.getInstance("TLSv1.2");
79+
} catch (NoSuchAlgorithmException tlsv12Exception) {
80+
try {
81+
Timber.w("TLSv1.2 is not supported in this device; falling through TLSv1.1");
82+
sslContext = SSLContext.getInstance("TLSv1.1");
83+
} catch (NoSuchAlgorithmException tlsv11Exception) {
84+
Timber.w("TLSv1.1 is not supported in this device; falling through TLSv1.0");
85+
sslContext = SSLContext.getInstance("TLSv1");
86+
// should be available in any device; see reference of supported protocols in
87+
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
88+
}
8489
}
8590
}
8691

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre
7474
}
7575

7676
private Socket enableTLSOnSocket(Socket socket) {
77-
if(socket != null && (socket instanceof SSLSocket)) {
78-
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"});
77+
if((socket instanceof SSLSocket)) {
78+
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2", "TLSv1.3"});
7979
}
8080
return socket;
8181
}

0 commit comments

Comments
 (0)