2016-12-30 04:54:05 +00:00
|
|
|
package org.thoughtcrime.securesms.push;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-01-11 23:37:51 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2016-12-30 04:54:05 +00:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.BuildConfig;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.whispersystems.signalservice.api.push.TrustStore;
|
2017-08-08 23:37:15 +00:00
|
|
|
import org.whispersystems.signalservice.internal.configuration.SignalCdnUrl;
|
|
|
|
import org.whispersystems.signalservice.internal.configuration.SignalServiceConfiguration;
|
|
|
|
import org.whispersystems.signalservice.internal.configuration.SignalServiceUrl;
|
2016-12-30 04:54:05 +00:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2017-01-11 23:37:51 +00:00
|
|
|
import okhttp3.CipherSuite;
|
|
|
|
import okhttp3.ConnectionSpec;
|
|
|
|
import okhttp3.TlsVersion;
|
|
|
|
|
2016-12-30 04:54:05 +00:00
|
|
|
public class SignalServiceNetworkAccess {
|
|
|
|
|
|
|
|
private static final String TAG = SignalServiceNetworkAccess.class.getName();
|
|
|
|
|
2017-08-23 17:45:46 +00:00
|
|
|
private static final String APPSPOT_SERVICE_REFLECTOR_HOST = "signal-reflector-meek.appspot.com";
|
|
|
|
private static final String APPSPOT_CDN_REFLECTOR_HOST = "signal-cdn-reflector.appspot.com";
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2017-01-11 23:37:51 +00:00
|
|
|
private static final ConnectionSpec GMAPS_CONNECTION_SPEC = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
|
|
|
.tlsVersions(TlsVersion.TLS_1_2)
|
|
|
|
.cipherSuites(CipherSuite.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA)
|
|
|
|
.supportsTlsExtensions(true)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
private static final ConnectionSpec GMAIL_CONNECTION_SPEC = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
|
|
|
.tlsVersions(TlsVersion.TLS_1_2)
|
|
|
|
.cipherSuites(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_RC4_128_SHA,
|
|
|
|
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)
|
|
|
|
.supportsTlsExtensions(true)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
private static final ConnectionSpec PLAY_CONNECTION_SPEC = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
|
|
|
.tlsVersions(TlsVersion.TLS_1_2)
|
|
|
|
.cipherSuites(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
|
|
|
|
CipherSuite.TLS_ECDHE_RSA_WITH_RC4_128_SHA,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA,
|
|
|
|
CipherSuite.TLS_RSA_WITH_RC4_128_SHA,
|
|
|
|
CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)
|
|
|
|
.supportsTlsExtensions(true)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
private final Map<String, SignalServiceConfiguration> censorshipConfiguration;
|
|
|
|
private final String[] censoredCountries;
|
|
|
|
private final SignalServiceConfiguration uncensoredConfiguration;
|
2016-12-30 04:54:05 +00:00
|
|
|
|
|
|
|
public SignalServiceNetworkAccess(Context context) {
|
2017-08-23 17:45:46 +00:00
|
|
|
final TrustStore googleTrustStore = new GoogleFrontingTrustStore(context);
|
|
|
|
final SignalServiceUrl baseGoogleService = new SignalServiceUrl("https://www.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAIL_CONNECTION_SPEC);
|
|
|
|
final SignalServiceUrl baseAndroidService = new SignalServiceUrl("https://android.clients.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, PLAY_CONNECTION_SPEC);
|
|
|
|
final SignalServiceUrl mapsOneAndroidService = new SignalServiceUrl("https://clients3.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAPS_CONNECTION_SPEC);
|
|
|
|
final SignalServiceUrl mapsTwoAndroidService = new SignalServiceUrl("https://clients4.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAPS_CONNECTION_SPEC);
|
|
|
|
final SignalServiceUrl mailAndroidService = new SignalServiceUrl("https://mail.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAIL_CONNECTION_SPEC);
|
|
|
|
|
|
|
|
final SignalCdnUrl baseGoogleCdn = new SignalCdnUrl("https://www.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAIL_CONNECTION_SPEC);
|
|
|
|
final SignalCdnUrl baseAndroidCdn = new SignalCdnUrl("https://android.clients.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, PLAY_CONNECTION_SPEC);
|
|
|
|
final SignalCdnUrl mapsOneAndroidCdn = new SignalCdnUrl("https://clients3.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAPS_CONNECTION_SPEC);
|
|
|
|
final SignalCdnUrl mapsTwoAndroidCdn = new SignalCdnUrl("https://clients4.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAPS_CONNECTION_SPEC);
|
|
|
|
final SignalCdnUrl mailAndroidCdn = new SignalCdnUrl("https://mail.google.com", APPSPOT_SERVICE_REFLECTOR_HOST, googleTrustStore, GMAIL_CONNECTION_SPEC);
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
this.censorshipConfiguration = new HashMap<String, SignalServiceConfiguration>() {{
|
|
|
|
put("+20", new SignalServiceConfiguration(new SignalServiceUrl[] {new SignalServiceUrl("https://www.google.com.eg",
|
2017-08-23 17:45:46 +00:00
|
|
|
APPSPOT_SERVICE_REFLECTOR_HOST,
|
2017-08-08 23:37:15 +00:00
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
2017-08-23 17:45:46 +00:00
|
|
|
baseAndroidService, mapsOneAndroidService, mapsTwoAndroidService, mailAndroidService},
|
|
|
|
new SignalCdnUrl[] {new SignalCdnUrl("https://www.google.com.eg",
|
|
|
|
APPSPOT_CDN_REFLECTOR_HOST,
|
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
|
|
|
baseAndroidCdn, mapsOneAndroidCdn, mapsTwoAndroidCdn, mailAndroidCdn, mailAndroidCdn}));
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
put("+971", new SignalServiceConfiguration(new SignalServiceUrl[] {new SignalServiceUrl("https://www.google.ae",
|
2017-08-23 17:45:46 +00:00
|
|
|
APPSPOT_SERVICE_REFLECTOR_HOST,
|
2017-08-08 23:37:15 +00:00
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
2017-08-23 17:45:46 +00:00
|
|
|
baseAndroidService, baseGoogleService, mapsOneAndroidService, mapsTwoAndroidService, mailAndroidService},
|
|
|
|
new SignalCdnUrl[] {new SignalCdnUrl("https://www.google.ae",
|
|
|
|
APPSPOT_CDN_REFLECTOR_HOST,
|
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
|
|
|
baseAndroidCdn, baseGoogleCdn, mapsOneAndroidCdn, mapsTwoAndroidCdn, mailAndroidCdn}));
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
put("+968", new SignalServiceConfiguration(new SignalServiceUrl[] {new SignalServiceUrl("https://www.google.com.om",
|
2017-08-23 17:45:46 +00:00
|
|
|
APPSPOT_SERVICE_REFLECTOR_HOST,
|
2017-08-08 23:37:15 +00:00
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
2017-08-23 17:45:46 +00:00
|
|
|
baseAndroidService, baseGoogleService, mapsOneAndroidService, mapsTwoAndroidService, mailAndroidService},
|
|
|
|
new SignalCdnUrl[] {new SignalCdnUrl("https://www.google.com.om",
|
|
|
|
APPSPOT_CDN_REFLECTOR_HOST,
|
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
|
|
|
baseAndroidCdn, baseGoogleCdn, mapsOneAndroidCdn, mapsTwoAndroidCdn, mailAndroidCdn}));
|
2017-10-03 21:08:41 +00:00
|
|
|
|
|
|
|
put("+974", new SignalServiceConfiguration(new SignalServiceUrl[] {new SignalServiceUrl("https://www.google.com.qa",
|
|
|
|
APPSPOT_SERVICE_REFLECTOR_HOST,
|
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
|
|
|
baseAndroidService, baseGoogleService, mapsOneAndroidService, mapsTwoAndroidService, mailAndroidService},
|
|
|
|
new SignalCdnUrl[] {new SignalCdnUrl("https://www.google.com.qa",
|
|
|
|
APPSPOT_CDN_REFLECTOR_HOST,
|
|
|
|
googleTrustStore, GMAIL_CONNECTION_SPEC),
|
|
|
|
baseAndroidCdn, baseGoogleCdn, mapsOneAndroidCdn, mapsTwoAndroidCdn, mailAndroidCdn}));
|
2016-12-30 04:54:05 +00:00
|
|
|
}};
|
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
this.uncensoredConfiguration = new SignalServiceConfiguration(new SignalServiceUrl[] {new SignalServiceUrl(BuildConfig.SIGNAL_URL, new SignalServiceTrustStore(context))},
|
|
|
|
new SignalCdnUrl[] {new SignalCdnUrl(BuildConfig.SIGNAL_CDN_URL, new SignalServiceTrustStore(context))});
|
2016-12-30 04:54:05 +00:00
|
|
|
|
|
|
|
this.censoredCountries = this.censorshipConfiguration.keySet().toArray(new String[0]);
|
|
|
|
}
|
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
public SignalServiceConfiguration getConfiguration(Context context) {
|
2016-12-30 04:54:05 +00:00
|
|
|
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
|
|
|
return getConfiguration(localNumber);
|
|
|
|
}
|
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
public SignalServiceConfiguration getConfiguration(@Nullable String localNumber) {
|
2017-01-11 23:37:51 +00:00
|
|
|
if (localNumber == null) return this.uncensoredConfiguration;
|
|
|
|
|
2016-12-30 04:54:05 +00:00
|
|
|
for (String censoredRegion : this.censoredCountries) {
|
|
|
|
if (localNumber.startsWith(censoredRegion)) {
|
|
|
|
return this.censorshipConfiguration.get(censoredRegion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.uncensoredConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCensored(Context context) {
|
|
|
|
return getConfiguration(context) != this.uncensoredConfiguration;
|
|
|
|
}
|
|
|
|
|
2017-01-11 23:37:51 +00:00
|
|
|
public boolean isCensored(String number) {
|
|
|
|
return getConfiguration(number) != this.uncensoredConfiguration;
|
|
|
|
}
|
|
|
|
|
2016-12-30 04:54:05 +00:00
|
|
|
}
|