class OadrPKISecurity {

	public static SSLContext createSSLContext(String clientPrivateKeyPemFilePath, String clientCertificatePemFilePath,
			List<String> trustCertificates, String password) throws OadrSecurityException {
		KeyManagerFactory kmf;
		TrustManagerFactory tmf;
		SSLContext sslContext;
		try {

			if (clientPrivateKeyPemFilePath != null && clientCertificatePemFilePath != null) {
				kmf = OadrPKISecurity.createKeyManagerFactory(clientPrivateKeyPemFilePath, clientCertificatePemFilePath,
						password);
			} else {
				kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
				kmf.init(null, null);
			}

			if (trustCertificates != null) {
				tmf = OadrPKISecurity.createTrustManagerFactory(trustCertificates);
			} else {
				tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
				tmf.init(KeyStore.getInstance("JKS"));
			}

			// SSL Context Factory

			sslContext = SSLContext.getInstance("TLS");

			// init ssl context
			String seed = UUID.randomUUID().toString();

			sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom(seed.getBytes()));

			return sslContext;

		} catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException e) {
			throw new OadrSecurityException(e);
		}
	}

	private  OadrPKISecurity();

}