0

我想从 sslContext 对象中检索属于 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) 对象中检索 keyManager 详细信息?

4

1 回答 1

1

似乎您无法KeyManager通过SSLContext. 为什么不将KeyManager数组保存在变量中?

KeyManager[] keyManagers = createKeyManagers();
SSLContext sslContext = newServerContext(keyManagers);

顺便问一下,你为什么要获得KeyManager[] 通过SSLContext?你打算用它做什么?你打算在哪里使用它?SSLContext充当安全套接字工厂或 SSLEngines 的工厂。KeyManager 应该由SSLServerSocketFactoryor内部使用SSLEngine

于 2021-01-30T15:13:44.303 回答