From dc73bc2a5c6007c1f33fc77506b040d35149b7b6 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 20 Nov 2013 00:45:51 -0800 Subject: [PATCH] Having calling code specify push URL to library. --- .../org/whispersystems/textsecure/Release.java | 7 ------- .../textsecure/push/PushServiceSocket.java | 18 ++++++++++-------- .../ApplicationPreferencesActivity.java | 3 ++- .../RegistrationProgressActivity.java | 7 ++++--- src/org/thoughtcrime/securesms/Release.java | 8 ++++++++ .../securesms/gcm/GcmIntentService.java | 6 ++++-- .../service/DirectoryRefreshService.java | 5 +++-- .../securesms/service/PushDownloader.java | 4 ++-- .../securesms/service/RegistrationService.java | 7 ++++--- .../securesms/transport/PushTransport.java | 5 +++-- .../transport/UniversalTransport.java | 4 ++-- 11 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 library/src/org/whispersystems/textsecure/Release.java create mode 100644 src/org/thoughtcrime/securesms/Release.java diff --git a/library/src/org/whispersystems/textsecure/Release.java b/library/src/org/whispersystems/textsecure/Release.java deleted file mode 100644 index 7596758ddf..0000000000 --- a/library/src/org/whispersystems/textsecure/Release.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.whispersystems.textsecure; - -public class Release { - public static final String PUSH_SERVICE_URL = "https://textsecure-service.whispersystems.org"; -// public static final String PUSH_SERVICE_URL = "http://192.168.1.135:8080"; - public static final boolean ENFORCE_SSL = true; -} diff --git a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java index bf83099aac..b1e80d4d22 100644 --- a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java +++ b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java @@ -8,7 +8,6 @@ import com.google.thoughtcrimegson.Gson; import org.apache.http.conn.ssl.StrictHostnameVerifier; import org.whispersystems.textsecure.R; -import org.whispersystems.textsecure.Release; import org.whispersystems.textsecure.crypto.IdentityKey; import org.whispersystems.textsecure.storage.PreKeyRecord; import org.whispersystems.textsecure.util.Base64; @@ -33,7 +32,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; @@ -51,20 +49,24 @@ public class PushServiceSocket { private static final String MESSAGE_PATH = "/v1/messages/"; private static final String ATTACHMENT_PATH = "/v1/attachments/%s"; + private static final boolean ENFORCE_SSL = true; + private final Context context; + private final String serviceUrl; private final String localNumber; private final String password; private final TrustManagerFactory trustManagerFactory; - public PushServiceSocket(Context context, String localNumber, String password) { + public PushServiceSocket(Context context, String serviceUrl, String localNumber, String password) { this.context = context.getApplicationContext(); + this.serviceUrl = serviceUrl; this.localNumber = localNumber; this.password = password; this.trustManagerFactory = initializeTrustManagerFactory(context); } - public PushServiceSocket(Context context, PushCredentials credentials) { - this(context, credentials.getLocalNumber(context), credentials.getPassword(context)); + public PushServiceSocket(Context context, String serviceUrl, PushCredentials credentials) { + this(context, serviceUrl, credentials.getLocalNumber(context), credentials.getPassword(context)); } public void createAccount(boolean voice) throws IOException { @@ -335,13 +337,13 @@ public class PushServiceSocket { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, trustManagerFactory.getTrustManagers(), null); - URL url = new URL(String.format("%s%s", Release.PUSH_SERVICE_URL, urlFragment)); - Log.w("PushServiceSocket", "Push service URL: " + Release.PUSH_SERVICE_URL); + URL url = new URL(String.format("%s%s", serviceUrl, urlFragment)); + Log.w("PushServiceSocket", "Push service URL: " + serviceUrl); Log.w("PushServiceSocket", "Opening URL: " + url); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - if (Release.ENFORCE_SSL) { + if (ENFORCE_SSL) { ((HttpsURLConnection)connection).setSSLSocketFactory(context.getSocketFactory()); ((HttpsURLConnection)connection).setHostnameVerifier(new StrictHostnameVerifier()); } diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 657b3f42a7..ee6af84c40 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -314,7 +314,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr protected Integer doInBackground(Void... params) { try { Context context = ApplicationPreferencesActivity.this; - PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance()); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, + TextSecurePushCredentials.getInstance()); socket.unregisterGcmId(); GCMRegistrar.unregister(context); diff --git a/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java b/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java index 0891055aaa..f3637c43c9 100644 --- a/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationProgressActivity.java @@ -29,8 +29,9 @@ import android.widget.TextView; import android.widget.Toast; import com.actionbarsherlock.app.SherlockActivity; -import org.whispersystems.textsecure.crypto.MasterSecret; + import org.thoughtcrime.securesms.service.RegistrationService; +import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.push.PushServiceSocket; import org.whispersystems.textsecure.push.RateLimitException; import org.whispersystems.textsecure.util.PhoneNumberFormatter; @@ -497,7 +498,7 @@ public class RegistrationProgressActivity extends SherlockActivity { @Override protected Integer doInBackground(Void... params) { try { - PushServiceSocket socket = new PushServiceSocket(context, e164number, password); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, e164number, password); socket.verifyAccount(code, signalingKey); return SUCCESS; } catch (RateLimitException e) { @@ -584,7 +585,7 @@ public class RegistrationProgressActivity extends SherlockActivity { @Override protected Integer doInBackground(Void... params) { try { - PushServiceSocket socket = new PushServiceSocket(context, e164number, password); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, e164number, password); socket.createAccount(true); return SUCCESS; diff --git a/src/org/thoughtcrime/securesms/Release.java b/src/org/thoughtcrime/securesms/Release.java new file mode 100644 index 0000000000..423afdb13e --- /dev/null +++ b/src/org/thoughtcrime/securesms/Release.java @@ -0,0 +1,8 @@ +package org.thoughtcrime.securesms; + +public class Release { + + public static final String PUSH_URL = "https://textsecure-service.whispersystems.org"; +// public static final String PUSH_SERVICE_URL = "http://192.168.1.135:8080"; + +} diff --git a/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java b/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java index 1f6618542a..bb4e88659d 100644 --- a/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java +++ b/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java @@ -5,6 +5,8 @@ import android.content.Intent; import android.util.Log; import com.google.android.gcm.GCMBaseIntentService; + +import org.thoughtcrime.securesms.Release; import org.thoughtcrime.securesms.service.RegistrationService; import org.thoughtcrime.securesms.service.SendReceiveService; import org.thoughtcrime.securesms.util.TextSecurePreferences; @@ -32,7 +34,7 @@ public class GcmIntentService extends GCMBaseIntentService { sendBroadcast(intent); } else { try { - PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance()); + PushServiceSocket pushSocket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance()); pushSocket.registerGcmId(registrationId); } catch (IOException e) { Log.w("GcmIntentService", e); @@ -43,7 +45,7 @@ public class GcmIntentService extends GCMBaseIntentService { @Override protected void onUnregistered(Context context, String registrationId) { try { - PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance()); + PushServiceSocket pushSocket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance()); pushSocket.unregisterGcmId(); } catch (IOException ioe) { Log.w("GcmIntentService", ioe); diff --git a/src/org/thoughtcrime/securesms/service/DirectoryRefreshService.java b/src/org/thoughtcrime/securesms/service/DirectoryRefreshService.java index 8f39a54e54..e9b70b6bee 100644 --- a/src/org/thoughtcrime/securesms/service/DirectoryRefreshService.java +++ b/src/org/thoughtcrime/securesms/service/DirectoryRefreshService.java @@ -1,6 +1,5 @@ package org.thoughtcrime.securesms.service; - import android.app.Service; import android.content.Context; import android.content.Intent; @@ -8,8 +7,10 @@ import android.os.IBinder; import android.os.PowerManager; import android.util.Log; +import org.thoughtcrime.securesms.Release; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePushCredentials; + import org.whispersystems.textsecure.directory.Directory; import org.whispersystems.textsecure.push.ContactTokenDetails; import org.whispersystems.textsecure.push.PushServiceSocket; @@ -59,7 +60,7 @@ public class DirectoryRefreshService extends Service { try { Log.w("DirectoryRefreshService", "Refreshing directory..."); Directory directory = Directory.getInstance(context); - PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance()); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance()); Set eligibleContactTokens = directory.getPushEligibleContactTokens(TextSecurePreferences.getLocalNumber(context)); List activeTokens = socket.retrieveDirectory(eligibleContactTokens); diff --git a/src/org/thoughtcrime/securesms/service/PushDownloader.java b/src/org/thoughtcrime/securesms/service/PushDownloader.java index bb5e4ef3f4..32ff719fd7 100644 --- a/src/org/thoughtcrime/securesms/service/PushDownloader.java +++ b/src/org/thoughtcrime/securesms/service/PushDownloader.java @@ -6,10 +6,10 @@ import android.content.Intent; import android.util.Log; import android.util.Pair; +import org.thoughtcrime.securesms.Release; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.EncryptingPartDatabase; import org.thoughtcrime.securesms.database.PartDatabase; -import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePushCredentials; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream; @@ -111,7 +111,7 @@ public class PushDownloader { } private File downloadAttachment(String relay, long contentLocation) throws IOException { - PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance()); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance()); return socket.retrieveAttachment(relay, contentLocation); } diff --git a/src/org/thoughtcrime/securesms/service/RegistrationService.java b/src/org/thoughtcrime/securesms/service/RegistrationService.java index 31fb6642d7..b6e7653e17 100644 --- a/src/org/thoughtcrime/securesms/service/RegistrationService.java +++ b/src/org/thoughtcrime/securesms/service/RegistrationService.java @@ -11,7 +11,9 @@ import android.os.IBinder; import android.util.Log; import com.google.android.gcm.GCMRegistrar; + import org.thoughtcrime.securesms.R; +import org.thoughtcrime.securesms.Release; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.gcm.GcmIntentService; import org.thoughtcrime.securesms.gcm.GcmRegistrationTimeoutException; @@ -20,7 +22,6 @@ import org.whispersystems.textsecure.crypto.IdentityKey; import org.whispersystems.textsecure.crypto.MasterSecret; import org.whispersystems.textsecure.crypto.PreKeyUtil; import org.whispersystems.textsecure.crypto.ecc.Curve; -import org.whispersystems.textsecure.crypto.ecc.ECPublicKey; import org.whispersystems.textsecure.directory.Directory; import org.whispersystems.textsecure.push.ContactTokenDetails; import org.whispersystems.textsecure.push.PushServiceSocket; @@ -197,7 +198,7 @@ public class RegistrationService extends Service { initializeGcmRegistrationListener(); initializePreKeyGenerator(masterSecret); - PushServiceSocket socket = new PushServiceSocket(this, number, password); + PushServiceSocket socket = new PushServiceSocket(this, Release.PUSH_URL, number, password); handleCommonRegistration(masterSecret, socket, number); @@ -237,7 +238,7 @@ public class RegistrationService extends Service { initializePreKeyGenerator(masterSecret); setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number)); - PushServiceSocket socket = new PushServiceSocket(this, number, password); + PushServiceSocket socket = new PushServiceSocket(this, Release.PUSH_URL, number, password); socket.createAccount(false); setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number)); diff --git a/src/org/thoughtcrime/securesms/transport/PushTransport.java b/src/org/thoughtcrime/securesms/transport/PushTransport.java index 121dc3c459..8fdb402df9 100644 --- a/src/org/thoughtcrime/securesms/transport/PushTransport.java +++ b/src/org/thoughtcrime/securesms/transport/PushTransport.java @@ -22,6 +22,7 @@ import android.util.Log; import com.google.protobuf.ByteString; +import org.thoughtcrime.securesms.Release; import org.thoughtcrime.securesms.crypto.IdentityKeyUtil; import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor; import org.thoughtcrime.securesms.database.model.SmsMessageRecord; @@ -74,7 +75,7 @@ public class PushTransport extends BaseTransport { TextSecurePushCredentials credentials = TextSecurePushCredentials.getInstance(); Recipient recipient = message.getIndividualRecipient(); long threadId = message.getThreadId(); - PushServiceSocket socket = new PushServiceSocket(context, credentials); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, credentials); PushDestination destination = PushDestination.create(context, credentials, recipient.getNumber()); @@ -96,7 +97,7 @@ public class PushTransport extends BaseTransport { { try { TextSecurePushCredentials credentials = TextSecurePushCredentials.getInstance(); - PushServiceSocket socket = new PushServiceSocket(context, credentials); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, credentials); String messageBody = PartParser.getMessageText(message.getBody()); List pushBodies = new LinkedList(); diff --git a/src/org/thoughtcrime/securesms/transport/UniversalTransport.java b/src/org/thoughtcrime/securesms/transport/UniversalTransport.java index d6da46db64..b2a6a7ed37 100644 --- a/src/org/thoughtcrime/securesms/transport/UniversalTransport.java +++ b/src/org/thoughtcrime/securesms/transport/UniversalTransport.java @@ -18,8 +18,8 @@ package org.thoughtcrime.securesms.transport; import android.content.Context; import android.util.Log; -import android.util.Pair; +import org.thoughtcrime.securesms.Release; import org.thoughtcrime.securesms.database.model.SmsMessageRecord; import org.thoughtcrime.securesms.mms.MmsSendResult; import org.thoughtcrime.securesms.recipients.Recipient; @@ -133,7 +133,7 @@ public class UniversalTransport { return directory.isActiveNumber(destination); } catch (NotInDirectoryException e) { try { - PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance()); + PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance()); String contactToken = directory.getToken(destination); ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);