Skip to content

Commit 6a935aa

Browse files
Do not enable TLSv1 if it is not a supported protocol
1 parent 5ea5683 commit 6a935aa

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/network/TLSSocketFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.net.UnknownHostException;
1515
import java.security.KeyManagementException;
1616
import java.security.NoSuchAlgorithmException;
17+
import java.util.Arrays;
1718

1819
import javax.net.ssl.SSLContext;
1920
import javax.net.ssl.SSLSocket;
@@ -71,7 +72,14 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre
7172

7273
private Socket enableTLSOnSocket(Socket socket) {
7374
if(socket != null && (socket instanceof SSLSocket)) {
74-
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"});
75+
SSLSocket sslSocket = ((SSLSocket)socket);
76+
String[] supportedProtocols = sslSocket.getSupportedProtocols();
77+
78+
if (Arrays.asList(supportedProtocols).contains("TLSv1")) {
79+
sslSocket.setEnabledProtocols(new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"});
80+
} else {
81+
sslSocket.setEnabledProtocols(new String[] {"TLSv1.1", "TLSv1.2"});
82+
}
7583
}
7684
return socket;
7785
}

0 commit comments

Comments
 (0)