简体   繁体   English

我真的需要手动将SSL证书导入Java密钥库吗?

[英]Do I Really Need to Import a SSL Cert into Java Keystore Manually?

I have a Java web app that has been running fine for several months. 我有一个运行了几个月的Java Web应用程序。 It integrates with the Box API ( https://upload.box.com/api/2.0 ) to save files to the cloud service. 它与Box API( https://upload.box.com/api/2.0 )集成,以将文件保存到云服务。 Out of the blue, we started receiving the dreaded javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated exception while trying to make a REST API call to the Box web service. 突然,我们开始收到可怕的javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated在尝试对Box Web服务进行REST API调用时, javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

There are tons of posts out there that tell you how to manually import the cert into your key store using the keytool utility. 那里有大量帖子,告诉您如何使用keytool实用程序将证书手动导入到密钥库中。 I understand that I can do this to fix the problem. 我知道我可以这样做来解决问题。 But is this really the correct fix? 但这真的是正确的解决方法吗?

The fact that my application has been running fine for months leads me to believe something in the certificate at https://upload.box.com changed. 我的应用程序可以正常运行几个月的事实使我相信https://upload.box.com证书中的某些内容已更改。 Looking at the cert in my web browser, the certificate seems valid and was only renewed a few weeks ago. 在我的Web浏览器中查看该证书,该证书似乎有效,并且仅在几周前进行了更新。 What is missing from my keystore? 我的密钥库缺少什么?

Is it the Root CA certificate that is missing from my keystore? 我的密钥库中缺少根CA证书吗? If that is the case, could I just copy the cacerts file from newer version of Java? 如果是这样,我可以从较新版本的Java复制cacerts文件吗? My app is currently running JDK 1.6.0_33. 我的应用程序当前正在运行JDK 1.6.0_33。

I am just trying to understand why this would suddenly stop working and what the "real" fix should be. 我只是想了解为什么这会突然停止工作,以及“真正的”修复应该是什么。 It doesn't seem like modifying the JDK keystore is the correct thing to do. 修改JDK密钥库似乎不是正确的事情。

I'll just assume you're using Apache HTTP Client 4.x, before 4.2.6, 4.3 Beta2 , in which case javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated is most likely to come from a certificate that isn't trusted (otherwise it means the server didn't send a cert, which is a different problem, more details in this answer ). 我只是假设您在4.2.6、4.3 Beta2之前使用Apache HTTP Client 4.x,在这种情况下, javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated很可能来自未通过认证的证书信任(否则意味着服务器未发送证书,这是一个不同的问题, 有关此答案的更多详细信息 )。

The current cert for server you're trying to access seems to have been issued on 07/04/2014, so this indicates that the certificate, and perhaps its chain has changed recently indeed. 您尝试访问的服务器的当前证书似乎已于2014年4月4日发布,因此这表明该证书及其链实际上最近已更改。

I don't have a JDK 1.6.0_33 at hand, but it's possible that some of these CA certs were not part of the default bundle. 我手头没有JDK 1.6.0_33,但是其中某些CA证书可能不是默认捆绑包的一部分。 In any case, it's worth updating cacerts , even on older JREs (if only to remove CA certs that should no longer be trusted, for example). 无论如何,即使在较旧的JRE上,也值得更新cacerts (例如,如果仅是删除不再受信任的CA证书)。 The JSSE Reference Guide clearly states (admittedly in the middle of a fairly long document, but it's worth searching for "important note"...): JSSE参考指南明确指出(当然,在相当长的文档中间,但是值得搜索“重要说明” ...):

IMPORTANT NOTE: The JDK ships with a limited number of trusted root certificates in the <java-home>/lib/security/cacerts file. 重要说明:JDK在<java-home>/lib/security/cacerts文件中随附了数量有限的受信任的根证书。 As documented in keytool, it is your responsibility to maintain (that is, add/remove) the certificates contained in this file if you use this file as a truststore. 如keytool中所述,如果您将此文件用作信任库,则有责任维护(即添加/删除)此文件中包含的证书。

Depending on the certificate configuration of the servers you contact, you may need to add additional root certificate(s). 根据您联系的服务器的证书配置,您可能需要添加其他根证书。 Obtain the needed specific root certificate(s) from the appropriate vendor. 从适当的供应商处获取所需的特定根证书。

If you can't upgrade your JRE (Java 6 is in general out of support), updating the cacerts file from a more recent version is certainly a sensible compromise. 如果您无法升级JRE(通常不支持Java 6),那么从较新的版本更新cacerts文件肯定是明智的选择。

Besides the various fixes in Java 7, Java 7+ would also allow you to connect to hosts that require SNI (although this doesn't seem to be the case for this particular host). 除了Java 7中的各种修复程序之外,Java 7+还允许您连接到需要SNI的主机(尽管对于特定的主机似乎并非如此)。

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

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