use of java.security.KeyManagementException in project camel by apache.
the class RabbitMQConnectionFactorySupport method createFactoryFor.
public ConnectionFactory createFactoryFor(final RabbitMQEndpoint endpoint) {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(endpoint.getUsername());
factory.setPassword(endpoint.getPassword());
factory.setVirtualHost(endpoint.getVhost());
factory.setHost(endpoint.getHostname());
factory.setPort(endpoint.getPortNumber());
if (endpoint.getClientProperties() != null) {
factory.setClientProperties(endpoint.getClientProperties());
}
factory.setConnectionTimeout(endpoint.getConnectionTimeout());
factory.setRequestedChannelMax(endpoint.getRequestedChannelMax());
factory.setRequestedFrameMax(endpoint.getRequestedFrameMax());
factory.setRequestedHeartbeat(endpoint.getRequestedHeartbeat());
if (endpoint.getSslProtocol() != null) {
try {
if (endpoint.getSslProtocol().equals("true")) {
factory.useSslProtocol();
} else if (endpoint.getTrustManager() == null) {
factory.useSslProtocol(endpoint.getSslProtocol());
} else {
factory.useSslProtocol(endpoint.getSslProtocol(), endpoint.getTrustManager());
}
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IllegalArgumentException("Invalid sslProtocol " + endpoint.getSslProtocol(), e);
}
}
if (endpoint.getAutomaticRecoveryEnabled() != null) {
factory.setAutomaticRecoveryEnabled(endpoint.getAutomaticRecoveryEnabled());
}
if (endpoint.getNetworkRecoveryInterval() != null) {
factory.setNetworkRecoveryInterval(endpoint.getNetworkRecoveryInterval());
}
if (endpoint.getTopologyRecoveryEnabled() != null) {
factory.setTopologyRecoveryEnabled(endpoint.getTopologyRecoveryEnabled());
}
return factory;
}
use of java.security.KeyManagementException in project android-async-http by loopj.
the class CustomCASample method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
InputStream is = null;
try {
// Configure the library to use a custom 'bks' file to perform
// SSL negotiation.
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
is = getResources().openRawResource(R.raw.store);
store.load(is, STORE_PASS.toCharArray());
getAsyncHttpClient().setSSLSocketFactory(new SecureSocketFactory(store, STORE_ALIAS));
} catch (IOException e) {
throw new KeyStoreException(e);
} catch (CertificateException e) {
throw new KeyStoreException(e);
} catch (NoSuchAlgorithmException e) {
throw new KeyStoreException(e);
} catch (KeyManagementException e) {
throw new KeyStoreException(e);
} catch (UnrecoverableKeyException e) {
throw new KeyStoreException(e);
} finally {
AsyncHttpClient.silentCloseInputStream(is);
}
} catch (KeyStoreException e) {
Log.e(LOG_TAG, "Unable to initialize key store", e);
showCustomCAHelp();
}
}
use of java.security.KeyManagementException in project keywhiz by square.
the class HttpClients method testSslClient.
/**
* Create a {@link OkHttpClient} for tests.
*
* @param keyStore Use a client certificate from keystore if present. Client certs disabled if null.
* @param keyStorePassword keyStore password. Client certs disabled if null.
* @param requestInterceptors Any request interceptors to register with client.
* @return new http client
*/
private static OkHttpClient testSslClient(@Nullable KeyStore keyStore, @Nullable String keyStorePassword, KeyStore trustStore, List<Interceptor> requestInterceptors) {
boolean usingClientCert = keyStore != null && keyStorePassword != null;
SSLContext sslContext;
try {
SSLContextBuilder sslContextBuilder = new SSLContextBuilder().useProtocol("TLSv1.2").loadTrustMaterial(trustStore);
if (usingClientCert) {
sslContextBuilder.loadKeyMaterial(keyStore, keyStorePassword.toCharArray());
}
sslContext = sslContextBuilder.build();
} catch (NoSuchAlgorithmException | KeyStoreException | UnrecoverableKeyException | KeyManagementException e) {
throw Throwables.propagate(e);
}
OkHttpClient.Builder client = new OkHttpClient().newBuilder().sslSocketFactory(sslContext.getSocketFactory()).connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS)).followSslRedirects(false);
client.followRedirects(false);
client.retryOnConnectionFailure(false);
// Won't use cookies and a client certificate at once.
if (!usingClientCert) {
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
client.cookieJar(new JavaNetCookieJar(cookieManager));
}
for (Interceptor interceptor : requestInterceptors) {
client.networkInterceptors().add(interceptor);
}
return client.build();
}
use of java.security.KeyManagementException in project torodb by torodb.
the class MongoClientConfigurationFactory method getMongoClientConfiguration.
public static MongoClientConfiguration getMongoClientConfiguration(AbstractReplication replication) {
HostAndPort syncSource = HostAndPort.fromString(replication.getSyncSource()).withDefaultPort(27017);
MongoClientConfiguration.Builder mongoClientConfigurationBuilder = new MongoClientConfiguration.Builder(syncSource);
Ssl ssl = replication.getSsl();
mongoClientConfigurationBuilder.setSslEnabled(ssl.getEnabled());
if (ssl.getEnabled()) {
try {
mongoClientConfigurationBuilder.setSslAllowInvalidHostnames(ssl.getAllowInvalidHostnames());
TrustManager[] tms = getTrustManagers(ssl);
KeyManager[] kms = getKeyManagers(ssl);
SSLContext sslContext;
if (ssl.getFipsMode()) {
sslContext = SSLContext.getInstance("TLS", "SunPKCS11-NSS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext.init(kms, tms, null);
mongoClientConfigurationBuilder.setSocketFactory(sslContext.getSocketFactory());
} catch (CertificateException | KeyManagementException | KeyStoreException | UnrecoverableKeyException | NoSuchProviderException | NoSuchAlgorithmException | IOException exception) {
throw new SystemException(exception);
}
}
Auth auth = replication.getAuth();
if (auth.getMode().isEnabled()) {
MongoAuthenticationConfiguration mongoAuthenticationConfiguration = getMongoAuthenticationConfiguration(auth, ssl);
mongoClientConfigurationBuilder.addAuthenticationConfiguration(mongoAuthenticationConfiguration);
}
return mongoClientConfigurationBuilder.build();
}
use of java.security.KeyManagementException in project pulsar by yahoo.
the class SecurityUtility method loadPrivateKeyFromPemFile.
public static PrivateKey loadPrivateKeyFromPemFile(String keyFilePath) throws KeyManagementException {
PrivateKey privateKey = null;
if (keyFilePath == null || keyFilePath.isEmpty()) {
return privateKey;
}
try (BufferedReader reader = new BufferedReader(new FileReader(keyFilePath))) {
StringBuilder sb = new StringBuilder();
String previousLine = "";
String currentLine = null;
// Skip the first line (-----BEGIN RSA PRIVATE KEY-----)
reader.readLine();
while ((currentLine = reader.readLine()) != null) {
sb.append(previousLine);
previousLine = currentLine;
}
// Skip the last line (-----END RSA PRIVATE KEY-----)
KeyFactory kf = KeyFactory.getInstance("RSA");
KeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(sb.toString()));
privateKey = kf.generatePrivate(keySpec);
} catch (GeneralSecurityException | IOException e) {
throw new KeyManagementException("Private key loading error", e);
}
return privateKey;
}
Aggregations