From a59feb7ad438575bd5a4bfbd6b9aec790f982320 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 27 Feb 2015 16:57:32 -0800 Subject: [PATCH] Rename PushAddress to TextSecureAddress // FREEBIE --- .../jobs/DeliveryReceiptJobTest.java | 10 +++--- .../api/TextSecureMessageSender.java | 32 +++++++++---------- .../api/messages/TextSecureMessage.java | 7 +++- ...ushAddress.java => TextSecureAddress.java} | 8 ++--- .../internal/push/OutgoingPushMessage.java | 4 +-- .../internal/push/PushServiceSocket.java | 6 ++-- .../securesms/AutoInitiateActivity.java | 4 +-- .../securesms/ConversationActivity.java | 5 ++- .../securesms/VerifyIdentityActivity.java | 4 +-- .../crypto/KeyExchangeInitiator.java | 6 ++-- .../securesms/crypto/MmsCipher.java | 6 ++-- .../securesms/crypto/SmsCipher.java | 6 ++-- .../storage/TextSecureSessionStore.java | 6 ++-- .../securesms/jobs/DeliveryReceiptJob.java | 8 ++--- .../securesms/jobs/PushGroupSendJob.java | 13 ++++---- .../securesms/jobs/PushMediaSendJob.java | 7 ++-- .../securesms/jobs/PushSendJob.java | 6 ++-- .../securesms/jobs/PushTextSendJob.java | 6 ++-- .../securesms/sms/IncomingTextMessage.java | 6 ++-- 19 files changed, 75 insertions(+), 75 deletions(-) rename libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/{PushAddress.java => TextSecureAddress.java} (89%) diff --git a/androidTest/java/org/thoughtcrime/securesms/jobs/DeliveryReceiptJobTest.java b/androidTest/java/org/thoughtcrime/securesms/jobs/DeliveryReceiptJobTest.java index 8ea87763ab..f71d54f1e7 100644 --- a/androidTest/java/org/thoughtcrime/securesms/jobs/DeliveryReceiptJobTest.java +++ b/androidTest/java/org/thoughtcrime/securesms/jobs/DeliveryReceiptJobTest.java @@ -1,13 +1,11 @@ package org.thoughtcrime.securesms.jobs; -import android.test.AndroidTestCase; - import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.thoughtcrime.securesms.TextSecureTestCase; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.whispersystems.textsecure.api.TextSecureMessageSender; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.exceptions.NotFoundException; import org.whispersystems.textsecure.api.push.exceptions.PushNetworkException; @@ -38,7 +36,7 @@ public class DeliveryReceiptJobTest extends TextSecureTestCase { deliveryReceiptJob.onRun(); - ArgumentCaptor captor = ArgumentCaptor.forClass(PushAddress.class); + ArgumentCaptor captor = ArgumentCaptor.forClass(TextSecureAddress.class); verify(textSecureMessageSender).sendDeliveryReceipt(captor.capture(), eq(timestamp)); assertTrue(captor.getValue().getRelay().equals("foo")); @@ -51,7 +49,7 @@ public class DeliveryReceiptJobTest extends TextSecureTestCase { Mockito.doThrow(new PushNetworkException("network error")) .when(textSecureMessageSender) - .sendDeliveryReceipt(any(PushAddress.class), eq(timestamp)); + .sendDeliveryReceipt(any(TextSecureAddress.class), eq(timestamp)); DeliveryReceiptJob deliveryReceiptJob = new DeliveryReceiptJob(getContext(), @@ -70,7 +68,7 @@ public class DeliveryReceiptJobTest extends TextSecureTestCase { Mockito.doThrow(new NotFoundException("not found")) .when(textSecureMessageSender) - .sendDeliveryReceipt(any(PushAddress.class), eq(timestamp)); + .sendDeliveryReceipt(any(TextSecureAddress.class), eq(timestamp)); try { deliveryReceiptJob.onRun(); diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageSender.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageSender.java index 1116d584c4..3ae6095bc7 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageSender.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageSender.java @@ -33,7 +33,7 @@ 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.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.api.push.exceptions.NetworkFailureException; import org.whispersystems.textsecure.api.push.exceptions.PushNetworkException; @@ -72,7 +72,7 @@ public class TextSecureMessageSender { private final PushServiceSocket socket; private final AxolotlStore store; - private final PushAddress syncAddress; + private final TextSecureAddress syncAddress; private final Optional eventListener; /** @@ -94,7 +94,7 @@ public class TextSecureMessageSender { { this.socket = new PushServiceSocket(url, trustStore, new StaticCredentialsProvider(user, password, null)); this.store = store; - this.syncAddress = new PushAddress(userId, user, null); + this.syncAddress = new TextSecureAddress(userId, user, null); this.eventListener = eventListener; } @@ -105,7 +105,7 @@ public class TextSecureMessageSender { * @param messageId The message id of the received message you're acknowledging. * @throws IOException */ - public void sendDeliveryReceipt(PushAddress recipient, long messageId) throws IOException { + public void sendDeliveryReceipt(TextSecureAddress recipient, long messageId) throws IOException { this.socket.sendReceipt(recipient.getNumber(), messageId, recipient.getRelay()); } @@ -117,7 +117,7 @@ public class TextSecureMessageSender { * @throws UntrustedIdentityException * @throws IOException */ - public void sendMessage(PushAddress recipient, TextSecureMessage message) + public void sendMessage(TextSecureAddress recipient, TextSecureMessage message) throws UntrustedIdentityException, IOException { byte[] content = createMessageContent(message); @@ -146,7 +146,7 @@ public class TextSecureMessageSender { * @throws IOException * @throws EncapsulatedExceptions */ - public void sendMessage(List recipients, TextSecureMessage message) + public void sendMessage(List recipients, TextSecureMessage message) throws IOException, EncapsulatedExceptions { byte[] content = createMessageContent(message); @@ -176,7 +176,7 @@ public class TextSecureMessageSender { return builder.build().toByteArray(); } - private byte[] createSyncMessageContent(byte[] content, PushAddress recipient, long timestamp) { + private byte[] createSyncMessageContent(byte[] content, TextSecureAddress recipient, long timestamp) { try { PushMessageContent.Builder builder = PushMessageContent.parseFrom(content).toBuilder(); builder.setSync(PushMessageContent.SyncMessageContext.newBuilder() @@ -213,14 +213,14 @@ public class TextSecureMessageSender { return builder.build(); } - private void sendMessage(List recipients, long timestamp, byte[] content) + private void sendMessage(List recipients, long timestamp, byte[] content) throws IOException, EncapsulatedExceptions { List untrustedIdentities = new LinkedList<>(); List unregisteredUsers = new LinkedList<>(); List networkExceptions = new LinkedList<>(); - for (PushAddress recipient : recipients) { + for (TextSecureAddress recipient : recipients) { try { sendMessage(recipient, timestamp, content); } catch (UntrustedIdentityException e) { @@ -240,7 +240,7 @@ public class TextSecureMessageSender { } } - private SendMessageResponse sendMessage(PushAddress recipient, long timestamp, byte[] content) + private SendMessageResponse sendMessage(TextSecureAddress recipient, long timestamp, byte[] content) throws UntrustedIdentityException, IOException { for (int i=0;i<3;i++) { @@ -297,7 +297,7 @@ public class TextSecureMessageSender { private OutgoingPushMessageList getEncryptedMessages(PushServiceSocket socket, - PushAddress recipient, + TextSecureAddress recipient, long timestamp, byte[] plaintext) throws IOException, UntrustedIdentityException @@ -305,8 +305,8 @@ public class TextSecureMessageSender { List messages = new LinkedList<>(); if (!recipient.equals(syncAddress)) { - PushBody masterBody = getEncryptedMessage(socket, recipient, PushAddress.DEFAULT_DEVICE_ID, plaintext); - messages.add(new OutgoingPushMessage(recipient, PushAddress.DEFAULT_DEVICE_ID, masterBody)); + PushBody masterBody = getEncryptedMessage(socket, recipient, TextSecureAddress.DEFAULT_DEVICE_ID, plaintext); + messages.add(new OutgoingPushMessage(recipient, TextSecureAddress.DEFAULT_DEVICE_ID, masterBody)); } for (int deviceId : store.getSubDeviceSessions(recipient.getRecipientId())) { @@ -317,7 +317,7 @@ public class TextSecureMessageSender { return new OutgoingPushMessageList(recipient.getNumber(), timestamp, recipient.getRelay(), messages); } - private PushBody getEncryptedMessage(PushServiceSocket socket, PushAddress recipient, int deviceId, byte[] plaintext) + private PushBody getEncryptedMessage(PushServiceSocket socket, TextSecureAddress recipient, int deviceId, byte[] plaintext) throws IOException, UntrustedIdentityException { if (!store.containsSession(recipient.getRecipientId(), deviceId)) { @@ -354,7 +354,7 @@ public class TextSecureMessageSender { } } - private void handleMismatchedDevices(PushServiceSocket socket, PushAddress recipient, + private void handleMismatchedDevices(PushServiceSocket socket, TextSecureAddress recipient, MismatchedDevices mismatchedDevices) throws IOException, UntrustedIdentityException { @@ -378,7 +378,7 @@ public class TextSecureMessageSender { } } - private void handleStaleDevices(PushAddress recipient, StaleDevices staleDevices) { + private void handleStaleDevices(TextSecureAddress recipient, StaleDevices staleDevices) { long recipientId = recipient.getRecipientId(); for (int staleDeviceId : staleDevices.getStaleDevices()) { diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/messages/TextSecureMessage.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/messages/TextSecureMessage.java index a70d073cfa..ef31e1e391 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/messages/TextSecureMessage.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/messages/TextSecureMessage.java @@ -18,6 +18,7 @@ package org.whispersystems.textsecure.api.messages; import org.whispersystems.libaxolotl.util.guava.Optional; +import java.util.LinkedList; import java.util.List; /** @@ -39,7 +40,11 @@ public class TextSecureMessage { * @param body The message contents. */ public TextSecureMessage(long timestamp, String body) { - this(timestamp, null, body); + this(timestamp, (List)null, body); + } + + public TextSecureMessage(final long timestamp, final TextSecureAttachment attachment, final String body) { + this(timestamp, new LinkedList() {{add(attachment);}}, body); } /** diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/PushAddress.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TextSecureAddress.java similarity index 89% rename from libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/PushAddress.java rename to libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TextSecureAddress.java index 7072fc8c65..ed44fdde73 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/PushAddress.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TextSecureAddress.java @@ -19,7 +19,7 @@ package org.whispersystems.textsecure.api.push; /** * A class representing a message destination or origin. */ -public class PushAddress { +public class TextSecureAddress { public static final int DEFAULT_DEVICE_ID = 1; @@ -34,7 +34,7 @@ public class PushAddress { * @param e164number The TextSecure username of this destination (eg e164 representation of a phone number). * @param relay The TextSecure federated server this user is registered with (if not your own server). */ - public PushAddress(long recipientId, String e164number, String relay) { + public TextSecureAddress(long recipientId, String e164number, String relay) { this.recipientId = recipientId; this.e164number = e164number; this.relay = relay; @@ -54,9 +54,9 @@ public class PushAddress { @Override public boolean equals(Object other) { - if (other == null || !(other instanceof PushAddress)) return false; + if (other == null || !(other instanceof TextSecureAddress)) return false; - PushAddress that = (PushAddress)other; + TextSecureAddress that = (TextSecureAddress)other; return this.recipientId == that.recipientId && equals(this.e164number, that.e164number) && diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/OutgoingPushMessage.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/OutgoingPushMessage.java index 845399a6df..66cd6c0217 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/OutgoingPushMessage.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/OutgoingPushMessage.java @@ -19,7 +19,7 @@ package org.whispersystems.textsecure.internal.push; import com.fasterxml.jackson.annotation.JsonProperty; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.internal.util.Base64; public class OutgoingPushMessage { @@ -33,7 +33,7 @@ public class OutgoingPushMessage { @JsonProperty private String body; - public OutgoingPushMessage(PushAddress address, int deviceId, PushBody body) { + public OutgoingPushMessage(TextSecureAddress address, int deviceId, PushBody body) { this.type = body.getType(); this.destinationDeviceId = deviceId; this.destinationRegistrationId = body.getRemoteRegistrationId(); diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/PushServiceSocket.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/PushServiceSocket.java index 942f788f10..a995906bb6 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/PushServiceSocket.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/internal/push/PushServiceSocket.java @@ -28,7 +28,7 @@ import org.whispersystems.libaxolotl.state.PreKeyRecord; import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; import org.whispersystems.textsecure.api.crypto.AttachmentCipherOutputStream; import org.whispersystems.textsecure.api.push.ContactTokenDetails; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.SignedPreKeyEntity; import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.api.push.exceptions.AuthorizationFailedException; @@ -194,7 +194,7 @@ public class PushServiceSocket { return preKeyStatus.getCount(); } - public List getPreKeys(PushAddress destination, int deviceIdInteger) throws IOException { + public List getPreKeys(TextSecureAddress destination, int deviceIdInteger) throws IOException { try { String deviceId = String.valueOf(deviceIdInteger); @@ -242,7 +242,7 @@ public class PushServiceSocket { } } - public PreKeyBundle getPreKey(PushAddress destination, int deviceId) throws IOException { + public PreKeyBundle getPreKey(TextSecureAddress destination, int deviceId) throws IOException { try { String path = String.format(PREKEY_DEVICE_PATH, destination.getNumber(), String.valueOf(deviceId)); diff --git a/src/org/thoughtcrime/securesms/AutoInitiateActivity.java b/src/org/thoughtcrime/securesms/AutoInitiateActivity.java index eb863cc170..1cd2029c3a 100644 --- a/src/org/thoughtcrime/securesms/AutoInitiateActivity.java +++ b/src/org/thoughtcrime/securesms/AutoInitiateActivity.java @@ -33,7 +33,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory; import org.thoughtcrime.securesms.util.MemoryCleaner; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.libaxolotl.state.SessionStore; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; /** * Activity which prompts the user to initiate a secure @@ -118,6 +118,6 @@ public class AutoInitiateActivity extends BaseActivity { Recipient recipient) { SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret); - return sessionStore.containsSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID); + return sessionStore.containsSession(recipient.getRecipientId(), TextSecureAddress.DEFAULT_DEVICE_ID); } } diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index a97183cc4a..57c657230e 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -68,7 +68,6 @@ import org.thoughtcrime.securesms.database.DraftDatabase.Draft; import org.thoughtcrime.securesms.database.DraftDatabase.Drafts; import org.thoughtcrime.securesms.database.GroupDatabase; import org.thoughtcrime.securesms.database.MmsSmsColumns.Types; -import org.thoughtcrime.securesms.database.TextSecureDirectory; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.mms.AttachmentManager; import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter; @@ -104,7 +103,7 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.libaxolotl.InvalidMessageException; import org.whispersystems.libaxolotl.state.SessionStore; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import java.io.IOException; import java.security.NoSuchAlgorithmException; @@ -689,7 +688,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity boolean isSecureSmsDestination = isSecureSmsAllowed && isSingleConversation() && sessionStore.containsSession(primaryRecipient.getRecipientId(), - PushAddress.DEFAULT_DEVICE_ID); + TextSecureAddress.DEFAULT_DEVICE_ID); if (isPushDestination || isSecureSmsDestination) { this.isEncryptedConversation = true; diff --git a/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java b/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java index cec8803011..10e11f5617 100644 --- a/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java +++ b/src/org/thoughtcrime/securesms/VerifyIdentityActivity.java @@ -33,7 +33,7 @@ import org.thoughtcrime.securesms.util.MemoryCleaner; import org.whispersystems.libaxolotl.IdentityKey; import org.whispersystems.libaxolotl.state.SessionRecord; import org.whispersystems.libaxolotl.state.SessionStore; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; /** * Activity for verifying identity keys. @@ -185,7 +185,7 @@ public class VerifyIdentityActivity extends KeyScanningActivity { private IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) { SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret); SessionRecord record = sessionStore.loadSession(recipient.getRecipientId(), - PushAddress.DEFAULT_DEVICE_ID); + TextSecureAddress.DEFAULT_DEVICE_ID); if (record == null) { return null; diff --git a/src/org/thoughtcrime/securesms/crypto/KeyExchangeInitiator.java b/src/org/thoughtcrime/securesms/crypto/KeyExchangeInitiator.java index ccb50c816a..544632012c 100644 --- a/src/org/thoughtcrime/securesms/crypto/KeyExchangeInitiator.java +++ b/src/org/thoughtcrime/securesms/crypto/KeyExchangeInitiator.java @@ -37,7 +37,7 @@ import org.whispersystems.libaxolotl.state.PreKeyStore; import org.whispersystems.libaxolotl.state.SessionRecord; import org.whispersystems.libaxolotl.state.SessionStore; import org.whispersystems.libaxolotl.state.SignedPreKeyStore; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; public class KeyExchangeInitiator { @@ -68,7 +68,7 @@ public class KeyExchangeInitiator { SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore, identityKeyStore, recipient.getRecipientId(), - PushAddress.DEFAULT_DEVICE_ID); + TextSecureAddress.DEFAULT_DEVICE_ID); KeyExchangeMessage keyExchangeMessage = sessionBuilder.process(); String serializedMessage = Base64.encodeBytesWithoutPadding(keyExchangeMessage.serialize()); @@ -81,7 +81,7 @@ public class KeyExchangeInitiator { Recipient recipient) { SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret); - SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID); + SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), TextSecureAddress.DEFAULT_DEVICE_ID); return sessionRecord.getSessionState().hasPendingKeyExchange(); } diff --git a/src/org/thoughtcrime/securesms/crypto/MmsCipher.java b/src/org/thoughtcrime/securesms/crypto/MmsCipher.java index 3dcce58638..3d12f3bbf3 100644 --- a/src/org/thoughtcrime/securesms/crypto/MmsCipher.java +++ b/src/org/thoughtcrime/securesms/crypto/MmsCipher.java @@ -19,7 +19,7 @@ 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.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import java.io.IOException; @@ -101,11 +101,11 @@ public class MmsCipher { throw new UndeliverableMessageException("PDU composition failed, null payload"); } - if (!axolotlStore.containsSession(recipientId, PushAddress.DEFAULT_DEVICE_ID)) { + if (!axolotlStore.containsSession(recipientId, TextSecureAddress.DEFAULT_DEVICE_ID)) { throw new NoSessionException("No session for: " + recipientId); } - SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, PushAddress.DEFAULT_DEVICE_ID); + SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, TextSecureAddress.DEFAULT_DEVICE_ID); CiphertextMessage ciphertextMessage = cipher.encrypt(pduBytes); byte[] encryptedPduBytes = textTransport.getEncodedMessage(ciphertextMessage.serialize()); diff --git a/src/org/thoughtcrime/securesms/crypto/SmsCipher.java b/src/org/thoughtcrime/securesms/crypto/SmsCipher.java index 59c93b162f..80f4334daf 100644 --- a/src/org/thoughtcrime/securesms/crypto/SmsCipher.java +++ b/src/org/thoughtcrime/securesms/crypto/SmsCipher.java @@ -30,7 +30,7 @@ import org.whispersystems.libaxolotl.protocol.KeyExchangeMessage; import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage; import org.whispersystems.libaxolotl.protocol.WhisperMessage; import org.whispersystems.libaxolotl.state.AxolotlStore; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import java.io.IOException; @@ -89,11 +89,11 @@ public class SmsCipher { byte[] paddedBody = transportDetails.getPaddedMessageBody(message.getMessageBody().getBytes()); long recipientId = message.getRecipients().getPrimaryRecipient().getRecipientId(); - if (!axolotlStore.containsSession(recipientId, PushAddress.DEFAULT_DEVICE_ID)) { + if (!axolotlStore.containsSession(recipientId, TextSecureAddress.DEFAULT_DEVICE_ID)) { throw new NoSessionException("No session for: " + recipientId); } - SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, PushAddress.DEFAULT_DEVICE_ID); + SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, TextSecureAddress.DEFAULT_DEVICE_ID); CiphertextMessage ciphertextMessage = cipher.encrypt(paddedBody); String encodedCiphertext = new String(transportDetails.getEncodedMessage(ciphertextMessage.serialize())); diff --git a/src/org/thoughtcrime/securesms/crypto/storage/TextSecureSessionStore.java b/src/org/thoughtcrime/securesms/crypto/storage/TextSecureSessionStore.java index c26a24845c..02227220af 100644 --- a/src/org/thoughtcrime/securesms/crypto/storage/TextSecureSessionStore.java +++ b/src/org/thoughtcrime/securesms/crypto/storage/TextSecureSessionStore.java @@ -9,7 +9,7 @@ import org.whispersystems.libaxolotl.InvalidMessageException; import org.whispersystems.libaxolotl.state.SessionRecord; import org.whispersystems.libaxolotl.state.SessionState; import org.whispersystems.libaxolotl.state.SessionStore; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.thoughtcrime.securesms.util.Conversions; import java.io.File; @@ -108,7 +108,7 @@ public class TextSecureSessionStore implements SessionStore { public void deleteAllSessions(long recipientId) { List devices = getSubDeviceSessions(recipientId); - deleteSession(recipientId, PushAddress.DEFAULT_DEVICE_ID); + deleteSession(recipientId, TextSecureAddress.DEFAULT_DEVICE_ID); for (int device : devices) { deleteSession(recipientId, device); @@ -156,7 +156,7 @@ public class TextSecureSessionStore implements SessionStore { } private String getSessionName(long recipientId, int deviceId) { - return recipientId + (deviceId == PushAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId); + return recipientId + (deviceId == TextSecureAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId); } private byte[] readBlob(FileInputStream in) throws IOException { diff --git a/src/org/thoughtcrime/securesms/jobs/DeliveryReceiptJob.java b/src/org/thoughtcrime/securesms/jobs/DeliveryReceiptJob.java index eac8f15ff1..d0d09e9584 100644 --- a/src/org/thoughtcrime/securesms/jobs/DeliveryReceiptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/DeliveryReceiptJob.java @@ -7,7 +7,7 @@ import org.thoughtcrime.securesms.dependencies.InjectableType; import org.whispersystems.jobqueue.JobParameters; import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.textsecure.api.TextSecureMessageSender; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.exceptions.NonSuccessfulResponseCodeException; import org.whispersystems.textsecure.api.push.exceptions.PushNetworkException; @@ -45,10 +45,10 @@ public class DeliveryReceiptJob extends ContextJob implements InjectableType { @Override public void onRun() throws IOException { Log.w("DeliveryReceiptJob", "Sending delivery receipt..."); - TextSecureMessageSender messageSender = messageSenderFactory.create(null); - PushAddress pushAddress = new PushAddress(-1, destination, relay); + TextSecureMessageSender messageSender = messageSenderFactory.create(null); + TextSecureAddress textSecureAddress = new TextSecureAddress(-1, destination, relay); - messageSender.sendDeliveryReceipt(pushAddress, timestamp); + messageSender.sendDeliveryReceipt(textSecureAddress, timestamp); } @Override diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index 9fde55bf86..7da2761343 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -25,10 +25,9 @@ import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; 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.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions; import org.whispersystems.textsecure.api.push.exceptions.NetworkFailureException; -import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException; import org.whispersystems.textsecure.api.util.InvalidNumberException; import org.whispersystems.textsecure.internal.push.PushMessageProtos; @@ -133,7 +132,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { byte[] groupId = GroupUtil.getDecodedId(message.getTo()[0].getString()); Recipients recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false); List attachments = getAttachments(masterSecret, message); - List addresses; + List addresses; if (filterRecipientId >= 0) addresses = getPushAddresses(filterRecipientId); else addresses = getPushAddresses(recipients); @@ -161,8 +160,8 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { } } - private List getPushAddresses(Recipients recipients) throws InvalidNumberException { - List addresses = new LinkedList<>(); + private List getPushAddresses(Recipients recipients) throws InvalidNumberException { + List addresses = new LinkedList<>(); for (Recipient recipient : recipients.getRecipientsList()) { addresses.add(getPushAddress(recipient)); @@ -171,8 +170,8 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType { return addresses; } - private List getPushAddresses(long filterRecipientId) throws InvalidNumberException { - List addresses = new LinkedList<>(); + private List getPushAddresses(long filterRecipientId) throws InvalidNumberException { + List addresses = new LinkedList<>(); addresses.add(getPushAddress(RecipientFactory.getRecipientForId(context, filterRecipientId, false))); return addresses; } diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index e83e76e45a..aa45845008 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -9,7 +9,6 @@ import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.NoSuchMessageException; -import org.thoughtcrime.securesms.database.SmsDatabase; import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.mms.MediaConstraints; import org.thoughtcrime.securesms.mms.PartParser; @@ -26,7 +25,7 @@ import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException; import org.whispersystems.textsecure.api.util.InvalidNumberException; @@ -119,7 +118,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { try { prepareMessageMedia(masterSecret, message, MediaConstraints.PUSH_CONSTRAINTS, false); Recipients recipients = RecipientFactory.getRecipientsFromString(context, destination, false); - PushAddress address = getPushAddress(recipients.getPrimaryRecipient()); + TextSecureAddress address = getPushAddress(recipients.getPrimaryRecipient()); List attachments = getAttachments(masterSecret, message); String body = PartParser.getMessageText(message.getBody()); TextSecureMessage mediaMessage = new TextSecureMessage(message.getSentTimestamp(), attachments, body); @@ -150,7 +149,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType { Log.w(TAG, "Falling back to MMS"); DatabaseFactory.getMmsDatabase(context).markAsForcedSms(mediaMessage.getDatabaseMessageId()); ApplicationContext.getInstance(context).getJobManager().add(new MmsSendJob(context, messageId)); - } else if (!axolotlStore.containsSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID)) { + } else if (!axolotlStore.containsSession(recipient.getRecipientId(), TextSecureAddress.DEFAULT_DEVICE_ID)) { Log.w(TAG, "Marking message as pending insecure SMS fallback"); throw new InsecureFallbackApprovalException("Pending user approval for fallback to insecure SMS"); } else { diff --git a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java index 7bc88775c7..d7615ec403 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -18,7 +18,7 @@ import org.whispersystems.jobqueue.JobParameters; import org.whispersystems.jobqueue.requirements.NetworkRequirement; import org.whispersystems.textsecure.api.messages.TextSecureAttachment; import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.util.InvalidNumberException; import java.io.IOException; @@ -76,10 +76,10 @@ public abstract class PushSendJob extends SendJob { } } - protected PushAddress getPushAddress(Recipient recipient) throws InvalidNumberException { + protected TextSecureAddress getPushAddress(Recipient recipient) throws InvalidNumberException { String e164number = Util.canonicalizeNumber(context, recipient.getNumber()); String relay = TextSecureDirectory.getInstance(context).getRelay(e164number); - return new PushAddress(recipient.getRecipientId(), e164number, relay); + return new TextSecureAddress(recipient.getRecipientId(), e164number, relay); } protected boolean isSmsFallbackApprovalRequired(String destination, boolean media) { diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index dad6e5f501..0d652ed7ba 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -24,7 +24,7 @@ import org.whispersystems.libaxolotl.state.AxolotlStore; import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; import org.whispersystems.textsecure.api.messages.TextSecureMessage; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException; import org.whispersystems.textsecure.api.util.InvalidNumberException; @@ -111,7 +111,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { boolean isSmsFallbackSupported = isSmsFallbackSupported(context, destination, false); try { - PushAddress address = getPushAddress(message.getIndividualRecipient()); + TextSecureAddress address = getPushAddress(message.getIndividualRecipient()); TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret); if (message.isEndSession()) { @@ -146,7 +146,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType { Log.w(TAG, "Falling back to SMS"); DatabaseFactory.getSmsDatabase(context).markAsForcedSms(smsMessage.getId()); ApplicationContext.getInstance(context).getJobManager().add(new SmsSendJob(context, messageId, destination)); - } else if (!axolotlStore.containsSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID)) { + } else if (!axolotlStore.containsSession(recipient.getRecipientId(), TextSecureAddress.DEFAULT_DEVICE_ID)) { Log.w(TAG, "Marking message as pending insecure fallback."); throw new InsecureFallbackApprovalException("Pending user approval for fallback to insecure SMS"); } else { diff --git a/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java b/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java index 114d227229..638d722a66 100644 --- a/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java +++ b/src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java @@ -7,7 +7,7 @@ import android.telephony.SmsMessage; import org.thoughtcrime.securesms.util.GroupUtil; import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.textsecure.api.messages.TextSecureGroup; -import org.whispersystems.textsecure.api.push.PushAddress; +import org.whispersystems.textsecure.api.push.TextSecureAddress; import java.util.List; @@ -39,7 +39,7 @@ public class IncomingTextMessage implements Parcelable { public IncomingTextMessage(SmsMessage message) { this.message = message.getDisplayMessageBody(); this.sender = message.getDisplayOriginatingAddress(); - this.senderDeviceId = PushAddress.DEFAULT_DEVICE_ID; + this.senderDeviceId = TextSecureAddress.DEFAULT_DEVICE_ID; this.protocol = message.getProtocolIdentifier(); this.serviceCenterAddress = message.getServiceCenterAddress(); this.replyPathPresent = message.isReplyPathPresent(); @@ -118,7 +118,7 @@ public class IncomingTextMessage implements Parcelable { { this.message = ""; this.sender = sender; - this.senderDeviceId = PushAddress.DEFAULT_DEVICE_ID; + this.senderDeviceId = TextSecureAddress.DEFAULT_DEVICE_ID; this.protocol = 31338; this.serviceCenterAddress = "Outgoing"; this.replyPathPresent = true;