class ZTSUtils {

    public static SSLContext createServerClientSSLContext(PrivateKeyStore privateKeyStore) {

        final String keyStorePath = System.getProperty(ATHENZ_PROP_KEYSTORE_PATH);
        if (keyStorePath == null) {
            LOGGER.error("Unable to create client ssl context: no keystore path specified");
            return null;
        }
        final String keyStorePasswordAppName = System.getProperty(ATHENZ_PROP_KEYSTORE_PASSWORD_APPNAME);
        final String keyStorePassword = System.getProperty(ATHENZ_PROP_KEYSTORE_PASSWORD);
        final String keyStoreType = System.getProperty(ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12");

        final String trustStorePath = System.getProperty(ATHENZ_PROP_TRUSTSTORE_PATH);
        if (trustStorePath == null) {
            LOGGER.error("Unable to create client ssl context: no truststore path specified");
            return null;
        }

        final String trustStorePassword = System.getProperty(ATHENZ_PROP_TRUSTSTORE_PASSWORD);
        final String trustStorePasswordAppName = System.getProperty(ATHENZ_PROP_TRUSTSTORE_PASSWORD_APPNAME);
        final String trustStoreType = System.getProperty(ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12");

        SSLContext sslcontext = null;
        try {
            TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            try (FileInputStream instream = new FileInputStream(new File(trustStorePath))) {
                KeyStore trustStore = KeyStore.getInstance(trustStoreType);
                final String password = getApplicationSecret(privateKeyStore, trustStorePasswordAppName, trustStorePassword);
                trustStore.load(instream, getPasswordChars(password));
                tmfactory.init(trustStore);
            }

            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            try (FileInputStream instream = new FileInputStream(new File(keyStorePath))) {
                KeyStore keyStore = KeyStore.getInstance(keyStoreType);
                final String password = getApplicationSecret(privateKeyStore, keyStorePasswordAppName, keyStorePassword);
                keyStore.load(instream, getPasswordChars(password));
                kmfactory.init(keyStore, getPasswordChars(password));
            }

            KeyManager[] keymanagers = kmfactory.getKeyManagers();
            TrustManager[] trustmanagers = tmfactory.getTrustManagers();

            sslcontext = SSLContext.getInstance("TLSv1.2");
            sslcontext.init(keymanagers, trustmanagers, new SecureRandom());
        } catch (Exception ex) {
            LOGGER.error("Unable to create server client ssl context", ex);
        }

        return sslcontext;
    }

}