KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(m_keyManagerAlgorithm);
// Use the keystore password as default if not given
keyFactory.init(keystore, m_keyManagerPassword == null ? m_keyStorePassword.toCharArray() : m_keyManagerPassword.toCharArray());
TrustManagerFactory trustFactory = null;
if (m_trustStoreName != null)
{
// User specified a trust store, retrieve it
if (m_trustStorePassword == null)
{
throw new IOException("TrustStore password cannot be null");
}
KeyStore trustStore = KeyStore.getInstance(m_trustStoreType);
InputStream trustStoreStream = getClass().getClassLoader().getResourceAsStream(m_trustStoreName);
// Check for nullity
if (trustStoreStream == null)
{
throw new IOException("Cannot find TrustStore " + m_trustStoreName);
}
trustStore.load(trustStoreStream, m_trustStorePassword.toCharArray());
trustFactory = TrustManagerFactory.getInstance(m_trustManagerAlgorithm);
trustFactory.init(trustStore);
}
SSLContext context = SSLContext.getInstance(m_sslProtocol);
// Below call does not handle TrustManagers, needed when server must authenticate clients.
context.init(keyFactory.getKeyManagers(), trustFactory == null ? null : trustFactory.getTrustManagers(), null);
SSLServerSocketFactory ssf = context.getServerSocketFactory();
SSLServerSocket serverSocket = (SSLServerSocket)ssf.createServerSocket(port, backlog, InetAddress.getByName(host));
return serverSocket;