use of org.whispersystems.signalservice.api.util.TlsProxySocketFactory in project Signal-Android by WhisperSystems.
the class PushServiceSocket method createConnectionClient.
private static OkHttpClient createConnectionClient(SignalUrl url, List<Interceptor> interceptors, Optional<Dns> dns, Optional<SignalProxy> proxy) {
try {
TrustManager[] trustManagers = BlacklistingTrustManager.createFor(url.getTrustStore());
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, null);
OkHttpClient.Builder builder = new OkHttpClient.Builder().sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))).dns(dns.or(Dns.SYSTEM));
if (proxy.isPresent()) {
builder.socketFactory(new TlsProxySocketFactory(proxy.get().getHost(), proxy.get().getPort(), dns));
}
builder.sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))).build();
builder.connectionPool(new ConnectionPool(5, 45, TimeUnit.SECONDS));
for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}
return builder.build();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new AssertionError(e);
}
}
use of org.whispersystems.signalservice.api.util.TlsProxySocketFactory in project Signal-Android by WhisperSystems.
the class WebSocketConnection method connect.
public synchronized Observable<WebSocketConnectionState> connect() {
log("connect()");
if (client == null) {
String filledUri;
if (credentialsProvider.isPresent()) {
String identifier = Objects.requireNonNull(credentialsProvider.get().getAci()).toString();
if (credentialsProvider.get().getDeviceId() != SignalServiceAddress.DEFAULT_DEVICE_ID) {
identifier += "." + credentialsProvider.get().getDeviceId();
}
filledUri = String.format(wsUri, identifier, credentialsProvider.get().getPassword());
} else {
filledUri = wsUri;
}
Pair<SSLSocketFactory, X509TrustManager> socketFactory = createTlsSocketFactory(trustStore);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().sslSocketFactory(new Tls12SocketFactory(socketFactory.first()), socketFactory.second()).connectionSpecs(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)).readTimeout(KEEPALIVE_TIMEOUT_SECONDS + 10, TimeUnit.SECONDS).dns(dns.or(Dns.SYSTEM)).connectTimeout(KEEPALIVE_TIMEOUT_SECONDS + 10, TimeUnit.SECONDS);
for (Interceptor interceptor : interceptors) {
clientBuilder.addInterceptor(interceptor);
}
if (signalProxy.isPresent()) {
clientBuilder.socketFactory(new TlsProxySocketFactory(signalProxy.get().getHost(), signalProxy.get().getPort(), dns));
}
OkHttpClient okHttpClient = clientBuilder.build();
Request.Builder requestBuilder = new Request.Builder().url(filledUri);
if (signalAgent != null) {
requestBuilder.addHeader("X-Signal-Agent", signalAgent);
}
webSocketState.onNext(WebSocketConnectionState.CONNECTING);
this.client = okHttpClient.newWebSocket(requestBuilder.build(), this);
}
return webSocketState;
}
use of org.whispersystems.signalservice.api.util.TlsProxySocketFactory in project Signal-Android by signalapp.
the class PushServiceSocket method createConnectionClient.
private static OkHttpClient createConnectionClient(SignalUrl url, List<Interceptor> interceptors, Optional<Dns> dns, Optional<SignalProxy> proxy) {
try {
TrustManager[] trustManagers = BlacklistingTrustManager.createFor(url.getTrustStore());
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, null);
OkHttpClient.Builder builder = new OkHttpClient.Builder().sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))).dns(dns.or(Dns.SYSTEM));
if (proxy.isPresent()) {
builder.socketFactory(new TlsProxySocketFactory(proxy.get().getHost(), proxy.get().getPort(), dns));
}
builder.sslSocketFactory(new Tls12SocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).connectionSpecs(url.getConnectionSpecs().or(Util.immutableList(ConnectionSpec.RESTRICTED_TLS))).build();
builder.connectionPool(new ConnectionPool(5, 45, TimeUnit.SECONDS));
for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}
return builder.build();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new AssertionError(e);
}
}
use of org.whispersystems.signalservice.api.util.TlsProxySocketFactory in project Signal-Android by signalapp.
the class WebSocketConnection method connect.
public synchronized Observable<WebSocketConnectionState> connect() {
log("connect()");
if (client == null) {
String filledUri;
if (credentialsProvider.isPresent()) {
String identifier = Objects.requireNonNull(credentialsProvider.get().getAci()).toString();
if (credentialsProvider.get().getDeviceId() != SignalServiceAddress.DEFAULT_DEVICE_ID) {
identifier += "." + credentialsProvider.get().getDeviceId();
}
filledUri = String.format(wsUri, identifier, credentialsProvider.get().getPassword());
} else {
filledUri = wsUri;
}
Pair<SSLSocketFactory, X509TrustManager> socketFactory = createTlsSocketFactory(trustStore);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().sslSocketFactory(new Tls12SocketFactory(socketFactory.first()), socketFactory.second()).connectionSpecs(Util.immutableList(ConnectionSpec.RESTRICTED_TLS)).readTimeout(KEEPALIVE_TIMEOUT_SECONDS + 10, TimeUnit.SECONDS).dns(dns.or(Dns.SYSTEM)).connectTimeout(KEEPALIVE_TIMEOUT_SECONDS + 10, TimeUnit.SECONDS);
for (Interceptor interceptor : interceptors) {
clientBuilder.addInterceptor(interceptor);
}
if (signalProxy.isPresent()) {
clientBuilder.socketFactory(new TlsProxySocketFactory(signalProxy.get().getHost(), signalProxy.get().getPort(), dns));
}
OkHttpClient okHttpClient = clientBuilder.build();
Request.Builder requestBuilder = new Request.Builder().url(filledUri);
if (signalAgent != null) {
requestBuilder.addHeader("X-Signal-Agent", signalAgent);
}
webSocketState.onNext(WebSocketConnectionState.CONNECTING);
this.client = okHttpClient.newWebSocket(requestBuilder.build(), this);
}
return webSocketState;
}
Aggregations