Fix invalid transportation options

1) Accounts in the directory that don't have supports_sms can't
   get encrypted SMS.
2) Push groups can't receive insecure SMS

// FREEBIE

Closes #2521
This commit is contained in:
Jake McGinty 2015-02-24 16:37:37 -08:00 committed by Moxie Marlinspike
parent ac0a1c0bc1
commit fcde642563
2 changed files with 35 additions and 9 deletions

View File

@ -68,6 +68,7 @@ import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts; import org.thoughtcrime.securesms.database.DraftDatabase.Drafts;
import org.thoughtcrime.securesms.database.GroupDatabase; import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.database.MmsSmsColumns.Types; import org.thoughtcrime.securesms.database.MmsSmsColumns.Types;
import org.thoughtcrime.securesms.database.TextSecureDirectory;
import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.mms.AttachmentManager; import org.thoughtcrime.securesms.mms.AttachmentManager;
import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter; import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter;
@ -681,25 +682,29 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private void initializeSecurity() { private void initializeSecurity() {
SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret); SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret);
Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient(); Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients()); boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
boolean isSecureDestination = isSingleConversation() && sessionStore.containsSession(primaryRecipient.getRecipientId(), boolean isSecureSmsAllowed = (!isPushDestination || DirectoryHelper.isSmsFallbackAllowed(this, getRecipients()));
PushAddress.DEFAULT_DEVICE_ID); boolean isSecureSmsDestination = isSecureSmsAllowed &&
isSingleConversation() &&
sessionStore.containsSession(primaryRecipient.getRecipientId(),
PushAddress.DEFAULT_DEVICE_ID);
if (isPushDestination || isSecureDestination) { if (isPushDestination || isSecureSmsDestination) {
this.isEncryptedConversation = true; this.isEncryptedConversation = true;
} else { } else {
this.isEncryptedConversation = false; this.isEncryptedConversation = false;
} }
sendButton.initializeAvailableTransports(!recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent()); sendButton.initializeAvailableTransports(!recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent());
if (!isPushDestination ) sendButton.disableTransport("textsecure"); if (!isPushDestination ) sendButton.disableTransport("textsecure");
if (!isSecureDestination) sendButton.disableTransport("secure_sms"); if (!isSecureSmsDestination ) sendButton.disableTransport("secure_sms");
if (recipients.isGroupRecipient()) sendButton.disableTransport("insecure_sms");
if (isPushDestination) { if (isPushDestination) {
sendButton.setDefaultTransport("textsecure"); sendButton.setDefaultTransport("textsecure");
} else if (isSecureDestination) { } else if (isSecureSmsDestination) {
sendButton.setDefaultTransport("secure_sms"); sendButton.setDefaultTransport("secure_sms");
} else { } else {
sendButton.setDefaultTransport("insecure_sms"); sendButton.setDefaultTransport("insecure_sms");

View File

@ -115,6 +115,27 @@ public class DirectoryHelper {
} }
} }
public static boolean isSmsFallbackAllowed(Context context, Recipients recipients) {
try {
if (recipients == null || !recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
return false;
}
final String number = recipients.getPrimaryRecipient().getNumber();
if (number == null) {
return false;
}
final String e164number = Util.canonicalizeNumber(context, number);
return TextSecureDirectory.getInstance(context).isSmsFallbackSupported(e164number);
} catch (InvalidNumberException e) {
Log.w(TAG, e);
return false;
}
}
public static interface DirectoryUpdateFinishedListener { public static interface DirectoryUpdateFinishedListener {
public void onUpdateFinished(); public void onUpdateFinished();
} }