Clean up key/identity verification Activites.

1) Get ride of the crazy button situation.
2) Actionbar-ify and abstract out the common actions.
3) Switch to full activities from dialog themes.
This commit is contained in:
Moxie Marlinspike 2012-07-23 13:42:29 -07:00
parent 8e3b08ebda
commit 78998d0c93
16 changed files with 432 additions and 514 deletions

View File

@ -43,18 +43,41 @@
android:label="Select Contacts"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".AutoInitiateActivity"
android:theme="@style/Theme.Sherlock.Dialog"
android:label="TextSecure Messaging Detected"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".ViewIdentityActivity"
android:theme="@style/Theme.Sherlock.Dialog"
android:label="Public Identity Key"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".PassphraseChangeActivity"
android:theme="@style/Theme.Sherlock.Dialog"
android:label="Change Passphrase"
android:launchMode="singleInstance"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".VerifyKeysActivity"
android:label="Verify Session"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".VerifyIdentityActivity"
android:label="Verify Identity"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".SaveIdentityActivity"
android:theme="@style/Theme.Sherlock.Dialog"
android:label="Save Identity"
android:windowSoftInputMode="stateVisible"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"/>
<activity android:name=".AutoInitiateActivity" android:theme="@android:style/Theme.Dialog" android:label="TextSecure Messaging Detected" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".ApplicationPreferencesActivity" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".PassphraseCreateActivity" android:theme="@android:style/Theme.Dialog" android:label="Create Passphrase" android:launchMode="singleInstance" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".PassphraseChangeActivity" android:theme="@android:style/Theme.Dialog" android:label="Change Passphrase" android:launchMode="singleInstance" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".SendKeyActivity" android:theme="@android:style/Theme.Dialog" android:label="Initiate Key Exchange" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".ReceiveKeyActivity" android:theme="@android:style/Theme.Dialog" android:label="Complete Key Exchange" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".VerifyKeysActivity" android:theme="@android:style/Theme.Dialog" android:label="Verify Session" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".VerifyIdentityActivity" android:theme="@android:style/Theme.Dialog" android:label="Verify Identity" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".VerifyImportedIdentityActivity" android:theme="@android:style/Theme.Dialog" android:label="Verify Imported Identity" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".ViewIdentityActivity" android:theme="@android:style/Theme.Dialog" android:label="Public Identity Key" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".SaveIdentityActivity" android:theme="@android:style/Theme.Dialog" android:label="Save Identity" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<activity android:name=".ReviewIdentitiesActivity" android:theme="@android:style/Theme.Dialog" android:label="Manage Identity Keys (Long click)" android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout"></activity>
<service android:enabled="true" android:name=".service.KeyCachingService"></service>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -12,6 +12,7 @@
android:textSize="12sp"
android:text="Old passphrase:"
android:padding="3dip" />
<EditText android:id="@+id/old_passphrase"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
@ -46,19 +47,17 @@
<TableRow>
<Button android:id="@+id/ok_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"/>
<Button android:id="@+id/cancel_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"/>
<Button android:id="@+id/ok_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"/>
</TableRow>
</TableLayout>
</ScrollView>

View File

@ -4,12 +4,7 @@
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
android:padding="16dip">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -21,27 +16,32 @@
android:padding="5dip"
android:id="@+id/identity_name"
android:text="" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
android:orientation="horizontal"
android:layout_marginBottom="16dip"
android:gravity="right">
<Button android:layout_width="100dip"
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*">
<TableRow>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_marginRight="17dip"
android:id="@+id/cancel_button"
android:text="Cancel"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:padding="5dip"
android:gravity="center"
android:id="@+id/ok_button"
android:text="Ok"/>
<Button android:layout_width="100dip"
android:layout_height="wrap_content"
android:visibility="visible"
android:padding="5dip"
android:gravity="center"
android:id="@+id/cancel_button"
android:text="Cancel"/>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>

View File

@ -2,69 +2,44 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="1">
<TableRow>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:layout_marginRight="16dip"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:textSize="12sp"
android:text="Their identity:\n(They read)"
android:padding="3dip" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Their identity (they read):"
android:padding="7dip" />
<TextView
android:textSize="20sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:id="@+id/friend_reads"
android:text=""
android:padding="3dip" />
</TableRow>
android:padding="7dip" />
<TableRow>
<TextView
android:text="Your identity:\n(You read)"
android:textSize="12sp"
android:padding="3dip" />
<TextView
android:id="@+id/you_read"
android:textSize="20sp"
android:typeface="monospace"
android:text=""
android:padding="3dip" />
</TableRow>
<TableRow>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="2">
android:text="Your identity (you read):"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="7dip" />
<Button android:id="@+id/verified_button"
android:padding="10dip"
android:layout_width="wrap_content"
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Verified!"/>
<Button android:id="@+id/abort_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abort"/>
<Button android:id="@+id/compare_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Compare"/>
<Button android:id="@+id/cancel_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
android:id="@+id/you_read"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:text=""
android:padding="7dip" />
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>

View File

@ -2,104 +2,47 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="1">
<TableRow>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dip"
android:layout_marginRight="16dip"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:textSize="12sp"
android:text="Your friend reads this:"
android:padding="3dip" />
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="They read this:"
android:padding="7dip" />
<TextView
android:textSize="20sp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:id="@+id/friend_reads"
android:text=""
android:padding="3dip" />
</TableRow>
android:padding="7dip" />
<TableRow>
<TextView
android:layout_marginTop="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="You read this:"
android:textSize="12sp"
android:padding="3dip" />
android:padding="7dip" />
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/you_read"
android:textSize="20sp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:text=""
android:padding="3dip" />
</TableRow>
android:padding="7dip" />
<TableRow>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="2">
<Button android:id="@+id/verified_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Verified!"/>
<Button android:id="@+id/abort_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abort"/>
<Button android:id="@+id/compare_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Compare"/>
<Button android:id="@+id/cancel_button"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
</TableRow>
</TableLayout>
</ScrollView>
<!---->
<!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- android:layout_width="fill_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="vertical"-->
<!-- android:padding="10px">-->
<!-- -->
<!-- <TextView android:id="@+id/your_fingerprint"-->
<!-- android:layout_width="fill_parent"-->
<!-- android:layout_height="wrap_content" -->
<!-- android:layout_marginBottom="10px"/>-->
<!---->
<!-- <TextView android:id="@+id/their_fingerprint"-->
<!-- android:layout_width="fill_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginBottom="20px" />-->
<!-- -->
<!-- <LinearLayout android:layout_width="fill_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="horizontal">-->
<!-- -->
<!-- <Button android:id="@+id/ok_button"-->
<!-- android:paddingLeft="30px"-->
<!-- android:paddingRight="30px"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginRight="15px"-->
<!-- android:text="Ok"-->
<!-- android:gravity="right"/>-->
<!-- -->
<!-- </LinearLayout>-->
<!--</LinearLayout>-->
<!---->
<!---->

View File

@ -27,13 +27,6 @@
android:layout_gravity="center"
android:layout_span="2">
<Button android:id="@+id/ok_button"
android:layout_margin="10dip"
android:padding="5dip"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Ok"/>
<Button android:id="@+id/compare_button"
android:layout_margin="10dip"
android:padding="5dip"
@ -41,6 +34,12 @@
android:layout_height="wrap_content"
android:text="Compare" />
<Button android:id="@+id/ok_button"
android:layout_margin="10dip"
android:padding="5dip"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Ok"/>
</LinearLayout>

View File

@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Security"
android:id="@+id/menu_security"
android:icon="@drawable/ic_menu_lock_unverified_holo_dark"
android:icon="@drawable/ic_menu_lock_verified_holo_dark"
android:showAsAction="ifRoom">
<menu>
<item android:title="Verify Session"

19
res/menu/key_scanning.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Compare"
android:id="@+id/menu_barcode"
android:icon="@drawable/ic_menu_barcode"
android:showAsAction="ifRoom">
<menu>
<item android:title="Scan to compare"
android:id="@+id/menu_scan"/>
<item android:title="Get scanned to compare"
android:id="@+id/menu_get_scanned"/>
</menu>
</item>
</menu>

7
res/menu/verify_keys.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Verified"
android:id="@+id/menu_session_verified"
android:icon="@drawable/ic_menu_done_holo_dark"
android:showAsAction="ifRoom" />
</menu>

View File

@ -16,44 +16,50 @@
*/
package org.thoughtcrime.securesms;
import android.content.Intent;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.thoughtcrime.securesms.crypto.SerializableKey;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.Dialogs;
import android.app.Activity;
import android.content.Intent;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
/**
* Activity for initiating/receiving key QR code scans.
*
* @author Moxie Marlinspike
*/
public abstract class KeyScanningActivity extends Activity {
private static final int MENU_ITEM_SCAN = 1;
private static final int MENU_ITEM_GET_SCANNED = 2;
public abstract class KeyScanningActivity extends SherlockActivity {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
menu.add(0, MENU_ITEM_SCAN, Menu.NONE, getScanString());
menu.add(0, MENU_ITEM_GET_SCANNED, Menu.NONE, getDisplayString());
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuInflater inflater = this.getSupportMenuInflater();
menu.clear();
inflater.inflate(R.menu.key_scanning, menu);
menu.findItem(R.id.menu_scan).setTitle(getScanString());
menu.findItem(R.id.menu_get_scanned).setTitle(getDisplayString());
return true;
}
@Override
public boolean onContextItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case MENU_ITEM_SCAN: initiateScan(); return true;
case MENU_ITEM_GET_SCANNED: initiateDisplay(); return true;
case R.id.menu_scan: initiateScan(); return true;
case R.id.menu_get_scanned: initiateDisplay(); return true;
case android.R.id.home: finish(); return true;
}
return false;

View File

@ -0,0 +1,40 @@
package org.thoughtcrime.securesms;
import android.os.Bundle;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
public abstract class KeyVerifyingActivity extends KeyScanningActivity {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuInflater inflater = this.getSupportMenuInflater();
inflater.inflate(R.menu.verify_keys, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.menu_session_verified: handleVerified(); return true;
}
return false;
}
protected abstract void handleVerified();
}

View File

@ -16,29 +16,26 @@
*/
package org.thoughtcrime.securesms;
import org.thoughtcrime.securesms.crypto.IdentityKey;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.KeyUtil;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.SessionRecord;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.MemoryCleaner;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import org.thoughtcrime.securesms.crypto.IdentityKey;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.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 {
public class VerifyIdentityActivity extends KeyVerifyingActivity {
private Recipient recipient;
private MasterSecret masterSecret;
@ -46,11 +43,6 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
private TextView localIdentityFingerprint;
private TextView remoteIdentityFingerprint;
private Button verifiedButton;
private Button abortButton;
private Button cancelButton;
private Button compareButton;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
@ -58,7 +50,6 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
initializeResources();
initializeFingerprints();
initializeListeners();
}
@Override
@ -67,6 +58,38 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
super.onDestroy();
}
@Override
protected void handleVerified() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setTitle("Mark Identity Verified?");
builder.setMessage("Are you sure you have validated the recipients' identity fingerprint " +
"and would like to mark it as verified?");
builder.setPositiveButton("Mark Verified", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SessionRecord sessionRecord = new SessionRecord(VerifyIdentityActivity.this,
masterSecret, recipient);
IdentityKey identityKey = sessionRecord.getIdentityKey();
String recipientName = recipient.getName();
Intent intent = new Intent(VerifyIdentityActivity.this,
SaveIdentityActivity.class);
intent.putExtra("name_suggestion", recipientName);
intent.putExtra("master_secret", masterSecret);
intent.putExtra("identity_key", identityKey);
startActivity(intent);
finish();
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
}
private void initializeLocalIdentityKey() {
if (!IdentityKeyUtil.hasIdentityKey(this)) {
localIdentityFingerprint.setText("You do not have an identity key.");
@ -82,19 +105,11 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
if (identityKey == null) {
remoteIdentityFingerprint.setText("Recipient has no identity key.");
verifiedButton.setEnabled(false);
} else {
remoteIdentityFingerprint.setText(identityKey.getFingerprint());
}
}
private void initializeListeners() {
verifiedButton.setOnClickListener(new VerifiedButtonListener());
cancelButton.setOnClickListener(new CancelButtonListener());
abortButton.setOnClickListener(new AbortButtonListener());
compareButton.setOnClickListener(new CompareButtonListener());
}
private void initializeFingerprints() {
initializeLocalIdentityKey();
initializeRemoteIdentityKey();
@ -105,75 +120,6 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
remoteIdentityFingerprint = (TextView)findViewById(R.id.friend_reads);
recipient = (Recipient)this.getIntent().getParcelableExtra("recipient");
masterSecret = (MasterSecret)this.getIntent().getParcelableExtra("master_secret");
verifiedButton = (Button)findViewById(R.id.verified_button);
abortButton = (Button)findViewById(R.id.abort_button);
cancelButton = (Button)findViewById(R.id.cancel_button);
compareButton = (Button)findViewById(R.id.compare_button);
}
private void abortSession() {
KeyUtil.abortSessionFor(this, recipient);
}
private void saveRemoteIdentity() {
SessionRecord sessionRecord = new SessionRecord(this, masterSecret, recipient);
IdentityKey identityKey = sessionRecord.getIdentityKey();
String recipientName = recipient.getName();
Intent intent = new Intent(this, SaveIdentityActivity.class);
intent.putExtra("name_suggestion", recipientName);
intent.putExtra("master_secret", masterSecret);
intent.putExtra("identity_key", identityKey);
startActivity(intent);
}
private class CancelButtonListener implements View.OnClickListener {
public void onClick(View v) {
finish();
}
}
private class CompareButtonListener implements View.OnClickListener {
public void onClick(View v) {
registerForContextMenu(compareButton);
compareButton.showContextMenu();
}
}
private class AbortButtonListener implements View.OnClickListener {
public void onClick(View v) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(VerifyIdentityActivity.this);
dialogBuilder.setTitle("Abort Session?");
dialogBuilder.setIcon(android.R.drawable.ic_dialog_info);
dialogBuilder.setMessage("Are you sure that you would like to abort this secure session?");
dialogBuilder.setCancelable(true);
dialogBuilder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
abortSession();
finish();
}
});
dialogBuilder.setNegativeButton(R.string.no, null);
dialogBuilder.show();
}
}
private class VerifiedButtonListener implements View.OnClickListener {
public void onClick(View v) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(VerifyIdentityActivity.this);
dialogBuilder.setTitle("Save Identity Key?");
dialogBuilder.setIcon(android.R.drawable.ic_dialog_info);
dialogBuilder.setMessage("Are you sure that you would like to mark this as a valid identity key for all future correspondence with this recipient? You should only do this if you have actually verified the fingerprint.");
dialogBuilder.setCancelable(true);
dialogBuilder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
saveRemoteIdentity();
finish();
}
});
dialogBuilder.setNegativeButton(R.string.no, null);
dialogBuilder.show();
}
}
@Override

View File

@ -16,7 +16,11 @@
*/
package org.thoughtcrime.securesms;
import org.thoughtcrime.securesms.crypto.KeyUtil;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.TextView;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.SerializableKey;
import org.thoughtcrime.securesms.database.SessionRecord;
@ -24,31 +28,20 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.Hex;
import org.thoughtcrime.securesms.util.MemoryCleaner;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/**
* Activity for verifying session keys.
*
* @author Moxie Marlinspike
*
*/
public class VerifyKeysActivity extends KeyScanningActivity {
public class VerifyKeysActivity extends KeyVerifyingActivity {
private byte[] yourFingerprintBytes;
private byte[] theirFingerprintBytes;
private TextView yourFingerprint;
private TextView theirFingerprint;
private Button verifiedButton;
private Button abortButton;
private Button cancelButton;
private Button compareButton;
private Recipient recipient;
private MasterSecret masterSecret;
@ -59,7 +52,6 @@ public class VerifyKeysActivity extends KeyScanningActivity {
initializeResources();
initializeFingerprints();
initializeCallbacks();
}
@Override
@ -68,11 +60,26 @@ public class VerifyKeysActivity extends KeyScanningActivity {
super.onDestroy();
}
private void initializeCallbacks() {
this.verifiedButton.setOnClickListener(new VerifiedListener());
this.abortButton.setOnClickListener(new AbortListener());
this.cancelButton.setOnClickListener(new CancelListener());
this.compareButton.setOnClickListener(new CompareListener());
@Override
protected void handleVerified() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setTitle("Mark Session Verified?");
builder.setMessage("Are you sure that you have validated these fingerprints and " +
"would like to mark this session as verified?");
builder.setPositiveButton("Mark Verified", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SessionRecord sessionRecord = new SessionRecord(VerifyKeysActivity.this, masterSecret,
recipient);
sessionRecord.setVerifiedSessionKey(true);
sessionRecord.save();
VerifyKeysActivity.this.finish();
}
});
builder.setNegativeButton("Cancel", null);
builder.show();
}
private void initializeResources() {
@ -80,10 +87,6 @@ public class VerifyKeysActivity extends KeyScanningActivity {
this.masterSecret = (MasterSecret)this.getIntent().getParcelableExtra("master_secret");
this.yourFingerprint = (TextView)findViewById(R.id.you_read);
this.theirFingerprint = (TextView)findViewById(R.id.friend_reads);
this.verifiedButton = (Button)findViewById(R.id.verified_button);
this.abortButton = (Button)findViewById(R.id.abort_button);
this.cancelButton = (Button)findViewById(R.id.cancel_button);
this.compareButton = (Button)findViewById(R.id.compare_button);
}
private void initializeFingerprints() {
@ -95,48 +98,6 @@ public class VerifyKeysActivity extends KeyScanningActivity {
this.theirFingerprint.setText(Hex.toString(theirFingerprintBytes));
}
private class VerifiedListener implements OnClickListener {
public void onClick(View v) {
SessionRecord sessionRecord = new SessionRecord(VerifyKeysActivity.this, masterSecret, recipient);
sessionRecord.setVerifiedSessionKey(true);
sessionRecord.save();
VerifyKeysActivity.this.finish();
}
}
private class CancelListener implements OnClickListener {
public void onClick(View v) {
VerifyKeysActivity.this.finish();
}
}
private class CompareListener implements View.OnClickListener {
public void onClick(View v) {
registerForContextMenu(compareButton);
compareButton.showContextMenu();
}
}
private class AbortListener implements OnClickListener {
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(VerifyKeysActivity.this);
builder.setTitle("Abort Secure Session Confirmation");
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setCancelable(true);
builder.setMessage("Are you sure that you want to abort this secure session?");
builder.setPositiveButton(R.string.yes, new AbortConfirmListener());
builder.setNegativeButton(R.string.no, null);
builder.show();
}
}
private class AbortConfirmListener implements DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int which) {
KeyUtil.abortSessionFor(VerifyKeysActivity.this, recipient);
VerifyKeysActivity.this.finish();
}
}
@Override
protected String getDisplayString() {
return "Get my fingerprint scanned";