From fcde642563980c65187ef695d8679d0b9afa12de Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Tue, 24 Feb 2015 16:37:37 -0800 Subject: [PATCH] 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 --- .../securesms/ConversationActivity.java | 23 +++++++++++-------- .../securesms/util/DirectoryHelper.java | 21 +++++++++++++++++ 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index bb849b42db..a97183cc4a 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -68,6 +68,7 @@ import org.thoughtcrime.securesms.database.DraftDatabase.Draft; import org.thoughtcrime.securesms.database.DraftDatabase.Drafts; import org.thoughtcrime.securesms.database.GroupDatabase; import org.thoughtcrime.securesms.database.MmsSmsColumns.Types; +import org.thoughtcrime.securesms.database.TextSecureDirectory; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.mms.AttachmentManager; import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter; @@ -681,25 +682,29 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private void initializeSecurity() { - SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret); - Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient(); - boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients()); - boolean isSecureDestination = isSingleConversation() && sessionStore.containsSession(primaryRecipient.getRecipientId(), - PushAddress.DEFAULT_DEVICE_ID); + SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret); + Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient(); + boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients()); + boolean isSecureSmsAllowed = (!isPushDestination || DirectoryHelper.isSmsFallbackAllowed(this, getRecipients())); + boolean isSecureSmsDestination = isSecureSmsAllowed && + isSingleConversation() && + sessionStore.containsSession(primaryRecipient.getRecipientId(), + PushAddress.DEFAULT_DEVICE_ID); - if (isPushDestination || isSecureDestination) { + if (isPushDestination || isSecureSmsDestination) { this.isEncryptedConversation = true; } else { this.isEncryptedConversation = false; } sendButton.initializeAvailableTransports(!recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent()); - if (!isPushDestination ) sendButton.disableTransport("textsecure"); - if (!isSecureDestination) sendButton.disableTransport("secure_sms"); + if (!isPushDestination ) sendButton.disableTransport("textsecure"); + if (!isSecureSmsDestination ) sendButton.disableTransport("secure_sms"); + if (recipients.isGroupRecipient()) sendButton.disableTransport("insecure_sms"); if (isPushDestination) { sendButton.setDefaultTransport("textsecure"); - } else if (isSecureDestination) { + } else if (isSecureSmsDestination) { sendButton.setDefaultTransport("secure_sms"); } else { sendButton.setDefaultTransport("insecure_sms"); diff --git a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java index aeb5216cf7..55436d08ef 100644 --- a/src/org/thoughtcrime/securesms/util/DirectoryHelper.java +++ b/src/org/thoughtcrime/securesms/util/DirectoryHelper.java @@ -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 void onUpdateFinished(); }