gpt4 book ai didi

ssl - UnboundId 使用来自 Websphere 的 SSL KeyStore

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:17 29 4
gpt4 key购买 nike

我正在开发一个始终在非 SSL 连接上使用 UnboundId 的遗留应用程序。我们的基础架构已更改,我需要将其重新设计为 SSL。所以我把代码改成如下

        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null);
FileInputStream fin1 = new FileInputStream("D:/mycert.cer");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
int i = 0;
Certificate cert = cf.generateCertificate(fin1);
trustStore.setCertificateEntry("cert " + i++, cert);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustStore.load(null);
tmf.init(trustStore);
TrustManager[] trustManagers = tmf.getTrustManagers();

SSLUtil sslUtil = new SSLUtil(trustManagers);
sslUtil.setDefaultSSLProtocol("TLSv1");
SSLSocketFactory sslServerSocketFactory = sslUtil.createSSLSocketFactory();
LDAPConnection connection = new LDAPConnection(sslServerSocketFactory, server, port, user, password);

此代码有效。然而,我们在 Websphere 上运行,所有证书都位于 Websphere keystore 中。在这种情况下,我下载了证书并从文件系统或资源中加载它。这不是我们想要的。我们想使用 Websphere 的 keystore 。

我在没有手动定义 thrustmanagers 和 keystores 的情况下尝试了这个,但后来我到处都遇到证书链接错误。

有什么方法可以配置 UnboundId 使用 websphere keystore 吗?

最佳答案

我们最终不得不采用半清洁解决方案。我们使用 websphere 服务器存储的 keystore 文件作为代码的输入。

        KeyStore trustStore = KeyStore.getInstance(trustStoreType);
File file = new File(keystoreLocation);
if(file.exists()){
FileInputStream keystoreFile = new FileInputStream(keystoreLocation);
trustStore.load(keystoreFile, keystorePassword.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustStore);
TrustManager[] trustManagers = tmf.getTrustManagers();

SSLUtil sslUtil = new SSLUtil(trustManagers);
sslUtil.setDefaultSSLProtocol(sslProtocol);
SSLSocketFactory sslServerSocketFactory = sslUtil.createSSLSocketFactory();
LDAPConnection connection = new LDAPConnection(sslServerSocketFactory, server, port, user, password);
return connection;
} else {
throw new TechnicalException("Keystore not found");
}

注意 keystoreLocation 这基本上是来自 websphere 的 keystore 文件,而 kesystorePassword.toCharArray() 是该特定 keystore 的 websphere 密码。这不是最干净的解决方案,但它让我们重新开始。也许这对将来的其他人有帮助

关于ssl - UnboundId 使用来自 Websphere 的 SSL KeyStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50674878/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com