1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-07-23 18:06:17 +00:00

Use TLSv1.3 if available

This commit is contained in:
agarcia 2020-06-15 14:16:45 +02:00
parent 7710db7612
commit 76a808cb0d
2 changed files with 16 additions and 11 deletions

View File

@ -71,6 +71,10 @@ public class HttpClient {
SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("TLSv1.3");
} catch (NoSuchAlgorithmException tlsv13Exception) {
try {
Timber.w("TLSv1.3 is not supported in this device; falling through TLSv1.2");
sslContext = SSLContext.getInstance("TLSv1.2");
} catch (NoSuchAlgorithmException tlsv12Exception) {
try {
@ -83,6 +87,7 @@ public class HttpClient {
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
}
}
}
sslContext.init(null, new TrustManager[]{trustManager}, null);

View File

@ -74,8 +74,8 @@ public class TLSSocketFactory extends SSLSocketFactory {
}
private Socket enableTLSOnSocket(Socket socket) {
if(socket != null && (socket instanceof SSLSocket)) {
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"});
if((socket instanceof SSLSocket)) {
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2", "TLSv1.3"});
}
return socket;
}