Eclipse unable to find valid certification path to requested target

时间:2019-03-17 22:56:12

标签: java javamail keystore

I am attempting to send an email via smtp to smtp.mailgun.org. I am not concerned about the java code that is attempting to send the email.

Environment:

Windows 10 Eclipse Photon Java 1.8.0_191 java package: com.sun.mail.javax.mail:1.6.2

I am trying to send through 587 using TLS. I don't have much experience creating or modifying keystores.

In the eclipse.ini, I added the following two arguments after the -vmargs

-Djavax.net.ssl.trustStore="C:/Program Files/Java/jdk1.8.0_192/jre/lib/security/cacerts "

-Djavax.net.ssl.trustStorePassword="password"

I restarted Eclipse and am continuing to get the error below.

javax.mail.MessagingException: Could not convert socket to TLS;
      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.smtp.SMTPTransport.startTLS(SMTPTransport.java:1652)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:534)
        at javax.mail.Service.connect(Service.java:291)
        at javax.mail.Service.connect(Service.java:172)
        at com.mako.mg.manager.MakoMailGunSmtpManager.sendEmail(MakoMailGunSmtpManager.java:158)
        at com.mako.mg.manager.MakoMailGunSmtpManager.main(MakoMailGunSmtpManager.java:180)
    Caused by: 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 sun.security.ssl.Alerts.getSSLException(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
        at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
        at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
        at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
        at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
        at sun.security.ssl.Handshaker.processLoop(Unknown Source)
        at sun.security.ssl.Handshaker.process_record(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
        at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:503)
        at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:443)
        at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1647)
        ... 5 more
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
        at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
        at sun.security.validator.Validator.validate(Unknown Source)
        at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
        ... 16 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
        at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
        at java.security.cert.CertPathBuilder.build(Unknown Source)
        ... 22 more

Is my Eclipse having a problem using the cacerts? or do I need to create a keystore from the cacerts?

I cannot find c:\users\<myuser>\.keystore. I am configured to view hidden files and folders.

Thank you for your help with this issue.

2 个答案:

答案 0 :(得分:1)

我添加了 -Djavax.net.debug = ssl 并仔细检查了失败之前的步骤。我发现我的防病毒程序造成了故障并导致了故障。关闭防病毒软件进行测试,电子邮件已成功发送。

在AVG网站上找到包含以下步骤的链接

  

打开AVG Antivirus,单击菜单->设置->组件->电子邮件   扫描仪->自定义。请在下一个窗口的“主要设置”下   禁用“扫描出站电子邮件”,并告诉我们是否可以解决   问题。

答案 1 :(得分:0)

以下为我工作:

打开AVG Antivirus,单击菜单->设置->组件->电子邮件扫描程序->自定义。在“主要设置”下的下一个窗口中,请禁用“扫描出站电子邮件”,并告诉我们是否可以解决问题。