That fuck shit the fascists are using
1/**
2 * Copyright (C) 2011 Whisper Systems
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package org.tm.archive;
18
19import android.content.Context;
20import android.os.AsyncTask;
21import android.os.Bundle;
22import android.text.Editable;
23import android.view.View;
24import android.view.View.OnClickListener;
25import android.widget.Button;
26import android.widget.EditText;
27
28import org.signal.core.util.logging.Log;
29import org.tm.archive.crypto.InvalidPassphraseException;
30import org.tm.archive.crypto.MasterSecret;
31import org.tm.archive.crypto.MasterSecretUtil;
32import org.tm.archive.util.DynamicLanguage;
33import org.tm.archive.util.DynamicTheme;
34import org.tm.archive.util.TextSecurePreferences;
35
36/**
37 * Activity for changing a user's local encryption passphrase.
38 *
39 * @author Moxie Marlinspike
40 */
41
42public class PassphraseChangeActivity extends PassphraseActivity {
43
44 private static final String TAG = Log.tag(PassphraseChangeActivity.class);
45
46 private DynamicTheme dynamicTheme = new DynamicTheme();
47 private DynamicLanguage dynamicLanguage = new DynamicLanguage();
48
49 private EditText originalPassphrase;
50 private EditText newPassphrase;
51 private EditText repeatPassphrase;
52 private Button okButton;
53 private Button cancelButton;
54
55 @Override
56 public void onCreate(Bundle savedInstanceState) {
57 dynamicTheme.onCreate(this);
58 dynamicLanguage.onCreate(this);
59 super.onCreate(savedInstanceState);
60
61 setContentView(R.layout.change_passphrase_activity);
62
63 initializeResources();
64 }
65
66 @Override
67 public void onResume() {
68 super.onResume();
69 dynamicTheme.onResume(this);
70 dynamicLanguage.onResume(this);
71 }
72
73 private void initializeResources() {
74 this.originalPassphrase = (EditText) findViewById(R.id.old_passphrase );
75 this.newPassphrase = (EditText) findViewById(R.id.new_passphrase );
76 this.repeatPassphrase = (EditText) findViewById(R.id.repeat_passphrase );
77
78 this.okButton = (Button ) findViewById(R.id.ok_button );
79 this.cancelButton = (Button ) findViewById(R.id.cancel_button );
80
81 this.okButton.setOnClickListener(new OkButtonClickListener());
82 this.cancelButton.setOnClickListener(new CancelButtonClickListener());
83
84 if (TextSecurePreferences.isPasswordDisabled(this)) {
85 this.originalPassphrase.setVisibility(View.GONE);
86 } else {
87 this.originalPassphrase.setVisibility(View.VISIBLE);
88 }
89 }
90
91 private void verifyAndSavePassphrases() {
92 Editable originalText = this.originalPassphrase.getText();
93 Editable newText = this.newPassphrase.getText();
94 Editable repeatText = this.repeatPassphrase.getText();
95
96 String original = (originalText == null ? "" : originalText.toString());
97 String passphrase = (newText == null ? "" : newText.toString());
98 String passphraseRepeat = (repeatText == null ? "" : repeatText.toString());
99
100 if (TextSecurePreferences.isPasswordDisabled(this)) {
101 original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE;
102 }
103
104 if (!passphrase.equals(passphraseRepeat)) {
105 this.newPassphrase.setText("");
106 this.repeatPassphrase.setText("");
107 this.newPassphrase.setError(getString(R.string.PassphraseChangeActivity_passphrases_dont_match_exclamation));
108 this.newPassphrase.requestFocus();
109 } else if (passphrase.equals("")) {
110 this.newPassphrase.setError(getString(R.string.PassphraseChangeActivity_enter_new_passphrase_exclamation));
111 this.newPassphrase.requestFocus();
112 } else {
113 new ChangePassphraseTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, original, passphrase);
114 }
115 }
116
117 private class CancelButtonClickListener implements OnClickListener {
118 public void onClick(View v) {
119 finish();
120 }
121 }
122
123 private class OkButtonClickListener implements OnClickListener {
124 public void onClick(View v) {
125 verifyAndSavePassphrases();
126 }
127 }
128
129 private class ChangePassphraseTask extends AsyncTask<String, Void, MasterSecret> {
130 private final Context context;
131
132 public ChangePassphraseTask(Context context) {
133 this.context = context;
134 }
135
136 @Override
137 protected void onPreExecute() {
138 okButton.setEnabled(false);
139 }
140
141 @Override
142 protected MasterSecret doInBackground(String... params) {
143 try {
144 MasterSecret masterSecret = MasterSecretUtil.changeMasterSecretPassphrase(context, params[0], params[1]);
145 TextSecurePreferences.setPasswordDisabled(context, false);
146
147 return masterSecret;
148
149 } catch (InvalidPassphraseException e) {
150 Log.w(TAG, e);
151 return null;
152 }
153 }
154
155 @Override
156 protected void onPostExecute(MasterSecret masterSecret) {
157 okButton.setEnabled(true);
158
159 if (masterSecret != null) {
160 setMasterSecret(masterSecret);
161 } else {
162 originalPassphrase.setText("");
163 originalPassphrase.setError(getString(R.string.PassphraseChangeActivity_incorrect_old_passphrase_exclamation));
164 originalPassphrase.requestFocus();
165 }
166 }
167 }
168
169 @Override
170 protected void cleanup() {
171 this.originalPassphrase = null;
172 this.newPassphrase = null;
173 this.repeatPassphrase = null;
174
175 System.gc();
176 }
177}