ValidatorException:在java中找不到可信证书

时间:2012-05-25 06:52:04

标签: java

使用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)

3 个答案:

答案 0 :(得分:0)

这可能是由java 1.9引起的,切换到java 1.8可能会解决您的问题。

答案 1 :(得分:0)

对于Windows,请尝试以下步骤:

从这里https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

下载jar

将local_policy.jar和US_export_policy.jar复制到$ JAVA_HOME / jre / lib / security(注意:这些jar已存在,因此您必须覆盖它们)。

然后重新启动应用程序以摆脱此异常。

答案 2 :(得分:-2)

这是证书问题。可以有两种解决方案:

1使用可信证书

2禁用证书检查。对于普通的Java代码,可以这样做(read here)。

在p12中应该有可能设置TrustManages。