From f5254e504d55e88d3e45d9ebfea156e6151cb671 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Tue, 15 May 2018 00:54:16 +0200 Subject: [PATCH] Hopefully fixed crash in Android 8.1 --- .../kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java | 6 ++++-- .../kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java index 6574809a..12114922 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -253,7 +253,9 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis //Handshake is blocking, so do it on another thread and free this thread to keep receiving new connection new Thread(() -> { try { - sslsocket.startHandshake(); + synchronized (this) { + sslsocket.startHandshake(); + } } catch (Exception e) { Log.e("KDE/LanLinkProvider", "Handshake failed with " + identityPacket.getString("deviceName")); e.printStackTrace(); @@ -286,7 +288,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis * @param connectionOrigin which side started this connection * @throws IOException if an exception is thrown by {@link LanLink#reset(Socket, LanLink.ConnectionStarted)} */ - private synchronized void addLink(final NetworkPacket identityPacket, Socket socket, LanLink.ConnectionStarted connectionOrigin) throws IOException { + private void addLink(final NetworkPacket identityPacket, Socket socket, LanLink.ConnectionStarted connectionOrigin) throws IOException { String deviceId = identityPacket.getString("deviceId"); LanLink currentLink = visibleComputers.get(deviceId); diff --git a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java index 758fd7a7..25ce5c87 100644 --- a/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SecurityHelpers/SslHelper.java @@ -42,6 +42,7 @@ import org.spongycastle.operator.jcajce.JcaContentSignerBuilder; import java.io.IOException; import java.math.BigInteger; import java.net.Socket; +import java.net.SocketException; import java.security.KeyStore; import java.security.MessageDigest; import java.security.PrivateKey; @@ -201,7 +202,7 @@ public class SslHelper { } - public static void configureSslSocket(SSLSocket socket, boolean isDeviceTrusted, boolean isClient) { + public static void configureSslSocket(SSLSocket socket, boolean isDeviceTrusted, boolean isClient) throws SocketException { socket.setEnabledProtocols(new String[]{"TLSv1"}); //Newer TLS versions are only supported on API 16+ @@ -223,6 +224,8 @@ public class SslHelper { } socket.setEnabledCipherSuites(supportedCiphers.toArray(new String[supportedCiphers.size()])); + socket.setSoTimeout(1000); + if (isClient) { socket.setUseClientMode(true); } else {