mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
1) Generate a Curve25519 identity key. 2) Use Curve25519 ephemerals and identities for v2 3DHE agreements. 3) Initiate v2 key exchange messages. 4) Accept v1 key exchange messages. 5) TOFU Curve25519 identities.
176 lines
5.7 KiB
Java
176 lines
5.7 KiB
Java
/**
|
|
* Copyright (C) 2011 Whisper Systems
|
|
* Copyright (C) 2013 Open Whisper Systems
|
|
*
|
|
* 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.
|
|
*
|
|
* 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;
|
|
|
|
import org.whispersystems.textsecure.crypto.IdentityKey;
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
|
import org.whispersystems.textsecure.crypto.ecc.Curve;
|
|
import org.whispersystems.textsecure.crypto.ecc.ECPublicKey;
|
|
import org.whispersystems.textsecure.crypto.protocol.CiphertextMessage;
|
|
import org.whispersystems.textsecure.storage.SessionRecord;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
|
|
|
/**
|
|
* Activity for verifying identity keys.
|
|
*
|
|
* @author Moxie Marlinspike
|
|
*/
|
|
public class VerifyIdentityActivity extends KeyScanningActivity {
|
|
|
|
private Recipient recipient;
|
|
private MasterSecret masterSecret;
|
|
|
|
private TextView localIdentityFingerprint;
|
|
private TextView remoteIdentityFingerprint;
|
|
|
|
private int keyType;
|
|
|
|
@Override
|
|
public void onCreate(Bundle state) {
|
|
super.onCreate(state);
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
setContentView(R.layout.verify_identity_activity);
|
|
|
|
initializeResources();
|
|
initializeFingerprints();
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
MemoryCleaner.clean(masterSecret);
|
|
super.onDestroy();
|
|
}
|
|
|
|
private void initializeLocalIdentityKey() {
|
|
if (!IdentityKeyUtil.hasIdentityKey(this, keyType)) {
|
|
localIdentityFingerprint.setText(R.string.VerifyIdentityActivity_you_do_not_have_an_identity_key);
|
|
return;
|
|
}
|
|
|
|
localIdentityFingerprint.setText(IdentityKeyUtil.getFingerprint(this, keyType));
|
|
}
|
|
|
|
private void initializeRemoteIdentityKey() {
|
|
IdentityKey identityKey = getIntent().getParcelableExtra("remote_identity");
|
|
|
|
if (identityKey == null) {
|
|
SessionRecord sessionRecord = new SessionRecord(this, masterSecret, recipient);
|
|
identityKey = sessionRecord.getIdentityKey();
|
|
}
|
|
|
|
if (identityKey == null) {
|
|
remoteIdentityFingerprint.setText(R.string.VerifyIdentityActivity_recipient_has_no_identity_key);
|
|
} else {
|
|
remoteIdentityFingerprint.setText(identityKey.getFingerprint());
|
|
}
|
|
}
|
|
|
|
private void initializeFingerprints() {
|
|
initializeLocalIdentityKey();
|
|
initializeRemoteIdentityKey();
|
|
}
|
|
|
|
private void initializeResources() {
|
|
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");
|
|
|
|
SessionRecord sessionRecord = new SessionRecord(this, masterSecret, recipient);
|
|
int sessionVersion = sessionRecord.getSessionVersion();
|
|
|
|
if (sessionVersion >= CiphertextMessage.CURVE25519_INTRODUCED_VERSION) {
|
|
this.keyType = Curve.DJB_TYPE;
|
|
} else {
|
|
this.keyType = Curve.NIST_TYPE;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void initiateDisplay() {
|
|
if (!IdentityKeyUtil.hasIdentityKey(this, keyType)) {
|
|
Toast.makeText(this,
|
|
R.string.VerifyIdentityActivity_you_don_t_have_an_identity_key_exclamation,
|
|
Toast.LENGTH_LONG).show();
|
|
return;
|
|
}
|
|
|
|
super.initiateDisplay();
|
|
}
|
|
|
|
@Override
|
|
protected void initiateScan() {
|
|
SessionRecord sessionRecord = new SessionRecord(this, masterSecret, recipient);
|
|
IdentityKey identityKey = sessionRecord.getIdentityKey();
|
|
|
|
if (identityKey == null) {
|
|
Toast.makeText(this, R.string.VerifyIdentityActivity_recipient_has_no_identity_key_exclamation,
|
|
Toast.LENGTH_LONG).show();
|
|
} else {
|
|
super.initiateScan();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected String getScanString() {
|
|
return getString(R.string.VerifyIdentityActivity_scan_their_key_to_compare);
|
|
}
|
|
|
|
@Override
|
|
protected String getDisplayString() {
|
|
return getString(R.string.VerifyIdentityActivity_get_my_key_scanned);
|
|
}
|
|
|
|
@Override
|
|
protected IdentityKey getIdentityKeyToCompare() {
|
|
SessionRecord sessionRecord = new SessionRecord(this, masterSecret, recipient);
|
|
return sessionRecord.getIdentityKey();
|
|
}
|
|
|
|
@Override
|
|
protected IdentityKey getIdentityKeyToDisplay() {
|
|
return IdentityKeyUtil.getIdentityKey(this, keyType);
|
|
}
|
|
|
|
@Override
|
|
protected String getNotVerifiedMessage() {
|
|
return getString(R.string.VerifyIdentityActivity_warning_the_scanned_key_does_not_match_please_check_the_fingerprint_text_carefully);
|
|
}
|
|
|
|
@Override
|
|
protected String getNotVerifiedTitle() {
|
|
return getString(R.string.VerifyIdentityActivity_not_verified_exclamation);
|
|
}
|
|
|
|
@Override
|
|
protected String getVerifiedMessage() {
|
|
return getString(R.string.VerifyIdentityActivity_their_key_is_correct_it_is_also_necessary_to_verify_your_key_with_them_as_well);
|
|
}
|
|
|
|
@Override
|
|
protected String getVerifiedTitle() {
|
|
return getString(R.string.VerifyIdentityActivity_verified_exclamation);
|
|
}
|
|
}
|