Merge pull request #841 from Jasintha/weekTrustManager

Fixing File stream closing issue and few formatting errors
revert-70aa11f8
Kamidu Sachith Punchihewa 7 years ago committed by GitHub
commit 474c656249

@ -74,7 +74,6 @@ public class Utils {
} }
public static Client getSSLClient() { public static Client getSSLClient() {
boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification")); boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2.ignoreHostnameVerification"));
if(isIgnoreHostnameVerification) { if(isIgnoreHostnameVerification) {
return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() { return new Client.Default(getSimpleTrustedSSLSocketFactory(), new HostnameVerifier() {
@ -82,7 +81,6 @@ public class Utils {
public boolean verify(String s, SSLSession sslSession) { public boolean verify(String s, SSLSession sslSession) {
return true; return true;
} }
}); });
}else { }else {
return new Client.Default(getTrustedSSLSocketFactory(), null); return new Client.Default(getTrustedSSLSocketFactory(), null);
@ -125,7 +123,6 @@ public class Utils {
KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword); KeyStore trustStore = loadTrustStore(trustStoreLocation,trustStorePassword);
return initSSLConnection(keyStore,keyStorePassword,trustStore); return initSSLConnection(keyStore,keyStorePassword,trustStore);
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException
|CertificateException | IOException | UnrecoverableKeyException e) { |CertificateException | IOException | UnrecoverableKeyException e) {
log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e); log.error("Error while creating the SSL socket factory due to "+e.getMessage(),e);
@ -134,7 +131,6 @@ public class Utils {
} }
private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException, private static SSLSocketFactory initSSLConnection(KeyStore keyStore,String keyStorePassword,KeyStore trustStore) throws NoSuchAlgorithmException, UnrecoverableKeyException,
KeyStoreException, KeyManagementException { KeyStoreException, KeyManagementException {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE);
@ -152,34 +148,22 @@ public class Utils {
private static KeyStore loadKeyStore(String keyStorePath, String ksPassword,String type) private static KeyStore loadKeyStore(String keyStorePath, String ksPassword,String type)
throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
InputStream fis = null; InputStream fileInputStream = null;
try { try {
char[] keypassChar = ksPassword.toCharArray(); char[] keypassChar = ksPassword.toCharArray();
KeyStore keyStore = KeyStore.getInstance(type); KeyStore keyStore = KeyStore.getInstance(type);
FileInputStream fileInputStream = new FileInputStream(keyStorePath); fileInputStream = new FileInputStream(keyStorePath);
keyStore.load(fileInputStream, keypassChar); keyStore.load(fileInputStream, keypassChar);
return keyStore; return keyStore;
} finally { } finally {
if (fis != null) { if (fileInputStream != null) {
fis.close(); fileInputStream.close();
} }
} }
} }
/**
* Loads the trustore
*
* @param trustStorePath - the trustore path in the filesystem.
* @param tsPassword - the truststore password
*/
private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) private static KeyStore loadTrustStore(String trustStorePath, String tsPassword)
throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
return loadKeyStore(trustStorePath,tsPassword,TRUST_STORE_TYPE); return loadKeyStore(trustStorePath,tsPassword,TRUST_STORE_TYPE);
} }
}
}
Loading…
Cancel
Save