formatting

This commit is contained in:
Moxie Marlinspike 2012-10-29 17:34:14 -07:00
parent 187ec95817
commit 3a9908b40d
2 changed files with 113 additions and 113 deletions

View File

@ -16,6 +16,14 @@
*/ */
package org.thoughtcrime.securesms.service; package org.thoughtcrime.securesms.service;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.crypto.DecryptingQueue; import org.thoughtcrime.securesms.crypto.DecryptingQueue;
import org.thoughtcrime.securesms.crypto.InvalidKeyException; import org.thoughtcrime.securesms.crypto.InvalidKeyException;
@ -30,14 +38,6 @@ import org.thoughtcrime.securesms.protocol.WirePrefix;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.sms.MultipartMessageHandler; import org.thoughtcrime.securesms.sms.MultipartMessageHandler;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
import android.util.Log;
public class SmsReceiver { public class SmsReceiver {
private MultipartMessageHandler multipartMessageHandler = new MultipartMessageHandler(); private MultipartMessageHandler multipartMessageHandler = new MultipartMessageHandler();
@ -102,28 +102,28 @@ public class SmsReceiver {
private void storeKeyExchangeMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) { private void storeKeyExchangeMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ApplicationPreferencesActivity.AUTO_KEY_EXCHANGE_PREF, true)) { if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ApplicationPreferencesActivity.AUTO_KEY_EXCHANGE_PREF, true)) {
try { try {
Recipient recipient = new Recipient(null, message.getDisplayOriginatingAddress(), null); Recipient recipient = new Recipient(null, message.getDisplayOriginatingAddress(), null);
KeyExchangeMessage keyExchangeMessage = new KeyExchangeMessage(messageBody); KeyExchangeMessage keyExchangeMessage = new KeyExchangeMessage(messageBody);
KeyExchangeProcessor processor = new KeyExchangeProcessor(context, masterSecret, recipient); KeyExchangeProcessor processor = new KeyExchangeProcessor(context, masterSecret, recipient);
Log.w("SmsReceiver", "Received key with fingerprint: " + keyExchangeMessage.getPublicKey().getFingerprint()); Log.w("SmsReceiver", "Received key with fingerprint: " + keyExchangeMessage.getPublicKey().getFingerprint());
if (processor.isStale(keyExchangeMessage)) { if (processor.isStale(keyExchangeMessage)) {
messageBody = messageBody.substring(Prefix.KEY_EXCHANGE.length()); messageBody = messageBody.substring(Prefix.KEY_EXCHANGE.length());
messageBody = Prefix.STALE_KEY_EXCHANGE + messageBody; messageBody = Prefix.STALE_KEY_EXCHANGE + messageBody;
} else if (!processor.hasCompletedSession() || processor.hasSameSessionIdentity(keyExchangeMessage)) { } else if (!processor.hasCompletedSession() || processor.hasSameSessionIdentity(keyExchangeMessage)) {
messageBody = messageBody.substring(Prefix.KEY_EXCHANGE.length()); messageBody = messageBody.substring(Prefix.KEY_EXCHANGE.length());
messageBody = Prefix.PROCESSED_KEY_EXCHANGE + messageBody; messageBody = Prefix.PROCESSED_KEY_EXCHANGE + messageBody;
long messageId = storeStandardMessage(masterSecret, message, messageBody); long messageId = storeStandardMessage(masterSecret, message, messageBody);
long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId); long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId);
processor.processKeyExchangeMessage(keyExchangeMessage, threadId); processor.processKeyExchangeMessage(keyExchangeMessage, threadId);
return; return;
} }
} catch (InvalidVersionException e) { } catch (InvalidVersionException e) {
Log.w("SmsReceiver", e); Log.w("SmsReceiver", e);
} catch (InvalidKeyException e) { } catch (InvalidKeyException e) {
Log.w("SmsReceiver", e); Log.w("SmsReceiver", e);
} }
} }

View File

@ -16,7 +16,13 @@
*/ */
package org.thoughtcrime.securesms.service; package org.thoughtcrime.securesms.service;
import java.util.ArrayList; import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.telephony.SmsManager;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterCipher; import org.thoughtcrime.securesms.crypto.MasterCipher;
import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.crypto.MasterSecret;
@ -32,13 +38,7 @@ import org.thoughtcrime.securesms.sms.MultipartMessageHandler;
import org.thoughtcrime.securesms.sms.SmsTransportDetails; import org.thoughtcrime.securesms.sms.SmsTransportDetails;
import org.thoughtcrime.securesms.util.InvalidMessageException; import org.thoughtcrime.securesms.util.InvalidMessageException;
import android.app.PendingIntent; import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.telephony.SmsManager;
import android.util.Log;
public class SmsSender { public class SmsSender {
@ -62,36 +62,36 @@ public class SmsSender {
else c = DatabaseFactory.getSmsDatabase(context).getMessage(messageId); else c = DatabaseFactory.getSmsDatabase(context).getMessage(messageId);
if (c != null && c.moveToFirst()) { if (c != null && c.moveToFirst()) {
do { do {
messageId = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.ID)); messageId = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.ID));
String body = c.getString(c.getColumnIndexOrThrow(SmsDatabase.BODY)); String body = c.getString(c.getColumnIndexOrThrow(SmsDatabase.BODY));
String address = c.getString(c.getColumnIndexOrThrow(SmsDatabase.ADDRESS)); String address = c.getString(c.getColumnIndexOrThrow(SmsDatabase.ADDRESS));
String messageText = getClearTextBody(masterCipher, body); String messageText = getClearTextBody(masterCipher, body);
long type = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.TYPE)); long type = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.TYPE));
if (!SmsDatabase.Types.isPendingMessageType(type)) if (!SmsDatabase.Types.isPendingMessageType(type))
continue; continue;
if (isSecureMessage(type)) if (isSecureMessage(type))
messageText = getAsymmetricEncrypt(masterSecret, messageText, address); messageText = getAsymmetricEncrypt(masterSecret, messageText, address);
Log.w("SMSSenderService", "Actually delivering: " + messageId); Log.w("SMSSenderService", "Actually delivering: " + messageId);
deliverTextMessage(address, messageText, messageId, type); deliverTextMessage(address, messageText, messageId, type);
} while (c.moveToNext()); } while (c.moveToNext());
} }
} finally { } finally {
if (c != null) if (c != null)
c.close(); c.close();
} }
} }
private String getClearTextBody(MasterCipher masterCipher, String body) { private String getClearTextBody(MasterCipher masterCipher, String body) {
if (body.startsWith(Prefix.SYMMETRIC_ENCRYPT)) { if (body.startsWith(Prefix.SYMMETRIC_ENCRYPT)) {
try { try {
return masterCipher.decryptBody(body.substring(Prefix.SYMMETRIC_ENCRYPT.length())); return masterCipher.decryptBody(body.substring(Prefix.SYMMETRIC_ENCRYPT.length()));
} catch (InvalidMessageException e) { } catch (InvalidMessageException e) {
return "Error decrypting message."; return "Error decrypting message.";
} }
} else { } else {
return body; return body;
@ -150,10 +150,10 @@ public class SmsSender {
// the message as a failure. That way at least it doesn't repeatedly crash every time you start // the message as a failure. That way at least it doesn't repeatedly crash every time you start
// the app. // the app.
try { try {
SmsManager.getDefault().sendTextMessage(recipient, null, messages.get(i), sentIntents.get(i), null); SmsManager.getDefault().sendTextMessage(recipient, null, messages.get(i), sentIntents.get(i), null);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
Log.w("SmsSender", npe); Log.w("SmsSender", npe);
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId); DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
} }
} }
} }