use of java.security.KeyManagementException in project vcell by virtualcell.
the class RemoteProxyVCellConnectionFactory method getVCellSoftwareVersion.
public static String getVCellSoftwareVersion(String apihost, Integer apiport) {
boolean bIgnoreCertProblems = true;
boolean bIgnoreHostMismatch = true;
try {
VCellApiClient tempApiClient = new VCellApiClient(apihost, apiport, bIgnoreCertProblems, bIgnoreHostMismatch);
String serverSoftwareVersion = tempApiClient.getServerSoftwareVersion();
return serverSoftwareVersion;
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
e.printStackTrace();
throw new RuntimeException("VCellApiClient configuration exception: " + e.getMessage(), e);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("VCellApiClient communication exception while retrieving server software version: " + e.getMessage(), e);
}
}
use of java.security.KeyManagementException in project web3sdk by FISCO-BCOS.
the class CertificateManager method buildKeyStore.
static File buildKeyStore(String url, char[] keyStorePassword) {
KeyStore keyStore;
try {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, keyStorePassword);
CertificateChainTrustManager certificateChainTrustManager = createCertificateChainTrustManager(keyStore);
URI endpoint = new URI(url);
SSLSocket sslSocket = createSslSocket(endpoint, certificateChainTrustManager);
if (!isTrustedEndPoint(sslSocket)) {
X509Certificate[] x509Certificates = certificateChainTrustManager.x509Certificates;
if (x509Certificates == null) {
throw new RuntimeException("Unable to obtain x509 certificate from server");
}
for (int i = 0; i < x509Certificates.length; i++) {
keyStore.setCertificateEntry(endpoint.getHost() + i, x509Certificates[i]);
}
}
SecureRandom random = new SecureRandom();
File keyFile = File.createTempFile("web3j-", "" + random.nextLong());
FileOutputStream fileOutputStream = new FileOutputStream(keyFile);
keyStore.store(fileOutputStream, keyStorePassword);
fileOutputStream.close();
deleteFileOnShutdown(keyFile);
return keyFile;
} catch (KeyStoreException e) {
throw new RuntimeException(e);
} catch (CertificateException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
use of java.security.KeyManagementException in project yamcs-studio by yamcs.
the class ResourceUtil method openRawURLStream.
/**
* Open URL Stream from remote.
*
* @param url
* @return
* @throws IOException
*/
private static InputStream openRawURLStream(final URL url) throws IOException {
if (url.getProtocol().equals("https")) {
// $NON-NLS-1$
// The code to support https protocol is provided by Eric Berryman (eric.berryman@gmail.com) from Frib
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
// Install the all-trusting trust manager
SSLContext sc = null;
try {
sc = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
try {
sc.init(null, trustAllCerts, new java.security.SecureRandom());
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
}
URLConnection connection = url.openConnection();
connection.setReadTimeout(PreferencesHelper.getURLFileLoadingTimeout());
return connection.getInputStream();
}
use of java.security.KeyManagementException in project ORCID-Source by ORCID.
the class DevJerseyClientConfig method createSslContext.
private SSLContext createSslContext() {
try {
// DANGER!!! Accepts all certs!
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext ssl = SSLContext.getInstance("TLS");
ssl.init(null, trustAllCerts, new SecureRandom());
return ssl;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
}
use of java.security.KeyManagementException in project ORCID-Source by ORCID.
the class OrcidJerseyT2ClientConfig method createSslContext.
private SSLContext createSslContext() {
try {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(keyStore, keyStorePassword.toCharArray());
KeyManager[] keyManagers = kmf.getKeyManagers();
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
// Use the trustStore if present, otherwise default to keyStore.
if (trustStore != null) {
tmf.init(trustStore);
} else {
tmf.init(keyStore);
}
TrustManager[] trustManagers = tmf.getTrustManagers();
SSLContext ssl = SSLContext.getInstance("TLS");
ssl.init(keyManagers, trustManagers, new SecureRandom());
return ssl;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyStoreException e) {
throw new RuntimeException(e);
} catch (UnrecoverableKeyException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
}
Aggregations