From d4718c373ac6400b238baa5d67e6a5f858070d71 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sun, 6 Sep 2015 11:45:19 -0700 Subject: [PATCH] Fix for scanning provided identity Fixes #4028 // FREEBIE --- .../securesms/VerifyIdentityActivity.java | 45 +++++++------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java b/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java index 6ce46af9f8..7a7fa3e161 100644 --- a/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java +++ b/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java @@ -19,6 +19,7 @@ package org.thoughtcrime.securesms; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.widget.TextView; import android.widget.Toast; @@ -51,39 +52,32 @@ public class VerifyIdentityActivity extends KeyScanningActivity { protected void onCreate(Bundle state, @NonNull MasterSecret masterSecret) { this.masterSecret = masterSecret; getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setTitle(R.string.AndroidManifest__verify_identity); + setContentView(R.layout.verify_identity_activity); - initializeResources(); - initializeFingerprints(); + this.localIdentityFingerprint = (TextView)findViewById(R.id.you_read); + this.remoteIdentityFingerprint = (TextView)findViewById(R.id.friend_reads); } @Override public void 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)) { localIdentityFingerprint.setText(R.string.VerifyIdentityActivity_you_do_not_have_an_identity_key); return; } localIdentityFingerprint.setText(IdentityKeyUtil.getIdentityKey(this).getFingerprint()); - } - - private void initializeRemoteIdentityKey() { - IdentityKeyParcelable identityKeyParcelable = getIntent().getParcelableExtra("remote_identity"); - IdentityKey identityKey = null; - - if (identityKeyParcelable != null) { - identityKey = identityKeyParcelable.get(); - } - if (identityKey == null) { - identityKey = getRemoteIdentityKey(masterSecret, recipient); - } + IdentityKey identityKey = getRemoteIdentityKey(masterSecret, recipient); if (identityKey == null) { 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 protected void initiateDisplay() { if (!IdentityKeyUtil.hasIdentityKey(this)) { @@ -167,7 +150,13 @@ public class VerifyIdentityActivity extends KeyScanningActivity { 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); AxolotlAddress axolotlAddress = new AxolotlAddress(recipient.getNumber(), TextSecureAddress.DEFAULT_DEVICE_ID); SessionRecord record = sessionStore.loadSession(axolotlAddress);