mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Having calling code specify push URL to library.
This commit is contained in:
parent
f8dda5afd6
commit
dc73bc2a5c
@ -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;
|
|
||||||
}
|
|
@ -8,7 +8,6 @@ import com.google.thoughtcrimegson.Gson;
|
|||||||
|
|
||||||
import org.apache.http.conn.ssl.StrictHostnameVerifier;
|
import org.apache.http.conn.ssl.StrictHostnameVerifier;
|
||||||
import org.whispersystems.textsecure.R;
|
import org.whispersystems.textsecure.R;
|
||||||
import org.whispersystems.textsecure.Release;
|
|
||||||
import org.whispersystems.textsecure.crypto.IdentityKey;
|
import org.whispersystems.textsecure.crypto.IdentityKey;
|
||||||
import org.whispersystems.textsecure.storage.PreKeyRecord;
|
import org.whispersystems.textsecure.storage.PreKeyRecord;
|
||||||
import org.whispersystems.textsecure.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
@ -33,7 +32,6 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.net.ssl.HostnameVerifier;
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.TrustManagerFactory;
|
import javax.net.ssl.TrustManagerFactory;
|
||||||
@ -51,20 +49,24 @@ public class PushServiceSocket {
|
|||||||
private static final String MESSAGE_PATH = "/v1/messages/";
|
private static final String MESSAGE_PATH = "/v1/messages/";
|
||||||
private static final String ATTACHMENT_PATH = "/v1/attachments/%s";
|
private static final String ATTACHMENT_PATH = "/v1/attachments/%s";
|
||||||
|
|
||||||
|
private static final boolean ENFORCE_SSL = true;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
private final String serviceUrl;
|
||||||
private final String localNumber;
|
private final String localNumber;
|
||||||
private final String password;
|
private final String password;
|
||||||
private final TrustManagerFactory trustManagerFactory;
|
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.context = context.getApplicationContext();
|
||||||
|
this.serviceUrl = serviceUrl;
|
||||||
this.localNumber = localNumber;
|
this.localNumber = localNumber;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.trustManagerFactory = initializeTrustManagerFactory(context);
|
this.trustManagerFactory = initializeTrustManagerFactory(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PushServiceSocket(Context context, PushCredentials credentials) {
|
public PushServiceSocket(Context context, String serviceUrl, PushCredentials credentials) {
|
||||||
this(context, credentials.getLocalNumber(context), credentials.getPassword(context));
|
this(context, serviceUrl, credentials.getLocalNumber(context), credentials.getPassword(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createAccount(boolean voice) throws IOException {
|
public void createAccount(boolean voice) throws IOException {
|
||||||
@ -335,13 +337,13 @@ public class PushServiceSocket {
|
|||||||
SSLContext context = SSLContext.getInstance("TLS");
|
SSLContext context = SSLContext.getInstance("TLS");
|
||||||
context.init(null, trustManagerFactory.getTrustManagers(), null);
|
context.init(null, trustManagerFactory.getTrustManagers(), null);
|
||||||
|
|
||||||
URL url = new URL(String.format("%s%s", Release.PUSH_SERVICE_URL, urlFragment));
|
URL url = new URL(String.format("%s%s", serviceUrl, urlFragment));
|
||||||
Log.w("PushServiceSocket", "Push service URL: " + Release.PUSH_SERVICE_URL);
|
Log.w("PushServiceSocket", "Push service URL: " + serviceUrl);
|
||||||
Log.w("PushServiceSocket", "Opening URL: " + url);
|
Log.w("PushServiceSocket", "Opening URL: " + url);
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
||||||
|
|
||||||
if (Release.ENFORCE_SSL) {
|
if (ENFORCE_SSL) {
|
||||||
((HttpsURLConnection)connection).setSSLSocketFactory(context.getSocketFactory());
|
((HttpsURLConnection)connection).setSSLSocketFactory(context.getSocketFactory());
|
||||||
((HttpsURLConnection)connection).setHostnameVerifier(new StrictHostnameVerifier());
|
((HttpsURLConnection)connection).setHostnameVerifier(new StrictHostnameVerifier());
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
|||||||
protected Integer doInBackground(Void... params) {
|
protected Integer doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
Context context = ApplicationPreferencesActivity.this;
|
Context context = ApplicationPreferencesActivity.this;
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL,
|
||||||
|
TextSecurePushCredentials.getInstance());
|
||||||
|
|
||||||
socket.unregisterGcmId();
|
socket.unregisterGcmId();
|
||||||
GCMRegistrar.unregister(context);
|
GCMRegistrar.unregister(context);
|
||||||
|
@ -29,8 +29,9 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
|
||||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||||
import org.whispersystems.textsecure.push.RateLimitException;
|
import org.whispersystems.textsecure.push.RateLimitException;
|
||||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||||
@ -497,7 +498,7 @@ public class RegistrationProgressActivity extends SherlockActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected Integer doInBackground(Void... params) {
|
protected Integer doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, e164number, password);
|
PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, e164number, password);
|
||||||
socket.verifyAccount(code, signalingKey);
|
socket.verifyAccount(code, signalingKey);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
} catch (RateLimitException e) {
|
} catch (RateLimitException e) {
|
||||||
@ -584,7 +585,7 @@ public class RegistrationProgressActivity extends SherlockActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected Integer doInBackground(Void... params) {
|
protected Integer doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, e164number, password);
|
PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, e164number, password);
|
||||||
socket.createAccount(true);
|
socket.createAccount(true);
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
8
src/org/thoughtcrime/securesms/Release.java
Normal file
8
src/org/thoughtcrime/securesms/Release.java
Normal file
@ -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";
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,8 @@ import android.content.Intent;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.gcm.GCMBaseIntentService;
|
import com.google.android.gcm.GCMBaseIntentService;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
@ -32,7 +34,7 @@ public class GcmIntentService extends GCMBaseIntentService {
|
|||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
PushServiceSocket pushSocket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance());
|
||||||
pushSocket.registerGcmId(registrationId);
|
pushSocket.registerGcmId(registrationId);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w("GcmIntentService", e);
|
Log.w("GcmIntentService", e);
|
||||||
@ -43,7 +45,7 @@ public class GcmIntentService extends GCMBaseIntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onUnregistered(Context context, String registrationId) {
|
protected void onUnregistered(Context context, String registrationId) {
|
||||||
try {
|
try {
|
||||||
PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
PushServiceSocket pushSocket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance());
|
||||||
pushSocket.unregisterGcmId();
|
pushSocket.unregisterGcmId();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.w("GcmIntentService", ioe);
|
Log.w("GcmIntentService", ioe);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.thoughtcrime.securesms.service;
|
package org.thoughtcrime.securesms.service;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -8,8 +7,10 @@ import android.os.IBinder;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
|
|
||||||
import org.whispersystems.textsecure.directory.Directory;
|
import org.whispersystems.textsecure.directory.Directory;
|
||||||
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
||||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||||
@ -59,7 +60,7 @@ public class DirectoryRefreshService extends Service {
|
|||||||
try {
|
try {
|
||||||
Log.w("DirectoryRefreshService", "Refreshing directory...");
|
Log.w("DirectoryRefreshService", "Refreshing directory...");
|
||||||
Directory directory = Directory.getInstance(context);
|
Directory directory = Directory.getInstance(context);
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance());
|
||||||
|
|
||||||
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(TextSecurePreferences.getLocalNumber(context));
|
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(TextSecurePreferences.getLocalNumber(context));
|
||||||
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
|
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
|
||||||
|
@ -6,10 +6,10 @@ import android.content.Intent;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.EncryptingPartDatabase;
|
import org.thoughtcrime.securesms.database.EncryptingPartDatabase;
|
||||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream;
|
import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream;
|
||||||
@ -111,7 +111,7 @@ public class PushDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private File downloadAttachment(String relay, long contentLocation) throws IOException {
|
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);
|
return socket.retrieveAttachment(relay, contentLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@ import android.os.IBinder;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.gcm.GCMRegistrar;
|
import com.google.android.gcm.GCMRegistrar;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||||
import org.thoughtcrime.securesms.gcm.GcmIntentService;
|
import org.thoughtcrime.securesms.gcm.GcmIntentService;
|
||||||
import org.thoughtcrime.securesms.gcm.GcmRegistrationTimeoutException;
|
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.MasterSecret;
|
||||||
import org.whispersystems.textsecure.crypto.PreKeyUtil;
|
import org.whispersystems.textsecure.crypto.PreKeyUtil;
|
||||||
import org.whispersystems.textsecure.crypto.ecc.Curve;
|
import org.whispersystems.textsecure.crypto.ecc.Curve;
|
||||||
import org.whispersystems.textsecure.crypto.ecc.ECPublicKey;
|
|
||||||
import org.whispersystems.textsecure.directory.Directory;
|
import org.whispersystems.textsecure.directory.Directory;
|
||||||
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
||||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||||
@ -197,7 +198,7 @@ public class RegistrationService extends Service {
|
|||||||
initializeGcmRegistrationListener();
|
initializeGcmRegistrationListener();
|
||||||
initializePreKeyGenerator(masterSecret);
|
initializePreKeyGenerator(masterSecret);
|
||||||
|
|
||||||
PushServiceSocket socket = new PushServiceSocket(this, number, password);
|
PushServiceSocket socket = new PushServiceSocket(this, Release.PUSH_URL, number, password);
|
||||||
|
|
||||||
handleCommonRegistration(masterSecret, socket, number);
|
handleCommonRegistration(masterSecret, socket, number);
|
||||||
|
|
||||||
@ -237,7 +238,7 @@ public class RegistrationService extends Service {
|
|||||||
initializePreKeyGenerator(masterSecret);
|
initializePreKeyGenerator(masterSecret);
|
||||||
|
|
||||||
setState(new RegistrationState(RegistrationState.STATE_CONNECTING, number));
|
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);
|
socket.createAccount(false);
|
||||||
|
|
||||||
setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
|
setState(new RegistrationState(RegistrationState.STATE_VERIFYING, number));
|
||||||
|
@ -22,6 +22,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
||||||
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
|
import org.thoughtcrime.securesms.crypto.KeyExchangeProcessor;
|
||||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||||
@ -74,7 +75,7 @@ public class PushTransport extends BaseTransport {
|
|||||||
TextSecurePushCredentials credentials = TextSecurePushCredentials.getInstance();
|
TextSecurePushCredentials credentials = TextSecurePushCredentials.getInstance();
|
||||||
Recipient recipient = message.getIndividualRecipient();
|
Recipient recipient = message.getIndividualRecipient();
|
||||||
long threadId = message.getThreadId();
|
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,
|
PushDestination destination = PushDestination.create(context, credentials,
|
||||||
recipient.getNumber());
|
recipient.getNumber());
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ public class PushTransport extends BaseTransport {
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
TextSecurePushCredentials credentials = TextSecurePushCredentials.getInstance();
|
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());
|
String messageBody = PartParser.getMessageText(message.getBody());
|
||||||
List<PushBody> pushBodies = new LinkedList<PushBody>();
|
List<PushBody> pushBodies = new LinkedList<PushBody>();
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ package org.thoughtcrime.securesms.transport;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.mms.MmsSendResult;
|
import org.thoughtcrime.securesms.mms.MmsSendResult;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
@ -133,7 +133,7 @@ public class UniversalTransport {
|
|||||||
return directory.isActiveNumber(destination);
|
return directory.isActiveNumber(destination);
|
||||||
} catch (NotInDirectoryException e) {
|
} catch (NotInDirectoryException e) {
|
||||||
try {
|
try {
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
PushServiceSocket socket = new PushServiceSocket(context, Release.PUSH_URL, TextSecurePushCredentials.getInstance());
|
||||||
String contactToken = directory.getToken(destination);
|
String contactToken = directory.getToken(destination);
|
||||||
ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);
|
ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user