热释光;dr-获取密钥库资源管理器(http://keystore-explorer.org/)省去你自己的麻烦。
p、 密钥库别名设置对某些java应用程序非常重要(例如:jetty provider ssl配置中的idempiere(/jettyhome/etc/jetty ssl context.xml)。在这些情况下,必须确保java正在查找的证书别名与它实际用来查找它的别名相匹配。
o、 第。
我需要在java应用程序中使用私有ca及其证书。我无法发现如何将私有ca根证书及其中介添加到java可信证书中。我已经找到并阅读了多篇关于如何做到这一点的文章,但我的努力并不能达到我所需要的。
我使用的是openjdk11。java cacerts fie位于 /usr/local/openjdk11/lib/security/cacerts
. 我相信它包含了java使用的可信证书列表。
我已手动将专用ca根证书和中间证书添加到此存储:
cp -p /usr/local/openjdk11/lib/security/cacerts /usr/local/openjdk11/lib/security/cacerts.cln
cp -p /usr/local/openjdk11/lib/security/cacerts /root/hll_jdk11_cacerts
JAVA_VERSION="11" keytool -import \
-trustcacerts \
-file /usr/local/etc/pki/tls/certs/CA_HLL_ROOT_2016.crt \
-alias 'hartelyneroot2016 [hll]' \
-keystore /root/hll_jdk11_cacerts
JAVA_VERSION="11" keytool -import \
-trustcacerts \
-file /usr/local/etc/pki/tls/certs/CA_HLL_ISSUER_2016.crt \
-alias 'hartelyneissuer2016 [hll]' \
-keystore /root/hll_jdk11_cacerts
JAVA_VERSION="11" keytool -list -rfc -keystore /root/hll_jdk11_cacerts | grep hll
Enter keystore password: changeit
Alias name: hartelyneissuer2016 [hll]
Alias name: hartelyneroot2016 [hll]
cp -p /root/hll_jdk11_cacerts /usr/local/openjdk11/lib/security/cacerts
据我所知,由ca\u hll\u issuer\u 2016和ca\u hll\u root\u 2016颁发的证书现在应该被此主机上的java识别为受信任。但是,他们不是。我要找出原因。
JAVA_VERSION="11" java SSLPoke google.ca 443
Successfully connected
JAVA_VERSION="11" java SSLPoke webmail.harte-lyne.ca 443
sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchor
但我不介意 openssl s_client
:
openssl s_client -connect webmail.harte-lyne.ca:443
CONNECTED(00000003)
depth=2 CN = CA_HLL_ROOT_2016, ST = Ontario, O = Harte & Lyne Limited, OU = Networked Data Services, C = CA, DC = harte-lyne, DC = ca, L = Hamilton
verify return:1
depth=1 CN = CA_HLL_ISSUER_2016, OU = Networked Data Services, O = Harte & Lyne Limited, L = Hamilton, ST = Ontario, C = CA, DC = harte-lyne, DC = ca
verify return:1
depth=0 CN = webmail.hamilton.harte-lyne.ca, OU = Networked Data Services, O = Harte & Lyne Limited, L = Hamilton, ST = Ontario, C = CA, DC = hamilton, DC = harte-lyne, DC = ca
verify return:1
---
Certificate chain
0 s:CN = webmail.hamilton.harte-lyne.ca, OU = Networked Data Services, O = Harte & Lyne Limited, L = Hamilton, ST = Ontario, C = CA, DC = hamilton, DC = harte-lyne, DC = ca
i:CN = CA_HLL_ISSUER_2016, OU = Networked Data Services, O = Harte & Lyne Limited, L = Hamilton, ST = Ontario, C = CA, DC = harte-lyne, DC = ca
1 s:CN = CA_HLL_ISSUER_2016, OU = Networked Data Services, O = Harte & Lyne Limited, L = Hamilton, ST = Ontario, C = CA, DC = harte-lyne, DC = ca
i:CN = CA_HLL_ROOT_2016, ST = Ontario, O = Harte & Lyne Limited, OU = Networked Data Services, C = CA, DC = harte-lyne, DC = ca, L = Hamilton
2 s:CN = CA_HLL_ROOT_2016, ST = Ontario, O = Harte & Lyne Limited, OU = Networked Data Services, C = CA, DC = harte-lyne, DC = ca, L = Hamilton
i:CN = CA_HLL_ROOT_2016, ST = Ontario, O = Harte & Lyne Limited, OU = Networked Data Services, C = CA, DC = harte-lyne, DC = ca, L = Hamilton
---
Server certificate
-----BEGIN CERTIFICATE-----
. . .
---
Acceptable client certificate CA names
. . .
CN = CA_HLL_ROOT_2016, ST = Ontario, O = Harte & Lyne Limited, OU = Networked Data Services, C = CA, DC = harte-lyne, DC = ca, L = Hamilton
. . .
CN = CA_HLL_ISSUER_2016, OU = Networked Data Services, O = Harte & Lyne Limited, L = Hamilton, ST = Ontario, C = CA, DC = harte-lyne, DC = ca
. . .
我错过了什么?如何将私有CA添加到java信任库?
按照回答中给出的建议,我按照给出的顺序做了:
openssl s_client -connect webmail.harte-lyne.ca:443 -showcerts > harte.crt
JAVA_VERSION="11" keytool -import -alias harte -file harte.crt -keystore cacerts -storepass changeit
. . .
Trust this certificate? [no]: yes
Certificate was added to keystore
JAVA_VERSION="11" java SSLPoke webmail.harte-lyne.ca 443
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我在openjdk中遇到了一个bug?
2条答案
按热度按时间snz8szmq1#
我知道您想对某个https调用执行客户端证书身份验证。仅仅信任证书是不够的。您需要使用已使用此ca签名的密钥对,https握手才能成功。
试试这个
qzwqbdag2#
不,这个别名对于默认的trustmanager(sslpoke使用)和我见过的其他任何一个都不重要。在用作信任库的密钥库中,必须有正确的证书(其中必须包含正确的cn),但别名并不重要。由于很难理解并且不可能复制系统上存在的内容,下面是一个aws ec2 t2.micro示例的从头开始的日志,该示例使用amazon linux 2 ami-0a0ad6b70e61be944,以及可用于该系统的openjdk 11,即amazon corretto,任何人都应该能够复制它。
第1部分--无法使用默认cacerts进行验证
第2部分——使用openssl获取根证书
第三部分——修改和使用cacerts;别名可以是任何东西
第4部分——使用自己的(自定义)密钥库;同上
ps:验证程序端(通常是服务器端)使用的密钥管理器是不同的。默认的keymanager不使用别名,但我见过很多其他的使用别名,最著名的是tomcat。在这些情况下,别名必须与配置相匹配,而不是cn或证书中的任何其他数据。