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: 1,010 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -1,64 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:textSize="12sp"
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"
android:password="true"/>
<EditText android:id="@+id/old_passphrase"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"/>
</TableRow>
<TableRow>
<TextView
android:text="New passphrase:"
android:textSize="12sp"
android:textSize="12sp"
android:padding="3dip" />
<EditText android:id="@+id/new_passphrase"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"
/>
<EditText android:id="@+id/new_passphrase"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"
/>
</TableRow>
<TableRow>
<TextView
android:text="Repeat new passphrase:"
android:textSize="12sp"
android:textSize="12sp"
android:padding="3dip" />
<EditText android:id="@+id/repeat_passphrase"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"
/>
<EditText android:id="@+id/repeat_passphrase"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"
/>
</TableRow>
<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"/>
</TableRow>
</TableLayout>
<TableRow>
<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

@ -1,47 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip">
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dip">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:text="Identity Name:" />
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:id="@+id/identity_name"
android:text="" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
<Button android:layout_width="100dip"
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"/>
</LinearLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:text="Identity Name:" />
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:id="@+id/identity_name"
android:text="" />
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dip"
android:gravity="right">
<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:id="@+id/ok_button"
android:text="Ok"/>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>

View file

@ -1,70 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView
android:textSize="12sp"
android:text="Their identity:\n(They read)"
android:padding="3dip" />
<TextView
android:textSize="20sp"
android:typeface="monospace"
android:id="@+id/friend_reads"
android:text=""
android:padding="3dip" />
</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">
<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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Their identity (they read):"
android:padding="7dip" />
<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>
<TextView
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="7dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your identity (you read):"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="7dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/you_read"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:text=""
android:padding="7dip" />
</LinearLayout>
</ScrollView>

View file

@ -1,105 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView
android:textSize="12sp"
android:text="Your friend reads this:"
android:padding="3dip" />
<TextView
android:textSize="20sp"
android:typeface="monospace"
android:id="@+id/friend_reads"
android:text=""
android:padding="3dip" />
</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">
<TableRow>
<TextView
android:text="You read this:"
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">
<TextView
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: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="7dip" />
<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:padding="7dip" />
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/you_read"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:text=""
android:padding="7dip" />
</LinearLayout>
<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

@ -1,50 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:shrinkColumns="1">
<TableRow>
<TextView
android:textSize="12sp"
android:textSize="12sp"
android:text="Your identity:"
android:padding="3dip" />
<TextView
android:textSize="20sp"
android:typeface="monospace"
android:id="@+id/identity_fingerprint"
android:textSize="20sp"
android:typeface="monospace"
android:id="@+id/identity_fingerprint"
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">
<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"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Compare" />
</LinearLayout>
</TableRow>
<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/compare_button"
android:layout_margin="10dip"
android:padding="5dip"
android:layout_width="100dip"
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>
</TableRow>
</TableLayout>
</ScrollView>

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

@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 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
@ -10,62 +10,68 @@
* 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.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) {
switch(item.getItemId()) {
case MENU_ITEM_SCAN: initiateScan(); return true;
case MENU_ITEM_GET_SCANNED: initiateDisplay(); return true;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
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;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if ((scanResult != null) && (scanResult.getContents() != null)) {
String data = scanResult.getContents();
if (data.equals(Base64.encodeBytes(getIdentityKeyToCompare().serialize()))) {
Dialogs.displayAlert(this, getVerifiedTitle(), getVerifiedMessage(), android.R.drawable.ic_dialog_info);
} else {
@ -75,11 +81,11 @@ public abstract class KeyScanningActivity extends Activity {
Toast.makeText(this, "No scanned key found!", Toast.LENGTH_LONG).show();
}
}
protected void initiateScan() {
IntentIntegrator.initiateScan(this);
}
protected void initiateDisplay() {
IntentIntegrator.shareText(this, Base64.encodeBytes(getIdentityKeyToDisplay().serialize()));
}
@ -92,8 +98,8 @@ public abstract class KeyScanningActivity extends Activity {
protected abstract SerializableKey getIdentityKeyToCompare();
protected abstract SerializableKey getIdentityKeyToDisplay();
protected abstract String getVerifiedTitle();
protected abstract String getVerifiedMessage();
}

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

@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 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
@ -10,170 +10,116 @@
* 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.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
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.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;
/**
* Activity for verifying identity keys.
*
*
* @author Moxie Marlinspike
*/
public class VerifyIdentityActivity extends KeyScanningActivity {
public class VerifyIdentityActivity extends KeyVerifyingActivity {
private Recipient recipient;
private MasterSecret masterSecret;
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);
setContentView(R.layout.verify_identity_activity);
initializeResources();
initializeFingerprints();
initializeListeners();
}
@Override
protected void onDestroy() {
MemoryCleaner.clean(masterSecret);
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.");
return;
}
localIdentityFingerprint.setText(IdentityKeyUtil.getFingerprint(this));
}
private void initializeRemoteIdentityKey() {
SessionRecord sessionRecord = new SessionRecord(this, masterSecret, recipient);
IdentityKey identityKey = sessionRecord.getIdentityKey();
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();
}
private void initializeResources() {
localIdentityFingerprint = (TextView)findViewById(R.id.you_read);
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
@ -182,22 +128,22 @@ public class VerifyIdentityActivity extends KeyScanningActivity {
Toast.makeText(this, "You don't have an identity key!", 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, "Recipient has no identity key!", Toast.LENGTH_LONG);
} else {
super.initiateScan();
}
}
}
@Override
protected String getScanString() {
return "Scan their key to compare";

View file

@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 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
@ -10,13 +10,17 @@
* 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 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,131 +28,88 @@ 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;
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.verify_keys_activity);
initializeResources();
initializeFingerprints();
initializeCallbacks();
}
@Override
protected void onDestroy() {
MemoryCleaner.clean(masterSecret);
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() {
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);
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() {
SessionRecord session = new SessionRecord(this, masterSecret, recipient);
this.yourFingerprintBytes = session.getLocalFingerprint();
this.theirFingerprintBytes = session.getRemoteFingerprint();
this.yourFingerprint.setText(Hex.toString(yourFingerprintBytes));
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";
}
@Override
protected String getScanString() {
return "Scan their fingerprint";
}
@Override
protected SerializableKey getIdentityKeyToCompare() {
protected SerializableKey getIdentityKeyToCompare() {
return new FingerprintKey(theirFingerprintBytes);
}
@ -176,14 +137,14 @@ public class VerifyKeysActivity extends KeyScanningActivity {
protected String getVerifiedTitle() {
return "Verified!";
}
private class FingerprintKey implements SerializableKey {
private final byte[] fingerprint;
public FingerprintKey(byte[] fingerprint) {
this.fingerprint = fingerprint;
}
public byte[] serialize() {
return fingerprint;
}