Java上的SSL异常:路径不与任何信任锚链接 [英] SSL Exception on Java: Path does not chain with any of the trust anchors
问题描述
我正在尝试使用MySQL Connector/J
(版本5.1.45
)和此AWS RDS
证书在Java
中与我的MySQL
database
建立SSL连接:
I am trying to establish a SSL connection with my MySQL
database
in Java
using MySQL Connector/J
(version 5.1.45
) and this AWS RDS
certificate here: https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
但是我得到以下Exception
:
java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
我可以将此异常追溯到line 297
上的MySQL Connector/J
类ExportControlled.java
:
I could trace this Exception down to the MySQL Connector/J
class ExportControlled.java
on line 297
:
CertPathValidatorResult result = this.validator.validate(certPath, this.validatorParams);
然后我就不能再深入了,因为它属于JRE
安全类,例如CertPathValidator
.
Then I can't go further down since this goes into the JRE
security classes, like CertPathValidator
.
由于我正在使用MySQL Connector/J
来完成整个SSL
魔术,所以我的双手被绑住了,我不知道发生了什么或如何解决此问题.该证书可以在MySQL Workbench
和Intelli J IDEA Database
上正常工作,所以我不知道为什么现在拒绝该证书.
Since I am using MySQL Connector/J
to do the whole SSL
magic, my hands are tied and I don't know what's going on or how to fix this. The certificate works fine on MySQL Workbench
and on Intelli J IDEA Database
, so I have no clue why it's being rejected now.
我该如何解决?
推荐答案
经过很多头痛之后,我解决了这个问题.信任库需要具有该链的所有证书,我正在使用 https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem ,它在理论上具有所有证书,但是当您将其导入密钥库文件时,keytool
会忽略除了第一个证书以外的所有证书,因此我的密钥库中只有根证书,而实际上没有我需要的根证书和AWS区域证书.
I fixed this after A LOT of headaches. The truststore needs to have ALL the certificates of the chain, I was using https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem, which IN THEORY has all the certificates, but when you import it to a keystore file, keytool
ignores all but the first certificate, so I only had the root certificate on my keystore and not the root and the AWS Region certificate that I actually needed.
目前,尚无办法导入所有证书,我尝试了几种方法,包括转换为PKCS7(支持证书链),但是keytool
每个证书都需要一个别名,因此您需要导入每个证书,给它起一个别名,一次.
For now, there's no way to bach import all the certificates, I tried several methods, including converting to PKCS7 (which supports certificates chains), but keytool
needs one alias for each certificate so you need to import each certificate and give it an alias, one at the time.
您可以编写一个程序来一次调用keytool
并一次加载一个证书,或者像我以前那样更懒惰,并使用 KeyStore Explorer .您将需要选择创建一个新的密钥库文件,并使用Examine File
选项打开捆绑的pem
证书,并为该证书上的每个证书选择import
,这会将所选证书导入到新的密钥库中.最后,您只需要为密钥库文件定义一个密码并保存即可.
You could make a program to call keytool
and load one certificate at a time or you could be a bit more lazy as I was and use KeyStore Explorer. You will need to select to create a new keystore file and open the bundled pem
certificate using the Examine File
option and for each certificate on it, select import
, this will import the selected certificate to the new keystore. At the end you just have to define a password for your keystore file and save it.
这篇关于Java上的SSL异常:路径不与任何信任锚链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!