diff --git a/CHANGELOG.md b/CHANGELOG.md index 22cadc0c..793db945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.2.1 + +- Fixed #425: plugin crashes on Android SDK levels < 24 + ## 3.2.0 - Feature #420: implement blacklist feature to disable SSL/TLS versions on Android (thanks to @MobisysGmbH) diff --git a/src/android/com/silkimen/http/TLSSocketFactory.java b/src/android/com/silkimen/http/TLSSocketFactory.java index 87d8f20a..3e4682f3 100644 --- a/src/android/com/silkimen/http/TLSSocketFactory.java +++ b/src/android/com/silkimen/http/TLSSocketFactory.java @@ -5,8 +5,8 @@ import java.net.Socket; import java.net.UnknownHostException; -import java.util.Arrays; -import java.util.stream.Stream; +import java.util.ArrayList; +import java.util.List; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; @@ -15,11 +15,15 @@ public class TLSSocketFactory extends SSLSocketFactory { private SSLSocketFactory delegate; - private String[] blacklistedProtocols; + private List blacklistedProtocols; public TLSSocketFactory(SSLContext context, String[] blacklistedProtocols) { this.delegate = context.getSocketFactory(); - this.blacklistedProtocols = Arrays.stream(blacklistedProtocols).map(String::trim).toArray(String[]::new); + this.blacklistedProtocols = new ArrayList(); + + for (int i = 0; i < blacklistedProtocols.length; ++i) { + this.blacklistedProtocols.add(blacklistedProtocols[i].trim()); + } } @Override @@ -65,12 +69,15 @@ private Socket enableTLSOnSocket(Socket socket) { } String[] supported = ((SSLSocket) socket).getSupportedProtocols(); + List filtered = new ArrayList(); - String[] filtered = Arrays.stream(supported).filter( - val -> Arrays.stream(this.blacklistedProtocols).noneMatch(val::equals) - ).toArray(String[]::new); + for (int i = 0; i < supported.length; ++i) { + if (!this.blacklistedProtocols.contains(supported[i])) { + filtered.add(supported[i]); + } + } - ((SSLSocket) socket).setEnabledProtocols(filtered); + ((SSLSocket) socket).setEnabledProtocols(filtered.toArray(new String[0])); return socket; }