【发布时间】:2020-03-30 15:57:22
【问题描述】:
我正在尝试在测试环境中将我的 Java 应用程序连接到 993 上的 IMAP 服务器邮件。
我正在尝试忽略证书验证,使用之前对类似问题的答案的建议,如下所示:
imapProps.put("mail.imaps.ssl.checkserveridentity", "false");
imapProps.put("mail.imaps.ssl.trust", "*");
但它似乎不起作用,我仍然遇到异常。
Cannot process current mailbox => sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;
nested exception is:
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
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:727)
所以我的问题是,是否真的可以使用 IMAPS 协议连接到邮件服务器,而无需检查或验证证书?
如果是,那么选择忽略证书验证不是双方的决定吗? JavaApp 和邮件服务器?
【问题讨论】:
-
规则 1:选择忽略验证与根本不使用 SSL 一样糟糕。修复它会更好(例如,通过将私有证书或信任锚导入客户端存储,或适当地配置 SSLContext)。
-
什么版本的JavaMail?您确定您使用的是“imap”协议而不是“imap”协议吗?调用 getStore 时使用什么协议名称?
-
您不能简单地忽略证书验证。你可以做的是写一个TrustManager that accepts what you want。那会奏效的。我使用 147 行代码来做一些类似的事情。但先问问自己:你是想写一百行左右的代码什么都不做,还是要检查证书?
-
正如我在帖子中提到的,这是一个测试环境,我只能控制 java 应用程序,但不能控制邮件服务器。 @Bill Shannon 我正在使用 Javamail 1.5.5,我使用 imap 来调用 getStore。
-
@BillShannon,您的提示实际上解决了我的问题,我在 get Store 中使用了“imap”,而在 imapProps 中使用了“imap”。如果您不介意添加您的评论作为答案,以获得更好的可见性。谢谢
标签: ssl certificate jakarta-mail imap