简体   繁体   English

VeriSign签名证书中的Java SSLHandshakeException

[英]Java SSLHandshakeException in VeriSign signed certificate

In a Java desktop application I need to connect to a SSL URL. 在Java桌面应用程序中,我需要连接到SSL URL。 When I try it, I get the exception: 尝试时,出现异常:

SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效证书路径

To solve it, I go to the address with my browser, download the certificate in .cert file and import in my java cacerts keystore using keytool command. 为了解决这个问题,我用浏览器转到该地址,将证书下载到.cert文件中,然后使用keytool命令导入到我的java cacerts密钥库中。 After this, the application works fine. 之后,该应用程序运行正常。

My question is: why java don't recognize the certificate if this is signed with VeriSign? 我的问题是:如果用VeriSign签名,为什么Java无法识别证书? VeriSign certificate is not installed in cacerts keystore by default? 默认情况下,cacerts密钥库中未安装VeriSign证书吗? Maybe I don't understand how SSL works. 也许我不明白SSL是如何工作的。 What's the difference between browser and java desktop behavior? 浏览器和Java桌面行为之间有什么区别? I can connect to this URL with my browser without installing nothing. 我可以使用浏览器连接到该URL,而无需进行任何安装。

Thanks 谢谢

When we access a secure site which uses SSL for providing identity and encryption, it provides a certificates which was verified by a trusted third party sites like verisign, godaddy or thwate. 当我们访问使用SSL提供身份和加密的安全站点时,它会提供由受信任的第三方站点(如verisign,godaddy或thwate)验证的证书。

By using certificates browser or java clients knows that they talking to the correct site (who it claims to be) and not on redirected proxy site. 通过使用证书,浏览器或Java客户端知道他们正在与正确的站点(据称是该站点)交谈,而不是在重定向的代理站点上交谈。 this step is pretty transparent if you access websites using browser because if certificate is not on browser's trusted store it will ask you to add that certificate and it will be subsequently added. 如果您使用浏览器访问网站,则此步骤非常透明,因为如果证书不在浏览器的受信任存储区中,它将要求您添加该证书,然后将其添加。

But when you access a secure site using Java program, this step of certificate hand shaking is not transparent to user and certificates are verified form JRE's trustStore. 但是,当您使用Java程序访问安全站点时,证书握手的这一步骤对用户而言并不透明,并且证书已通过JRE的trustStore进行了验证。

Read more: http://javarevisited.blogspot.com/2012/03/add-list-certficates-java-keystore.html#ixzz32v1wL3Gl 了解更多: http : //javarevisited.blogspot.com/2012/03/add-list-certficates-java-keystore.html#ixzz32v1wL3Gl

You did not say which certificate you imported into the keystore. 您没有说要导入密钥库的证书。 Usually there are several certificates involved in the verification: 通常,验证涉及多个证书:

  • the trusted root certificate, which is stored in the keystore or browser (Java does not share the keystore with the browser) 受信任的根证书,该证书存储在密钥库或浏览器中(Java不与浏览器共享密钥库)
  • the leaf certificate which identifies the site 标识站点的叶子证书
  • and most times also intermediate certificates, which provide a signed way from the leaf certificate to the trusted root and thus establish a trusted path 多数情况下还提供中间证书,这些证书提供了从叶证书到受信任根的签名方式,从而建立了受信任路径

If any of the intermediate certificates is missing, the verification fails. 如果缺少任何中间证书,则验证失败。 So the server has to send not only the leaf certificate, but all intermediate certificates too. 因此,服务器不仅必须发送叶证书,还必须发送所有中间证书。 And this is where lots of sites fail, eg they don't provide the full certificate chain. 这就是许多站点失败的地方,例如,它们不提供完整的证书链。

But why does this work in the browser? 但是,为什么这在浏览器中有效呢? Because enough sites fail to provide the intermediate certificates and because the browser wants to provide the best experience, they will cache the intermediate certificates. 由于足够多的站点无法提供中间证书,并且由于浏览器希望提供最佳体验,因此它们将缓存中间证书。 Thus, if you go to one site signed by verisign which provides the trusted chain, and then go to another site signed with the same certificate, but which does not provide the chain, then it will still work, because the chain certificates are cached from the other side. 因此,如果您转到由提供了受信任链的verisign签名的一个站点,然后再转到使用相同证书但未提供该链的站点签名,则该站点仍将起作用,因为链证书是从另一边。

But, if you use a fresh system (or simply a new browser profile with firefox) and visit the misconfigured site first, it will complain there too, as much as the Java application did. 但是,如果您使用的是全新系统(或者只是使用Firefox的新浏览器配置文件)并首先访问配置错误的网站,那么该网站也会像Java应用程序一样抱怨该网站。 And if you just import the relevant intermediate certificate into the keystore and thus trust it it will work too, because it does not need the rest of the chain to get a path to a trusted certificate. 而且,如果您只是将相关的中间证书导入密钥库中并因此信任它,那么它也将起作用,因为它不需要链的其余部分即可获取通往受信任证书的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM