use of javax.net.ssl.TrustManagerFactory in project java-apns by notnoop.
the class SSLContextBuilder method withTrustKeyStore.
public SSLContextBuilder withTrustKeyStore(KeyStore keyStore, String keyStorePassword) throws InvalidSSLConfig {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
trustManagerFactory.init(keyStore);
trustManagers = trustManagerFactory.getTrustManagers();
return this;
} catch (GeneralSecurityException e) {
throw new InvalidSSLConfig(e);
}
}
use of javax.net.ssl.TrustManagerFactory in project java-apns by notnoop.
the class SSLContextBuilder method withDefaultTrustKeyStore.
public SSLContextBuilder withDefaultTrustKeyStore() throws InvalidSSLConfig {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
trustManagerFactory.init((KeyStore) null);
trustManagers = trustManagerFactory.getTrustManagers();
return this;
} catch (GeneralSecurityException e) {
throw new InvalidSSLConfig(e);
}
}
use of javax.net.ssl.TrustManagerFactory in project Tusky by Vavassor.
the class OkHttpUtils method enableHigherTlsOnPreLollipop.
private static OkHttpClient.Builder enableHigherTlsOnPreLollipop(OkHttpClient.Builder builder) {
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
try {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
}
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
builder.sslSocketFactory(new SSLSocketFactoryCompat(sslSocketFactory), trustManager);
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
Log.e(TAG, "Failed enabling TLS 1.1 & 1.2. " + e.getMessage());
}
}
return builder;
}
use of javax.net.ssl.TrustManagerFactory in project voltdb by VoltDB.
the class SSLConfiguration method createTrustManagers.
/**
* Creates the trust managers required to initiate the {@link SSLContext}, using a JKS keystore as an input.
*
* @param filepath - the path to the JKS keystore.
* @param keystorePassword - the keystore's password.
* @return {@link TrustManager} array, that will be used to initiate the {@link SSLContext}.
* @throws Exception
*/
private static TrustManager[] createTrustManagers(String filepath, String keystorePassword) throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException {
KeyStore trustStore = KeyStore.getInstance("JKS");
try (InputStream trustStoreIS = new FileInputStream(filepath)) {
trustStore.load(trustStoreIS, keystorePassword.toCharArray());
}
TrustManagerFactory trustFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustFactory.init(trustStore);
return trustFactory.getTrustManagers();
}
use of javax.net.ssl.TrustManagerFactory in project android_frameworks_base by ResurrectionRemix.
the class TestUtils method getSSLContext.
public static SSLContext getSSLContext(ConfigSource source) throws Exception {
ApplicationConfig config = new ApplicationConfig(source);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX", new NetworkSecurityConfigProvider());
tmf.init(new RootTrustManagerFactorySpi.ApplicationConfigParameters(config));
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
return context;
}
Aggregations