2010-12-06 72 views
1

我正在研究一個Web服務客戶端,它需要與啓用了雙向身份驗證的服務器進行通信。收到致命警報:unknown_ca while mutual authentication

我已經完成了以下步驟。

  1. 添加的服務器證書(自籤),以信任存儲和使用SSLSocketFactory將其設置爲HttpsURLConnection
  2. 將服務器管理員的客戶端證書(CA簽名)添加到其信任的商店。
  3. 通過導入客戶端證書並創建一個keymanager到`HttpsURLConnection'來創建密鑰庫。

當我嘗試運行此示例中,我發現了一個異常說

org.springframework.ws.soap.axiom.AxiomSoapMessageException: Could not write message to OutputStream: java.net.SocketException: Software caused connection abort: recv failed; nested exception is javax.xml.stream.XMLStreamException: java.net.SocketException: Software caused connection abort: recv failed 
     at org.springframework.ws.soap.axiom.AxiomSoapMessage.writeTo(AxiomSoapMessage.java:261) 
     at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:45) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:586) 
     at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:549) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502) 
     at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:480) 
     at test.SamlTest.request(SamlTest.java:29) 
     at test.SamlTest.main(SamlTest.java:63) 
    Caused by: javax.xml.stream.XMLStreamException: java.net.SocketException: Software caused connection abort: recv failed 
     at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeStartDocument(Unknown Source) 
     at org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:193) 
     at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:756) 
     at org.apache.axiom.soap.impl.llom.SOAPMessageImpl.internalSerialize(SOAPMessageImpl.java:71) 
     at org.apache.axiom.om.impl.llom.OMDocumentImpl.internalSerialize(OMDocumentImpl.java:324) 
     at org.apache.axiom.om.impl.llom.OMDocumentImpl.serialize(OMDocumentImpl.java:375) 
     at org.springframework.ws.soap.axiom.AxiomSoapMessage.writeTo(AxiomSoapMessage.java:252) 
     ... 7 more 
    Caused by: java.net.SocketException: Software caused connection abort: recv failed 
     at java.net.SocketInputStream.socketRead0(Native Method) 
     at java.net.SocketInputStream.read(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.InputRecord.readV3Record(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
     at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) 
     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 
     at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source) 
     at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source) 
     at org.springframework.ws.transport.http.HttpUrlConnection.getRequestOutputStream(HttpUrlConnection.java:81) 
     at org.springframework.ws.transport.AbstractSenderConnection$RequestTransportOutputStream.createOutputStream(AbstractSenderConnection.java:101) 
     at org.springframework.ws.transport.TransportOutputStream.getOutputStream(TransportOutputStream.java:41) 
     at org.springframework.ws.transport.TransportOutputStream.write(TransportOutputStream.java:64) 
     at com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.write(Unknown Source) 
     at com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.write(Unknown Source) 
     ... 14 more 

我缺少什麼?

修訂

請找到使JVM日誌

後的日誌
trigger seeding of SecureRandom 
    done seeding SecureRandom 
    %% No cached client session 
    *** ClientHello, TLSv1 
    RandomCookie: GMT: 1274794757 bytes = { 250, 192, 120, 159, 84, 244, 96, 103, 128, 221, 36, 200, 229, 95, 84, 152, 179, 202, 161, 56, 95, 161, 234, 136, 128, 52, 45, 228 } 
    Session ID: {} 
    Compression Methods: { 0 } 
    *** 
    main, WRITE: TLSv1 Handshake, length = 73 
    main, WRITE: SSLv2 client hello message, length = 98 
    main, READ: TLSv1 Handshake, length = 74 
    *** ServerHello, TLSv1 
    Cipher Suite: SSL_RSA_WITH_RC4_128_MD5 
    Compression Method: 0 
    *** 
    %% Created: [Session-1, SSL_RSA_WITH_RC4_128_MD5] 
    ** SSL_RSA_WITH_RC4_128_MD5 
    main, READ: TLSv1 Handshake, length = 976 
    *** Certificate chain 
    chain [0] = [ 
    [ 
     Version: V3 
     Subject: [email protected], [email protected], OU=MyOU, O=xyz 
     Signature Algorithm: MD5withRSA, OID = 1.2.840.113549.1.1.4 

     Key: Sun RSA public key, 1024 bits 
     public exponent: 65537 
     Validity: [From: Tue Jul 18 02:30:07 IST 2006, 
        To: Mon Jul 13 02:30:07 IST 2026] 
     Issuer: [email protected], [email protected], OU=MyOU, O=xyz 
     SerialNumber: [ ] 

    Certificate Extensions: 3 
    [1]: ObjectId: 2.5.29.14 Criticality=false 
    SubjectKeyIdentifier [ 
    KeyIdentifier [ 
    ] 
    ] 

    [2]: ObjectId: 2.5.29.35 Criticality=false 
    AuthorityKeyIdentifier [ 
    KeyIdentifier [ 
    ] 

    [[email protected], [email protected], OU=MyOU, O=xyz] 
    SerialNumber: [ ecbcae10 2ba4c279] 
    ] 

    [3]: ObjectId: 2.5.29.19 Criticality=false 
    BasicConstraints:[ 
     CA:true 
     PathLen:2147483647 
    ] 

    ] 
     Algorithm: [MD5withRSA] 
     Signature: 

    ] 
    *** 
    main, SEND TLSv1 ALERT: fatal, description = certificate_unknown 
    main, WRITE: TLSv1 Alert, length = 2 
    main, called closeSocket() 
    main, handling exception: 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 
    Exception in thread "main" 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.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) 
     at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) 
     at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) 
     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
     at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source) 
     at com.arun.test.http.TiMutualAuthClient.main(TiMutualAuthClient.java:71) 
    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 com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
     at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) 
     ... 13 more 
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 
     at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) 
     at java.security.cert.CertPathBuilder.build(Unknown Source) 
     ... 19 more 

謝謝

+0

我得到了一個類似的錯誤 - 我最終做的是從我的瀏覽器中導出自簽名密鑰,然後將其導入到可信密鑰中,詳見此問題:http://stackoverflow.com/questions/2893819/ tell-java-to-accept-self-signed-ssl-certificate – jocull 2012-06-05 20:46:25

+0

這裏仍然沒有'unknown_ca alert'。 – EJP 2017-04-19 21:41:20

回答

2

我認爲問題出在我用的客戶端證書上。它具有以下擴展名的值設置

證書密鑰用法
關鍵
簽名
不可否認
密鑰加密
數據加密

擴展密鑰用法
不嚴重
TLS Web服務器身份驗證(1.3.6.1.5.5.7.3.1)
TLS Web客戶端身份驗證(1.3.6.1.5.5.7.3.2)

一旦我創建了一個自簽名證書,沒有任何擴展和用它作爲我的客戶端證書,它工作正常。

5

客戶是否密鑰庫包含專用密鑰條目?從您的描述中不清楚。也不清楚unknown_ca來自哪裏:它不會出現在你的堆棧跟蹤中。最好使用-Djavax.net.debug = ssl來運行客戶端,握手併發布結果。

+0

感謝您的回覆..我不確定密鑰庫中的客戶機密鑰..我會檢查它並更新問題。 – 2010-12-06 08:59:44

0

您需要將認證用戶的CA的公鑰(或用戶自己的公鑰)(如果它是自己使用的自認證密鑰)放入服務器的密鑰庫中。否則,服務器根本不知道用戶的證書是真實的還是正在冒充他人的人呈現。在那裏提前獲得證書可以讓服務器瞭解身份並信任它(SSL協議要求這是防止微不足道的中間人攻擊的一部分)。

相關問題