Skip to content

Commit d97252d

Browse files
committed
Add ability to disable local encryption passphrase.
1 parent 68b82c1 commit d97252d

8 files changed

Lines changed: 189 additions & 93 deletions

File tree

AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126

127127
<activity android:name=".PassphraseChangeActivity"
128128
android:label="@string/AndroidManifest__change_passphrase"
129-
android:launchMode="singleInstance"
130129
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
131130

132131
<activity android:name=".VerifyKeysActivity"

res/layout/change_passphrase_activity.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
android:orientation="vertical">
2222

2323
<TextView style="@style/Registration.Label"
24+
android:id="@+id/old_passphrase_label"
2425
android:layout_width="fill_parent"
2526
android:textAllCaps="true"
2627
android:text="@string/change_passphrase_activity__old_passphrase" />

res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<string name="ApplicationPreferencesActivity_are_you_sure_you_would_like_to_immediately_trim_all_conversation_threads_to_the_s_most_recent_messages">Are you sure you would like to immediately trim all conversation threads to the %s most recent messages?</string>
1515
<string name="ApplicationPreferencesActivity_delete">Delete</string>
1616
<string name="ApplicationPreferencesActivity_my">My</string>
17+
<string name="ApplicationPreferencesActivity_disable_storage_encryption">Disable storage encryption?</string>
18+
<string name="ApplicationPreferencesActivity_warning_this_will_disable_storage_encryption_for_all_messages">
19+
Warning, this will disable storage encryption for all messages and keys. Your encrypted
20+
sessions will continue to function, but anyone with physical access to your device will be
21+
able to access them.
22+
</string>
23+
<string name="ApplicationPreferencesActivity_disable">Disable</string>
1724

1825
<!-- AttachmentTypeSelectorAdapter -->
1926

res/xml/preferences.xml

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,30 @@
115115

116116
<PreferenceCategory android:title="@string/preferences__passphrase">
117117

118-
<Preference android:key="pref_change_passphrase"
119-
android:title="@string/preferences__change_passphrase"
120-
android:summary="@string/preferences__change_my_passphrase"/>
121-
122-
<CheckBoxPreference android:defaultValue="false"
123-
android:key="pref_timeout_passphrase"
124-
android:summary="@string/preferences__forget_passphrase_from_memory_after_some_interval"
125-
android:title="@string/preferences__timeout_passphrase" />
126-
127-
128-
<org.thoughtcrime.securesms.preferences.PassphraseTimeoutPreference
129-
android:key="pref_timeout_interval"
130-
android:defaultValue="300"
131-
android:title="@string/preferences__pref_timeout_interval_title"
132-
android:summary="@string/preferences__the_amount_of_time_to_wait_before_forgetting_passphrase"
133-
android:dependency="pref_timeout_passphrase"
134-
android:dialogTitle="@string/preferences__pref_timeout_interval_dialogtitle" />
118+
<Preference android:key="pref_change_passphrase"
119+
android:title="@string/preferences__change_passphrase"
120+
android:summary="@string/preferences__change_my_passphrase"
121+
android:dependency="pref_disable_passphrase"/>
122+
123+
<CheckBoxPreference android:key="pref_disable_passphrase"
124+
android:defaultValue="false"
125+
android:title="Disable Passphrase"
126+
android:disableDependentsState="true"
127+
android:summary="Disable local encryption of messages and keys"/>
128+
129+
<CheckBoxPreference android:defaultValue="false"
130+
android:key="pref_timeout_passphrase"
131+
android:summary="@string/preferences__forget_passphrase_from_memory_after_some_interval"
132+
android:title="@string/preferences__timeout_passphrase"
133+
android:dependency="pref_disable_passphrase"/>
134+
135+
<org.thoughtcrime.securesms.preferences.PassphraseTimeoutPreference
136+
android:key="pref_timeout_interval"
137+
android:defaultValue="300"
138+
android:title="@string/preferences__pref_timeout_interval_title"
139+
android:summary="@string/preferences__the_amount_of_time_to_wait_before_forgetting_passphrase"
140+
android:dependency="pref_timeout_passphrase"
141+
android:dialogTitle="@string/preferences__pref_timeout_interval_dialogtitle" />
135142

136143

137144
</PreferenceCategory>
@@ -142,16 +149,6 @@
142149
android:title="@string/preferences__complete_key_exchanges"
143150
android:summary="@string/preferences__automatically_complete_key_exchanges_for_new_sessions_or_for_existing_sessions_with_the_same_identity_key" />
144151

145-
<PreferenceScreen android:title="@string/preferences__identity_key_settings">
146-
<Preference android:key="pref_view_identity"
147-
android:title="@string/preferences__view_my_identity_key"
148-
android:summary="@string/preferences__view_my_identity_key"/>
149-
150-
<Preference android:key="pref_manage_identity"
151-
android:title="@string/preferences__manage_identity_keys"
152-
android:summary="@string/preferences__manage_configured_identity_keys"/>
153-
</PreferenceScreen>
154-
155152
<PreferenceScreen android:title="@string/preferences__advanced_mms_access_point_names">
156153
<CheckBoxPreference android:key="pref_use_local_apns"
157154
android:defaultValue="false"

src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.content.SharedPreferences;
2424
import android.net.Uri;
2525
import android.os.Bundle;
26+
import android.preference.CheckBoxPreference;
2627
import android.preference.EditTextPreference;
2728
import android.preference.Preference;
2829
import android.preference.PreferenceManager;
@@ -34,9 +35,9 @@
3435
import com.actionbarsherlock.view.MenuItem;
3536
import org.thoughtcrime.securesms.contacts.ContactAccessor;
3637
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
37-
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
3838
import org.thoughtcrime.securesms.crypto.MasterSecret;
3939
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
40+
import org.thoughtcrime.securesms.service.KeyCachingService;
4041
import org.thoughtcrime.securesms.util.DynamicLanguage;
4142
import org.thoughtcrime.securesms.util.DynamicTheme;
4243
import org.thoughtcrime.securesms.util.MemoryCleaner;
@@ -53,7 +54,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
5354
implements SharedPreferences.OnSharedPreferenceChangeListener
5455
{
5556

56-
private static final int PICK_IDENTITY_CONTACT = 1;
57+
private static final int PICK_IDENTITY_CONTACT = 1;
58+
private static final int ENABLE_PASSPHRASE_ACTIVITY = 2;
5759

5860
public static final String RINGTONE_PREF = "pref_key_ringtone";
5961
public static final String VIBRATE_PREF = "pref_key_vibrate";
@@ -73,17 +75,15 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
7375

7476
private static final String DISPLAY_CATEGORY_PREF = "pref_display_category";
7577

76-
private static final String VIEW_MY_IDENTITY_PREF = "pref_view_identity";
77-
private static final String MANAGE_IDENTITIES_PREF = "pref_manage_identity";
7878
private static final String CHANGE_PASSPHRASE_PREF = "pref_change_passphrase";
79+
public static final String DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase";
7980

8081
public static final String USE_LOCAL_MMS_APNS_PREF = "pref_use_local_apns";
8182
public static final String MMSC_HOST_PREF = "pref_apn_mmsc_host";
8283
public static final String MMSC_PROXY_HOST_PREF = "pref_apn_mms_proxy";
8384
public static final String MMSC_PROXY_PORT_PREF = "pref_apn_mms_proxy_port";
8485

8586
public static final String SMS_DELIVERY_REPORT_PREF = "pref_delivery_report_sms";
86-
public static final String MMS_DELIVERY_REPORT_PREF = "pref_delivery_report_mms";
8787

8888
public static final String THREAD_TRIM_ENABLED = "pref_trim_threads";
8989
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
@@ -110,16 +110,14 @@ protected void onCreate(Bundle icicle) {
110110
initializeIdentitySelection();
111111
initializeEditTextSummaries();
112112

113-
this.findPreference(VIEW_MY_IDENTITY_PREF)
114-
.setOnPreferenceClickListener(new ViewMyIdentityClickListener());
115-
this.findPreference(MANAGE_IDENTITIES_PREF)
116-
.setOnPreferenceClickListener(new ManageIdentitiesClickListener());
117113
this.findPreference(CHANGE_PASSPHRASE_PREF)
118114
.setOnPreferenceClickListener(new ChangePassphraseClickListener());
119115
this.findPreference(THREAD_TRIM_NOW)
120116
.setOnPreferenceClickListener(new TrimNowClickListener());
121117
this.findPreference(THREAD_TRIM_LENGTH)
122118
.setOnPreferenceChangeListener(new TrimLengthValidationListener());
119+
this.findPreference(DISABLE_PASSPHRASE_PREF)
120+
.setOnPreferenceChangeListener(new DisablePassphraseClickListener());
123121
}
124122

125123
@Override
@@ -151,9 +149,12 @@ public void onDestroy() {
151149
public void onActivityResult(int reqCode, int resultCode, Intent data) {
152150
super.onActivityResult(reqCode, resultCode, data);
153151

152+
Log.w("ApplicationPreferencesActivity", "Got result: " + resultCode + " for req: " + reqCode);
153+
154154
if (resultCode == Activity.RESULT_OK) {
155155
switch (reqCode) {
156-
case PICK_IDENTITY_CONTACT: handleIdentitySelection(data); break;
156+
case PICK_IDENTITY_CONTACT: handleIdentitySelection(data); break;
157+
case ENABLE_PASSPHRASE_ACTIVITY: finish(); break;
157158
}
158159
}
159160
}
@@ -247,37 +248,6 @@ public boolean onPreferenceClick(Preference preference) {
247248
}
248249
}
249250

250-
private class ViewMyIdentityClickListener implements Preference.OnPreferenceClickListener {
251-
@Override
252-
public boolean onPreferenceClick(Preference preference) {
253-
Intent viewIdentityIntent = new Intent(ApplicationPreferencesActivity.this, ViewIdentityActivity.class);
254-
viewIdentityIntent.putExtra("identity_key", IdentityKeyUtil.getIdentityKey(ApplicationPreferencesActivity.this));
255-
viewIdentityIntent.putExtra("title", getString(R.string.ApplicationPreferencesActivity_my) + " " +
256-
getString(R.string.ViewIdentityActivity_identity_fingerprint));
257-
startActivity(viewIdentityIntent);
258-
259-
return true;
260-
}
261-
}
262-
263-
private class ManageIdentitiesClickListener implements Preference.OnPreferenceClickListener {
264-
@Override
265-
public boolean onPreferenceClick(Preference preference) {
266-
MasterSecret masterSecret = (MasterSecret)getIntent().getParcelableExtra("master_secret");
267-
268-
if (masterSecret != null) {
269-
Intent manageIntent = new Intent(ApplicationPreferencesActivity.this, ReviewIdentitiesActivity.class);
270-
manageIntent.putExtra("master_secret", masterSecret);
271-
startActivity(manageIntent);
272-
} else {
273-
Toast.makeText(ApplicationPreferencesActivity.this,
274-
R.string.ApplicationPreferenceActivity_you_need_to_have_entered_your_passphrase_before_managing_keys,
275-
Toast.LENGTH_LONG).show();
276-
}
277-
278-
return true;
279-
}
280-
}
281251

282252
private class ChangePassphraseClickListener implements Preference.OnPreferenceClickListener {
283253
@Override
@@ -319,6 +289,48 @@ public void onClick(DialogInterface dialog, int which) {
319289
}
320290
}
321291

292+
private class DisablePassphraseClickListener implements Preference.OnPreferenceChangeListener {
293+
294+
@Override
295+
public boolean onPreferenceChange(final Preference preference, Object newValue) {
296+
if (!((CheckBoxPreference)preference).isChecked()) {
297+
AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationPreferencesActivity.this);
298+
builder.setTitle(R.string.ApplicationPreferencesActivity_disable_storage_encryption);
299+
builder.setMessage(R.string.ApplicationPreferencesActivity_warning_this_will_disable_storage_encryption_for_all_messages);
300+
builder.setIcon(android.R.drawable.ic_dialog_alert);
301+
builder.setPositiveButton(R.string.ApplicationPreferencesActivity_disable, new DialogInterface.OnClickListener() {
302+
@Override
303+
public void onClick(DialogInterface dialog, int which) {
304+
MasterSecret masterSecret = getIntent().getParcelableExtra("master_secret");
305+
MasterSecretUtil.changeMasterSecretPassphrase(ApplicationPreferencesActivity.this,
306+
masterSecret,
307+
MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
308+
309+
310+
PreferenceManager.getDefaultSharedPreferences(ApplicationPreferencesActivity.this)
311+
.edit()
312+
.putBoolean(DISABLE_PASSPHRASE_PREF, true)
313+
.commit();
314+
315+
((CheckBoxPreference)preference).setChecked(true);
316+
317+
Intent intent = new Intent(ApplicationPreferencesActivity.this, KeyCachingService.class);
318+
intent.setAction(KeyCachingService.DISABLE_ACTION);
319+
startService(intent);
320+
}
321+
});
322+
builder.setNegativeButton(android.R.string.cancel, null);
323+
builder.show();
324+
} else {
325+
Intent intent = new Intent(ApplicationPreferencesActivity.this,
326+
PassphraseChangeActivity.class);
327+
startActivityForResult(intent, ENABLE_PASSPHRASE_ACTIVITY);
328+
}
329+
330+
return false;
331+
}
332+
}
333+
322334
private class TrimLengthValidationListener implements Preference.OnPreferenceChangeListener {
323335

324336
public TrimLengthValidationListener() {
@@ -343,7 +355,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
343355
return false;
344356
}
345357

346-
preference.setSummary((String)newValue + " " +
358+
preference.setSummary(newValue + " " +
347359
getString(R.string.ApplicationPreferencesActivity_messages_per_conversation));
348360
return true;
349361
}

src/org/thoughtcrime/securesms/PassphraseChangeActivity.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
package org.thoughtcrime.securesms;
1818

1919
import android.os.Bundle;
20+
import android.preference.PreferenceManager;
2021
import android.text.Editable;
2122
import android.view.View;
2223
import android.view.View.OnClickListener;
2324
import android.widget.Button;
2425
import android.widget.EditText;
26+
import android.widget.TextView;
2527
import android.widget.Toast;
2628

2729
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
@@ -36,11 +38,13 @@
3638
*/
3739

3840
public class PassphraseChangeActivity extends PassphraseActivity {
39-
private EditText originalPassphrase;
40-
private EditText newPassphrase;
41-
private EditText repeatPassphrase;
42-
private Button okButton;
43-
private Button cancelButton;
41+
42+
private EditText originalPassphrase;
43+
private EditText newPassphrase;
44+
private EditText repeatPassphrase;
45+
private TextView originalPassphraseLabel;
46+
private Button okButton;
47+
private Button cancelButton;
4448

4549
@Override
4650
public void onCreate(Bundle savedInstanceState) {
@@ -52,15 +56,24 @@ public void onCreate(Bundle savedInstanceState) {
5256
}
5357

5458
private void initializeResources() {
55-
this.originalPassphrase = (EditText) findViewById(R.id.old_passphrase);
56-
this.newPassphrase = (EditText) findViewById(R.id.new_passphrase);
57-
this.repeatPassphrase = (EditText) findViewById(R.id.repeat_passphrase);
59+
this.originalPassphraseLabel = (TextView) findViewById(R.id.old_passphrase_label);
60+
this.originalPassphrase = (EditText) findViewById(R.id.old_passphrase );
61+
this.newPassphrase = (EditText) findViewById(R.id.new_passphrase );
62+
this.repeatPassphrase = (EditText) findViewById(R.id.repeat_passphrase );
5863

59-
this.okButton = (Button) findViewById(R.id.ok_button);
60-
this.cancelButton = (Button) findViewById(R.id.cancel_button);
64+
this.okButton = (Button ) findViewById(R.id.ok_button );
65+
this.cancelButton = (Button ) findViewById(R.id.cancel_button );
6166

6267
this.okButton.setOnClickListener(new OkButtonClickListener());
6368
this.cancelButton.setOnClickListener(new CancelButtonClickListener());
69+
70+
if (isPassphraseDisabled()) {
71+
this.originalPassphrase.setVisibility(View.GONE);
72+
this.originalPassphraseLabel.setVisibility(View.GONE);
73+
} else {
74+
this.originalPassphrase.setVisibility(View.VISIBLE);
75+
this.originalPassphraseLabel.setVisibility(View.VISIBLE);
76+
}
6477
}
6578

6679
private void verifyAndSavePassphrases() {
@@ -72,6 +85,10 @@ private void verifyAndSavePassphrases() {
7285
String passphrase = (newText == null ? "" : newText.toString());
7386
String passphraseRepeat = (repeatText == null ? "" : repeatText.toString());
7487

88+
if (isPassphraseDisabled()) {
89+
original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE;
90+
}
91+
7592
try {
7693
if (!passphrase.equals(passphraseRepeat)) {
7794
Toast.makeText(getApplicationContext(),
@@ -81,6 +98,12 @@ private void verifyAndSavePassphrases() {
8198
this.repeatPassphrase.setText("");
8299
} else {
83100
MasterSecret masterSecret = MasterSecretUtil.changeMasterSecretPassphrase(this, original, passphrase);
101+
102+
PreferenceManager.getDefaultSharedPreferences(this)
103+
.edit()
104+
.putBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false)
105+
.commit();
106+
84107
MemoryCleaner.clean(original);
85108
MemoryCleaner.clean(passphrase);
86109
MemoryCleaner.clean(passphraseRepeat);
@@ -94,6 +117,11 @@ private void verifyAndSavePassphrases() {
94117
}
95118
}
96119

120+
private boolean isPassphraseDisabled() {
121+
return PreferenceManager.getDefaultSharedPreferences(this)
122+
.getBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
123+
}
124+
97125
private class CancelButtonClickListener implements OnClickListener {
98126
public void onClick(View v) {
99127
finish();

0 commit comments

Comments
 (0)