2012-08-01 00:02:50 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-08-01 00:02:50 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-08-01 00:02:50 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2012-12-01 23:57:44 +00:00
|
|
|
import android.os.AsyncTask;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2013-02-17 19:42:30 +00:00
|
|
|
import android.widget.LinearLayout;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2012-08-01 00:02:50 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
2014-01-08 00:27:00 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2013-08-18 01:37:18 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2012-08-01 00:02:50 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
2013-05-07 23:31:11 +00:00
|
|
|
import org.thoughtcrime.securesms.util.VersionTracker;
|
2013-07-10 02:48:33 +00:00
|
|
|
import org.whispersystems.textsecure.util.Util;
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* Activity for creating a user's local encryption passphrase.
|
2012-08-01 00:02:50 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
2012-10-01 02:56:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public class PassphraseCreateActivity extends PassphraseActivity {
|
|
|
|
|
2013-02-17 19:42:30 +00:00
|
|
|
private LinearLayout createLayout;
|
|
|
|
private LinearLayout progressLayout;
|
|
|
|
|
2012-10-01 02:56:29 +00:00
|
|
|
private EditText passphraseEdit;
|
|
|
|
private EditText passphraseRepeatEdit;
|
|
|
|
private Button okButton;
|
2014-01-08 00:27:00 +00:00
|
|
|
private Button skipButton;
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2012-10-01 02:56:29 +00:00
|
|
|
public PassphraseCreateActivity() { }
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
setContentView(R.layout.create_passphrase_activity);
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
initializeResources();
|
|
|
|
}
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeResources() {
|
2013-02-17 19:42:30 +00:00
|
|
|
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);
|
2014-01-08 00:27:00 +00:00
|
|
|
this.skipButton = (Button) findViewById(R.id.skip_button);
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2012-12-01 23:57:44 +00:00
|
|
|
this.okButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
verifyAndSavePassphrases();
|
|
|
|
}
|
|
|
|
});
|
2014-01-08 00:27:00 +00:00
|
|
|
|
|
|
|
this.skipButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
disablePassphrase();
|
|
|
|
}
|
|
|
|
});
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void verifyAndSavePassphrases() {
|
2013-02-17 19:42:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
String passphrase = this.passphraseEdit.getText().toString();
|
|
|
|
String passphraseRepeat = this.passphraseRepeatEdit.getText().toString();
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (!passphrase.equals(passphraseRepeat)) {
|
2013-02-17 19:42:30 +00:00
|
|
|
Toast.makeText(this, R.string.PassphraseCreateActivity_passphrases_dont_match, Toast.LENGTH_SHORT).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
this.passphraseEdit.setText("");
|
|
|
|
this.passphraseRepeatEdit.setText("");
|
2013-02-17 19:42:30 +00:00
|
|
|
return;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2013-02-17 19:42:30 +00:00
|
|
|
|
|
|
|
// We do this, but the edit boxes are basically impossible to clean up.
|
|
|
|
MemoryCleaner.clean(passphraseRepeat);
|
|
|
|
new SecretGenerator().execute(passphrase);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2014-01-08 00:27:00 +00:00
|
|
|
private void disablePassphrase() {
|
|
|
|
TextSecurePreferences.setPasswordDisabled(this, true);
|
|
|
|
new SecretGenerator().execute(MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-01 23:57:44 +00:00
|
|
|
private class SecretGenerator extends AsyncTask<String, Void, Void> {
|
|
|
|
private MasterSecret masterSecret;
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2012-12-01 23:57:44 +00:00
|
|
|
@Override
|
|
|
|
protected void onPreExecute() {
|
2013-02-17 19:42:30 +00:00
|
|
|
createLayout.setVisibility(View.GONE);
|
|
|
|
progressLayout.setVisibility(View.VISIBLE);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
2012-12-01 23:57:44 +00:00
|
|
|
protected Void doInBackground(String... params) {
|
|
|
|
String passphrase = params[0];
|
|
|
|
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);
|
|
|
|
IdentityKeyUtil.generateIdentityKeys(PassphraseCreateActivity.this, masterSecret);
|
2013-05-07 23:31:11 +00:00
|
|
|
VersionTracker.updateLastSeenVersion(PassphraseCreateActivity.this);
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2012-12-01 23:57:44 +00:00
|
|
|
return null;
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-08-01 00:02:50 +00:00
|
|
|
|
2012-12-01 23:57:44 +00:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void param) {
|
|
|
|
setMasterSecret(masterSecret);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void cleanup() {
|
|
|
|
this.passphraseEdit = null;
|
|
|
|
this.passphraseRepeatEdit = null;
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
}
|