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;
|
2018-07-18 15:27:05 +00:00
|
|
|
import org.whispersystems.signalservice.internal.configuration.SignalContactDiscoveryUrl;
|
2017-08-08 23:37:15 +00:00
|
|
|
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 {
|
|
|
|
|
2018-05-22 09:13:10 +00:00
|
|
|
@SuppressWarnings("unused")
|
2018-12-06 20:14:20 +00:00
|
|
|
private static final String TAG = SignalServiceNetworkAccess.class.getSimpleName();
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2018-03-27 21:22:56 +00:00
|
|
|
private static final String COUNTRY_CODE_EGYPT = "+20";
|
|
|
|
private static final String COUNTRY_CODE_UAE = "+971";
|
|
|
|
private static final String COUNTRY_CODE_OMAN = "+968";
|
|
|
|
private static final String COUNTRY_CODE_QATAR = "+974";
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2018-03-27 21:22:56 +00:00
|
|
|
private static final String SERVICE_REFLECTOR_HOST = "textsecure-service-reflected.whispersystems.org";
|
2017-01-11 23:37:51 +00:00
|
|
|
|
2018-03-27 21:22:56 +00:00
|
|
|
private static final ConnectionSpec SOUQ_CONNECTION_SPEC = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
2017-01-11 23:37:51 +00:00
|
|
|
.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_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,
|
2018-03-27 21:22:56 +00:00
|
|
|
CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA)
|
2017-01-11 23:37:51 +00:00
|
|
|
.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) {
|
2018-03-27 21:22:56 +00:00
|
|
|
final TrustStore trustStore = new DomainFrontingTrustStore(context);
|
|
|
|
final SignalServiceUrl service = new SignalServiceUrl("https://cms.souqcdn.com", SERVICE_REFLECTOR_HOST, trustStore, SOUQ_CONNECTION_SPEC);
|
|
|
|
final SignalCdnUrl serviceCdn = new SignalCdnUrl("https://cms.souqcdn.com", SERVICE_REFLECTOR_HOST, trustStore, SOUQ_CONNECTION_SPEC);
|
2018-07-18 15:27:05 +00:00
|
|
|
final SignalContactDiscoveryUrl serviceContact = new SignalContactDiscoveryUrl("https://cms.souqcdn.com", SERVICE_REFLECTOR_HOST, trustStore, SOUQ_CONNECTION_SPEC);
|
2018-03-27 21:22:56 +00:00
|
|
|
final SignalServiceConfiguration serviceConfig = new SignalServiceConfiguration(new SignalServiceUrl[] { service },
|
2018-07-18 15:27:05 +00:00
|
|
|
new SignalCdnUrl[] { serviceCdn },
|
|
|
|
new SignalContactDiscoveryUrl[] { serviceContact });
|
2016-12-30 04:54:05 +00:00
|
|
|
|
2017-08-08 23:37:15 +00:00
|
|
|
this.censorshipConfiguration = new HashMap<String, SignalServiceConfiguration>() {{
|
2018-03-27 21:22:56 +00:00
|
|
|
put(COUNTRY_CODE_EGYPT, serviceConfig);
|
|
|
|
put(COUNTRY_CODE_UAE, serviceConfig);
|
|
|
|
put(COUNTRY_CODE_OMAN, serviceConfig);
|
|
|
|
put(COUNTRY_CODE_QATAR, serviceConfig);
|
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))},
|
2018-07-18 15:27:05 +00:00
|
|
|
new SignalCdnUrl[] {new SignalCdnUrl(BuildConfig.SIGNAL_CDN_URL, new SignalServiceTrustStore(context))},
|
|
|
|
new SignalContactDiscoveryUrl[] {new SignalContactDiscoveryUrl(BuildConfig.SIGNAL_CONTACT_DISCOVERY_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
|
|
|
}
|