2012-07-23 20:42:29 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2013-11-10 12:15:29 +00:00
|
|
|
* Copyright (C) 2013 Open Whisper Systems
|
2012-07-23 20:42:29 +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-07-23 20:42:29 +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;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2012-07-23 20:42:29 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
2013-11-26 01:00:20 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2014-04-09 20:26:06 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2013-11-26 01:00:20 +00:00
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
|
|
|
import org.whispersystems.textsecure.crypto.IdentityKey;
|
2013-08-18 01:37:18 +00:00
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2013-11-26 01:00:20 +00:00
|
|
|
import org.whispersystems.textsecure.storage.Session;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* Activity for verifying identity keys.
|
2012-07-23 20:42:29 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
2013-05-23 23:36:24 +00:00
|
|
|
public class VerifyIdentityActivity extends KeyScanningActivity {
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2014-04-09 20:26:06 +00:00
|
|
|
private Recipient recipient;
|
2011-12-20 18:20:44 +00:00
|
|
|
private MasterSecret masterSecret;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private TextView localIdentityFingerprint;
|
|
|
|
private TextView remoteIdentityFingerprint;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2014-04-09 20:26:06 +00:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme ();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle state) {
|
2014-04-09 20:26:06 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
2011-12-20 18:20:44 +00:00
|
|
|
super.onCreate(state);
|
2013-05-23 23:36:24 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2011-12-20 18:20:44 +00:00
|
|
|
setContentView(R.layout.verify_identity_activity);
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
initializeResources();
|
|
|
|
initializeFingerprints();
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2014-04-09 20:26:06 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
getSupportActionBar().setTitle(R.string.AndroidManifest__verify_identity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
MemoryCleaner.clean(masterSecret);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeLocalIdentityKey() {
|
2014-04-10 03:02:46 +00:00
|
|
|
if (!IdentityKeyUtil.hasIdentityKey(this)) {
|
2012-09-20 02:56:04 +00:00
|
|
|
localIdentityFingerprint.setText(R.string.VerifyIdentityActivity_you_do_not_have_an_identity_key);
|
2011-12-20 18:20:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2014-04-10 03:02:46 +00:00
|
|
|
localIdentityFingerprint.setText(IdentityKeyUtil.getIdentityKey(this).getFingerprint());
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeRemoteIdentityKey() {
|
2013-09-14 20:33:23 +00:00
|
|
|
IdentityKey identityKey = getIntent().getParcelableExtra("remote_identity");
|
|
|
|
|
|
|
|
if (identityKey == null) {
|
2013-11-26 01:00:20 +00:00
|
|
|
identityKey = Session.getRemoteIdentityKey(this, masterSecret, recipient);
|
2013-09-14 20:33:23 +00:00
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (identityKey == null) {
|
2012-09-20 02:56:04 +00:00
|
|
|
remoteIdentityFingerprint.setText(R.string.VerifyIdentityActivity_recipient_has_no_identity_key);
|
2011-12-20 18:20:44 +00:00
|
|
|
} else {
|
|
|
|
remoteIdentityFingerprint.setText(identityKey.getFingerprint());
|
|
|
|
}
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeFingerprints() {
|
|
|
|
initializeLocalIdentityKey();
|
|
|
|
initializeRemoteIdentityKey();
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeResources() {
|
2013-11-10 12:15:29 +00:00
|
|
|
this.localIdentityFingerprint = (TextView)findViewById(R.id.you_read);
|
|
|
|
this.remoteIdentityFingerprint = (TextView)findViewById(R.id.friend_reads);
|
|
|
|
this.recipient = this.getIntent().getParcelableExtra("recipient");
|
|
|
|
this.masterSecret = this.getIntent().getParcelableExtra("master_secret");
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void initiateDisplay() {
|
2014-04-10 03:02:46 +00:00
|
|
|
if (!IdentityKeyUtil.hasIdentityKey(this)) {
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this,
|
|
|
|
R.string.VerifyIdentityActivity_you_don_t_have_an_identity_key_exclamation,
|
|
|
|
Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
super.initiateDisplay();
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
protected void initiateScan() {
|
2013-11-26 01:00:20 +00:00
|
|
|
IdentityKey identityKey = Session.getRemoteIdentityKey(this, masterSecret, recipient);
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
if (identityKey == null) {
|
2012-09-20 02:56:04 +00:00
|
|
|
Toast.makeText(this, R.string.VerifyIdentityActivity_recipient_has_no_identity_key_exclamation,
|
|
|
|
Toast.LENGTH_LONG).show();
|
2011-12-20 18:20:44 +00:00
|
|
|
} else {
|
|
|
|
super.initiateScan();
|
2012-07-23 20:42:29 +00:00
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
protected String getScanString() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_scan_their_key_to_compare);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDisplayString() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_get_my_key_scanned);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected IdentityKey getIdentityKeyToCompare() {
|
2013-11-26 01:00:20 +00:00
|
|
|
return Session.getRemoteIdentityKey(this, masterSecret, recipient);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected IdentityKey getIdentityKeyToDisplay() {
|
2014-04-10 03:02:46 +00:00
|
|
|
return IdentityKeyUtil.getIdentityKey(this);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getNotVerifiedMessage() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_warning_the_scanned_key_does_not_match_please_check_the_fingerprint_text_carefully);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getNotVerifiedTitle() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_not_verified_exclamation);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getVerifiedMessage() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_their_key_is_correct_it_is_also_necessary_to_verify_your_key_with_them_as_well);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getVerifiedTitle() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_verified_exclamation);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
}
|