对于愿意进行本地配置更改的用户(包括备份配置文件)的详细解答:
1.在更改之前测试它是否正常工作
如果您还没有测试程序,则可以使用我的java SSLPing ping程序来测试TLS握手(它将与任何SSL / TLS端口一起使用,而不仅仅是HTTPS)。我将使用预构建的SSLPing.jar,但是阅读代码并自己构建它是一项快速而轻松的任务:
$ git clone https://github.com/dimalinux/SSLPing.git
Cloning into 'SSLPing'...
[... output snipped ...]
由于我的Java版本早于1.8.0_101(在撰写本文时尚未发布),因此默认情况下不会验证Let's Encrypt证书。在应用此修复程序之前,让我们看看失败是什么样的:
$ java -jar SSLPing/dist/SSLPing.jar helloworld.letsencrypt.org 443
About to connect to 'helloworld.letsencrypt.org' on port 443
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
[... output snipped ...]
2.导入证书
我在设置了JAVA_HOME环境变量的Mac OS X上。以后的命令将假定为您要修改的Java安装设置了此变量:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/
对我们将要修改的cacerts文件进行备份,这样您就可以撤消所有更改,而无需重新安装JDK:
$ sudo cp -a $JAVA_HOME/jre/lib/security/cacerts $JAVA_HOME/jre/lib/security/cacerts.orig
下载我们需要导入的签名证书:
$ wget https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.der
执行导入:
$ sudo keytool -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit -noprompt -importcert -alias lets-encrypt-x3-cross-signed -file lets-encrypt-x3-cross-signed.der
Certificate was added to keystore
3.更改后验证其是否正常运行
验证Java现在是否愿意连接到SSL端口:
$ java -jar SSLPing/dist/SSLPing.jar helloworld.letsencrypt.org 443
About to connect to 'helloworld.letsencrypt.org' on port 443
Successfully connected