String keyStoreType,
String keyManagerFactoryAlgorithm, String certAlias)
throws GeneralSecurityException, IOException
{
// Initialize the SSLContext to work with our key managers.
final SSLContext sslContext = SSLContext
.getInstance(TRANSPORT_LAYER_SECURITY_CODE);
final TrustManager[] trustManagers;
final KeyManager[] keyManagers;
if (trustStorePath != null)
{
final KeyStore ts = SSLUtil.getInitializedKeyStore(trustStorePath,
trustStorePassword, trustStoreType);
final TrustManagerFactory tmf = TrustManagerFactory
.getInstance(trustManagerFactoryAlgorithm);
tmf.init(ts);
trustManagers = tmf.getTrustManagers();
}
else
{
trustManagers = null;
}
if (keyStorePath != null)
{
if (certAlias != null)
{
keyManagers = new KeyManager[] { new QpidClientX509KeyManager(
certAlias, keyStorePath, keyStoreType, keyStorePassword,
keyManagerFactoryAlgorithm) };
}
else
{
final KeyStore ks = SSLUtil.getInitializedKeyStore(
keyStorePath, keyStorePassword, keyStoreType);
char[] keyStoreCharPassword = keyStorePassword == null ? null : keyStorePassword.toCharArray();
// Set up key manager factory to use our key store
final KeyManagerFactory kmf = KeyManagerFactory
.getInstance(keyManagerFactoryAlgorithm);
kmf.init(ks, keyStoreCharPassword);
keyManagers = kmf.getKeyManagers();
}
}
else
{
keyManagers = null;
}
sslContext.init(keyManagers, trustManagers, null);
return sslContext;
}