mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 23:25:10 +00:00
Unpair only when there is no certificate
Unpairing on every error was a bit too aggressive. BUG: 367937
This commit is contained in:
@@ -198,6 +198,20 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
SharedPreferences preferences = context.getSharedPreferences("trusted_devices", Context.MODE_PRIVATE);
|
SharedPreferences preferences = context.getSharedPreferences("trusted_devices", Context.MODE_PRIVATE);
|
||||||
boolean isDeviceTrusted = preferences.getBoolean(deviceId, false);
|
boolean isDeviceTrusted = preferences.getBoolean(deviceId, false);
|
||||||
|
|
||||||
|
if (isDeviceTrusted && !SslHelper.isCertificateStored(context, deviceId)) {
|
||||||
|
//Device paired with and old version, we can't use it as we lack the certificate
|
||||||
|
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
Device device = service.getDevice(deviceId);
|
||||||
|
if (device == null) return;
|
||||||
|
device.unpair();
|
||||||
|
//Retry as unpaired
|
||||||
|
identityPackageReceived(identityPackage, socket, connectionStarted);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Log.i("KDE/LanLinkProvider","Starting SSL handshake with " + identityPackage.getString("deviceName") + " trusted:"+isDeviceTrusted);
|
Log.i("KDE/LanLinkProvider","Starting SSL handshake with " + identityPackage.getString("deviceName") + " trusted:"+isDeviceTrusted);
|
||||||
|
|
||||||
final SSLSocket sslsocket = SslHelper.convertToSslSocket(context, socket, deviceId, isDeviceTrusted, clientMode);
|
final SSLSocket sslsocket = SslHelper.convertToSslSocket(context, socket, deviceId, isDeviceTrusted, clientMode);
|
||||||
@@ -249,15 +263,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
|
||||||
Log.e("LanLinkProvider", "Unpairing "+(device != null));
|
|
||||||
if (device == null) return;
|
|
||||||
device.unpair();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -131,6 +131,12 @@ public class SslHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isCertificateStored(Context context, String deviceId) {
|
||||||
|
SharedPreferences devicePreferences = context.getSharedPreferences(deviceId, Context.MODE_PRIVATE);
|
||||||
|
String cert = devicePreferences.getString("certificate", "");
|
||||||
|
return !cert.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public static SSLContext getSslContext(Context context, String deviceId, boolean isDeviceTrusted) {
|
public static SSLContext getSslContext(Context context, String deviceId, boolean isDeviceTrusted) {
|
||||||
//TODO: Cache
|
//TODO: Cache
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user