Rename EncryptedMessage

This commit is contained in:
Moxie Marlinspike 2013-08-21 17:32:54 -07:00
parent 90814be167
commit 43492b66c4
9 changed files with 42 additions and 59 deletions

View File

@ -14,23 +14,13 @@
* 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.whispersystems.textsecure.crypto.protocol; package org.whispersystems.textsecure.crypto;
import android.content.Context; import android.content.Context;
import android.util.Log;
import org.whispersystems.textsecure.crypto.IdentityKeyPair;
import org.whispersystems.textsecure.crypto.InvalidKeyException;
import org.whispersystems.textsecure.crypto.InvalidMessageException;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.MessageMac;
import org.whispersystems.textsecure.crypto.PublicKey;
import org.whispersystems.textsecure.crypto.SessionCipher;
import org.whispersystems.textsecure.crypto.SessionCipher.SessionCipherContext; import org.whispersystems.textsecure.crypto.SessionCipher.SessionCipherContext;
import org.whispersystems.textsecure.crypto.TransportDetails;
import org.whispersystems.textsecure.storage.CanonicalRecipientAddress; import org.whispersystems.textsecure.storage.CanonicalRecipientAddress;
import org.whispersystems.textsecure.util.Conversions; import org.whispersystems.textsecure.util.Conversions;
import org.whispersystems.textsecure.util.Hex;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -41,7 +31,7 @@ import java.nio.ByteBuffer;
* @author Moxie Marlinspike * @author Moxie Marlinspike
*/ */
public class EncryptedMessage { public class MessageCipher {
public static final int SUPPORTED_VERSION = 2; public static final int SUPPORTED_VERSION = 2;
public static final int CRADLE_AGREEMENT_VERSION = 2; public static final int CRADLE_AGREEMENT_VERSION = 2;
@ -65,9 +55,9 @@ public class EncryptedMessage {
private final IdentityKeyPair localIdentityKey; private final IdentityKeyPair localIdentityKey;
private final TransportDetails transportDetails; private final TransportDetails transportDetails;
public EncryptedMessage(Context context, MasterSecret masterSecret, public MessageCipher(Context context, MasterSecret masterSecret,
IdentityKeyPair localIdentityKey, IdentityKeyPair localIdentityKey,
TransportDetails transportDetails) TransportDetails transportDetails)
{ {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
this.masterSecret = masterSecret; this.masterSecret = masterSecret;

View File

@ -19,10 +19,7 @@ package org.whispersystems.textsecure.crypto;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import org.spongycastle.crypto.AsymmetricCipherKeyPair;
import org.spongycastle.crypto.agreement.ECDHBasicAgreement;
import org.spongycastle.crypto.params.ECPublicKeyParameters; import org.spongycastle.crypto.params.ECPublicKeyParameters;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import org.whispersystems.textsecure.storage.CanonicalRecipientAddress; import org.whispersystems.textsecure.storage.CanonicalRecipientAddress;
import org.whispersystems.textsecure.storage.InvalidKeyIdException; import org.whispersystems.textsecure.storage.InvalidKeyIdException;
import org.whispersystems.textsecure.storage.LocalKeyRecord; import org.whispersystems.textsecure.storage.LocalKeyRecord;
@ -59,7 +56,7 @@ public class SessionCipher {
public static final int CIPHER_KEY_LENGTH = 16; public static final int CIPHER_KEY_LENGTH = 16;
public static final int MAC_KEY_LENGTH = 20; public static final int MAC_KEY_LENGTH = 20;
public static final int ENCRYPTED_MESSAGE_OVERHEAD = EncryptedMessage.HEADER_LENGTH + MessageMac.MAC_LENGTH; public static final int ENCRYPTED_MESSAGE_OVERHEAD = MessageCipher.HEADER_LENGTH + MessageMac.MAC_LENGTH;
public SessionCipherContext getEncryptionContext(Context context, public SessionCipherContext getEncryptionContext(Context context,
MasterSecret masterSecret, MasterSecret masterSecret,
@ -309,7 +306,7 @@ public class SessionCipher {
IdentityKey remoteIdentityKey = records.getSessionRecord().getIdentityKey(); IdentityKey remoteIdentityKey = records.getSessionRecord().getIdentityKey();
if (isInitiallyExchangedKeys(records, localKeyId, remoteKeyId) && if (isInitiallyExchangedKeys(records, localKeyId, remoteKeyId) &&
messageVersion >= EncryptedMessage.CRADLE_AGREEMENT_VERSION) messageVersion >= MessageCipher.CRADLE_AGREEMENT_VERSION)
{ {
return SharedSecretCalculator.calculateSharedSecret(localKeyPair, localIdentityKey, return SharedSecretCalculator.calculateSharedSecret(localKeyPair, localIdentityKey,
remoteKey, remoteIdentityKey); remoteKey, remoteIdentityKey);

View File

@ -16,6 +16,7 @@
*/ */
package org.whispersystems.textsecure.crypto.protocol; package org.whispersystems.textsecure.crypto.protocol;
import org.whispersystems.textsecure.crypto.MessageCipher;
import org.whispersystems.textsecure.crypto.IdentityKey; import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.InvalidKeyException; import org.whispersystems.textsecure.crypto.InvalidKeyException;
import org.whispersystems.textsecure.crypto.InvalidVersionException; import org.whispersystems.textsecure.crypto.InvalidVersionException;
@ -34,14 +35,14 @@ import java.io.IOException;
*/ */
public class PreKeyBundleMessage { public class PreKeyBundleMessage {
private static final int VERSION_LENGTH = EncryptedMessage.VERSION_LENGTH; private static final int VERSION_LENGTH = MessageCipher.VERSION_LENGTH;
private static final int IDENTITY_KEY_LENGTH = IdentityKey.SIZE; private static final int IDENTITY_KEY_LENGTH = IdentityKey.SIZE;
public static final int HEADER_LENGTH = IDENTITY_KEY_LENGTH + EncryptedMessage.HEADER_LENGTH; public static final int HEADER_LENGTH = IDENTITY_KEY_LENGTH + MessageCipher.HEADER_LENGTH;
private static final int VERSION_OFFSET = EncryptedMessage.VERSION_OFFSET; private static final int VERSION_OFFSET = MessageCipher.VERSION_OFFSET;
private static final int IDENTITY_KEY_OFFSET = VERSION_OFFSET + EncryptedMessage.VERSION_LENGTH; private static final int IDENTITY_KEY_OFFSET = VERSION_OFFSET + MessageCipher.VERSION_LENGTH;
private static final int PUBLIC_KEY_OFFSET = IDENTITY_KEY_LENGTH + EncryptedMessage.NEXT_KEY_OFFSET; private static final int PUBLIC_KEY_OFFSET = IDENTITY_KEY_LENGTH + MessageCipher.NEXT_KEY_OFFSET;
private static final int PREKEY_ID_OFFSET = IDENTITY_KEY_LENGTH + EncryptedMessage.RECEIVER_KEY_ID_OFFSET; private static final int PREKEY_ID_OFFSET = IDENTITY_KEY_LENGTH + MessageCipher.RECEIVER_KEY_ID_OFFSET;
private final byte[] messageBytes; private final byte[] messageBytes;
@ -57,9 +58,9 @@ public class PreKeyBundleMessage {
this.messageBytes = Base64.decodeWithoutPadding(message); this.messageBytes = Base64.decodeWithoutPadding(message);
this.messageVersion = Conversions.highBitsToInt(this.messageBytes[VERSION_OFFSET]); this.messageVersion = Conversions.highBitsToInt(this.messageBytes[VERSION_OFFSET]);
if (messageVersion > EncryptedMessage.SUPPORTED_VERSION) if (messageVersion > MessageCipher.SUPPORTED_VERSION)
throw new InvalidVersionException("Key exchange with version: " + messageVersion + throw new InvalidVersionException("Key exchange with version: " + messageVersion +
" but we only support: " + EncryptedMessage.SUPPORTED_VERSION); " but we only support: " + MessageCipher.SUPPORTED_VERSION);
this.supportedVersion = Conversions.lowBitsToInt(messageBytes[VERSION_OFFSET]); this.supportedVersion = Conversions.lowBitsToInt(messageBytes[VERSION_OFFSET]);
this.publicKey = new PublicKey(messageBytes, PUBLIC_KEY_OFFSET); this.publicKey = new PublicKey(messageBytes, PUBLIC_KEY_OFFSET);
@ -77,11 +78,11 @@ public class PreKeyBundleMessage {
public PreKeyBundleMessage(IdentityKey identityKey, byte[] bundledMessage) { public PreKeyBundleMessage(IdentityKey identityKey, byte[] bundledMessage) {
try { try {
this.supportedVersion = EncryptedMessage.SUPPORTED_VERSION; this.supportedVersion = MessageCipher.SUPPORTED_VERSION;
this.messageVersion = EncryptedMessage.SUPPORTED_VERSION; this.messageVersion = MessageCipher.SUPPORTED_VERSION;
this.identityKey = identityKey; this.identityKey = identityKey;
this.publicKey = new PublicKey(bundledMessage, EncryptedMessage.NEXT_KEY_OFFSET); this.publicKey = new PublicKey(bundledMessage, MessageCipher.NEXT_KEY_OFFSET);
this.preKeyId = Conversions.byteArrayToMedium(bundledMessage, EncryptedMessage.RECEIVER_KEY_ID_OFFSET); this.preKeyId = Conversions.byteArrayToMedium(bundledMessage, MessageCipher.RECEIVER_KEY_ID_OFFSET);
this.bundledMessage = bundledMessage; this.bundledMessage = bundledMessage;
this.messageBytes = new byte[IDENTITY_KEY_LENGTH + bundledMessage.length]; this.messageBytes = new byte[IDENTITY_KEY_LENGTH + bundledMessage.length];

View File

@ -34,13 +34,12 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.RecipientFormattingException; import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.SmsTransportDetails; import org.thoughtcrime.securesms.sms.SmsTransportDetails;
import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.IdentityKeyPair; import org.whispersystems.textsecure.crypto.IdentityKeyPair;
import org.whispersystems.textsecure.crypto.InvalidKeyException; import org.whispersystems.textsecure.crypto.InvalidKeyException;
import org.whispersystems.textsecure.crypto.InvalidMessageException; import org.whispersystems.textsecure.crypto.InvalidMessageException;
import org.whispersystems.textsecure.crypto.InvalidVersionException; import org.whispersystems.textsecure.crypto.InvalidVersionException;
import org.whispersystems.textsecure.crypto.MessageCipher;
import org.whispersystems.textsecure.crypto.SessionCipher; import org.whispersystems.textsecure.crypto.SessionCipher;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import org.whispersystems.textsecure.util.Hex; import org.whispersystems.textsecure.util.Hex;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.WorkerThread; import org.thoughtcrime.securesms.util.WorkerThread;
@ -198,8 +197,8 @@ public class DecryptingQueue {
synchronized (SessionCipher.CIPHER_LOCK) { synchronized (SessionCipher.CIPHER_LOCK) {
Log.w("DecryptingQueue", "Decrypting: " + Hex.toString(ciphertextPduBytes)); Log.w("DecryptingQueue", "Decrypting: " + Hex.toString(ciphertextPduBytes));
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret); IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
EncryptedMessage message = new EncryptedMessage(context, masterSecret, identityKey, new TextTransport()); MessageCipher message = new MessageCipher(context, masterSecret, identityKey, new TextTransport());
try { try {
plaintextPduBytes = message.decrypt(recipient, ciphertextPduBytes); plaintextPduBytes = message.decrypt(recipient, ciphertextPduBytes);
@ -279,8 +278,8 @@ public class DecryptingQueue {
return; return;
} }
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret); IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
EncryptedMessage message = new EncryptedMessage(context, masterSecret, identityKey, new SmsTransportDetails()); MessageCipher message = new MessageCipher(context, masterSecret, identityKey, new SmsTransportDetails());
plaintextBody = new String(message.decrypt(recipient, body.getBytes())); plaintextBody = new String(message.decrypt(recipient, body.getBytes()));
} catch (InvalidMessageException e) { } catch (InvalidMessageException e) {

View File

@ -26,9 +26,9 @@ import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.KeyPair; import org.whispersystems.textsecure.crypto.KeyPair;
import org.whispersystems.textsecure.crypto.KeyUtil; import org.whispersystems.textsecure.crypto.KeyUtil;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.MessageCipher;
import org.whispersystems.textsecure.crypto.PublicKey; import org.whispersystems.textsecure.crypto.PublicKey;
import org.whispersystems.textsecure.crypto.protocol.PreKeyBundleMessage; import org.whispersystems.textsecure.crypto.protocol.PreKeyBundleMessage;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import org.whispersystems.textsecure.push.PreKeyEntity; import org.whispersystems.textsecure.push.PreKeyEntity;
import org.whispersystems.textsecure.storage.InvalidKeyIdException; import org.whispersystems.textsecure.storage.InvalidKeyIdException;
import org.whispersystems.textsecure.storage.LocalKeyRecord; import org.whispersystems.textsecure.storage.LocalKeyRecord;
@ -125,7 +125,7 @@ public class KeyExchangeProcessor {
sessionRecord.setSessionId(localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprintBytes(), sessionRecord.setSessionId(localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprintBytes(),
remoteKeyRecord.getCurrentRemoteKey().getFingerprintBytes()); remoteKeyRecord.getCurrentRemoteKey().getFingerprintBytes());
sessionRecord.setIdentityKey(remoteIdentity); sessionRecord.setIdentityKey(remoteIdentity);
sessionRecord.setSessionVersion(Math.min(message.getSupportedVersion(), EncryptedMessage.SUPPORTED_VERSION)); sessionRecord.setSessionVersion(Math.min(message.getSupportedVersion(), MessageCipher.SUPPORTED_VERSION));
localKeyRecord.save(); localKeyRecord.save();
@ -149,7 +149,7 @@ public class KeyExchangeProcessor {
sessionRecord.setSessionId(localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprintBytes(), sessionRecord.setSessionId(localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprintBytes(),
remoteKeyRecord.getCurrentRemoteKey().getFingerprintBytes()); remoteKeyRecord.getCurrentRemoteKey().getFingerprintBytes());
sessionRecord.setIdentityKey(message.getIdentityKey()); sessionRecord.setIdentityKey(message.getIdentityKey());
sessionRecord.setSessionVersion(EncryptedMessage.SUPPORTED_VERSION); sessionRecord.setSessionVersion(MessageCipher.SUPPORTED_VERSION);
sessionRecord.save(); sessionRecord.save();
DatabaseFactory.getIdentityDatabase(context) DatabaseFactory.getIdentityDatabase(context)
@ -162,7 +162,7 @@ public class KeyExchangeProcessor {
if (needsResponseFromUs()) { if (needsResponseFromUs()) {
localKeyRecord = KeyUtil.initializeRecordFor(recipient, context, masterSecret); localKeyRecord = KeyUtil.initializeRecordFor(recipient, context, masterSecret);
KeyExchangeMessage ourMessage = new KeyExchangeMessage(context, masterSecret, Math.min(EncryptedMessage.SUPPORTED_VERSION, message.getMaxVersion()), localKeyRecord, initiateKeyId); KeyExchangeMessage ourMessage = new KeyExchangeMessage(context, masterSecret, Math.min(MessageCipher.SUPPORTED_VERSION, message.getMaxVersion()), localKeyRecord, initiateKeyId);
OutgoingKeyExchangeMessage textMessage = new OutgoingKeyExchangeMessage(recipient, ourMessage.serialize()); OutgoingKeyExchangeMessage textMessage = new OutgoingKeyExchangeMessage(recipient, ourMessage.serialize());
Log.w("KeyExchangeProcessor", "Responding with key exchange message fingerprint: " + ourMessage.getPublicKey().getFingerprint()); Log.w("KeyExchangeProcessor", "Responding with key exchange message fingerprint: " + ourMessage.getPublicKey().getFingerprint());
Log.w("KeyExchangeProcessor", "Which has a local key record fingerprint: " + localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprint()); Log.w("KeyExchangeProcessor", "Which has a local key record fingerprint: " + localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprint());
@ -176,9 +176,9 @@ public class KeyExchangeProcessor {
sessionRecord.setSessionId(localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprintBytes(), sessionRecord.setSessionId(localKeyRecord.getCurrentKeyPair().getPublicKey().getFingerprintBytes(),
remoteKeyRecord.getCurrentRemoteKey().getFingerprintBytes()); remoteKeyRecord.getCurrentRemoteKey().getFingerprintBytes());
sessionRecord.setIdentityKey(message.getIdentityKey()); sessionRecord.setIdentityKey(message.getIdentityKey());
sessionRecord.setSessionVersion(Math.min(EncryptedMessage.SUPPORTED_VERSION, message.getMaxVersion())); sessionRecord.setSessionVersion(Math.min(MessageCipher.SUPPORTED_VERSION, message.getMaxVersion()));
Log.w("KeyExchangeUtil", "Setting session version: " + Math.min(EncryptedMessage.SUPPORTED_VERSION, message.getMaxVersion())); Log.w("KeyExchangeUtil", "Setting session version: " + Math.min(MessageCipher.SUPPORTED_VERSION, message.getMaxVersion()));
sessionRecord.save(); sessionRecord.save();

View File

@ -24,8 +24,8 @@ import org.whispersystems.textsecure.crypto.InvalidVersionException;
import org.whispersystems.textsecure.crypto.IdentityKey; import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.InvalidKeyException; import org.whispersystems.textsecure.crypto.InvalidKeyException;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.MessageCipher;
import org.whispersystems.textsecure.crypto.PublicKey; import org.whispersystems.textsecure.crypto.PublicKey;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import org.whispersystems.textsecure.storage.LocalKeyRecord; import org.whispersystems.textsecure.storage.LocalKeyRecord;
import org.whispersystems.textsecure.util.Base64; import org.whispersystems.textsecure.util.Base64;
import org.whispersystems.textsecure.util.Conversions; import org.whispersystems.textsecure.util.Conversions;
@ -67,7 +67,7 @@ public class KeyExchangeMessage {
public KeyExchangeMessage(Context context, MasterSecret masterSecret, int messageVersion, LocalKeyRecord record, int highIdBits) { public KeyExchangeMessage(Context context, MasterSecret masterSecret, int messageVersion, LocalKeyRecord record, int highIdBits) {
this.publicKey = new PublicKey(record.getCurrentKeyPair().getPublicKey()); this.publicKey = new PublicKey(record.getCurrentKeyPair().getPublicKey());
this.messageVersion = messageVersion; this.messageVersion = messageVersion;
this.supportedVersion = EncryptedMessage.SUPPORTED_VERSION; this.supportedVersion = MessageCipher.SUPPORTED_VERSION;
publicKey.setId(publicKey.getId() | (highIdBits << 12)); publicKey.setId(publicKey.getId() | (highIdBits << 12));
@ -93,9 +93,9 @@ public class KeyExchangeMessage {
this.supportedVersion = Conversions.lowBitsToInt(keyBytes[0]); this.supportedVersion = Conversions.lowBitsToInt(keyBytes[0]);
this.serialized = messageBody; this.serialized = messageBody;
if (messageVersion > EncryptedMessage.SUPPORTED_VERSION) if (messageVersion > MessageCipher.SUPPORTED_VERSION)
throw new InvalidVersionException("Key exchange with version: " + messageVersion + throw new InvalidVersionException("Key exchange with version: " + messageVersion +
" but we only support: " + EncryptedMessage.SUPPORTED_VERSION); " but we only support: " + MessageCipher.SUPPORTED_VERSION);
if (messageVersion >= 1) if (messageVersion >= 1)
keyBytes = Base64.decodeWithoutPadding(messageBody); keyBytes = Base64.decodeWithoutPadding(messageBody);

View File

@ -6,10 +6,9 @@ import android.util.Log;
import android.util.Pair; import android.util.Pair;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.IdentityKeyPair; import org.whispersystems.textsecure.crypto.IdentityKeyPair;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.SessionCipher; import org.whispersystems.textsecure.crypto.MessageCipher;
import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.MmsDatabase;
import org.thoughtcrime.securesms.mms.MmsRadio; import org.thoughtcrime.securesms.mms.MmsRadio;
import org.thoughtcrime.securesms.mms.MmsRadioException; import org.thoughtcrime.securesms.mms.MmsRadioException;
@ -17,7 +16,6 @@ import org.thoughtcrime.securesms.mms.MmsSendHelper;
import org.thoughtcrime.securesms.mms.TextTransport; import org.thoughtcrime.securesms.mms.TextTransport;
import org.thoughtcrime.securesms.protocol.WirePrefix; import org.thoughtcrime.securesms.protocol.WirePrefix;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import org.whispersystems.textsecure.util.Hex; import org.whispersystems.textsecure.util.Hex;
import java.io.IOException; import java.io.IOException;
@ -138,7 +136,7 @@ public class MmsTransport {
private byte[] getEncryptedPdu(MasterSecret masterSecret, String recipient, byte[] pduBytes) { private byte[] getEncryptedPdu(MasterSecret masterSecret, String recipient, byte[] pduBytes) {
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret); IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
EncryptedMessage message = new EncryptedMessage(context, masterSecret, identityKey, new TextTransport()); MessageCipher message = new MessageCipher(context, masterSecret, identityKey, new TextTransport());
return message.encrypt(new Recipient(null, recipient, null, null), pduBytes); return message.encrypt(new Recipient(null, recipient, null, null), pduBytes);
} }

View File

@ -14,10 +14,9 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.textsecure.crypto.IdentityKey; import org.whispersystems.textsecure.crypto.IdentityKey;
import org.whispersystems.textsecure.crypto.IdentityKeyPair; import org.whispersystems.textsecure.crypto.IdentityKeyPair;
import org.whispersystems.textsecure.crypto.InvalidKeyException;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.MessageCipher;
import org.whispersystems.textsecure.crypto.protocol.PreKeyBundleMessage; import org.whispersystems.textsecure.crypto.protocol.PreKeyBundleMessage;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import org.whispersystems.textsecure.push.PreKeyEntity; import org.whispersystems.textsecure.push.PreKeyEntity;
import org.whispersystems.textsecure.push.PushAttachmentData; import org.whispersystems.textsecure.push.PushAttachmentData;
import org.whispersystems.textsecure.push.PushServiceSocket; import org.whispersystems.textsecure.push.PushServiceSocket;
@ -120,7 +119,7 @@ public class PushTransport extends BaseTransport {
processor.processKeyExchangeMessage(preKey); processor.processKeyExchangeMessage(preKey);
EncryptedMessage message = new EncryptedMessage(context, masterSecret, identityKeyPair, new RawTransportDetails()); MessageCipher message = new MessageCipher(context, masterSecret, identityKeyPair, new RawTransportDetails());
byte[] bundledMessage = message.encrypt(recipient, plaintext.getBytes()); byte[] bundledMessage = message.encrypt(recipient, plaintext.getBytes());
PreKeyBundleMessage preKeyBundleMessage = new PreKeyBundleMessage(identityKey, bundledMessage); PreKeyBundleMessage preKeyBundleMessage = new PreKeyBundleMessage(identityKey, bundledMessage);
@ -131,7 +130,7 @@ public class PushTransport extends BaseTransport {
throws IOException throws IOException
{ {
IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret); IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
EncryptedMessage message = new EncryptedMessage(context, masterSecret, identityKeyPair, new TextTransport()); MessageCipher message = new MessageCipher(context, masterSecret, identityKeyPair, new TextTransport());
return message.encrypt(recipient, plaintext.getBytes()); return message.encrypt(recipient, plaintext.getBytes());
} }

View File

@ -8,7 +8,7 @@ import android.util.Log;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.whispersystems.textsecure.crypto.IdentityKeyPair; import org.whispersystems.textsecure.crypto.IdentityKeyPair;
import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.MasterSecret;
import org.whispersystems.textsecure.crypto.SessionCipher; import org.whispersystems.textsecure.crypto.MessageCipher;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.SendReceiveService; import org.thoughtcrime.securesms.service.SendReceiveService;
@ -17,7 +17,6 @@ import org.thoughtcrime.securesms.sms.MultipartSmsMessageHandler;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage; import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.sms.SmsTransportDetails; import org.thoughtcrime.securesms.sms.SmsTransportDetails;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.crypto.protocol.EncryptedMessage;
import java.util.ArrayList; import java.util.ArrayList;
@ -142,7 +141,7 @@ public class SmsTransport extends BaseTransport {
private String getAsymmetricEncrypt(MasterSecret masterSecret, String body, Recipient recipient) { private String getAsymmetricEncrypt(MasterSecret masterSecret, String body, Recipient recipient) {
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret); IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context, masterSecret);
EncryptedMessage message = new EncryptedMessage(context, masterSecret, identityKey, new SmsTransportDetails()); MessageCipher message = new MessageCipher(context, masterSecret, identityKey, new SmsTransportDetails());
return new String(message.encrypt(recipient, body.getBytes())); return new String(message.encrypt(recipient, body.getBytes()));
} }
} }