2012-07-31 14:18:14 -07:00
|
|
|
/**
|
2011-12-20 10:20:44 -08:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-31 14:18:14 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08: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-07-31 14:18:14 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08: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;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
2012-08-07 19:06:23 -07:00
|
|
|
import android.text.Editable;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2012-07-31 14:18:14 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
2013-08-17 18:37:18 -07:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2012-07-31 14:18:14 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
/**
|
|
|
|
* Activity that prompts for a users's passphrase.
|
2012-07-31 14:18:14 -07:00
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
2011-12-20 10:20:44 -08:00
|
|
|
*/
|
|
|
|
public class PassphrasePromptActivity extends PassphraseActivity {
|
|
|
|
|
|
|
|
private EditText passphraseText;
|
2012-07-31 14:18:14 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
setContentView(R.layout.prompt_passphrase_activity);
|
|
|
|
initializeResources();
|
|
|
|
}
|
2012-07-31 14:18:14 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
private void initializeResources() {
|
2013-05-06 19:27:09 -07:00
|
|
|
Button okButton = (Button) findViewById(R.id.ok_button);
|
|
|
|
passphraseText = (EditText)findViewById(R.id.passphrase_edit);
|
2012-07-31 14:18:14 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
okButton.setOnClickListener(new OkButtonClickListener());
|
|
|
|
}
|
2012-07-31 14:18:14 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
private class OkButtonClickListener implements OnClickListener {
|
2013-02-17 11:42:30 -08:00
|
|
|
@Override
|
2011-12-20 10:20:44 -08:00
|
|
|
public void onClick(View v) {
|
|
|
|
try {
|
2012-08-07 19:06:23 -07:00
|
|
|
Editable text = passphraseText.getText();
|
|
|
|
String passphrase = (text == null ? "" : text.toString());
|
2011-12-20 10:20:44 -08:00
|
|
|
MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(PassphrasePromptActivity.this, passphrase);
|
2012-07-31 14:18:14 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
MemoryCleaner.clean(passphrase);
|
|
|
|
setMasterSecret(masterSecret);
|
|
|
|
} catch (InvalidPassphraseException ipe) {
|
2013-02-21 14:47:18 -08:00
|
|
|
passphraseText.setText("");
|
2012-09-07 20:03:23 -07:00
|
|
|
Toast.makeText(getApplicationContext(),
|
2012-09-19 19:56:04 -07:00
|
|
|
R.string.PassphrasePromptActivity_invalid_passphrase_exclamation,
|
2012-09-07 20:03:23 -07:00
|
|
|
Toast.LENGTH_SHORT).show();
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 14:18:14 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
@Override
|
|
|
|
protected void cleanup() {
|
2013-05-06 19:27:09 -07:00
|
|
|
this.passphraseText.setText("");
|
2011-12-20 10:20:44 -08:00
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
}
|