JDK 导入 CA 证书

1
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

导致这个错误的原因是没有有效的证书,因此导入相应的证书就可以正常访问了。

证书可以通过网站 -> Certificate -> Details -> Export 获取。

  1. 导入证书
1
keytool -import -keystore ~/Opt/jdk1.8.0_181/jre/lib/security/cacerts -alias ca -storepass changeit -keypass changeit -file ~/Downloads/ca.crt
  1. 删除证书
1
keytool -delete -keystore ~/Opt/jdk1.8.0_181/jre/lib/security/cacerts -alias ca -storepass changeit
  1. 查看证书
1
keytool -list -keystore ~/Opt/jdk1.8.0_181/jre/lib/security/cacerts -alias ca