【发布时间】:2013-06-26 16:09:45
【问题描述】:
我在尝试连接到服务器的 SMTP 邮件服务器的服务器上有一个 java 方法,但我收到了这个错误:
stack trace: org.apache.commons.mail.EmailException: Sending the email
to the following server failed : mail.mycompanyname.com:465
检索完整的堆栈跟踪后,我注意到以下行,它重复了 3 次/尝试:
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
服务器在 Apache 服务器上安装了证书。但是,我使用 GlassFish 作为访问 java 方法的 Web 应用程序(在客户端)的应用程序服务器,而 GlassFish 位于 Apache Server 之后。我没有针对此证书在 GlassFish 上进行任何调整。
我看到了一些其他类似的问题和答案,例如这里,但我不明白如何实现它:
PKIX path building failed: unable to find valid certification path to requested target
另外,还有这个,但我不知道如何在我的情况下使用它,如果合适的话:
Unable to find valid certification path to requested target - error even after cert imported
所以我的问题是,从 Java 的角度来看,我需要做什么才能清除此错误?
我是否只需要创建一个属性文件,如下所示?:
Which is the default location for keystore/truststore of Java applications?
或者,我是否还需要设置 TrustStore?
我需要在 GlassFish 上设置什么吗?
希望有人可以帮助我了解这里的基础知识。提前感谢任何 cmets。
更新:
好的,终于在下面 Hiro2K 的出色帮助下搞定了。所缺少的只是将 Apache Webserver 的 SMTP 邮件服务器使用的证书导入 GlassFish。 Hiro2k 下面的命令运行良好,但我的麻烦是找到正确的证书。
使用WHM,我可以看到邮件服务器,在我的例子中是Exim,引用了host1.mycompany.com,所以我自然选择了自签名的认证名称host1.mycompany.com.crt。但是,此证书已过期,因此无法使用。我必须进入 Exim 的配置文件以找到其名为 exim.crt 的证书,并将该证书导入 GlassFish。然后它起作用了。
请注意,服务器上还有很多证书,包括 imap(例如 imapd.pem)和 pop3(pop3.pem)等。非常混乱。
【问题讨论】:
标签: java ssl glassfish ssl-certificate keystore