use of javax.net.ssl.TrustManagerFactory in project support-core-plugin by jenkinsci.
the class RootCAs method getRootCAList.
public static void getRootCAList(StringWriter writer) {
try {
// Inspired by:
// https://github.com/jenkinsci/jenkins-scripts/pull/82/files
// https://stackoverflow.com/questions/8884831/listing-certificates-in-jvm-trust-store
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
for (int i = 0; i < trustManagers.length; i++) {
writer.append("===== Trust Manager ").append(String.valueOf(i)).append(" =====\n");
TrustManager trustManager = trustManagers[i];
if (trustManager instanceof X509TrustManager) {
final X509Certificate[] acceptedIssuers = ((X509TrustManager) trustManager).getAcceptedIssuers();
writer.append("It is an X.509 Trust Manager containing ").append(String.valueOf(acceptedIssuers.length)).append(" certificates:\n");
for (X509Certificate x509Certificate : acceptedIssuers) {
writer.append(x509Certificate.getSubjectX500Principal().toString()).append('\n');
}
} else {
writer.append("Skipping as it is not an X.509 Trust Manager.\n");
writer.append("Class Name: ").append(trustManager.getClass().getName()).append('\n');
}
}
} catch (KeyStoreException | NoSuchAlgorithmException e) {
writer.write(Functions.printThrowable(e));
}
}
use of javax.net.ssl.TrustManagerFactory in project coprhd-controller by CoprHD.
the class ViPRX509TrustManager method loadTrustManager.
/**
* loads the trust manager using the vipr keystore.
*/
private synchronized void loadTrustManager() {
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(X509_ALGORITHM);
tmf.init(keystore);
for (TrustManager trustManager : tmf.getTrustManagers()) {
if (trustManager instanceof X509TrustManager) {
defaultViPRTrustManager = (X509TrustManager) trustManager;
log.debug("found a X509TrustManager instance");
break;
}
}
log.info("renew trust manager. the # of certificates in trust store is {}", defaultViPRTrustManager.getAcceptedIssuers().length);
} catch (GeneralSecurityException e) {
log.error(e.getMessage(), e);
}
}
use of javax.net.ssl.TrustManagerFactory in project coprhd-controller by CoprHD.
the class CimListener method getClientCertificate.
/**
* @param connectionInfo
* @throws KeyStoreException
* @throws NoSuchAlgorithmException
* @throws CertificateException
* @throws IOException
* @throws KeyManagementException
* @throws ConnectionManagerException
*/
public void getClientCertificate(CimConnectionInfo connectionInfo) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException, ConnectionManagerException {
char[] passphrase;
String passphraseStr = "changeit";
passphrase = passphraseStr.toCharArray();
KeyStore ks = getTrustStore(_trustStoreLocation, passphrase);
SSLContext context = SSLContext.getInstance("TLS");
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
X509TrustManager defaultTrustManager = (X509TrustManager) tmf.getTrustManagers()[0];
TrustedCertManager tm = new TrustedCertManager(defaultTrustManager);
s_logger.debug("Created trust manager");
context.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory factory = context.getSocketFactory();
String smiHost = connectionInfo.getHost();
int smiPort = defaultSMISSSLPort;
if (connectionInfo.getUseSSL()) {
smiPort = connectionInfo.getPort();
}
s_logger.debug("Opening connection to {}:{}", smiHost, smiPort);
SSLSocket socket = (SSLSocket) factory.createSocket(smiHost, smiPort);
socket.setSoTimeout(10000);
try {
s_logger.debug("Starting SSL negotiation");
socket.startHandshake();
socket.close();
socket = null;
} catch (SSLException e) {
// We ignore this exception. What we really need is the SSL
// handshake results.
} finally {
if (socket != null) {
socket.close();
}
}
X509Certificate[] chain = tm.chain;
if (chain == null) {
s_logger.debug("Error getting client certificate chain");
throw new ConnectionManagerException("Error getting client certificate chain");
}
X509Certificate cert0 = chain[0];
String alias0 = smiHost + "-" + "1";
ks.setCertificateEntry(alias0, cert0);
s_logger.debug("Added a certificate to the truststore with alias: {}", alias0);
File trustStoreOut = new File(_trustStoreLocation);
if (trustStoreOut.exists()) {
// Save the original truststore
File trustStoreOutSaved = new File(_trustStoreLocation + "~");
if (trustStoreOutSaved.exists()) {
trustStoreOut.delete();
}
trustStoreOut.renameTo(trustStoreOutSaved);
}
OutputStream out2 = new FileOutputStream(_trustStoreLocation);
ks.store(out2, passphrase);
out2.close();
s_logger.debug("Created/updated the trust store: {}", _trustStoreLocation);
restart();
}
use of javax.net.ssl.TrustManagerFactory in project oxCore by GluuFederation.
the class SslDefaultHttpClient method getTrustManagers.
private TrustManager[] getTrustManagers() throws Exception {
KeyStore keyStore = getKeyStore(this.trustStoreType, this.trustStorePath, this.trustStorePassword);
TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmFactory.init(keyStore);
return tmFactory.getTrustManagers();
}
use of javax.net.ssl.TrustManagerFactory in project android_frameworks_base by crdroidandroid.
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