mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Correctly handle key conflict resolution for incoming push.
This commit is contained in:
parent
315cf2d8e4
commit
125a60290f
@ -354,6 +354,7 @@ public class ConversationItem extends LinearLayout {
|
|||||||
intent.putExtra("message_id", messageRecord.getId());
|
intent.putExtra("message_id", messageRecord.getId());
|
||||||
intent.putExtra("is_bundle", messageRecord.isBundleKeyExchange());
|
intent.putExtra("is_bundle", messageRecord.isBundleKeyExchange());
|
||||||
intent.putExtra("is_identity_update", messageRecord.isIdentityUpdate());
|
intent.putExtra("is_identity_update", messageRecord.isIdentityUpdate());
|
||||||
|
intent.putExtra("is_push", messageRecord.isPush());
|
||||||
intent.putExtra("master_secret", masterSecret);
|
intent.putExtra("master_secret", masterSecret);
|
||||||
intent.putExtra("sent", messageRecord.isOutgoing());
|
intent.putExtra("sent", messageRecord.isOutgoing());
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
@ -36,8 +36,10 @@ import org.thoughtcrime.securesms.crypto.KeyExchangeProcessorV2;
|
|||||||
import org.thoughtcrime.securesms.crypto.protocol.KeyExchangeMessage;
|
import org.thoughtcrime.securesms.crypto.protocol.KeyExchangeMessage;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
|
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||||
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
|
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
|
||||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.textsecure.crypto.IdentityKey;
|
import org.whispersystems.textsecure.crypto.IdentityKey;
|
||||||
import org.whispersystems.textsecure.crypto.InvalidKeyException;
|
import org.whispersystems.textsecure.crypto.InvalidKeyException;
|
||||||
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
||||||
@ -45,12 +47,16 @@ import org.whispersystems.textsecure.crypto.InvalidVersionException;
|
|||||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
import org.whispersystems.textsecure.crypto.protocol.CiphertextMessage;
|
import org.whispersystems.textsecure.crypto.protocol.CiphertextMessage;
|
||||||
import org.whispersystems.textsecure.crypto.protocol.PreKeyWhisperMessage;
|
import org.whispersystems.textsecure.crypto.protocol.PreKeyWhisperMessage;
|
||||||
|
import org.whispersystems.textsecure.push.IncomingPushMessage;
|
||||||
import org.whispersystems.textsecure.storage.InvalidKeyIdException;
|
import org.whispersystems.textsecure.storage.InvalidKeyIdException;
|
||||||
import org.whispersystems.textsecure.storage.RecipientDevice;
|
import org.whispersystems.textsecure.storage.RecipientDevice;
|
||||||
import org.whispersystems.textsecure.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.whispersystems.textsecure.push.PushMessageProtos.IncomingPushMessageSignal.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity for displaying sent/received session keys.
|
* Activity for displaying sent/received session keys.
|
||||||
*
|
*
|
||||||
@ -162,8 +168,14 @@ public class ReceiveKeyActivity extends Activity {
|
|||||||
String messageBody = getIntent().getStringExtra("body");
|
String messageBody = getIntent().getStringExtra("body");
|
||||||
|
|
||||||
if (getIntent().getBooleanExtra("is_bundle", false)) {
|
if (getIntent().getBooleanExtra("is_bundle", false)) {
|
||||||
SmsTransportDetails transportDetails = new SmsTransportDetails();
|
boolean isPush = getIntent().getBooleanExtra("is_push", false);
|
||||||
byte[] body = transportDetails.getDecodedMessage(messageBody.getBytes());
|
byte[] body;
|
||||||
|
|
||||||
|
if (isPush) {
|
||||||
|
body = Base64.decode(messageBody.getBytes());
|
||||||
|
} else {
|
||||||
|
body = new SmsTransportDetails().getDecodedMessage(messageBody.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
this.keyExchangeMessageBundle = new PreKeyWhisperMessage(body);
|
this.keyExchangeMessageBundle = new PreKeyWhisperMessage(body);
|
||||||
} else if (getIntent().getBooleanExtra("is_identity_update", false)) {
|
} else if (getIntent().getBooleanExtra("is_identity_update", false)) {
|
||||||
@ -227,16 +239,30 @@ public class ReceiveKeyActivity extends Activity {
|
|||||||
masterSecret, recipientDevice);
|
masterSecret, recipientDevice);
|
||||||
processor.processKeyExchangeMessage(keyExchangeMessageBundle);
|
processor.processKeyExchangeMessage(keyExchangeMessageBundle);
|
||||||
|
|
||||||
CiphertextMessage bundledMessage = keyExchangeMessageBundle.getWhisperMessage();
|
CiphertextMessage bundledMessage = keyExchangeMessageBundle.getWhisperMessage();
|
||||||
SmsTransportDetails transportDetails = new SmsTransportDetails();
|
|
||||||
String messageBody = new String(transportDetails.getEncodedMessage(bundledMessage.serialize()));
|
|
||||||
|
|
||||||
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
if (getIntent().getBooleanExtra("is_push", false)) {
|
||||||
.updateBundleMessageBody(masterSecret, messageId, messageBody);
|
String source = Util.canonicalizeNumber(ReceiveKeyActivity.this, recipient.getNumber());
|
||||||
|
IncomingPushMessage incoming = new IncomingPushMessage(Type.CIPHERTEXT_VALUE, source, recipientDeviceId, bundledMessage.serialize(), System.currentTimeMillis());
|
||||||
|
|
||||||
DecryptingQueue.scheduleDecryption(ReceiveKeyActivity.this, masterSecret, messageId,
|
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
||||||
threadId, recipient.getNumber(), recipientDeviceId,
|
.markAsProcessedKeyExchange(messageId);
|
||||||
messageBody, true, false, false);
|
|
||||||
|
Intent intent = new Intent(ReceiveKeyActivity.this, SendReceiveService.class);
|
||||||
|
intent.setAction(SendReceiveService.RECEIVE_PUSH_ACTION);
|
||||||
|
intent.putExtra("message", incoming);
|
||||||
|
startService(intent);
|
||||||
|
} else {
|
||||||
|
SmsTransportDetails transportDetails = new SmsTransportDetails();
|
||||||
|
String messageBody = new String(transportDetails.getEncodedMessage(bundledMessage.serialize()));
|
||||||
|
|
||||||
|
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
||||||
|
.updateBundleMessageBody(masterSecret, messageId, messageBody);
|
||||||
|
|
||||||
|
DecryptingQueue.scheduleDecryption(ReceiveKeyActivity.this, masterSecret, messageId,
|
||||||
|
threadId, recipient.getNumber(), recipientDeviceId,
|
||||||
|
messageBody, true, false, false);
|
||||||
|
}
|
||||||
} catch (InvalidKeyIdException e) {
|
} catch (InvalidKeyIdException e) {
|
||||||
Log.w("ReceiveKeyActivity", e);
|
Log.w("ReceiveKeyActivity", e);
|
||||||
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
||||||
@ -245,6 +271,10 @@ public class ReceiveKeyActivity extends Activity {
|
|||||||
Log.w("ReceiveKeyActivity", e);
|
Log.w("ReceiveKeyActivity", e);
|
||||||
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
||||||
.markAsCorruptKeyExchange(messageId);
|
.markAsCorruptKeyExchange(messageId);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
Log.w("ReceiveKeyActivity", e);
|
||||||
|
DatabaseFactory.getEncryptingSmsDatabase(ReceiveKeyActivity.this)
|
||||||
|
.markAsCorruptKeyExchange(messageId);
|
||||||
}
|
}
|
||||||
} else if (identityUpdateMessage != null) {
|
} else if (identityUpdateMessage != null) {
|
||||||
DatabaseFactory.getIdentityDatabase(ReceiveKeyActivity.this)
|
DatabaseFactory.getIdentityDatabase(ReceiveKeyActivity.this)
|
||||||
|
@ -36,6 +36,7 @@ import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent;
|
|||||||
import org.whispersystems.textsecure.storage.InvalidKeyIdException;
|
import org.whispersystems.textsecure.storage.InvalidKeyIdException;
|
||||||
import org.whispersystems.textsecure.storage.RecipientDevice;
|
import org.whispersystems.textsecure.storage.RecipientDevice;
|
||||||
import org.whispersystems.textsecure.storage.Session;
|
import org.whispersystems.textsecure.storage.Session;
|
||||||
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import ws.com.google.android.mms.MmsException;
|
import ws.com.google.android.mms.MmsException;
|
||||||
|
|
||||||
@ -121,12 +122,11 @@ public class PushReceiver {
|
|||||||
IncomingPushMessage bundledMessage = message.withBody(preKeyExchange.getWhisperMessage().serialize());
|
IncomingPushMessage bundledMessage = message.withBody(preKeyExchange.getWhisperMessage().serialize());
|
||||||
handleReceivedSecureMessage(masterSecret, bundledMessage);
|
handleReceivedSecureMessage(masterSecret, bundledMessage);
|
||||||
} else {
|
} else {
|
||||||
SmsTransportDetails transportDetails = new SmsTransportDetails();
|
String encoded = Base64.encodeBytes(message.getBody());
|
||||||
String encoded = new String(transportDetails.getEncodedMessage(message.getBody()));
|
IncomingTextMessage textMessage = new IncomingTextMessage(message, encoded, null);
|
||||||
IncomingTextMessage textMessage = new IncomingTextMessage(message, "", null);
|
IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded);
|
||||||
|
|
||||||
textMessage = new IncomingPreKeyBundleMessage(textMessage, encoded);
|
DatabaseFactory.getEncryptingSmsDatabase(context).insertMessageInbox(masterSecret, bundleMessage);
|
||||||
DatabaseFactory.getEncryptingSmsDatabase(context).insertMessageInbox(masterSecret, textMessage);
|
|
||||||
}
|
}
|
||||||
} catch (InvalidKeyException e) {
|
} catch (InvalidKeyException e) {
|
||||||
Log.w("PushReceiver", e);
|
Log.w("PushReceiver", e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user