我正在尝试使用MySQL Connector/J(版本5.1.45)和此AWS RDS证书在Java中与我的MySQL database建立SSL连接: s3.amazonaws/rds-downloads/rds-combined-ca-bundle.pem
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: s3.amazonaws/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.
我该如何解决?
推荐答案经过很多头痛之后,我解决了这个问题.信任库需要具有该链的所有证书,我正在使用 s3.amazonaws/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 s3.amazonaws/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异常:路径不与任何信任锚链接
发布评论