Skip to content

Commit c188214

Browse files
committed
Release 1.5.1
1 parent e85590a commit c188214

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 1.5.1 (released 21.11.2017)
4+
5+
- Support for TLSv1.1 and TLSv1.2 only servers
6+
- Fixing a security issue
7+
- Changed ConcurrentHashMap to ConcurrentSkipListMap for sorting feature
8+
39
## 1.5.0 (released 18.11.2017)
410

511
- Initial Public Version

library/src/main/java/com/vorlonsoft/android/http/MySSLSocketFactory.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.vorlonsoft.android.http;
1818

19+
import android.util.Log;
20+
1921
import java.io.BufferedInputStream;
2022
import java.io.IOException;
2123
import java.io.InputStream;
@@ -56,7 +58,7 @@
5658
* certificate validation on every device, use with caution
5759
*/
5860
public class MySSLSocketFactory extends SSLSocketFactory {
59-
final SSLContext sslContext = SSLContext.getInstance("TLS");
61+
SSLContext sslContext;
6062

6163
/**
6264
* Creates a new SSL Socket Factory with the given KeyStore.
@@ -70,6 +72,21 @@ public class MySSLSocketFactory extends SSLSocketFactory {
7072
public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
7173
super(truststore);
7274

75+
try {
76+
sslContext = SSLContext.getInstance("TLSv1.2");
77+
Log.w("SSLSocketFactory", "TLSv1.2 is supported");
78+
} catch (NoSuchAlgorithmException e2) {
79+
try {
80+
Log.w("SSLSocketFactory", "TLSv1.2 is not supported in this device; falling through TLSv1.1");
81+
sslContext = SSLContext.getInstance("TLSv1.1");
82+
} catch (NoSuchAlgorithmException e1) {
83+
Log.w("SSLSocketFactory", "TLSv1.2 and TLSv1.1 is not supported in this device; falling through TLSv1.0");
84+
sslContext = SSLContext.getInstance("TLSv1");
85+
// should be available in any device; see reference of supported protocols in
86+
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
87+
}
88+
}
89+
7390
X509TrustManager tm = new X509TrustManager() {
7491
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
7592
try {
@@ -214,8 +231,13 @@ public Socket createSocket() throws IOException {
214231
*/
215232
private void enableSecureProtocols(Socket socket) {
216233
// set all supported protocols
217-
SSLParameters params = sslContext.getSupportedSSLParameters();
218-
((SSLSocket) socket).setEnabledProtocols(params.getProtocols());
234+
try {
235+
SSLParameters params = sslContext.getSupportedSSLParameters();
236+
((SSLSocket) socket).setEnabledProtocols(params.getProtocols());
237+
}catch (Exception e)
238+
{
239+
Log.w("SSLSocketFactory", e);
240+
}
219241
}
220242

221243
/**

0 commit comments

Comments
 (0)