Refactor out old classes.

master
Moxie Marlinspike 2014-11-12 09:09:55 -08:00
parent f9934bd8e5
commit f09abff407
16 changed files with 53 additions and 102 deletions

View File

@ -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;
}
@ -21,4 +24,11 @@ public class PushAddress extends RecipientDevice {
return relay;
}
public long getRecipientId() {
return recipientId;
}
public int getDeviceId() {
return deviceId;
}
}

View File

@ -1,6 +0,0 @@
package org.whispersystems.textsecure.storage;
public interface CanonicalRecipient {
// public String getNumber();
public long getRecipientId();
}

View File

@ -1,31 +0,0 @@
package org.whispersystems.textsecure.storage;
public class RecipientDevice {
public static final int DEFAULT_DEVICE_ID = 1;
private final long recipientId;
private final int deviceId;
public RecipientDevice(long recipientId, int deviceId) {
this.recipientId = recipientId;
this.deviceId = deviceId;
}
public long getRecipientId() {
return recipientId;
}
public int getDeviceId() {
return deviceId;
}
public CanonicalRecipient getRecipient() {
return new CanonicalRecipient() {
@Override
public long getRecipientId() {
return recipientId;
}
};
}
}

View File

@ -26,14 +26,14 @@ import android.view.View;
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
@ -118,6 +118,6 @@ public class AutoInitiateActivity extends Activity {
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);
}
}

View File

@ -107,7 +107,7 @@ import org.thoughtcrime.securesms.util.MemoryCleaner;
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;
@ -318,7 +318,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
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);
@ -697,7 +697,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
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;

View File

@ -21,7 +21,10 @@ import android.os.Bundle;
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;
@ -29,10 +32,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.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.
@ -184,7 +184,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(),
RecipientDevice.DEFAULT_DEVICE_ID);
PushAddress.DEFAULT_DEVICE_ID);
if (record == null) {
return null;

View File

@ -31,12 +31,12 @@ import org.thoughtcrime.securesms.sms.OutgoingKeyExchangeMessage;
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 {
@ -68,7 +68,7 @@ public class KeyExchangeInitiator {
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());
@ -81,7 +81,7 @@ public class KeyExchangeInitiator {
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();
}

View File

@ -17,7 +17,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.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.util.Util;
import java.io.IOException;
@ -92,11 +92,11 @@ public class MmsCipher {
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());

View File

@ -3,25 +3,7 @@ package org.thoughtcrime.securesms.crypto;
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.

View File

@ -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.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
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, 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()));

View File

@ -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.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
import org.whispersystems.textsecure.util.Conversions;
import java.io.File;
@ -108,7 +108,7 @@ public class TextSecureSessionStore implements SessionStore {
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);
@ -156,7 +156,7 @@ public class TextSecureSessionStore implements SessionStore {
}
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 {

View File

@ -26,7 +26,6 @@ import org.whispersystems.textsecure.api.messages.TextSecureAttachment;
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;
@ -138,7 +137,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(), 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 {

View File

@ -24,7 +24,6 @@ import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
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;
@ -137,7 +136,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(), 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 {

View File

@ -25,15 +25,13 @@ import android.util.Log;
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();

View File

@ -35,14 +35,14 @@ public class IncomingGroupMessage extends IncomingTextMessage {
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, "");
// }
}

View File

@ -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.storage.RecipientDevice;
import org.whispersystems.textsecure.push.PushAddress;
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 = RecipientDevice.DEFAULT_DEVICE_ID;
this.senderDeviceId = PushAddress.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 = RecipientDevice.DEFAULT_DEVICE_ID;
this.senderDeviceId = PushAddress.DEFAULT_DEVICE_ID;
this.protocol = 31338;
this.serviceCenterAddress = "Outgoing";
this.replyPathPresent = true;