ValidatorException: 在 java 中找不到受信任的证书
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10749803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ValidatorException: No trusted certificate found in java
提问by AppDeveloperIOS
When trying Apple push notifications from a Java server using a p12 file, I get an error. Is there a problem with my p12 file or my Java code?
使用 p12 文件从 Java 服务器尝试 Apple 推送通知时,出现错误。我的 p12 文件或 Java 代码有问题吗?
run:
@:theodore nonis
C=IN, CN=Apple Development IOS Push Services: com.ducont.myPushApp, UID=com.ducont.myPushApp
theodore nonis
ok
init Stores...
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1591)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:975)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:123)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1107)
at javatest.Main.APNSender(Main.java:88)
at javatest.Main.main(Main.java:114)
Caused by: sun.security.validator.ValidatorException: No trusted certificate found
at sun.security.validator.SimpleValidator.buildTrustedChain(SimpleValidator.java:304)
at sun.security.validator.SimpleValidator.engineValidate(SimpleValidator.java:107)
at sun.security.validator.Validator.validate(Validator.java:218)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:954)
... 9 more
BUILD SUCCESSFUL (total time: 2 seconds)
回答by ZhiQiang Fan
this might be caused by java 1.9, switch to java 1.8 might resolve your problem.
这可能是由 java 1.9 引起的,切换到 java 1.8 可能会解决您的问题。
回答by Deepak Jain
Try below steps for windows:
对于 Windows,请尝试以下步骤:
Download jars from here https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
从这里下载 jars https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
Copy local_policy.jar and US_export_policy.jar to the $JAVA_HOME/jre/lib/security (Note: these jars will be already there so you have to overwrite them).
将 local_policy.jar 和 US_export_policy.jar 复制到 $JAVA_HOME/jre/lib/security(注意:这些 jar 文件已经存在,因此您必须覆盖它们)。
Then restart your application to get rid of this exception.
然后重新启动您的应用程序以消除此异常。
回答by alexey28
This is certificate problem. There can be two solutions:
这是证书问题。可能有两种解决方案:
1 Use trusted certificate
1 使用可信证书
2 Disable certificate checking. For plain java code it can be done that way (read here).
2 禁用证书检查。对于普通的 Java 代码,可以通过这种方式完成(阅读此处)。
In p12 should be some possibility to set up TrustManages.
在 p12 中应该可以设置 TrustManages。