diff --git a/library/src/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java b/library/src/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java index e4b6a02beb..07f52f195f 100644 --- a/library/src/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java +++ b/library/src/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java @@ -5,7 +5,7 @@ import android.content.Context; import org.whispersystems.libaxolotl.InvalidMessageException; import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.textsecure.api.messages.TextSecureAttachmentPointer; -import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream; +import org.whispersystems.textsecure.api.crypto.AttachmentCipherInputStream; import org.whispersystems.textsecure.push.PushServiceSocket; import java.io.File; diff --git a/library/src/org/whispersystems/textsecure/api/TextSecureMessageSender.java b/library/src/org/whispersystems/textsecure/api/TextSecureMessageSender.java index 691683e599..e892ddbacc 100644 --- a/library/src/org/whispersystems/textsecure/api/TextSecureMessageSender.java +++ b/library/src/org/whispersystems/textsecure/api/TextSecureMessageSender.java @@ -15,8 +15,8 @@ import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream; import org.whispersystems.textsecure.api.messages.TextSecureGroup; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.crypto.TextSecureCipher; -import org.whispersystems.textsecure.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.crypto.TextSecureCipher; +import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.push.MismatchedDevices; import org.whispersystems.textsecure.push.OutgoingPushMessage; import org.whispersystems.textsecure.push.OutgoingPushMessageList; diff --git a/library/src/org/whispersystems/textsecure/crypto/AttachmentCipherInputStream.java b/library/src/org/whispersystems/textsecure/api/crypto/AttachmentCipherInputStream.java similarity index 99% rename from library/src/org/whispersystems/textsecure/crypto/AttachmentCipherInputStream.java rename to library/src/org/whispersystems/textsecure/api/crypto/AttachmentCipherInputStream.java index 2d72a17bdd..7235e8f6e1 100644 --- a/library/src/org/whispersystems/textsecure/crypto/AttachmentCipherInputStream.java +++ b/library/src/org/whispersystems/textsecure/api/crypto/AttachmentCipherInputStream.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.whispersystems.textsecure.crypto; +package org.whispersystems.textsecure.api.crypto; import android.util.Log; diff --git a/library/src/org/whispersystems/textsecure/crypto/AttachmentCipherOutputStream.java b/library/src/org/whispersystems/textsecure/api/crypto/AttachmentCipherOutputStream.java similarity index 98% rename from library/src/org/whispersystems/textsecure/crypto/AttachmentCipherOutputStream.java rename to library/src/org/whispersystems/textsecure/api/crypto/AttachmentCipherOutputStream.java index 08be47fbed..dbeed63f73 100644 --- a/library/src/org/whispersystems/textsecure/crypto/AttachmentCipherOutputStream.java +++ b/library/src/org/whispersystems/textsecure/api/crypto/AttachmentCipherOutputStream.java @@ -1,4 +1,4 @@ -package org.whispersystems.textsecure.crypto; +package org.whispersystems.textsecure.api.crypto; import org.whispersystems.textsecure.util.Util; diff --git a/library/src/org/whispersystems/textsecure/crypto/TextSecureCipher.java b/library/src/org/whispersystems/textsecure/api/crypto/TextSecureCipher.java similarity index 97% rename from library/src/org/whispersystems/textsecure/crypto/TextSecureCipher.java rename to library/src/org/whispersystems/textsecure/api/crypto/TextSecureCipher.java index dcf238f1e3..dfb2213efc 100644 --- a/library/src/org/whispersystems/textsecure/crypto/TextSecureCipher.java +++ b/library/src/org/whispersystems/textsecure/api/crypto/TextSecureCipher.java @@ -1,4 +1,4 @@ -package org.whispersystems.textsecure.crypto; +package org.whispersystems.textsecure.api.crypto; import com.google.protobuf.InvalidProtocolBufferException; @@ -30,8 +30,8 @@ import static org.whispersystems.textsecure.push.PushMessageProtos.PushMessageCo public class TextSecureCipher { - private final SessionCipher sessionCipher; - private final TransportDetails transportDetails; + private final SessionCipher sessionCipher; + private final PushTransportDetails transportDetails; public TextSecureCipher(AxolotlStore axolotlStore, long recipientId, int deviceId) { int sessionVersion = axolotlStore.loadSession(recipientId, deviceId) diff --git a/library/src/org/whispersystems/textsecure/crypto/UntrustedIdentityException.java b/library/src/org/whispersystems/textsecure/api/crypto/UntrustedIdentityException.java similarity index 92% rename from library/src/org/whispersystems/textsecure/crypto/UntrustedIdentityException.java rename to library/src/org/whispersystems/textsecure/api/crypto/UntrustedIdentityException.java index 51b86d325c..c9214ac742 100644 --- a/library/src/org/whispersystems/textsecure/crypto/UntrustedIdentityException.java +++ b/library/src/org/whispersystems/textsecure/api/crypto/UntrustedIdentityException.java @@ -1,4 +1,4 @@ -package org.whispersystems.textsecure.crypto; +package org.whispersystems.textsecure.api.crypto; import org.whispersystems.libaxolotl.IdentityKey; diff --git a/library/src/org/whispersystems/textsecure/crypto/TransportDetails.java b/library/src/org/whispersystems/textsecure/crypto/TransportDetails.java deleted file mode 100644 index 9ecd0ced62..0000000000 --- a/library/src/org/whispersystems/textsecure/crypto/TransportDetails.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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 - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * 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 . - */ -package org.whispersystems.textsecure.crypto; - -import java.io.IOException; - - -public interface TransportDetails { - public byte[] getStrippedPaddingMessageBody(byte[] messageWithPadding); - public byte[] getPaddedMessageBody(byte[] messageBody); - - public byte[] getEncodedMessage(byte[] messageWithMac); - public byte[] getDecodedMessage(byte[] encodedMessageBytes) throws IOException; -} diff --git a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java index e7cb9899d1..bd0615396b 100644 --- a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java +++ b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java @@ -28,7 +28,7 @@ import org.whispersystems.libaxolotl.ecc.ECPublicKey; import org.whispersystems.libaxolotl.state.PreKeyBundle; import org.whispersystems.libaxolotl.state.PreKeyRecord; import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; -import org.whispersystems.textsecure.crypto.AttachmentCipherOutputStream; +import org.whispersystems.textsecure.api.crypto.AttachmentCipherOutputStream; import org.whispersystems.textsecure.push.exceptions.AuthorizationFailedException; import org.whispersystems.textsecure.push.exceptions.ExpectationFailedException; import org.whispersystems.textsecure.push.exceptions.MismatchedDevicesException; diff --git a/library/src/org/whispersystems/textsecure/push/PushTransportDetails.java b/library/src/org/whispersystems/textsecure/push/PushTransportDetails.java index 55f03bd729..d9f7f3cfb4 100644 --- a/library/src/org/whispersystems/textsecure/push/PushTransportDetails.java +++ b/library/src/org/whispersystems/textsecure/push/PushTransportDetails.java @@ -18,11 +18,7 @@ package org.whispersystems.textsecure.push; import android.util.Log; -import org.whispersystems.textsecure.crypto.TransportDetails; - -import java.io.IOException; - -public class PushTransportDetails implements TransportDetails { +public class PushTransportDetails { private final int messageVersion; @@ -30,7 +26,6 @@ public class PushTransportDetails implements TransportDetails { this.messageVersion = messageVersion; } - @Override public byte[] getStrippedPaddingMessageBody(byte[] messageWithPadding) { if (messageVersion < 2) throw new AssertionError("Unknown version: " + messageVersion); else if (messageVersion == 2) return messageWithPadding; @@ -53,7 +48,6 @@ public class PushTransportDetails implements TransportDetails { return strippedMessage; } - @Override public byte[] getPaddedMessageBody(byte[] messageBody) { if (messageVersion < 2) throw new AssertionError("Unknown version: " + messageVersion); else if (messageVersion == 2) return messageBody; @@ -68,16 +62,6 @@ public class PushTransportDetails implements TransportDetails { return paddedMessage; } - @Override - public byte[] getEncodedMessage(byte[] messageWithMac) { - return messageWithMac; - } - - @Override - public byte[] getDecodedMessage(byte[] encodedMessageBytes) throws IOException { - return encodedMessageBytes; - } - private int getPaddedMessageLength(int messageLength) { int messageLengthWithTerminator = messageLength + 1; int messagePartCount = messageLengthWithTerminator / 160; diff --git a/library/src/org/whispersystems/textsecure/push/exceptions/EncapsulatedExceptions.java b/library/src/org/whispersystems/textsecure/push/exceptions/EncapsulatedExceptions.java index 80732db1fb..9913dc6014 100644 --- a/library/src/org/whispersystems/textsecure/push/exceptions/EncapsulatedExceptions.java +++ b/library/src/org/whispersystems/textsecure/push/exceptions/EncapsulatedExceptions.java @@ -1,6 +1,6 @@ package org.whispersystems.textsecure.push.exceptions; -import org.whispersystems.textsecure.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.push.UnregisteredUserException; import java.util.List; diff --git a/src/org/thoughtcrime/securesms/crypto/MmsCipher.java b/src/org/thoughtcrime/securesms/crypto/MmsCipher.java index e90e2351e7..aaf887871e 100644 --- a/src/org/thoughtcrime/securesms/crypto/MmsCipher.java +++ b/src/org/thoughtcrime/securesms/crypto/MmsCipher.java @@ -3,14 +3,11 @@ package org.thoughtcrime.securesms.crypto; import android.content.Context; import android.util.Log; -import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore; import org.thoughtcrime.securesms.mms.TextTransport; import org.thoughtcrime.securesms.protocol.WirePrefix; -import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.recipients.RecipientFormattingException; import org.thoughtcrime.securesms.recipients.Recipients; -import org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException; import org.whispersystems.libaxolotl.DuplicateMessageException; import org.whispersystems.libaxolotl.InvalidMessageException; import org.whispersystems.libaxolotl.LegacyMessageException; @@ -20,7 +17,6 @@ import org.whispersystems.libaxolotl.protocol.CiphertextMessage; import org.whispersystems.libaxolotl.protocol.WhisperMessage; import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.libaxolotl.util.guava.Optional; -import org.whispersystems.textsecure.crypto.TextSecureCipher; import org.whispersystems.textsecure.storage.RecipientDevice; import org.whispersystems.textsecure.util.Util; @@ -101,7 +97,7 @@ public class MmsCipher { } SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, RecipientDevice.DEFAULT_DEVICE_ID); - CiphertextMessage ciphertextMessage = cipher.encrypt(textTransport.getPaddedMessageBody(pduBytes)); + CiphertextMessage ciphertextMessage = cipher.encrypt(pduBytes); byte[] encryptedPduBytes = textTransport.getEncodedMessage(ciphertextMessage.serialize()); PduBody body = new PduBody(); diff --git a/src/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java b/src/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java index b67c283bfe..a243d71322 100644 --- a/src/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java +++ b/src/org/thoughtcrime/securesms/jobs/AvatarDownloadJob.java @@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.util.GroupUtil; import org.whispersystems.jobqueue.JobParameters; import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.libaxolotl.InvalidMessageException; -import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream; +import org.whispersystems.textsecure.api.crypto.AttachmentCipherInputStream; import org.whispersystems.textsecure.push.PushServiceSocket; import org.whispersystems.textsecure.push.exceptions.NonSuccessfulResponseCodeException; diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index e648c60131..40b03f4207 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -42,7 +42,7 @@ import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.textsecure.api.messages.TextSecureEnvelope; import org.whispersystems.textsecure.api.messages.TextSecureGroup; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.crypto.TextSecureCipher; +import org.whispersystems.textsecure.api.crypto.TextSecureCipher; import org.whispersystems.textsecure.util.Base64; import ws.com.google.android.mms.MmsException; diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 35633e2e7e..8230c3c880 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -22,7 +22,7 @@ import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureGroup; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.push.PushAddress; import org.whispersystems.textsecure.push.PushMessageProtos; import org.whispersystems.textsecure.push.exceptions.EncapsulatedExceptions; diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index a2b08a682f..9c2d1dc53c 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -23,7 +23,7 @@ import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.push.PushAddress; import org.whispersystems.textsecure.push.UnregisteredUserException; import org.whispersystems.textsecure.storage.RecipientDevice; diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index e6fdc754ac..787406b89c 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.EncryptingSmsDatabase; import org.thoughtcrime.securesms.database.NoSuchMessageException; -import org.thoughtcrime.securesms.database.SmsDatabase; import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.notifications.MessageNotifier; import org.thoughtcrime.securesms.push.TextSecureMessageSenderFactory; @@ -22,7 +21,7 @@ import org.thoughtcrime.securesms.transport.SecureFallbackApprovalException; import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.crypto.UntrustedIdentityException; +import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.push.PushAddress; import org.whispersystems.textsecure.push.UnregisteredUserException; import org.whispersystems.textsecure.storage.RecipientDevice; diff --git a/src/org/thoughtcrime/securesms/mms/TextTransport.java b/src/org/thoughtcrime/securesms/mms/TextTransport.java index f1141ca371..79b67fea2e 100644 --- a/src/org/thoughtcrime/securesms/mms/TextTransport.java +++ b/src/org/thoughtcrime/securesms/mms/TextTransport.java @@ -1,5 +1,6 @@ /** * Copyright (C) 2011 Whisper Systems + * Copyright (C) 2014 Open 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 @@ -18,29 +19,15 @@ package org.thoughtcrime.securesms.mms; import java.io.IOException; -import org.whispersystems.textsecure.crypto.TransportDetails; import org.whispersystems.textsecure.util.Base64; -public class TextTransport implements TransportDetails { +public class TextTransport { - @Override public byte[] getDecodedMessage(byte[] encodedMessageBytes) throws IOException { return Base64.decode(encodedMessageBytes); } - @Override public byte[] getEncodedMessage(byte[] messageWithMac) { return Base64.encodeBytes(messageWithMac).getBytes(); } - - @Override - public byte[] getPaddedMessageBody(byte[] messageBody) { - return messageBody; - } - - @Override - public byte[] getStrippedPaddingMessageBody(byte[] messageWithPadding) { - return messageWithPadding; - } - } diff --git a/src/org/thoughtcrime/securesms/sms/SmsTransportDetails.java b/src/org/thoughtcrime/securesms/sms/SmsTransportDetails.java index d40235b075..b481a62281 100644 --- a/src/org/thoughtcrime/securesms/sms/SmsTransportDetails.java +++ b/src/org/thoughtcrime/securesms/sms/SmsTransportDetails.java @@ -1,5 +1,6 @@ /** * Copyright (C) 2011 Whisper Systems + * Copyright (C) 2014 Open 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 @@ -20,12 +21,11 @@ import android.util.Log; import org.thoughtcrime.securesms.protocol.WirePrefix; import org.whispersystems.libaxolotl.protocol.CiphertextMessage; -import org.whispersystems.textsecure.crypto.TransportDetails; import org.whispersystems.textsecure.util.Base64; import java.io.IOException; -public class SmsTransportDetails implements TransportDetails { +public class SmsTransportDetails { public static final int SMS_SIZE = 160; public static final int MULTIPART_SMS_SIZE = 153; @@ -37,20 +37,17 @@ public class SmsTransportDetails implements TransportDetails { public static final int ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE = SINGLE_MESSAGE_MAX_BYTES - CiphertextMessage.ENCRYPTED_MESSAGE_OVERHEAD; - @Override public byte[] getEncodedMessage(byte[] messageWithMac) { String encodedMessage = Base64.encodeBytesWithoutPadding(messageWithMac); Log.w("SmsTransportDetails", "Encoded Message Length: " + encodedMessage.length()); return encodedMessage.getBytes(); } - @Override public byte[] getDecodedMessage(byte[] encodedMessageBytes) throws IOException { String encodedMessage = new String(encodedMessageBytes); return Base64.decodeWithoutPadding(encodedMessage); } - @Override public byte[] getStrippedPaddingMessageBody(byte[] messageWithPadding) { int paddingBeginsIndex = 0; @@ -70,7 +67,6 @@ public class SmsTransportDetails implements TransportDetails { return message; } - @Override public byte[] getPaddedMessageBody(byte[] messageBody) { int paddedBodySize = getMaxBodySizeForBytes(messageBody.length); Log.w("SmsTransportDetails", "Padding message body out to: " + paddedBodySize);