我有一个在Dropwizard上运行的服务器(即为其Web服务器运行Jetty).我正在尝试为它设置SSL.
我有一个由CA签署的证书(特别是Comodo,通过Namecheap).我安装了根证书和中间证书,然后安装了我自己的证书(使用Comodo支持的说明.但是,当我第一次尝试连接到我的服务器时(它启动正常),我收到一个错误:( sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
当然堆栈跟踪更长,但这是根本原因.)
我已经尝试过搜索这个错误,并且一直有人说这应该只发生在自签名证书上,而我的证书不是.尽管如此,我尝试下载InstallCert.java程序,该程序似乎源自Sun博客上的一篇(现已删除)文章.具体来说,我从这个页面获得了学位.
在几次(失败的)尝试通过命令行使其工作(这是另一次的讨论)后,我最终让它运行正常.现在我从程序得到的输出是:
Loading KeyStore C:\Program Files\Java\jdk1.8.0_05\jre\lib\security\cacerts... Opening connection to localhost:8443... Starting SSL handshake... Exception in thread "main" java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:150) at java.net.SocketInputStream.read(SocketInputStream.java:121) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355) at com.aw.ad.util.InstallCert.main(InstallCert.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) Process finished with exit code 1
同时,如果我用我的网站打开窗口,它会再次传递unable to find valid certification path to requested target
错误并崩溃(从而导致超时).实质上,在我看来,由于SSL问题,InstallCerts(应该修复我的SSL问题)导致我的服务器崩溃.
如果我尝试使用类似的东西openssl s_client -connect localhost:8443 -showcerts
(这是我在某处看到的建议,将结果保存到.pem文件并安装),同样的事情发生了.
这个问题有解决方案吗?我错过了一些明显的东西吗?
您可能错过了从Comodo根CA到您站点的证书的整个证书链.检查您在Dropwizard中配置的密钥库,看看是否全部拥有它们.最简单的方法是查找证书的颁发者,您需要拥有相同主题的证书,然后查找该证书的颁发者等等.确保尝试使用发行方的密钥指纹(密钥标识符)和发行方的发行方链接您的证书的授权密钥标识符证书扩展.如果你提供
keytool -list -keystore <your keystore> -rfc
我或许可以帮你更多......
后来添加:
我设法完全重现了你的问题.TL; DR; 加:
validateCerts: true trustStorePath: lyonesgamer.com.keystore enableCRLDP: true
我创建了一个包含链(单个条目,3个证书,ca,从属ca和最终实体证书)的密钥库,以及另一个仅包含两个ca证书作为可信条目的密钥库.然后我配置了keyStorePath
,keyStorePassword
,trustStorePath
和validateCerts: true
.
这导致:
java.security.cert.CertificateException: Unable to validate certificate: unable to find valid certification path to requested target
添加后-Djava.security.debug=certpath
我发现撤销检查失败了,这实际上是证书链失败的根本原因:
certpath: SunCertPathBuilder.depthFirstSearchForward(): validation failed: java.security.cert.CertPathValidatorException: Could not determine revocation status
然后我记得如果你没有为CertPath API启用CRL Distribution Point扩展使用,你需要自己指定CRL.幸运的是,Dropwizard可以选择启用CRLDP : enableCRLDP: true
. 启用它后,应用程序成功启动.
或者,您可以将CRL保存在文件中并指向crlPath
它.