From 9215322846f592184a784ae31a3a55d62b1374e5 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 12 Nov 2014 17:09:59 -0800 Subject: [PATCH] Abstract out TrustStore interface. // FREEBIE --- .../textsecure/api/TextSecureAccountManager.java | 3 ++- .../textsecure/api/TextSecureMessageReceiver.java | 3 ++- .../textsecure/api/TextSecureMessageSender.java | 3 ++- .../whispersystems/textsecure/api/push/TrustStore.java | 9 +++++++++ .../textsecure/internal/push/PushServiceSocket.java | 6 +----- .../securesms/push/TextSecurePushTrustStore.java | 3 ++- 6 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TrustStore.java diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureAccountManager.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureAccountManager.java index e305650caa..d912d3ba85 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureAccountManager.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureAccountManager.java @@ -21,6 +21,7 @@ import org.whispersystems.libaxolotl.state.PreKeyRecord; import org.whispersystems.libaxolotl.state.SignedPreKeyRecord; import org.whispersystems.libaxolotl.util.guava.Optional; import org.whispersystems.textsecure.api.push.ContactTokenDetails; +import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.internal.push.PushServiceSocket; import org.whispersystems.textsecure.api.push.SignedPreKeyEntity; @@ -32,7 +33,7 @@ public class TextSecureAccountManager { private final PushServiceSocket pushServiceSocket; - public TextSecureAccountManager(String url, PushServiceSocket.TrustStore trustStore, + public TextSecureAccountManager(String url, TrustStore trustStore, String user, String password) { this.pushServiceSocket = new PushServiceSocket(url, trustStore, user, password); diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java index ccaa96ae79..221a32e27b 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageReceiver.java @@ -19,6 +19,7 @@ package org.whispersystems.textsecure.api; import org.whispersystems.libaxolotl.InvalidMessageException; import org.whispersystems.textsecure.api.crypto.AttachmentCipherInputStream; import org.whispersystems.textsecure.api.messages.TextSecureAttachmentPointer; +import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.internal.push.PushServiceSocket; import java.io.File; @@ -29,7 +30,7 @@ public class TextSecureMessageReceiver { private final PushServiceSocket socket; - public TextSecureMessageReceiver(String url, PushServiceSocket.TrustStore trustStore, + public TextSecureMessageReceiver(String url, TrustStore trustStore, String user, String password) { this.socket = new PushServiceSocket(url, trustStore, user, password); 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 6560f82c88..045b1b9422 100644 --- a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageSender.java +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/TextSecureMessageSender.java @@ -33,6 +33,7 @@ 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.TrustStore; import org.whispersystems.textsecure.internal.push.MismatchedDevices; import org.whispersystems.textsecure.internal.push.OutgoingPushMessage; import org.whispersystems.textsecure.internal.push.OutgoingPushMessageList; @@ -63,7 +64,7 @@ public class TextSecureMessageSender { private final AxolotlStore store; private final Optional eventListener; - public TextSecureMessageSender(String url, PushServiceSocket.TrustStore trustStore, + public TextSecureMessageSender(String url, TrustStore trustStore, String user, String password, AxolotlStore store, Optional eventListener) { diff --git a/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TrustStore.java b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TrustStore.java new file mode 100644 index 0000000000..2b5227029b --- /dev/null +++ b/libtextsecure/src/main/java/org/whispersystems/textsecure/api/push/TrustStore.java @@ -0,0 +1,9 @@ +package org.whispersystems.textsecure.api.push; + +import java.io.InputStream; + +public interface TrustStore { + public InputStream getKeyStoreInputStream(); + public String getKeyStorePassword(); +} + 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 6891159a41..a3efaad5e3 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 @@ -31,6 +31,7 @@ import org.whispersystems.textsecure.api.push.PushAddress; import org.whispersystems.textsecure.api.crypto.AttachmentCipherOutputStream; import org.whispersystems.textsecure.api.push.ContactTokenDetails; import org.whispersystems.textsecure.api.push.SignedPreKeyEntity; +import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException; import org.whispersystems.textsecure.internal.push.exceptions.MismatchedDevicesException; import org.whispersystems.textsecure.internal.push.exceptions.StaleDevicesException; @@ -559,9 +560,4 @@ public class PushServiceSocket { return location; } } - - public interface TrustStore { - public InputStream getKeyStoreInputStream(); - public String getKeyStorePassword(); - } } diff --git a/src/org/thoughtcrime/securesms/push/TextSecurePushTrustStore.java b/src/org/thoughtcrime/securesms/push/TextSecurePushTrustStore.java index 6859fcd397..98785a0576 100644 --- a/src/org/thoughtcrime/securesms/push/TextSecurePushTrustStore.java +++ b/src/org/thoughtcrime/securesms/push/TextSecurePushTrustStore.java @@ -3,11 +3,12 @@ package org.thoughtcrime.securesms.push; import android.content.Context; import org.thoughtcrime.securesms.R; +import org.whispersystems.textsecure.api.push.TrustStore; import org.whispersystems.textsecure.internal.push.PushServiceSocket; import java.io.InputStream; -public class TextSecurePushTrustStore implements PushServiceSocket.TrustStore { +public class TextSecurePushTrustStore implements TrustStore { private final Context context;