Skip to content

Commit

Permalink
Refactor out old classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Nov 12, 2014
1 parent f9934bd commit f09abff
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package org.whispersystems.textsecure.push;

import org.whispersystems.textsecure.storage.RecipientDevice;
public class PushAddress {

public class PushAddress extends RecipientDevice {
public static final int DEFAULT_DEVICE_ID = 1;

private final long recipientId;
private final String e164number;
private final int deviceId;
private final String relay;

public PushAddress(long recipientId, String e164number, int deviceId, String relay) {
super(recipientId, deviceId);
this.recipientId = recipientId;
this.e164number = e164number;
this.deviceId = deviceId;
this.relay = relay;
}

Expand All @@ -21,4 +24,11 @@ public String getRelay() {
return relay;
}

public long getRecipientId() {
return recipientId;
}

public int getDeviceId() {
return deviceId;
}
}

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions src/org/thoughtcrime/securesms/AutoInitiateActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import android.widget.Button;

import org.thoughtcrime.securesms.crypto.KeyExchangeInitiator;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.protocol.Tag;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.MemoryCleaner;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libaxolotl.state.SessionStore;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.whispersystems.textsecure.push.PushAddress;

/**
* Activity which prompts the user to initiate a secure
Expand Down Expand Up @@ -118,6 +118,6 @@ private static boolean isExchangeQualified(Context context,
Recipient recipient)
{
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
return sessionStore.containsSession(recipient.getRecipientId(), RecipientDevice.DEFAULT_DEVICE_ID);
return sessionStore.containsSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID);
}
}
6 changes: 3 additions & 3 deletions src/org/thoughtcrime/securesms/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libaxolotl.InvalidMessageException;
import org.whispersystems.libaxolotl.state.SessionStore;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.util.Util;

import java.io.IOException;
Expand Down Expand Up @@ -318,7 +318,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMen
Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
boolean isSecureDestination = isSingleConversation() && sessionStore.containsSession(primaryRecipient.getRecipientId(),
RecipientDevice.DEFAULT_DEVICE_ID);
PushAddress.DEFAULT_DEVICE_ID);

getMenuInflater().inflate(R.menu.conversation_button_context, menu);

Expand Down Expand Up @@ -697,7 +697,7 @@ private void initializeSecurity() {
Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
boolean isSecureDestination = isSingleConversation() && sessionStore.containsSession(primaryRecipient.getRecipientId(),
RecipientDevice.DEFAULT_DEVICE_ID);
PushAddress.DEFAULT_DEVICE_ID);

if (isPushDestination || isSecureDestination) {
this.isEncryptedConversation = true;
Expand Down
10 changes: 5 additions & 5 deletions src/org/thoughtcrime/securesms/VerifyIdentityActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
import android.widget.TextView;
import android.widget.Toast;

import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
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.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.whispersystems.textsecure.push.PushAddress;

/**
* Activity for verifying identity keys.
Expand Down Expand Up @@ -184,7 +184,7 @@ protected String getVerifiedTitle() {
private IdentityKey getRemoteIdentityKey(MasterSecret masterSecret, Recipient recipient) {
SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret);
SessionRecord record = sessionStore.loadSession(recipient.getRecipientId(),
RecipientDevice.DEFAULT_DEVICE_ID);
PushAddress.DEFAULT_DEVICE_ID);

if (record == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import org.thoughtcrime.securesms.util.Dialogs;
import org.whispersystems.libaxolotl.SessionBuilder;
import org.whispersystems.libaxolotl.protocol.KeyExchangeMessage;
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
import org.whispersystems.libaxolotl.state.PreKeyStore;
import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SessionStore;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.util.Base64;

public class KeyExchangeInitiator {
Expand Down Expand Up @@ -68,7 +68,7 @@ private static void initiateKeyExchange(Context context, MasterSecret masterSecr

SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
identityKeyStore, recipient.getRecipientId(),
RecipientDevice.DEFAULT_DEVICE_ID);
PushAddress.DEFAULT_DEVICE_ID);

KeyExchangeMessage keyExchangeMessage = sessionBuilder.process();
String serializedMessage = Base64.encodeBytesWithoutPadding(keyExchangeMessage.serialize());
Expand All @@ -81,7 +81,7 @@ private static boolean hasInitiatedSession(Context context, MasterSecret masterS
Recipient recipient)
{
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), RecipientDevice.DEFAULT_DEVICE_ID);
SessionRecord sessionRecord = sessionStore.loadSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID);

return sessionRecord.getSessionState().hasPendingKeyExchange();
}
Expand Down
6 changes: 3 additions & 3 deletions src/org/thoughtcrime/securesms/crypto/MmsCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.whispersystems.libaxolotl.protocol.WhisperMessage;
import org.whispersystems.libaxolotl.state.AxolotlStore;
import org.whispersystems.libaxolotl.util.guava.Optional;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.util.Util;

import java.io.IOException;
Expand Down Expand Up @@ -92,11 +92,11 @@ public SendReq encrypt(Context context, SendReq message)
long recipientId = recipients.getPrimaryRecipient().getRecipientId();
byte[] pduBytes = new PduComposer(context, message).make();

if (!axolotlStore.containsSession(recipientId, RecipientDevice.DEFAULT_DEVICE_ID)) {
if (!axolotlStore.containsSession(recipientId, PushAddress.DEFAULT_DEVICE_ID)) {
throw new NoSessionException("No session for: " + recipientId);
}

SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, RecipientDevice.DEFAULT_DEVICE_ID);
SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, PushAddress.DEFAULT_DEVICE_ID);
CiphertextMessage ciphertextMessage = cipher.encrypt(pduBytes);
byte[] encryptedPduBytes = textTransport.getEncodedMessage(ciphertextMessage.serialize());

Expand Down
18 changes: 0 additions & 18 deletions src/org/thoughtcrime/securesms/crypto/SecurityEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,7 @@
import android.content.Context;
import android.content.Intent;

import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.sms.OutgoingKeyExchangeMessage;
import org.whispersystems.libaxolotl.InvalidKeyException;
import org.whispersystems.libaxolotl.SessionBuilder;
import org.whispersystems.libaxolotl.StaleKeyExchangeException;
import org.whispersystems.libaxolotl.UntrustedIdentityException;
import org.whispersystems.libaxolotl.protocol.KeyExchangeMessage;
import org.whispersystems.libaxolotl.state.SignedPreKeyStore;
import org.whispersystems.libaxolotl.state.IdentityKeyStore;
import org.whispersystems.libaxolotl.state.PreKeyBundle;
import org.whispersystems.libaxolotl.state.PreKeyStore;
import org.whispersystems.libaxolotl.state.SessionStore;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.util.Base64;

/**
* This class processes key exchange interactions.
Expand Down
6 changes: 3 additions & 3 deletions src/org/thoughtcrime/securesms/crypto/SmsCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage;
import org.whispersystems.libaxolotl.protocol.WhisperMessage;
import org.whispersystems.libaxolotl.state.AxolotlStore;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;

import java.io.IOException;

Expand Down Expand Up @@ -89,11 +89,11 @@ public OutgoingTextMessage encrypt(OutgoingTextMessage message) throws NoSession
byte[] paddedBody = transportDetails.getPaddedMessageBody(message.getMessageBody().getBytes());
long recipientId = message.getRecipients().getPrimaryRecipient().getRecipientId();

if (!axolotlStore.containsSession(recipientId, RecipientDevice.DEFAULT_DEVICE_ID)) {
if (!axolotlStore.containsSession(recipientId, PushAddress.DEFAULT_DEVICE_ID)) {
throw new NoSessionException("No session for: " + recipientId);
}

SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, RecipientDevice.DEFAULT_DEVICE_ID);
SessionCipher cipher = new SessionCipher(axolotlStore, recipientId, PushAddress.DEFAULT_DEVICE_ID);
CiphertextMessage ciphertextMessage = cipher.encrypt(paddedBody);
String encodedCiphertext = new String(transportDetails.getEncodedMessage(ciphertextMessage.serialize()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.whispersystems.libaxolotl.state.SessionRecord;
import org.whispersystems.libaxolotl.state.SessionState;
import org.whispersystems.libaxolotl.state.SessionStore;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.util.Conversions;

import java.io.File;
Expand Down Expand Up @@ -108,7 +108,7 @@ public void deleteSession(long recipientId, int deviceId) {
public void deleteAllSessions(long recipientId) {
List<Integer> devices = getSubDeviceSessions(recipientId);

deleteSession(recipientId, RecipientDevice.DEFAULT_DEVICE_ID);
deleteSession(recipientId, PushAddress.DEFAULT_DEVICE_ID);

for (int device : devices) {
deleteSession(recipientId, device);
Expand Down Expand Up @@ -156,7 +156,7 @@ private File getSessionDirectory() {
}

private String getSessionName(long recipientId, int deviceId) {
return recipientId + (deviceId == RecipientDevice.DEFAULT_DEVICE_ID ? "" : "." + deviceId);
return recipientId + (deviceId == PushAddress.DEFAULT_DEVICE_ID ? "" : "." + deviceId);
}

private byte[] readBlob(FileInputStream in) throws IOException {
Expand Down
3 changes: 1 addition & 2 deletions src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.whispersystems.textsecure.api.messages.TextSecureMessage;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.push.UnregisteredUserException;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.util.InvalidNumberException;

import java.io.IOException;
Expand Down Expand Up @@ -138,7 +137,7 @@ private void fallbackOrAskApproval(MasterSecret masterSecret, SendReq mediaMessa
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(), RecipientDevice.DEFAULT_DEVICE_ID)) {
} else if (!axolotlStore.containsSession(recipient.getRecipientId(), PushAddress.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 {
Expand Down
3 changes: 1 addition & 2 deletions src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.whispersystems.textsecure.api.messages.TextSecureMessage;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.push.UnregisteredUserException;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.util.InvalidNumberException;

import java.io.IOException;
Expand Down Expand Up @@ -137,7 +136,7 @@ private void fallbackOrAskApproval(MasterSecret masterSecret, SmsMessageRecord s
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(), RecipientDevice.DEFAULT_DEVICE_ID)) {
} else if (!axolotlStore.containsSession(recipient.getRecipientId(), PushAddress.DEFAULT_DEVICE_ID)) {
Log.w(TAG, "Marking message as pending insecure fallback.");
throw new InsecureFallbackApprovalException("Pending user approval for fallback to insecure SMS");
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/org/thoughtcrime/securesms/recipients/Recipient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@

import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.GroupUtil;
import org.whispersystems.textsecure.storage.CanonicalRecipient;
import org.whispersystems.textsecure.util.FutureTaskListener;
import org.whispersystems.textsecure.util.ListenableFutureTask;

import java.util.HashSet;

public class Recipient implements Parcelable, CanonicalRecipient {
public class Recipient implements Parcelable {

private final static String TAG = Recipient.class.getSimpleName();

Expand Down
18 changes: 9 additions & 9 deletions src/org/thoughtcrime/securesms/sms/IncomingGroupMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public boolean isQuit() {
return groupContext.getType().getNumber() == GroupContext.Type.QUIT_VALUE;
}

public static IncomingGroupMessage createForQuit(String groupId, String user) throws IOException {
IncomingTextMessage base = new IncomingTextMessage(user, groupId);
GroupContext context = GroupContext.newBuilder()
.setType(GroupContext.Type.QUIT)
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId)))
.build();

return new IncomingGroupMessage(base, context, "");
}
// public static IncomingGroupMessage createForQuit(String groupId, String user) throws IOException {
// IncomingTextMessage base = new IncomingTextMessage(user, groupId);
// GroupContext context = GroupContext.newBuilder()
// .setType(GroupContext.Type.QUIT)
// .setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId)))
// .build();
//
// return new IncomingGroupMessage(base, context, "");
// }

}
6 changes: 3 additions & 3 deletions src/org/thoughtcrime/securesms/sms/IncomingTextMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.thoughtcrime.securesms.util.GroupUtil;
import org.whispersystems.libaxolotl.util.guava.Optional;
import org.whispersystems.textsecure.api.messages.TextSecureGroup;
import org.whispersystems.textsecure.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;

import java.util.List;

Expand Down Expand Up @@ -39,7 +39,7 @@ public IncomingTextMessage[] newArray(int size) {
public IncomingTextMessage(SmsMessage message) {
this.message = message.getDisplayMessageBody();
this.sender = message.getDisplayOriginatingAddress();
this.senderDeviceId = RecipientDevice.DEFAULT_DEVICE_ID;
this.senderDeviceId = PushAddress.DEFAULT_DEVICE_ID;
this.protocol = message.getProtocolIdentifier();
this.serviceCenterAddress = message.getServiceCenterAddress();
this.replyPathPresent = message.isReplyPathPresent();
Expand Down Expand Up @@ -118,7 +118,7 @@ protected IncomingTextMessage(String sender, String groupId)
{
this.message = "";
this.sender = sender;
this.senderDeviceId = RecipientDevice.DEFAULT_DEVICE_ID;
this.senderDeviceId = PushAddress.DEFAULT_DEVICE_ID;
this.protocol = 31338;
this.serviceCenterAddress = "Outgoing";
this.replyPathPresent = true;
Expand Down

0 comments on commit f09abff

Please sign in to comment.