我尝试使用自签名证书通过带有ssl的imap获取电子邮件,但这不起作用。当我尝试连接时,我得到“PKIX路径验证失败”异常。我已经将我的证书添加到java keystore中,并在代码中设置了相关属性,但我不确定这是否足够。我的情况有一些细节:
我创建了自己的密钥库,并使用keytool命令将此证书导入其中:
keytool -import -trustcacerts -alias root -file mycert.crt -keystore C:\Users\me\Desktop\keystore.jks
System.setProperty("javax.net.ssl.keyStore", "C:/Users/me/Desktop/keystore.jks");
System.setProperty("javax.net.ssl.trustStore", "C:/Users/me/Desktop/keystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "123456");
System.setProperty("javax.net.ssl.keyStorePassword", "123456");
Message[] emails;
Folder folder = null;
Store store = null;
try {
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
store = session.getStore("imaps");
store.connect(host,login, password);
folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
emails = folder.getMessages();
System.out.println("You've got: "+emails.length+" emails");
} catch (Exception e) {
e.printStackTrace();
}
finally {
if (folder != null)
folder.close(false);
if (store != null)
store.close();
}
javax.mail.MessagingException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: unrecognized critical extension(s);
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: unrecognized critical extension(s)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:674)
at javax.mail.Service.connect(Service.java:345)
at javax.mail.Service.connect(Service.java:226)
at Mail.checkMailBox(Mail.java:69)
at Mail.main(Mail.java:99)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: unrecognized critical extension(s)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1886)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:270)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:333)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:116)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:115)
at com.sun.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:689)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:638)
... 4 more
Caused by: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: unrecognized critical extension(s)
at sun.security.validator.PKIXValidator.doValidate(PKIXValidator.java:350)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:260)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:326)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1323)
... 18 more
Caused by: java.security.cert.CertPathValidatorException: unrecognized critical extension(s)
at sun.security.provider.certpath.PKIXMasterCertPathValidator.validate(PKIXMasterCertPathValidator.java:192)
at sun.security.provider.certpath.PKIXCertPathValidator.doValidate(PKIXCertPathValidator.java:351)
at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(PKIXCertPathValidator.java:191)
at java.security.cert.CertPathValidator.validate(CertPathValidator.java:279)
at sun.security.validator.PKIXValidator.doValidate(PKIXValidator.java:345)
... 24 more
在我的代码中是否还有我需要的东西,或者我的证书有什么问题?造成这个问题的原因是什么?请帮帮忙。
你好,阿图尔
我看不出你做错了什么,但你可能想试试这里描述的程序。请参阅JavaMail FAQ条目,并提供更多建议。
在使用IDEA Ultimate创建/克隆Spring项目时,我总是得到PKIX路径验证失败:Java . security . cert . certpathvalidatorexception:有效性检查失败 这是完整的错误消息 我似乎找不到与此问题相关的答案,那里有很多PKIX路径验证失败,但我似乎找不到我的问题的解决方案。
我刚刚为我们的域名购买了一个新的通配符ssl证书,因为我们的旧证书即将到期。我已经将它安装在我们的cas服务器和应用服务器上,但是我在我们的应用服务器上得到以下堆栈跟踪: 两个服务器上的证书是相同的。
我有一个类,它用一个xml点击一个安全的URL(以https开头),然后在最后处理xml并返回响应。但在这样做的同时,我也遇到了一些例外<代码>javax。网ssl。例外:太阳。安全验证器。ValidatorException:PKIX路径生成失败:sun。安全供应商。certpath。SunCertPathBuilderException:找不到请求目标的有效认证路径 我在谷歌上搜索了很多,找到
我正在获取javax.net.ssl.sslHandShakeException:Sun.Security.Validator.ValidatorException:PKIX路径构建失败:Sun.Security.Provider.CertPath.SunCertPathBuilderException:找不到请求目标的有效认证路径异常,如何解决?这是我的密钥库
问题内容: 我正在与一个名为CommWeb的商户帐户集成,并向其URL(https://migs.mastercard.com.au/vpcdps)发送一个SSL帖子。当我尝试发送帖子时,出现以下异常: 执行该帖子的代码(我没有写过,并且已经存在于我们的代码库中)是: 商户帐户集成的文档对证书一无所知。他们确实提供了一些似乎盲目接受证书的示例JSP代码: 我们的Web应用程序有一个密钥库,我尝试使
我正在使用eclipse,在尝试执行此函数时,出现了以下错误。 我想发送一个GET请求以及证书和密钥。我可以下载任何格式的证书,所以这不是问题。我知道我需要将此添加到java keystone中,但在尝试了各种建议后,我仍然无法修复此问题。 下面是错误-