disable passphrase creation on registration

// FREEBIE
Closes #1726
This commit is contained in:
Jake McGinty
2014-07-21 23:44:01 -10:00
committed by Moxie Marlinspike
parent 9ef14a0f64
commit bea3c33223
4 changed files with 44 additions and 151 deletions

View File

@@ -16,7 +16,9 @@
*/
package org.thoughtcrime.securesms;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@@ -24,6 +26,8 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.crypto.MasterSecret;
@@ -40,14 +44,6 @@ import org.whispersystems.textsecure.util.Util;
public class PassphraseCreateActivity extends PassphraseActivity {
private LinearLayout createLayout;
private LinearLayout progressLayout;
private EditText passphraseEdit;
private EditText passphraseRepeatEdit;
private Button okButton;
private Button skipButton;
public PassphraseCreateActivity() { }
@Override
@@ -60,53 +56,12 @@ public class PassphraseCreateActivity extends PassphraseActivity {
}
private void initializeResources() {
this.createLayout = (LinearLayout)findViewById(R.id.create_layout);
this.progressLayout = (LinearLayout)findViewById(R.id.progress_layout);
this.passphraseEdit = (EditText) findViewById(R.id.passphrase_edit);
this.passphraseRepeatEdit = (EditText) findViewById(R.id.passphrase_edit_repeat);
this.okButton = (Button) findViewById(R.id.ok_button);
this.skipButton = (Button) findViewById(R.id.skip_button);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.light_centered_app_title);
mitigateAndroidTilingBug();
this.okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
verifyAndSavePassphrases();
}
});
this.skipButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disablePassphrase();
}
});
}
private void verifyAndSavePassphrases() {
if (Util.isEmpty(this.passphraseEdit) || Util.isEmpty(this.passphraseRepeatEdit)) {
Toast.makeText(this, R.string.PassphraseCreateActivity_you_must_specify_a_password, Toast.LENGTH_SHORT).show();
return;
}
String passphrase = this.passphraseEdit.getText().toString();
String passphraseRepeat = this.passphraseRepeatEdit.getText().toString();
if (!passphrase.equals(passphraseRepeat)) {
Toast.makeText(this, R.string.PassphraseCreateActivity_passphrases_dont_match, Toast.LENGTH_SHORT).show();
this.passphraseEdit.setText("");
this.passphraseRepeatEdit.setText("");
return;
}
// We do this, but the edit boxes are basically impossible to clean up.
MemoryCleaner.clean(passphraseRepeat);
new SecretGenerator().execute(passphrase);
}
private void disablePassphrase() {
TextSecurePreferences.setPasswordDisabled(this, true);
new SecretGenerator().execute(MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
}
private class SecretGenerator extends AsyncTask<String, Void, Void> {
@@ -114,8 +69,6 @@ public class PassphraseCreateActivity extends PassphraseActivity {
@Override
protected void onPreExecute() {
createLayout.setVisibility(View.GONE);
progressLayout.setVisibility(View.VISIBLE);
}
@Override
@@ -124,7 +77,6 @@ public class PassphraseCreateActivity extends PassphraseActivity {
masterSecret = MasterSecretUtil.generateMasterSecret(PassphraseCreateActivity.this,
passphrase);
// We do this, but the edit boxes are basically impossible to clean up.
MemoryCleaner.clean(passphrase);
MasterSecretUtil.generateAsymmetricMasterSecret(PassphraseCreateActivity.this, masterSecret);
@@ -140,10 +92,17 @@ public class PassphraseCreateActivity extends PassphraseActivity {
}
}
private void mitigateAndroidTilingBug() {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Drawable actionBarBackground = getResources().getDrawable(R.drawable.background_pattern_repeat);
Util.fixBackgroundRepeat(actionBarBackground);
getSupportActionBar().setBackgroundDrawable(actionBarBackground);
Util.fixBackgroundRepeat(findViewById(R.id.scroll_parent).getBackground());
}
}
@Override
protected void cleanup() {
this.passphraseEdit = null;
this.passphraseRepeatEdit = null;
System.gc();
}
}