[英]How to retrieve the KeyManager, TrustManager, and SecureRandom object being used by the SSL Client?
[英]How to retrieve keyManager details from SSLContext?
我想從 sslContext object 中檢索屬於 keyManager 的credentialMap 。
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) object 中檢索 keyManager 詳細信息?
看來您無法通過SSLContext
的某些方法獲取KeyManager
數組。 為什么不將KeyManager
數組保存在變量中?
KeyManager[] keyManagers = createKeyManagers();
SSLContext sslContext = newServerContext(keyManagers);
順便問一下,為什么要通過SSLContext
獲取KeyManager[]
? 你打算用它做什么? 你打算在哪里使用它? SSLContext
充當安全套接字工廠或 SSLEngines 的工廠。 KeyManager 應該由SSLServerSocketFactory
或SSLEngine
在內部使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.