Secure conversation detection on compose.

This commit is contained in:
Moxie Marlinspike 2012-08-01 17:39:36 -07:00
parent 31d59dddef
commit 45ae16e684

View File

@ -121,7 +121,7 @@ public class ConversationActivity extends SherlockFragmentActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
initializeSecurity(recipients); initializeSecurity();
initializeTitleBar(); initializeTitleBar();
calculateCharactersRemaining(); calculateCharactersRemaining();
} }
@ -184,14 +184,14 @@ public class ConversationActivity extends SherlockFragmentActivity {
MenuInflater inflater = this.getSupportMenuInflater(); MenuInflater inflater = this.getSupportMenuInflater();
menu.clear(); menu.clear();
if (isSingleExistingConversation() && sendEncrypted) if (isSingleConversation() && sendEncrypted)
{ {
if (isAuthenticatedSession()) { if (isAuthenticatedSession()) {
inflater.inflate(R.menu.conversation_secure_verified, menu); inflater.inflate(R.menu.conversation_secure_verified, menu);
} else { } else {
inflater.inflate(R.menu.conversation_secure_unverified, menu); inflater.inflate(R.menu.conversation_secure_unverified, menu);
} }
} else if (isSingleExistingConversation()) { } else if (isSingleConversation()) {
inflater.inflate(R.menu.conversation_insecure, menu); inflater.inflate(R.menu.conversation_insecure, menu);
} }
@ -238,20 +238,20 @@ public class ConversationActivity extends SherlockFragmentActivity {
private void handleVerifyRecipient() { private void handleVerifyRecipient() {
Intent verifyIdentityIntent = new Intent(this, VerifyIdentityActivity.class); Intent verifyIdentityIntent = new Intent(this, VerifyIdentityActivity.class);
verifyIdentityIntent.putExtra("recipient", recipients.getPrimaryRecipient()); verifyIdentityIntent.putExtra("recipient", getRecipients().getPrimaryRecipient());
verifyIdentityIntent.putExtra("master_secret", masterSecret); verifyIdentityIntent.putExtra("master_secret", masterSecret);
startActivity(verifyIdentityIntent); startActivity(verifyIdentityIntent);
} }
private void handleVerifySession() { private void handleVerifySession() {
Intent verifyKeysIntent = new Intent(this, VerifyKeysActivity.class); Intent verifyKeysIntent = new Intent(this, VerifyKeysActivity.class);
verifyKeysIntent.putExtra("recipient", recipients.getPrimaryRecipient()); verifyKeysIntent.putExtra("recipient", getRecipients().getPrimaryRecipient());
verifyKeysIntent.putExtra("master_secret", masterSecret); verifyKeysIntent.putExtra("master_secret", masterSecret);
startActivity(verifyKeysIntent); startActivity(verifyKeysIntent);
} }
private void handleStartSecureSession() { private void handleStartSecureSession() {
Recipient recipient = recipients.getPrimaryRecipient(); final Recipient recipient = getRecipients().getPrimaryRecipient();
String recipientName = (recipient.getName() == null ? recipient.getNumber() : recipient.getName()); String recipientName = (recipient.getName() == null ? recipient.getNumber() : recipient.getName());
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Initiate Secure Session?"); builder.setTitle("Initiate Secure Session?");
@ -262,7 +262,7 @@ public class ConversationActivity extends SherlockFragmentActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
KeyExchangeInitiator.initiate(ConversationActivity.this, masterSecret, KeyExchangeInitiator.initiate(ConversationActivity.this, masterSecret,
recipients.getPrimaryRecipient(), true); recipient, true);
} }
}); });
@ -279,9 +279,9 @@ public class ConversationActivity extends SherlockFragmentActivity {
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (recipients != null && recipients.isSingleRecipient()) { if (isSingleConversation()) {
KeyUtil.abortSessionFor(ConversationActivity.this, recipients.getPrimaryRecipient()); KeyUtil.abortSessionFor(ConversationActivity.this, getRecipients().getPrimaryRecipient());
initializeSecurity(recipients); initializeSecurity();
initializeTitleBar(); initializeTitleBar();
} }
} }
@ -332,25 +332,26 @@ public class ConversationActivity extends SherlockFragmentActivity {
String title = null; String title = null;
String subtitle = null; String subtitle = null;
if (isSingleExistingConversation()) { if (isSingleConversation()) {
if (sendEncrypted) { if (sendEncrypted) {
title = AuthenticityCalculator.getAuthenticatedName(this, title = AuthenticityCalculator.getAuthenticatedName(this,
recipients.getPrimaryRecipient(), getRecipients().getPrimaryRecipient(),
masterSecret); masterSecret);
} }
if (title == null || title.trim().length() == 0) { if (title == null || title.trim().length() == 0) {
title = recipients.getPrimaryRecipient().getName(); title = getRecipients().getPrimaryRecipient().getName();
} }
if (title == null || title.trim().length() == 0) { if (title == null || title.trim().length() == 0) {
title = recipients.getPrimaryRecipient().getNumber(); title = getRecipients().getPrimaryRecipient().getNumber();
} else { } else {
subtitle = recipients.getPrimaryRecipient().getNumber(); subtitle = getRecipients().getPrimaryRecipient().getNumber();
} }
} else { } else {
title = "Compose Message"; title = "Compose Message";
subtitle = "";
} }
this.getSupportActionBar().setTitle(title); this.getSupportActionBar().setTitle(title);
@ -361,9 +362,9 @@ public class ConversationActivity extends SherlockFragmentActivity {
this.invalidateOptionsMenu(); this.invalidateOptionsMenu();
} }
private void initializeSecurity(Recipients recipients) { private void initializeSecurity() {
if (isSingleExistingConversation() && if (isSingleConversation() &&
KeyUtil.isSessionFor(this, recipients.getPrimaryRecipient())) KeyUtil.isSessionFor(this, getRecipients().getPrimaryRecipient()))
{ {
sendButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_menu_lock_holo_light, 0); sendButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_menu_lock_holo_light, 0);
sendButton.setCompoundDrawablePadding(15); sendButton.setCompoundDrawablePadding(15);
@ -430,7 +431,7 @@ public class ConversationActivity extends SherlockFragmentActivity {
return; return;
if (intent.getLongExtra("thread_id", -1) == threadId) { if (intent.getLongExtra("thread_id", -1) == threadId) {
initializeSecurity(recipients); initializeSecurity();
initializeTitleBar(); initializeTitleBar();
calculateCharactersRemaining(); calculateCharactersRemaining();
} }
@ -514,19 +515,24 @@ public class ConversationActivity extends SherlockFragmentActivity {
return this.recipients != null && this.threadId != -1; return this.recipients != null && this.threadId != -1;
} }
private boolean isSingleExistingConversation() { private boolean isSingleConversation() {
return this.recipients != null && this.recipients.isSingleRecipient(); return getRecipients() != null && getRecipients().isSingleRecipient();
} }
private boolean isAuthenticatedSession() { private boolean isAuthenticatedSession() {
return AuthenticityCalculator.isAuthenticated(this, return AuthenticityCalculator.isAuthenticated(this,
recipients.getPrimaryRecipient(), getRecipients().getPrimaryRecipient(),
masterSecret); masterSecret);
} }
private Recipients getRecipients() throws RecipientFormattingException { private Recipients getRecipients() {
try {
if (isExistingConversation()) return this.recipients; if (isExistingConversation()) return this.recipients;
else return recipientsPanel.getRecipients(); else return recipientsPanel.getRecipients();
} catch (RecipientFormattingException rfe) {
Log.w("ConversationActivity", rfe);
return null;
}
} }
private String getMessage() throws InvalidMessageException { private String getMessage() throws InvalidMessageException {
@ -559,12 +565,17 @@ public class ConversationActivity extends SherlockFragmentActivity {
this.recipientsPanel.setVisibility(View.GONE); this.recipientsPanel.setVisibility(View.GONE);
initializeTitleBar(); initializeTitleBar();
initializeSecurity();
} }
} }
private void sendMessage(boolean sendEncrypted) { private void sendMessage(boolean sendEncrypted) {
try { try {
Recipients recipients = getRecipients(); Recipients recipients = getRecipients();
if (recipients == null)
throw new RecipientFormattingException("Badly formatted");
String message = getMessage(); String message = getMessage();
long allocatedThreadId; long allocatedThreadId;
@ -622,7 +633,9 @@ public class ConversationActivity extends SherlockFragmentActivity {
private class RecipientsPanelChangeListener implements RecipientsPanel.RecipientsPanelChangedListener { private class RecipientsPanelChangeListener implements RecipientsPanel.RecipientsPanelChangedListener {
public void onRecipientsPanelUpdate(Recipients recipients) { public void onRecipientsPanelUpdate(Recipients recipients) {
initializeSecurity(recipients); initializeSecurity();
initializeTitleBar();
calculateCharactersRemaining();
} }
} }