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

@ -1,6 +1,6 @@
/** /**
* Copyright (C) 2011 Whisper Systems * Copyright (C) 2011 Whisper Systems
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
@ -10,12 +10,20 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
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,106 +38,98 @@ 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();
private final Context context; private final Context context;
public SmsReceiver(Context context) { public SmsReceiver(Context context) {
this.context = context; this.context = context;
} }
private String assembleSecureMessageFragments(String sender, String messageBody) { private String assembleSecureMessageFragments(String sender, String messageBody) {
String localPrefix; String localPrefix;
if (WirePrefix.isEncryptedMessage(messageBody)) { if (WirePrefix.isEncryptedMessage(messageBody)) {
localPrefix = Prefix.ASYMMETRIC_ENCRYPT; localPrefix = Prefix.ASYMMETRIC_ENCRYPT;
} else { } else {
localPrefix = Prefix.KEY_EXCHANGE; localPrefix = Prefix.KEY_EXCHANGE;
} }
Log.w("SMSReceiverService", "Calculated local prefix for message: " + messageBody + " - Local Prefix: " + localPrefix); Log.w("SMSReceiverService", "Calculated local prefix for message: " + messageBody + " - Local Prefix: " + localPrefix);
messageBody = messageBody.substring(WirePrefix.PREFIX_SIZE); messageBody = messageBody.substring(WirePrefix.PREFIX_SIZE);
Log.w("SMSReceiverService", "Parsed off wire prefix: " + messageBody); Log.w("SMSReceiverService", "Parsed off wire prefix: " + messageBody);
if (!multipartMessageHandler.isManualTransport(messageBody)) if (!multipartMessageHandler.isManualTransport(messageBody))
return localPrefix + messageBody; return localPrefix + messageBody;
else else
return multipartMessageHandler.processPotentialMultipartMessage(localPrefix, sender, messageBody); return multipartMessageHandler.processPotentialMultipartMessage(localPrefix, sender, messageBody);
} }
private String assembleMessageFragments(SmsMessage[] messages) { private String assembleMessageFragments(SmsMessage[] messages) {
StringBuilder body = new StringBuilder(); StringBuilder body = new StringBuilder();
for (SmsMessage message : messages) { for (SmsMessage message : messages) {
body.append(message.getDisplayMessageBody()); body.append(message.getDisplayMessageBody());
} }
String messageBody = body.toString(); String messageBody = body.toString();
if (WirePrefix.isEncryptedMessage(messageBody) || WirePrefix.isKeyExchange(messageBody)) { if (WirePrefix.isEncryptedMessage(messageBody) || WirePrefix.isKeyExchange(messageBody)) {
return assembleSecureMessageFragments(messages[0].getDisplayOriginatingAddress(), messageBody); return assembleSecureMessageFragments(messages[0].getDisplayOriginatingAddress(), messageBody);
} else { } else {
return messageBody; return messageBody;
} }
} }
private void storeSecureMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) { private void storeSecureMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) {
long messageId = DatabaseFactory.getSmsDatabase(context).insertSecureMessageReceived(message, messageBody); long messageId = DatabaseFactory.getSmsDatabase(context).insertSecureMessageReceived(message, messageBody);
Log.w("SmsReceiver", "Inserted secure message received: " + messageId); Log.w("SmsReceiver", "Inserted secure message received: " + messageId);
if (masterSecret != null) if (masterSecret != null)
DecryptingQueue.scheduleDecryption(context, masterSecret, messageId, message.getDisplayOriginatingAddress(), messageBody); DecryptingQueue.scheduleDecryption(context, masterSecret, messageId, message.getDisplayOriginatingAddress(), messageBody);
} }
private long storeStandardMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) { private long storeStandardMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) {
if (masterSecret != null) return DatabaseFactory.getEncryptingSmsDatabase(context).insertMessageReceived(masterSecret, message, messageBody); if (masterSecret != null) return DatabaseFactory.getEncryptingSmsDatabase(context).insertMessageReceived(masterSecret, message, messageBody);
else if (MasterSecretUtil.hasAsymmericMasterSecret(context)) return DatabaseFactory.getEncryptingSmsDatabase(context).insertMessageReceived(MasterSecretUtil.getAsymmetricMasterSecret(context, null), message, messageBody); else if (MasterSecretUtil.hasAsymmericMasterSecret(context)) return DatabaseFactory.getEncryptingSmsDatabase(context).insertMessageReceived(MasterSecretUtil.getAsymmetricMasterSecret(context, null), message, messageBody);
else return DatabaseFactory.getSmsDatabase(context).insertMessageReceived(message, messageBody); else return DatabaseFactory.getSmsDatabase(context).insertMessageReceived(message, messageBody);
} }
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);
} }
} }
storeStandardMessage(masterSecret, message, messageBody); storeStandardMessage(masterSecret, message, messageBody);
} }
private boolean storeMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) { private boolean storeMessage(MasterSecret masterSecret, SmsMessage message, String messageBody) {
if (messageBody.startsWith(Prefix.ASYMMETRIC_ENCRYPT)) { if (messageBody.startsWith(Prefix.ASYMMETRIC_ENCRYPT)) {
storeSecureMessage(masterSecret, message, messageBody); storeSecureMessage(masterSecret, message, messageBody);
@ -138,48 +138,48 @@ public class SmsReceiver {
} else { } else {
storeStandardMessage(masterSecret, message, messageBody); storeStandardMessage(masterSecret, message, messageBody);
} }
return true; return true;
} }
private SmsMessage[] parseMessages(Bundle bundle) { private SmsMessage[] parseMessages(Bundle bundle) {
Object[] pdus = (Object[])bundle.get("pdus"); Object[] pdus = (Object[])bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length]; SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i=0;i<pdus.length;i++) for (int i=0;i<pdus.length;i++)
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]); messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
return messages; return messages;
} }
private void handleReceiveMessage(MasterSecret masterSecret, Intent intent) { private void handleReceiveMessage(MasterSecret masterSecret, Intent intent) {
Bundle bundle = intent.getExtras(); Bundle bundle = intent.getExtras();
SmsMessage[] messages = parseMessages(bundle); SmsMessage[] messages = parseMessages(bundle);
String message = assembleMessageFragments(messages); String message = assembleMessageFragments(messages);
if (message != null) { if (message != null) {
storeMessage(masterSecret, messages[0], message); storeMessage(masterSecret, messages[0], message);
MessageNotifier.updateNotification(context, true); MessageNotifier.updateNotification(context, true);
} }
} }
private void handleSentMessage(Intent intent) { private void handleSentMessage(Intent intent) {
long messageId = intent.getLongExtra("message_id", -1); long messageId = intent.getLongExtra("message_id", -1);
long type = intent.getLongExtra("type", -1); long type = intent.getLongExtra("type", -1);
Log.w("SMSReceiverService", "Intent resultcode: " + intent.getIntExtra("ResultCode", 42)); Log.w("SMSReceiverService", "Intent resultcode: " + intent.getIntExtra("ResultCode", 42));
Log.w("SMSReceiverService", "Running sent callback: " + messageId + "," + type); Log.w("SMSReceiverService", "Running sent callback: " + messageId + "," + type);
if (intent.getIntExtra("ResultCode", -31337) == Activity.RESULT_OK) if (intent.getIntExtra("ResultCode", -31337) == Activity.RESULT_OK)
DatabaseFactory.getSmsDatabase(context).markAsSent(messageId, type); DatabaseFactory.getSmsDatabase(context).markAsSent(messageId, type);
else else
DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId); DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
} }
public void process(MasterSecret masterSecret, Intent intent) { public void process(MasterSecret masterSecret, Intent intent) {
if (intent.getAction().equals(SendReceiveService.RECEIVE_SMS_ACTION)) if (intent.getAction().equals(SendReceiveService.RECEIVE_SMS_ACTION))
handleReceiveMessage(masterSecret, intent); handleReceiveMessage(masterSecret, intent);
else if (intent.getAction().equals(SendReceiveService.SENT_SMS_ACTION)) else if (intent.getAction().equals(SendReceiveService.SENT_SMS_ACTION))
handleSentMessage(intent); handleSentMessage(intent);
} }
} }

View File

@ -1,6 +1,6 @@
/** /**
* Copyright (C) 2011 Whisper Systems * Copyright (C) 2011 Whisper Systems
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
@ -10,13 +10,19 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
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,24 +38,18 @@ 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 {
private final MultipartMessageHandler multipartMessageHandler = new MultipartMessageHandler(); private final MultipartMessageHandler multipartMessageHandler = new MultipartMessageHandler();
private final Context context; private final Context context;
public SmsSender(Context context) { public SmsSender(Context context) {
this.context = context; this.context = context;
} }
public void process(MasterSecret masterSecret, Intent intent) { public void process(MasterSecret masterSecret, Intent intent) {
MasterCipher masterCipher = new MasterCipher(masterSecret); MasterCipher masterCipher = new MasterCipher(masterSecret);
long messageId = intent.getLongExtra("message_id", -1); long messageId = intent.getLongExtra("message_id", -1);
@ -60,44 +60,44 @@ public class SmsSender {
try { try {
if (messageId == -1) c = DatabaseFactory.getSmsDatabase(context).getOutgoingMessages(); if (messageId == -1) c = DatabaseFactory.getSmsDatabase(context).getOutgoingMessages();
else c = DatabaseFactory.getSmsDatabase(context).getMessage(messageId); else c = DatabaseFactory.getSmsDatabase(context).getMessage(messageId);
if (c != null && c.moveToFirst()) {
do {
messageId = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.ID));
String body = c.getString(c.getColumnIndexOrThrow(SmsDatabase.BODY));
String address = c.getString(c.getColumnIndexOrThrow(SmsDatabase.ADDRESS));
String messageText = getClearTextBody(masterCipher, body);
long type = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.TYPE));
if (!SmsDatabase.Types.isPendingMessageType(type))
continue;
if (isSecureMessage(type))
messageText = getAsymmetricEncrypt(masterSecret, messageText, address);
Log.w("SMSSenderService", "Actually delivering: " + messageId);
deliverTextMessage(address, messageText, messageId, type); if (c != null && c.moveToFirst()) {
} while (c.moveToNext()); do {
} messageId = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.ID));
String body = c.getString(c.getColumnIndexOrThrow(SmsDatabase.BODY));
String address = c.getString(c.getColumnIndexOrThrow(SmsDatabase.ADDRESS));
String messageText = getClearTextBody(masterCipher, body);
long type = c.getLong(c.getColumnIndexOrThrow(SmsDatabase.TYPE));
if (!SmsDatabase.Types.isPendingMessageType(type))
continue;
if (isSecureMessage(type))
messageText = getAsymmetricEncrypt(masterSecret, messageText, address);
Log.w("SMSSenderService", "Actually delivering: " + messageId);
deliverTextMessage(address, messageText, messageId, type);
} 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;
} }
} }
private ArrayList<PendingIntent> constructSentIntents(long messageId, long type, ArrayList<String> messages) { private ArrayList<PendingIntent> constructSentIntents(long messageId, long type, ArrayList<String> messages) {
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(messages.size()); ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(messages.size());
@ -107,10 +107,10 @@ public class SmsSender {
pending.putExtra("message_id", messageId); pending.putExtra("message_id", messageId);
sentIntents.add(PendingIntent.getBroadcast(context, 0, pending, 0)); sentIntents.add(PendingIntent.getBroadcast(context, 0, pending, 0));
} }
return sentIntents; return sentIntents;
} }
private void deliverGSMTransportTextMessage(String recipient, String text, long messageId, long type) { private void deliverGSMTransportTextMessage(String recipient, String text, long messageId, long type) {
ArrayList<String> messages = SmsManager.getDefault().divideMessage(text); ArrayList<String> messages = SmsManager.getDefault().divideMessage(text);
ArrayList<PendingIntent> sentIntents = constructSentIntents(messageId, type, messages); ArrayList<PendingIntent> sentIntents = constructSentIntents(messageId, type, messages);
@ -128,7 +128,7 @@ public class SmsSender {
private void deliverSecureTransportTextMessage(String recipient, String text, long messageId, long type) { private void deliverSecureTransportTextMessage(String recipient, String text, long messageId, long type) {
WirePrefix prefix; WirePrefix prefix;
if (isSecureMessage(type)) { if (isSecureMessage(type)) {
prefix = new SecureMessageWirePrefix(); prefix = new SecureMessageWirePrefix();
text = text.substring(Prefix.ASYMMETRIC_ENCRYPT.length()); text = text.substring(Prefix.ASYMMETRIC_ENCRYPT.length());
@ -136,12 +136,12 @@ public class SmsSender {
prefix = new KeyExchangeWirePrefix(); prefix = new KeyExchangeWirePrefix();
text = text.substring(Prefix.KEY_EXCHANGE.length()); text = text.substring(Prefix.KEY_EXCHANGE.length());
} }
if (!multipartMessageHandler.isManualTransport(text)) { if (!multipartMessageHandler.isManualTransport(text)) {
deliverGSMTransportTextMessage(recipient, prefix.calculatePrefix(text) + text, messageId, type); deliverGSMTransportTextMessage(recipient, prefix.calculatePrefix(text) + text, messageId, type);
return; return;
} }
ArrayList<String> messages = multipartMessageHandler.divideMessage(recipient, text, prefix); ArrayList<String> messages = multipartMessageHandler.divideMessage(recipient, text, prefix);
ArrayList<PendingIntent> sentIntents = constructSentIntents(messageId, type, messages); ArrayList<PendingIntent> sentIntents = constructSentIntents(messageId, type, messages);
for (int i=0;i<messages.size();i++) { for (int i=0;i<messages.size();i++) {
@ -150,34 +150,34 @@ 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);
} }
} }
} }
private void deliverTextMessage(String recipient, String text, long messageId, long type) { private void deliverTextMessage(String recipient, String text, long messageId, long type) {
if (!isSecureMessage(type) && !isKeyExchange(text)) if (!isSecureMessage(type) && !isKeyExchange(text))
deliverGSMTransportTextMessage(recipient, text, messageId, type); deliverGSMTransportTextMessage(recipient, text, messageId, type);
else else
deliverSecureTransportTextMessage(recipient, text, messageId, type); deliverSecureTransportTextMessage(recipient, text, messageId, type);
} }
private boolean isSecureMessage(long type) { private boolean isSecureMessage(long type) {
return type == SmsDatabase.Types.ENCRYPTING_TYPE; return type == SmsDatabase.Types.ENCRYPTING_TYPE;
} }
private boolean isKeyExchange(String messageText) { private boolean isKeyExchange(String messageText) {
return messageText.startsWith(Prefix.KEY_EXCHANGE); return messageText.startsWith(Prefix.KEY_EXCHANGE);
} }
private String getAsymmetricEncrypt(MasterSecret masterSecret, String body, String address) { private String getAsymmetricEncrypt(MasterSecret masterSecret, String body, String address) {
synchronized (SessionCipher.CIPHER_LOCK) { synchronized (SessionCipher.CIPHER_LOCK) {
SessionCipher cipher = new SessionCipher(context, masterSecret, new Recipient(null, address, null), new SmsTransportDetails()); SessionCipher cipher = new SessionCipher(context, masterSecret, new Recipient(null, address, null), new SmsTransportDetails());
return new String(cipher.encryptMessage(body.getBytes())); return new String(cipher.encryptMessage(body.getBytes()));
} }
} }
} }