Java7拒绝在信任存储信任证书Java7拒绝在信任存储信任证书(Java7 Refusing to

2019-06-02 17:54发布

我有一个奇怪的问题 - 供应商使用TLS的SSLv3既具有自签名的客户端和服务器证书。 这尚未与Java1.5的和Java1.6的一个问题 - 简单地导入客户端证书和私钥到密钥库和服务器公共证书到信任。 一切工作正常。 然而,随着Java7服务器证书失败,即使正在使用相同的信任被信任。 我试过Windows和Red Hat都使用Java7(03年7月1日,04和05,x86和x64版本),但没有成功。

我重新从头密钥库/信任,他们只包含这些证书。 适当的系统属性已被置位(javax.net.ssl.keyStore,javax.net.ssl.trustStore中)和关键方面是完全相同的代码和配置完全运行在JDK5 / 6。

我茫然 - 我无法找到额外的检查任何引用,但我会认为事实证书位于信任库应该意味着它无论是自签名的信任。

任何帮助表示赞赏。 广告

异常跟踪:

Exception in thread "main" javax.net.ssl.SSLHandshakeException:     sun.security.validator.ValidatorException: PKIX path validation failed:     java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1868)
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:1338)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154)
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:998)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:685)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:111)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at com.alltria.ypsilon.testing.TestSSL.main(TestSSL.java:65)
Caused by: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.validator.PKIXValidator.doValidate(PKIXValidator.java:350)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:249)
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:1320)
... 13 more
Caused by: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
at sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(PKIXCertPathValidator.java:208)
at java.security.cert.CertPathValidator.validate(CertPathValidator.java:279)
at sun.security.validator.PKIXValidator.doValidate(PKIXValidator.java:345)
... 19 more
Java Result: 1

在SSL调试失败,部分试图验证服务器证书:

***
%% Invalidated:  [Session-1, SSL_RSA_WITH_RC4_128_SHA]
main, SEND SSLv3 ALERT:  fatal, description = certificate_unknown
main, WRITE: SSLv3 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 00 00 02 02 2E                               .......
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
main, called close()
main, called closeInternal(true)

Answer 1:

其实我有一个有点类似的问题,在使用Java 1.6,当一个Tomcat应用程序将信任CA证书的信任,并与Java 1.7拒绝它。 加入后keyUsage到它的工作原理我的CA证书(阅读bug报告后, JDK-7018897:证书路径验证不能处理不好密钥使用自签名证书 )。

我做了什么(Ubuntu的12.04 64):

  1. 编辑/etc/ssl/openssl.cnf文件,并取消keyUsage符合v3_ca部分。
  2. 生成旧新CA证书具有keyUsage使用下面的命令包括:

     openssl x509 -in oldca.pem -clrext -signkey oldca.key -extfile /etc/ssl/openssl.cnf -extensions v3_ca -out newca.pem 
  3. 从信任删除旧的CA密钥并插入新的。



Answer 2:

在JDK 1.7打交道时,我也遇到过这种情况。 如果REQ命令与-x509选项调用,这是更好地取消注释的keyUsage线v3_ca部分并生成再次与CA(见http://wwwneu.secit.at/web/documentation/openssl/openssl_cnf.html )

openssl req -new -x509 -days 3650 -keyout ca.key -out ca.crt -config openssl.cnf -extensions v3_ca -batch

如果你使用生成的CA证书签署其它证书,请确保您还要取消该项目basicConstraints = CA:true和值设置为true



Answer 3:

对于一些原因的Java 8不接受自签名的证书,甚至加入到它的cacerts商店。

我针对的解决方法是创建一个自定义密钥库:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj "/C=MA/ST=ByExample/L=Test/O=Chapter3/OU=Org/CN=bip70.com" -node小号

keytool -import -keystore clientkeystore -file cert.der -alias bip70.com -storepass changeit

然后使用作为JVM参数使用它在我的IDE: -Djavax.net.ssl.trustStore=clientkeystore



文章来源: Java7 Refusing to trust certificate in trust store