我想检索credentialMap
从sslContext对象属于keyManager。public static void main(String[] args) throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, NoSuchProviderException, KeyManagementException {
SSLContext sslContext = newServerContext(createKeyManagers());
// how to get keyManager from sslContext?
}
public static SSLContext newServerContext(KeyManager[] keyManagers)
throws NoSuchAlgorithmException, NoSuchProviderException,
KeyManagementException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, null, new SecureRandom());
return ctx;
}
public static KeyManager[] createKeyManagers()
throws KeyStoreException, IOException, NoSuchAlgorithmException,
CertificateException, UnrecoverableKeyException
{
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream keyStoreFile = new FileInputStream("F:\IdeaProjects\NewFeature\keystore.jks");
String keyStorePassword = "changeit";
keyStore.load(keyStoreFile, keyStorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, keyStorePassword.toCharArray());
return kmf.getKeyManagers();
}
我如何从ctx(SSLContext)对象检索keyManager详细信息?
似乎无法通过SSLContext
的某些方法获得KeyManager
数组。为什么不将KeyManager
数组保存在一个变量中?
KeyManager[] keyManagers = createKeyManagers();
SSLContext sslContext = newServerContext(keyManagers);
顺便问一下,为什么要通过SSLContext
获得KeyManager[]
?你打算怎么处理它?你打算在哪里使用它?SSLContext
充当安全套接字工厂或sslengine的工厂。KeyManager应该由SSLServerSocketFactory
或SSLEngine
在内部使用。