Fix for scanning provided identity

Fixes #4028
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-09-06 11:45:19 -07:00
parent 797513b372
commit d4718c373a

View file

@ -19,6 +19,7 @@ package org.thoughtcrime.securesms;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -51,39 +52,32 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) { protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) {
this.masterSecret = masterSecret; this.masterSecret = masterSecret;
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.AndroidManifest__verify_identity);
setContentView(R.layout.verify_identity_activity); setContentView(R.layout.verify_identity_activity);
initializeResources(); this.localIdentityFingerprint = (TextView)findViewById(R.id.you_read);
initializeFingerprints(); this.remoteIdentityFingerprint = (TextView)findViewById(R.id.friend_reads);
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getSupportActionBar().setTitle(R.string.AndroidManifest__verify_identity);
this.recipient = RecipientFactory.getRecipientForId(this, this.getIntent().getLongExtra("recipient", -1), true);
initializeFingerprints();
} }
private void initializeLocalIdentityKey() { private void initializeFingerprints() {
if (!IdentityKeyUtil.hasIdentityKey(this)) { if (!IdentityKeyUtil.hasIdentityKey(this)) {
localIdentityFingerprint.setText(R.string.VerifyIdentityActivity_you_do_not_have_an_identity_key); localIdentityFingerprint.setText(R.string.VerifyIdentityActivity_you_do_not_have_an_identity_key);
return; return;
} }
localIdentityFingerprint.setText(IdentityKeyUtil.getIdentityKey(this).getFingerprint()); localIdentityFingerprint.setText(IdentityKeyUtil.getIdentityKey(this).getFingerprint());
}
private void initializeRemoteIdentityKey() { IdentityKey identityKey = getRemoteIdentityKey(masterSecret, recipient);
IdentityKeyParcelable identityKeyParcelable = getIntent().getParcelableExtra("remote_identity");
IdentityKey identityKey = null;
if (identityKeyParcelable != null) {
identityKey = identityKeyParcelable.get();
}
if (identityKey == null) {
identityKey = getRemoteIdentityKey(masterSecret, recipient);
}
if (identityKey == null) { if (identityKey == null) {
remoteIdentityFingerprint.setText(R.string.VerifyIdentityActivity_recipient_has_no_identity_key); remoteIdentityFingerprint.setText(R.string.VerifyIdentityActivity_recipient_has_no_identity_key);
@ -92,17 +86,6 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
} }
} }
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 = RecipientFactory.getRecipientForId(this, this.getIntent().getLongExtra("recipient", -1), true);
}
@Override @Override
protected void initiateDisplay() { protected void initiateDisplay() {
if (!IdentityKeyUtil.hasIdentityKey(this)) { if (!IdentityKeyUtil.hasIdentityKey(this)) {
@ -167,7 +150,13 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
return getString(R.string.VerifyIdentityActivity_verified_exclamation); return getString(R.string.VerifyIdentityActivity_verified_exclamation);
} }
private IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) { private @Nullable IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) {
IdentityKeyParcelable identityKeyParcelable = getIntent().getParcelableExtra("remote_identity");
if (identityKeyParcelable != null) {
return identityKeyParcelable.get();
}
SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret); SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret);
AxolotlAddress axolotlAddress = new AxolotlAddress(recipient.getNumber(), TextSecureAddress.DEFAULT_DEVICE_ID); AxolotlAddress axolotlAddress = new AxolotlAddress(recipient.getNumber(), TextSecureAddress.DEFAULT_DEVICE_ID);
SessionRecord record = sessionStore.loadSession(axolotlAddress); SessionRecord record = sessionStore.loadSession(axolotlAddress);