mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-05 00:25:09 +00:00
NetworkPackage.encrypt now returns a new package instead of changing itself
This was causing problems with plugins that keep a reference to the packages they have already sent, like the telephony plugin, because the package became encrypted (and thus inaccessible) after sending it. BUG: 326275
This commit is contained in:
@@ -22,7 +22,7 @@ public class LanLink extends BaseLink {
|
|||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (session == null) return;
|
if (session == null) return;
|
||||||
Log.i("LanLink", "Disconnect: "+session.getRemoteAddress().toString());
|
//Log.i("LanLink", "Disconnect: "+session.getRemoteAddress().toString());
|
||||||
session.close(true);
|
session.close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ public class LanLink extends BaseLink {
|
|||||||
if (thread == null) return false;
|
if (thread == null) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
np.encrypt(key);
|
np = np.encrypt(key);
|
||||||
WriteFuture future = session.write(np.serialize());
|
WriteFuture future = session.write(np.serialize());
|
||||||
if (!future.await().isWritten()) return false;
|
if (!future.await().isWritten()) return false;
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ public class LoopbackLink extends BaseLink {
|
|||||||
@Override
|
@Override
|
||||||
public boolean sendPackageEncrypted(NetworkPackage in, PublicKey key) {
|
public boolean sendPackageEncrypted(NetworkPackage in, PublicKey key) {
|
||||||
try {
|
try {
|
||||||
in.encrypt(key);
|
in = in.encrypt(key);
|
||||||
String s = in.serialize();
|
String s = in.serialize();
|
||||||
NetworkPackage out= NetworkPackage.unserialize(s);
|
NetworkPackage out= NetworkPackage.unserialize(s);
|
||||||
out.decrypt(privateKey);
|
out.decrypt(privateKey);
|
||||||
|
@@ -469,6 +469,7 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
//Log.e("sendPackage", "Sending package...");
|
//Log.e("sendPackage", "Sending package...");
|
||||||
|
//Log.e("sendPackage", np.serialize());
|
||||||
|
|
||||||
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
boolean useEncryption = (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_PAIR) && isPaired());
|
||||||
|
|
||||||
|
@@ -76,6 +76,9 @@ public class NetworkPackage {
|
|||||||
public double getDouble(String key) { return mBody.optDouble(key,Double.NaN); }
|
public double getDouble(String key) { return mBody.optDouble(key,Double.NaN); }
|
||||||
public double getDouble(String key, double defaultValue) { return mBody.optDouble(key,defaultValue); }
|
public double getDouble(String key, double defaultValue) { return mBody.optDouble(key,defaultValue); }
|
||||||
public void set(String key, double value) { try { mBody.put(key,value); } catch(Exception e) { } }
|
public void set(String key, double value) { try { mBody.put(key,value); } catch(Exception e) { } }
|
||||||
|
public JSONArray getJSONArray(String key) { return mBody.optJSONArray(key); }
|
||||||
|
public void set(String key, JSONArray value) { try { mBody.put(key,value); } catch(Exception e) { } }
|
||||||
|
|
||||||
public ArrayList<String> getStringList(String key) {
|
public ArrayList<String> getStringList(String key) {
|
||||||
JSONArray jsonArray = mBody.optJSONArray(key);
|
JSONArray jsonArray = mBody.optJSONArray(key);
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
@@ -105,7 +108,6 @@ public class NetworkPackage {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean has(String key) { return mBody.has(key); }
|
public boolean has(String key) { return mBody.has(key); }
|
||||||
|
|
||||||
public boolean isEncrypted() { return mType.equals(PACKAGE_TYPE_ENCRYPTED); }
|
public boolean isEncrypted() { return mType.equals(PACKAGE_TYPE_ENCRYPTED); }
|
||||||
@@ -163,7 +165,7 @@ public class NetworkPackage {
|
|||||||
return np;
|
return np;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void encrypt(PublicKey publicKey) throws Exception {
|
public NetworkPackage encrypt(PublicKey publicKey) throws Exception {
|
||||||
|
|
||||||
String serialized = serialize();
|
String serialized = serialize();
|
||||||
|
|
||||||
@@ -185,17 +187,11 @@ public class NetworkPackage {
|
|||||||
chunks.put(Base64.encodeToString(encryptedChunk, Base64.NO_WRAP));
|
chunks.put(Base64.encodeToString(encryptedChunk, Base64.NO_WRAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
mId = System.currentTimeMillis();
|
//Log.i("NetworkPackage", "Encrypted " + chunks.length()+" chunks");
|
||||||
mType = NetworkPackage.PACKAGE_TYPE_ENCRYPTED;
|
|
||||||
mBody = new JSONObject();
|
|
||||||
try {
|
|
||||||
mBody.put("data", chunks);
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.e("NetworkPackage","Exception");
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i("NetworkPackage", "Encrypted " + chunks.length()+" chunks");
|
NetworkPackage encrypted = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_ENCRYPTED);
|
||||||
|
encrypted.set("data", chunks);
|
||||||
|
return encrypted;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user