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;
|
2014-12-15 20:25:55 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-09-06 18:45:19 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2011-12-20 18:20:44 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2014-11-12 17:09:55 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2012-07-23 20:42:29 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
2014-11-12 17:09:55 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
|
2013-11-26 01:00:20 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2014-12-29 19:43:10 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
2016-03-25 17:19:12 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Hex;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.libsignal.SignalProtocolAddress;
|
|
|
|
import org.whispersystems.libsignal.IdentityKey;
|
|
|
|
import org.whispersystems.libsignal.state.SessionRecord;
|
|
|
|
import org.whispersystems.libsignal.state.SessionStore;
|
|
|
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
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-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
|
|
|
|
this.masterSecret = masterSecret;
|
2013-05-23 23:36:24 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2015-09-06 18:45:19 +00:00
|
|
|
getSupportActionBar().setTitle(R.string.AndroidManifest__verify_identity);
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
setContentView(R.layout.verify_identity_activity);
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2015-09-06 18:45:19 +00:00
|
|
|
this.localIdentityFingerprint = (TextView)findViewById(R.id.you_read);
|
|
|
|
this.remoteIdentityFingerprint = (TextView)findViewById(R.id.friend_reads);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2014-04-09 20:26:06 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2015-09-06 18:45:19 +00:00
|
|
|
this.recipient = RecipientFactory.getRecipientForId(this, this.getIntent().getLongExtra("recipient", -1), true);
|
|
|
|
|
|
|
|
initializeFingerprints();
|
2014-04-09 20:26:06 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 18:45:19 +00:00
|
|
|
private void initializeFingerprints() {
|
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
|
|
|
|
2016-03-25 17:19:12 +00:00
|
|
|
localIdentityFingerprint.setText(Hex.toString(IdentityKeyUtil.getIdentityKey(this).serialize()));
|
2013-09-14 20:33:23 +00:00
|
|
|
|
2015-09-06 18:45:19 +00:00
|
|
|
IdentityKey identityKey = getRemoteIdentityKey(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
|
|
|
remoteIdentityFingerprint.setText(R.string.VerifyIdentityActivity_recipient_has_no_identity_key);
|
2011-12-20 18:20:44 +00:00
|
|
|
} else {
|
2016-03-25 17:19:12 +00:00
|
|
|
remoteIdentityFingerprint.setText(Hex.toString(identityKey.serialize()));
|
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 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() {
|
2014-04-22 21:33:29 +00:00
|
|
|
IdentityKey identityKey = getRemoteIdentityKey(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() {
|
2016-02-11 21:45:49 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_scan_contacts_qr_code);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDisplayString() {
|
2016-02-11 21:45:49 +00:00
|
|
|
return getString(R.string.VerifyIdentityActivity_display_your_qr_code);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected IdentityKey getIdentityKeyToCompare() {
|
2014-04-22 21:33:29 +00:00
|
|
|
return getRemoteIdentityKey(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
|
|
|
}
|
2014-04-22 21:33:29 +00:00
|
|
|
|
2015-09-06 18:45:19 +00:00
|
|
|
private @Nullable IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) {
|
|
|
|
IdentityKeyParcelable identityKeyParcelable = getIntent().getParcelableExtra("remote_identity");
|
|
|
|
|
|
|
|
if (identityKeyParcelable != null) {
|
|
|
|
return identityKeyParcelable.get();
|
|
|
|
}
|
|
|
|
|
2016-03-23 17:34:41 +00:00
|
|
|
SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret);
|
|
|
|
SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(recipient.getNumber(), SignalServiceAddress.DEFAULT_DEVICE_ID);
|
|
|
|
SessionRecord record = sessionStore.loadSession(axolotlAddress);
|
2014-04-22 21:33:29 +00:00
|
|
|
|
|
|
|
if (record == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return record.getSessionState().getRemoteIdentityKey();
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|