use of com.nextdoor.bender.ipc.TransportFactoryInitException in project bender by Nextdoor.
the class AbstractHttpTransportFactory method getSSLContext.
/**
* There isn't an easy way in java to trust non-self signed certs. Just allow all until java
* KeyStore functionality is added to Bender.
*
* @return a context that trusts all SSL certs
*/
private SSLContext getSSLContext() {
/*
* Create SSLContext and TrustManager that will trust all SSL certs.
*
* Copy pasta from http://stackoverflow.com/a/4837230
*/
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext ctx;
try {
ctx = SSLContext.getInstance("TLS");
} catch (NoSuchAlgorithmException e) {
throw new TransportFactoryInitException("JVM does not have proper libraries for TSL");
}
try {
ctx.init(null, new TrustManager[] { tm }, new java.security.SecureRandom());
} catch (KeyManagementException e) {
throw new TransportFactoryInitException("Unable to init SSLContext with TrustManager", e);
}
return ctx;
}
use of com.nextdoor.bender.ipc.TransportFactoryInitException in project bender by Nextdoor.
the class TcpTransportFactory method newInstance.
@Override
public Transport newInstance() throws TransportFactoryInitException {
try {
Socket socket;
if (config.getUseSSL()) {
socket = SSLSocketFactory.getDefault().createSocket(config.getHostname(), config.getPort());
} else {
socket = new Socket(config.getHostname(), config.getPort());
}
socket.setReuseAddress(true);
Sink sink = Okio.sink(socket);
sink.timeout().timeout(config.getTimeout(), TimeUnit.MILLISECONDS);
return new TcpTransport(sink, config.getRetryCount(), config.getRetryDelay());
} catch (IOException ex) {
throw new TransportFactoryInitException("Error while creating tcp transport", ex);
}
}
Aggregations