Update behavior for incoming SMS path.

1) On KitKat, unencrypted SMS messages are never stored in
   TextSecure unless it is set as the system-wide default.

2) On KitKat, if TextSecure is set as the system-wide default,
   provide an option to change the default to a different app.

3) Don't store the TextSecure challenge on KitKat+ devices.
This commit is contained in:
Moxie Marlinspike 2014-02-28 13:36:47 -08:00
parent a3e900ecbe
commit 81ee9e31c5
4 changed files with 33 additions and 21 deletions

View File

@ -27,6 +27,10 @@
<string name="ApplicationPreferencesActivity_you_are_not_registered_with_the_push_service">You are not registered with the push service...</string> <string name="ApplicationPreferencesActivity_you_are_not_registered_with_the_push_service">You are not registered with the push service...</string>
<string name="ApplicationPreferencesActivity_updating_directory">Updating directory</string> <string name="ApplicationPreferencesActivity_updating_directory">Updating directory</string>
<string name="ApplicationPreferencesActivity_updating_push_directory">Updating push directory...</string> <string name="ApplicationPreferencesActivity_updating_push_directory">Updating push directory...</string>
<string name="ApplicationPreferencesActivity_sms_enabled">SMS Enabled</string>
<string name="ApplicationPreferencesActivity_touch_to_change_your_default_sms_app">Touch to change your default SMS app</string>
<string name="ApplicationPreferencesActivity_sms_disabled">SMS Disabled</string>
<string name="ApplicationPreferencesActivity_touch_to_make_textsecure_your_default_sms_app">Touch to make TextSecure your default SMS app</string>
<!-- AttachmentTypeSelectorAdapter --> <!-- AttachmentTypeSelectorAdapter -->

View File

@ -38,6 +38,7 @@ import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.preference.RingtonePreference; import android.preference.RingtonePreference;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.provider.Settings;
import android.provider.Telephony; import android.provider.Telephony;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -101,7 +102,6 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
initializeIdentitySelection(); initializeIdentitySelection();
initializePlatformSpecificOptions();
initializeSmsFallbackOption(); initializeSmsFallbackOption();
initializePushMessagingToggle(); initializePushMessagingToggle();
@ -142,6 +142,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
super.onResume(); super.onResume();
dynamicTheme.onResume(this); dynamicTheme.onResume(this);
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
initializePlatformSpecificOptions();
} }
@Override @Override
@ -187,21 +189,26 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
private void initializePlatformSpecificOptions() { private void initializePlatformSpecificOptions() {
PreferenceGroup generalCategory = (PreferenceGroup) findPreference("general_category"); PreferenceGroup generalCategory = (PreferenceGroup) findPreference("general_category");
Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF); Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF);
Preference allSmsPreference = findPreference(TextSecurePreferences.ALL_SMS_PREF);
Preference allMmsPreference = findPreference(TextSecurePreferences.ALL_MMS_PREF);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
generalCategory.removePreference(findPreference(TextSecurePreferences.ALL_SMS_PREF)); if (allSmsPreference != null) generalCategory.removePreference(allSmsPreference);
generalCategory.removePreference(findPreference(TextSecurePreferences.ALL_MMS_PREF)); if (allMmsPreference != null) generalCategory.removePreference(allMmsPreference);
if (Util.isDefaultSmsProvider(this)) { if (Util.isDefaultSmsProvider(this)) {
generalCategory.removePreference(defaultPreference); defaultPreference.setIntent(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_enabled));
defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_change_your_default_sms_app));
} else { } else {
Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName()); intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, getPackageName());
defaultPreference.setIntent(intent); defaultPreference.setIntent(intent);
defaultPreference.setTitle(getString(R.string.ApplicationPreferencesActivity_sms_disabled));
defaultPreference.setSummary(getString(R.string.ApplicationPreferencesActivity_touch_to_make_textsecure_your_default_sms_app));
} }
} else { } else {
generalCategory.removePreference(defaultPreference); if (defaultPreference != null) generalCategory.removePreference(defaultPreference);
} }
} }

View File

@ -50,8 +50,7 @@ public class MmsListener extends BroadcastReceiver {
return false; return false;
} }
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT &&
TextSecurePreferences.isSmsFallbackEnabled(context)) ||
TextSecurePreferences.isInterceptAllMmsEnabled(context)) TextSecurePreferences.isInterceptAllMmsEnabled(context))
{ {
return true; return true;
@ -76,7 +75,10 @@ public class MmsListener extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.w("MmsListener", "Got MMS broadcast..." + intent.getAction()); Log.w("MmsListener", "Got MMS broadcast..." + intent.getAction());
if (isRelevant(context, intent)) { if (Telephony.Sms.Intents.WAP_PUSH_DELIVER_ACTION.equals(intent.getAction()) ||
(Telephony.Sms.Intents.WAP_PUSH_RECEIVED_ACTION.equals(intent.getAction()) &&
isRelevant(context, intent)))
{
Log.w("MmsListener", "Relevant!"); Log.w("MmsListener", "Relevant!");
intent.setAction(SendReceiveService.RECEIVE_MMS_ACTION); intent.setAction(SendReceiveService.RECEIVE_MMS_ACTION);
intent.putExtra("ResultCode", this.getResultCode()); intent.putExtra("ResultCode", this.getResultCode());

View File

@ -19,25 +19,23 @@ package org.thoughtcrime.securesms.service;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager; import android.os.Bundle;
import android.provider.Telephony;
import android.telephony.SmsMessage; import android.telephony.SmsMessage;
import android.util.Log; import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.protocol.WirePrefix; import org.thoughtcrime.securesms.protocol.WirePrefix;
import org.thoughtcrime.securesms.sms.IncomingTextMessage; import org.thoughtcrime.securesms.sms.IncomingTextMessage;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import java.util.ArrayList; import java.util.ArrayList;
public class SmsListener extends BroadcastReceiver { public class SmsListener extends BroadcastReceiver {
private static final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED"; private static final String SMS_RECEIVED_ACTION = Telephony.Sms.Intents.SMS_RECEIVED_ACTION;
private static final String SMS_DELIVERED_ACTION = "android.provider.Telephony.SMS_DELIVER"; private static final String SMS_DELIVERED_ACTION = Telephony.Sms.Intents.SMS_DELIVER_ACTION;
private boolean isExemption(SmsMessage message, String messageBody) { private boolean isExemption(SmsMessage message, String messageBody) {
@ -103,6 +101,9 @@ public class SmsListener extends BroadcastReceiver {
if (!ApplicationMigrationService.isDatabaseImported(context)) if (!ApplicationMigrationService.isDatabaseImported(context))
return false; return false;
if (isChallenge(context, intent))
return false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
SMS_RECEIVED_ACTION.equals(intent.getAction()) && SMS_RECEIVED_ACTION.equals(intent.getAction()) &&
Util.isDefaultSmsProvider(context)) Util.isDefaultSmsProvider(context))
@ -110,8 +111,7 @@ public class SmsListener extends BroadcastReceiver {
return false; return false;
} }
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT &&
TextSecurePreferences.isSmsFallbackEnabled(context)) ||
TextSecurePreferences.isInterceptAllSmsEnabled(context)) TextSecurePreferences.isInterceptAllSmsEnabled(context))
{ {
return true; return true;
@ -154,9 +154,8 @@ public class SmsListener extends BroadcastReceiver {
context.sendBroadcast(challengeIntent); context.sendBroadcast(challengeIntent);
abortBroadcast(); abortBroadcast();
} else if ((intent.getAction().equals(SMS_RECEIVED_ACTION) || } else if ((intent.getAction().equals(SMS_DELIVERED_ACTION)) ||
intent.getAction().equals(SMS_DELIVERED_ACTION)) && (intent.getAction().equals(SMS_RECEIVED_ACTION)) && isRelevant(context, intent))
isRelevant(context, intent))
{ {
Intent receivedIntent = new Intent(context, SendReceiveService.class); Intent receivedIntent = new Intent(context, SendReceiveService.class);
receivedIntent.setAction(SendReceiveService.RECEIVE_SMS_ACTION); receivedIntent.setAction(SendReceiveService.RECEIVE_SMS_ACTION);