use of javax.net.ssl.SSLSocketFactory in project atlasdb by palantir.
the class Leaders method createInstrumentedLocalServices.
public static LocalPaxosServices createInstrumentedLocalServices(LeaderConfig config, Supplier<LeaderRuntimeConfig> runtime, RemotePaxosServerSpec remotePaxosServerSpec, String userAgent) {
UUID leaderUuid = UUID.randomUUID();
PaxosLeadershipEventRecorder leadershipEventRecorder = PaxosLeadershipEventRecorder.create(AtlasDbMetrics.getMetricRegistry(), leaderUuid.toString());
PaxosAcceptor ourAcceptor = AtlasDbMetrics.instrument(PaxosAcceptor.class, PaxosAcceptorImpl.newAcceptor(config.acceptorLogDir().getPath()));
PaxosLearner ourLearner = AtlasDbMetrics.instrument(PaxosLearner.class, PaxosLearnerImpl.newLearner(config.learnerLogDir().getPath(), leadershipEventRecorder));
Optional<SSLSocketFactory> sslSocketFactory = ServiceCreator.createSslSocketFactory(config.sslConfiguration());
List<PaxosLearner> learners = createProxyAndLocalList(ourLearner, remotePaxosServerSpec.remoteLearnerUris(), sslSocketFactory, PaxosLearner.class, userAgent);
List<PaxosAcceptor> acceptors = createProxyAndLocalList(ourAcceptor, remotePaxosServerSpec.remoteAcceptorUris(), sslSocketFactory, PaxosAcceptor.class, userAgent);
Map<PingableLeader, HostAndPort> otherLeaders = generatePingables(remotePaxosServerSpec.remoteLeaderUris(), sslSocketFactory, userAgent);
InstrumentedExecutorService proposerExecutorService = new InstrumentedExecutorService(PTExecutors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("atlas-proposer-%d").setDaemon(true).build()), AtlasDbMetrics.getMetricRegistry(), MetricRegistry.name(PaxosProposer.class, "executor"));
PaxosProposer proposer = AtlasDbMetrics.instrument(PaxosProposer.class, PaxosProposerImpl.newProposer(ourLearner, acceptors, learners, config.quorumSize(), leaderUuid, proposerExecutorService));
InstrumentedExecutorService leaderElectionExecutor = new InstrumentedExecutorService(PTExecutors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("atlas-leaders-election-%d").setDaemon(true).build()), AtlasDbMetrics.getMetricRegistry(), MetricRegistry.name(PaxosLeaderElectionService.class, "executor"));
PaxosLeaderElectionService paxosLeaderElectionService = new PaxosLeaderElectionServiceBuilder().proposer(proposer).knowledge(ourLearner).potentialLeadersToHosts(otherLeaders).acceptors(acceptors).learners(learners).executor(leaderElectionExecutor).pingRateMs(config.pingRateMs()).randomWaitBeforeProposingLeadershipMs(config.randomWaitBeforeProposingLeadershipMs()).leaderPingResponseWaitMs(config.leaderPingResponseWaitMs()).eventRecorder(leadershipEventRecorder).onlyLogOnQuorumFailure(JavaSuppliers.compose(LeaderRuntimeConfig::onlyLogOnQuorumFailure, runtime)).build();
LeaderElectionService leaderElectionService = AtlasDbMetrics.instrument(LeaderElectionService.class, paxosLeaderElectionService);
PingableLeader pingableLeader = AtlasDbMetrics.instrument(PingableLeader.class, paxosLeaderElectionService);
return ImmutableLocalPaxosServices.builder().ourAcceptor(ourAcceptor).ourLearner(ourLearner).leaderElectionService(leaderElectionService).pingableLeader(pingableLeader).build();
}
use of javax.net.ssl.SSLSocketFactory in project atlasdb by palantir.
the class CassandraClientFactory method getRawClient.
private static Cassandra.Client getRawClient(InetSocketAddress addr, CassandraKeyValueServiceConfig config) throws TException {
TSocket thriftSocket = new TSocket(addr.getHostString(), addr.getPort(), config.socketTimeoutMillis());
thriftSocket.open();
try {
thriftSocket.getSocket().setKeepAlive(true);
thriftSocket.getSocket().setSoTimeout(config.socketQueryTimeoutMillis());
} catch (SocketException e) {
log.error("Couldn't set socket keep alive for host {}", SafeArg.of("address", CassandraLogHelper.host(addr)));
}
if (config.usingSsl()) {
boolean success = false;
try {
final SSLSocketFactory factory;
if (config.sslConfiguration().isPresent()) {
factory = SslSocketFactories.createSslSocketFactory(config.sslConfiguration().get());
} else {
factory = sslSocketFactories.getUnchecked(addr);
}
SSLSocket socket = (SSLSocket) factory.createSocket(thriftSocket.getSocket(), addr.getHostString(), addr.getPort(), true);
thriftSocket = new TSocket(socket);
success = true;
} catch (IOException e) {
throw new TTransportException(e);
} finally {
if (!success) {
thriftSocket.close();
}
}
}
TTransport thriftFramedTransport = new TFramedTransport(thriftSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES);
TProtocol protocol = new TBinaryProtocol(thriftFramedTransport);
Cassandra.Client client = new Cassandra.Client(protocol);
if (config.credentials().isPresent()) {
try {
login(client, config.credentials().get());
} catch (TException e) {
client.getOutputProtocol().getTransport().close();
log.error("Exception thrown attempting to authenticate with config provided credentials", e);
throw e;
}
}
return client;
}
use of javax.net.ssl.SSLSocketFactory in project openmeetings by apache.
the class SignInPage method prepareConnection.
private void prepareConnection(URLConnection _connection) {
if (!(_connection instanceof HttpsURLConnection)) {
return;
}
if (!cfgDao.getBool(CONFIG_IGNORE_BAD_SSL, false)) {
return;
}
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
// no-op
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
// no-op
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
} };
try {
HttpsURLConnection connection = (HttpsURLConnection) _connection;
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
connection.setSSLSocketFactory(sslSocketFactory);
connection.setHostnameVerifier((arg0, arg1) -> true);
} catch (Exception e) {
log.error("[prepareConnection]", e);
}
}
use of javax.net.ssl.SSLSocketFactory in project Gladys-Android-App by LeptitGeek.
the class SelfSigningClientBuilder method getUnsafeOkHttpClient.
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
return new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS).sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]).hostnameVerifier(new HostnameVerifier() {
@SuppressLint("BadHostnameVerifier")
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.net.ssl.SSLSocketFactory in project OA4MP by ncsa.
the class LDAPSSLSocketFactory method getSF.
protected SSLSocketFactory getSF() throws GeneralSecurityException, IOException {
SSLContext sc = SSLContext.getInstance("SSL");
MyTrustManager mtm = new MyTrustManager(null, getSslConfiguration());
mtm.setHost(getLdapConfiguration().getServer());
TrustManager[] trustAllCerts = new TrustManager[] { mtm };
sc.init(getKeyManagerFactory().getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory sf = sc.getSocketFactory();
// this.socket = (SSLSocket) sf.createSocket(this.hostLookup(), this.port);
return sf;
}
Aggregations