Delete archived sessions on identity change

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-02-19 12:29:08 -08:00
parent 7d10560575
commit 0075940050
2 changed files with 28 additions and 13 deletions

View File

@ -11,6 +11,7 @@ import android.text.method.LinkMovementMethod;
import android.widget.TextView; import android.widget.TextView;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.IdentityDatabase; import org.thoughtcrime.securesms.database.IdentityDatabase;
import org.thoughtcrime.securesms.database.MmsAddressDatabase; import org.thoughtcrime.securesms.database.MmsAddressDatabase;
@ -27,8 +28,10 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender; import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.util.Base64; import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VerifySpan; import org.thoughtcrime.securesms.util.VerifySpan;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos; import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import java.io.IOException; import java.io.IOException;
@ -45,8 +48,11 @@ public class ConfirmIdentityDialog extends AlertDialog {
IdentityKeyMismatch mismatch) IdentityKeyMismatch mismatch)
{ {
super(context); super(context);
try {
Recipient recipient = RecipientFactory.getRecipientForId(context, mismatch.getRecipientId(), false); Recipient recipient = RecipientFactory.getRecipientForId(context, mismatch.getRecipientId(), false);
String name = recipient.toShortString(); String name = recipient.toShortString();
String number = Util.canonicalizeNumber(context, recipient.getNumber());
String introduction = String.format(context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed), name, name); String introduction = String.format(context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed), name, name);
SpannableString spannableString = new SpannableString(introduction + " " + SpannableString spannableString = new SpannableString(introduction + " " +
context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact)); context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact));
@ -58,8 +64,11 @@ public class ConfirmIdentityDialog extends AlertDialog {
setTitle(name); setTitle(name);
setMessage(spannableString); setMessage(spannableString);
setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ConfirmIdentityDialog_accept), new AcceptListener(masterSecret, messageRecord, mismatch)); setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ConfirmIdentityDialog_accept), new AcceptListener(masterSecret, messageRecord, mismatch, number));
setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), new CancelListener()); setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), new CancelListener());
} catch (InvalidNumberException e) {
throw new AssertionError(e);
}
} }
@Override @Override
@ -78,11 +87,13 @@ public class ConfirmIdentityDialog extends AlertDialog {
private final MasterSecret masterSecret; private final MasterSecret masterSecret;
private final MessageRecord messageRecord; private final MessageRecord messageRecord;
private final IdentityKeyMismatch mismatch; private final IdentityKeyMismatch mismatch;
private final String number;
private AcceptListener(MasterSecret masterSecret, MessageRecord messageRecord, IdentityKeyMismatch mismatch) { private AcceptListener(MasterSecret masterSecret, MessageRecord messageRecord, IdentityKeyMismatch mismatch, String number) {
this.masterSecret = masterSecret; this.masterSecret = masterSecret;
this.messageRecord = messageRecord; this.messageRecord = messageRecord;
this.mismatch = mismatch; this.mismatch = mismatch;
this.number = number;
} }
@Override @Override
@ -96,6 +107,8 @@ public class ConfirmIdentityDialog extends AlertDialog {
identityDatabase.saveIdentity(mismatch.getRecipientId(), identityDatabase.saveIdentity(mismatch.getRecipientId(),
mismatch.getIdentityKey()); mismatch.getIdentityKey());
new TextSecureSessionStore(getContext()).deleteAllSessions(number);
processMessageRecord(messageRecord); processMessageRecord(messageRecord);
processPendingMessageRecords(messageRecord.getThreadId(), mismatch); processPendingMessageRecords(messageRecord.getThreadId(), mismatch);

View File

@ -4,6 +4,7 @@ import android.content.Context;
import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.SessionUtil;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.jobs.IdentityUpdateJob; import org.thoughtcrime.securesms.jobs.IdentityUpdateJob;
import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.recipients.RecipientFactory;
@ -47,6 +48,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
return true; return true;
} else if (!TextSecurePreferences.isBlockingIdentityUpdates(context)) { } else if (!TextSecurePreferences.isBlockingIdentityUpdates(context)) {
saveIdentity(address, identityKey); saveIdentity(address, identityKey);
new TextSecureSessionStore(context).deleteAllSessions(address.getName());
ApplicationContext.getInstance(context) ApplicationContext.getInstance(context)
.getJobManager() .getJobManager()