2012-07-23 20:42:29 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 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;
|
|
|
|
|
2012-07-23 20:42:29 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
|
|
import org.thoughtcrime.securesms.crypto.SerializableKey;
|
2013-04-01 02:16:06 +00:00
|
|
|
import org.thoughtcrime.securesms.database.keys.SessionRecord;
|
2011-12-20 18:20:44 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.util.Hex;
|
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activity for verifying session 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 VerifyKeysActivity extends KeyScanningActivity {
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
private byte[] yourFingerprintBytes;
|
|
|
|
private byte[] theirFingerprintBytes;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private TextView yourFingerprint;
|
|
|
|
private TextView theirFingerprint;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private Recipient recipient;
|
|
|
|
private MasterSecret masterSecret;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle state) {
|
|
|
|
super.onCreate(state);
|
|
|
|
setContentView(R.layout.verify_keys_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
|
|
|
|
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 initializeResources() {
|
|
|
|
this.recipient = (Recipient)this.getIntent().getParcelableExtra("recipient");
|
|
|
|
this.masterSecret = (MasterSecret)this.getIntent().getParcelableExtra("master_secret");
|
|
|
|
this.yourFingerprint = (TextView)findViewById(R.id.you_read);
|
|
|
|
this.theirFingerprint = (TextView)findViewById(R.id.friend_reads);
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private void initializeFingerprints() {
|
|
|
|
SessionRecord session = new SessionRecord(this, masterSecret, recipient);
|
|
|
|
this.yourFingerprintBytes = session.getLocalFingerprint();
|
|
|
|
this.theirFingerprintBytes = session.getRemoteFingerprint();
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
this.yourFingerprint.setText(Hex.toString(yourFingerprintBytes));
|
|
|
|
this.theirFingerprint.setText(Hex.toString(theirFingerprintBytes));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDisplayString() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyKeysActivity_get_my_fingerprint_scanned);
|
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.VerifyKeysActivity_scan_their_fingerprint);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-07-23 20:42:29 +00:00
|
|
|
protected SerializableKey getIdentityKeyToCompare() {
|
2011-12-20 18:20:44 +00:00
|
|
|
return new FingerprintKey(theirFingerprintBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected SerializableKey getIdentityKeyToDisplay() {
|
|
|
|
return new FingerprintKey(yourFingerprintBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getNotVerifiedMessage() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyKeysActivity_warning_the_scanned_key_does_not_match_please_check_the_fingerprint_text_carefully2);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getNotVerifiedTitle() {
|
2012-09-20 02:56:04 +00:00
|
|
|
return getString(R.string.VerifyKeysActivity_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.VerifyKeysActivity_their_key_is_correct_it_is_also_necessary_to_get_your_fingerprint_scanned_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.VerifyKeysActivity_verified_exclamation);
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
private class FingerprintKey implements SerializableKey {
|
|
|
|
private final byte[] fingerprint;
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public FingerprintKey(byte[] fingerprint) {
|
|
|
|
this.fingerprint = fingerprint;
|
|
|
|
}
|
2012-07-23 20:42:29 +00:00
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
public byte[] serialize() {
|
|
|
|
return fingerprint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|