簡體   English   中英

如何從 SSLContext 中檢索 keyManager 詳細信息?

[英]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 應該由SSLServerSocketFactorySSLEngine在內部使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM