Skip to content

Commit

Permalink
Display legacy message error when V1 message is received.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Apr 10, 2014
1 parent be725e9 commit 89d93e7
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 12 deletions.
Expand Up @@ -133,4 +133,9 @@ public int getType() {
return CiphertextMessage.WHISPER_TYPE;
}

public static boolean isLegacy(byte[] message) {
return message != null && message.length >= 1 &&
Conversions.highBitsToInt(message[0]) <= CiphertextMessage.UNSUPPORTED_VERSION;
}

}
3 changes: 3 additions & 0 deletions res/values/strings.xml
Expand Up @@ -198,6 +198,9 @@
<!-- NotificationMmsMessageRecord -->
<string name="NotificationMmsMessageRecord_multimedia_message">Multimedia Message</string>

<!-- MessageRecord -->
<string name="MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported">Message encrypted with a legacy protocol version that is no longer supported. Please ask the sender to upgrade TextSecure to the most recent version.</string>

<!-- PassphraseChangeActivity -->
<string name="PassphraseChangeActivity_passphrases_dont_match_exclamation">Passphrases Don\'t Match!</string>
<string name="PassphraseChangeActivity_incorrect_old_passphrase_exclamation">Incorrect old passphrase!</string>
Expand Down
13 changes: 8 additions & 5 deletions src/org/thoughtcrime/securesms/crypto/DecryptingQueue.java
Expand Up @@ -47,6 +47,7 @@
import org.whispersystems.textsecure.crypto.InvalidVersionException;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.SessionCipher;
import org.whispersystems.textsecure.crypto.protocol.WhisperMessage;
import org.whispersystems.textsecure.push.IncomingPushMessage;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.storage.Session;
Expand Down Expand Up @@ -375,15 +376,17 @@ private void handleRemoteAsymmetricEncrypt() {
Recipient recipient = recipients.getPrimaryRecipient();
RecipientDevice recipientDevice = new RecipientDevice(recipient.getRecipientId(), deviceId);

SmsTransportDetails transportDetails = new SmsTransportDetails();
byte[] decodedCiphertext = transportDetails.getDecodedMessage(body.getBytes());

if (!Session.hasSession(context, masterSecret, recipient)) {
database.markAsNoSession(messageId);
if (WhisperMessage.isLegacy(decodedCiphertext)) database.markAsLegacyVersion(messageId);
else database.markAsNoSession(messageId);
return;
}

SmsTransportDetails transportDetails = new SmsTransportDetails();
SessionCipher sessionCipher = SessionCipher.createFor(context, masterSecret, recipientDevice);
byte[] decodedCiphertext = transportDetails.getDecodedMessage(body.getBytes());
byte[] paddedPlaintext = sessionCipher.decrypt(decodedCiphertext);
SessionCipher sessionCipher = SessionCipher.createFor(context, masterSecret, recipientDevice);
byte[] paddedPlaintext = sessionCipher.decrypt(decodedCiphertext);

plaintextBody = new String(transportDetails.getStrippedPaddingMessageBody(paddedPlaintext));

Expand Down
2 changes: 1 addition & 1 deletion src/org/thoughtcrime/securesms/database/MmsDatabase.java
Expand Up @@ -362,7 +362,7 @@ public void markAsDecryptDuplicate(long messageId, long threadId) {
}

public void markAsLegacyVersion(long messageId, long threadId) {
updateMailboxBitmask(messageId, 0, Types.LEGACY_MESSAGE_BIT);
updateMailboxBitmask(messageId, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_LEGACY_BIT);
notifyConversationListeners(threadId);
}

Expand Down
6 changes: 5 additions & 1 deletion src/org/thoughtcrime/securesms/database/MmsSmsColumns.java
Expand Up @@ -47,7 +47,6 @@ public static class Types {
protected static final long SECURE_MESSAGE_BIT = 0x800000;
protected static final long END_SESSION_BIT = 0x400000;
protected static final long PUSH_MESSAGE_BIT = 0x200000;
protected static final long LEGACY_MESSAGE_BIT = 0x100000;

// Group Message Information
protected static final long GROUP_UPDATE_BIT = 0x10000;
Expand All @@ -61,6 +60,7 @@ public static class Types {
protected static final long ENCRYPTION_REMOTE_FAILED_BIT = 0x10000000;
protected static final long ENCRYPTION_REMOTE_NO_SESSION_BIT = 0x08000000;
protected static final long ENCRYPTION_REMOTE_DUPLICATE_BIT = 0x04000000;
protected static final long ENCRYPTION_REMOTE_LEGACY_BIT = 0x02000000;

public static boolean isFailedMessageType(long type) {
return (type & BASE_TYPE_MASK) == BASE_SENT_FAILED_TYPE;
Expand Down Expand Up @@ -172,6 +172,10 @@ public static boolean isNoRemoteSessionType(long type) {
return (type & ENCRYPTION_REMOTE_NO_SESSION_BIT) != 0;
}

public static boolean isLegacyType(long type) {
return (type & ENCRYPTION_REMOTE_LEGACY_BIT) != 0;
}

public static long translateFromSystemBaseType(long theirType) {
// public static final int NONE_TYPE = 0;
// public static final int INBOX_TYPE = 1;
Expand Down
10 changes: 5 additions & 5 deletions src/org/thoughtcrime/securesms/database/SmsDatabase.java
Expand Up @@ -170,10 +170,6 @@ public void markAsInvalidVersionKeyExchange(long id) {
updateTypeBitmask(id, 0, Types.KEY_EXCHANGE_INVALID_VERSION_BIT);
}

public void markAsLegacyVersion(long id) {
updateTypeBitmask(id, 0, Types.LEGACY_MESSAGE_BIT);
}

public void markAsSecure(long id) {
updateTypeBitmask(id, 0, Types.SECURE_MESSAGE_BIT);
}
Expand Down Expand Up @@ -206,6 +202,10 @@ public void markAsDecrypting(long id) {
updateTypeBitmask(id, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_BIT);
}

public void markAsLegacyVersion(long id) {
updateTypeBitmask(id, Types.ENCRYPTION_MASK, Types.ENCRYPTION_REMOTE_LEGACY_BIT);
}

public void markAsOutbox(long id) {
updateTypeBitmask(id, Types.BASE_TYPE_MASK, Types.BASE_OUTBOX_TYPE);
}
Expand Down Expand Up @@ -280,7 +280,7 @@ protected Pair<Long, Long> insertMessageInbox(IncomingTextMessage message, long
else if (((IncomingKeyExchangeMessage)message).isCorrupted()) type |= Types.KEY_EXCHANGE_CORRUPTED_BIT;
else if (((IncomingKeyExchangeMessage)message).isInvalidVersion()) type |= Types.KEY_EXCHANGE_INVALID_VERSION_BIT;
else if (((IncomingKeyExchangeMessage)message).isIdentityUpdate()) type |= Types.KEY_EXCHANGE_IDENTITY_UPDATE_BIT;
else if (((IncomingKeyExchangeMessage)message).isLegacyVersion()) type |= Types.LEGACY_MESSAGE_BIT;
else if (((IncomingKeyExchangeMessage)message).isLegacyVersion()) type |= Types.ENCRYPTION_REMOTE_LEGACY_BIT;
else if (((IncomingKeyExchangeMessage)message).isPreKeyBundle()) type |= Types.KEY_EXCHANGE_BUNDLE_BIT;
} else if (message.isSecureMessage()) {
type |= Types.SECURE_MESSAGE_BIT;
Expand Down
Expand Up @@ -78,6 +78,8 @@ public SpannableString getDisplayBody() {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_duplicate_message));
} else if (MmsDatabase.Types.isNoRemoteSessionType(type)) {
return emphasisAdded(context.getString(R.string.MmsMessageRecord_mms_message_encrypted_for_non_existing_session));
} else if (isLegacyMessage()) {
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
} else if (!getBody().isPlaintext()) {
return emphasisAdded(context.getString(R.string.MessageNotifier_encrypted_message));
}
Expand Down
Expand Up @@ -81,6 +81,10 @@ public boolean isSecure() {
return MmsSmsColumns.Types.isSecureType(type);
}

public boolean isLegacyMessage() {
return MmsSmsColumns.Types.isLegacyType(type);
}

@Override
public SpannableString getDisplayBody() {
if (isGroupUpdate() && isOutgoing()) {
Expand Down
Expand Up @@ -21,6 +21,7 @@
import android.text.SpannableString;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.MmsSmsColumns;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.protocol.Tag;
import org.thoughtcrime.securesms.recipients.Recipient;
Expand Down Expand Up @@ -63,6 +64,8 @@ public SpannableString getDisplayBody() {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_received_corrupted_key_exchange_message));
} else if (isInvalidVersionKeyExchange()) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_received_key_exchange_message_for_invalid_protocol_version));
} else if (MmsSmsColumns.Types.isLegacyType(type)) {
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
} else if (isBundleKeyExchange()) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_received_message_with_unknown_identity_key_click_to_process));
} else if (isIdentityUpdate()) {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import android.text.style.StyleSpan;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.MmsSmsColumns;
import org.thoughtcrime.securesms.database.SmsDatabase;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.GroupUtil;
Expand Down Expand Up @@ -69,6 +70,8 @@ public SpannableString getDisplayBody() {
return emphasisAdded(context.getString(R.string.MessageNotifier_encrypted_message));
} else if (SmsDatabase.Types.isEndSessionType(type)) {
return emphasisAdded(context.getString(R.string.TheadRecord_secure_session_ended));
} else if (MmsSmsColumns.Types.isLegacyType(type)) {
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
} else {
if (Util.isEmpty(getBody().getBody())) {
return new SpannableString(context.getString(R.string.MessageNotifier_no_subject));
Expand Down

0 comments on commit 89d93e7

Please sign in to comment.