我需要支持客户端和服务器之间的相互身份验证。到目前为止,单向身份验证正在运行,即我们能够针对存储在信任存储中的CA证书验证证书。
对于相互身份验证,我执行了以下步骤:
我在keystore位置安装了此客户端证书,该位置与使用以下命令的信任存储区别不同 sudo / usr / java / default / bin / keytool -import -alias $ file_name -file $ file_name.crt -keystore keystore.jks -storepass changeit -noprompt
我创建了SSLContext,如下所示 sslContext.init(keyManagers,trustStore,NULL_SECURE_RANDOM);
现在我们正在尝试从客户端与服务器通信,我正在收到握手失败错误
<HASH_VALUE>
main, READ: TLSv1.2 Handshake, length = 333
*** ECDH ServerKeyExchange
Signature Algorithm SHA512withRSA
Server key: Sun EC public key, 256 bits
public x coord: 10253619320081805931384466854469954543531656069378199159702043393618555071374
public y coord: 88104986257121586743271984238217759117375506314354198659212202676684306616776
parameters: secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)
[read] MD5 and SHA1 hashes: len = 333
main, READ: TLSv1.2 Handshake, length = 453
*** CertificateRequest
Cert Types: ECDSA, RSA, DSS
Supported Signature Algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA224withECDSA, SHA224withRSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
Cert Authorities:
<O=saurav, OU=xxx, C=IN, CN=XX_CA>
<O=saurav, OU=xxx, C=IN, CN=YY_CA>
<O=saurav, OU=xxx, C=IN, CN=ZZ_CA>
<O=saurav, OU=xxx, C=IN, CN=XX_CA>
<O=saurav, OU=xxx, C=IN, CN=YY_CA>
....
main, READ: TLSv1.2 Handshake, length = 4
*** ServerHelloDone
[read] MD5 and SHA1 hashes: len = 4
0000: 0E 00 00 00 ....
Warning: no suitable certificate found - continuing without client authentication
*** Certificate chain
<Empty>
***
*** ECDHClientKeyExchange
ECDH Public value: {.... }
[write] MD5 and SHA1 hashes: len = 77
main, WRITE: TLSv1.2 Handshake, length = 77
.1
INSSION KEYGEN:
PreMaster Secret:
0000: A2 ED 45 23 FE D5 CF 02 49 B2 28 1F 37 1A C6 EA ..E#....I.(.7...
0010: CF DE E7 E8 11 A5 2F 2D 1F CE 89 B4 BE D3 D3 92 ....../-........
CONNECTION KEYGEN:
Client Nonce:
0000: 5A F4 46 1C A1 65 28 10 49 E5 8A 47 8C 10 AD 98 Z.F..e(.I..G....
0010: 21 BA 57 20 DC 48 C2 84 B0 C9 FD 14 B3 41 0B 21 !.W .H.......A.!
Server Nonce:
0000: 5A F4 46 1D 0A 7D AA 8D E3 EE 0B 16 9A 20 D2 00 Z.F.......... ..
0010: DD 60 36 0C C3 8D 96 1B 94 24 E5 AB 7A C1 D7 14 .`6......$..z...
Master Secret:
0000: BA 3E FF B8 EB 4B 5E 70 0F 07 B9 00 F1 10 DD B6 .>...K^p........
0010: DF AC 69 87 21 B1 BE CD 5E 97 96 55 E4 4C 41 B3 ..i.!...^..U.LA.
0020: C8 0B FC 2E 4B 08 65 82 82 9A A6 0F AE 39 41 0E ....K.e......9A.
Client MAC write INcret:
0000: 77 34 7D 71 F5 5E 15 8E 14 0B BA A9 C0 11 15 A0 w4.q.^..........
0010: C1 AA B1 05 3A F0 87 1F 96 EC E0 19 AE 78 39 1B ....:........x9.
Server MAC write Secret:
0000: F7 CB D9 B4 53 D8 8E 37 25 3A E9 1D 1A D9 CB 3D ....S..7%:.....=
0010: 80 52 D5 D2 7C 66 AB 99 16 9E D7 EA CE 1F 6F 00 .R...f........o.
Client write key:
0000: 69 FD 1A C3 30 D3 0D 72 37 7F 43 4A A9 20 D5 4B i...0..r7.CJ. .K
Server write key:
0000: 86 C9 46 E0 D7 99 A9 24 3F 50 DA 26 C9 0B D8 26 ..F....$?P.&...&
... no IV derived for this protocol
main, WRITE: TLSv1.2 Change Cipher Spec, length = 1
[Raw write]: length = 6
0000: 14 03 03 00 01 01 ......
*** Finished
verify_data: { 104, 207, 194, 200, 118, 209, 56, 63, 206, 199, 95, 238 }
***
[write] MD5 and SHA1 hashes: len = 16
..
main, WRITE: TLSv1.2 Handshake, length = 80
main, waiting for close_notify or alert: state 1
[Raw read]: length = 5
0000: 15 03 03 00 02 .....
[Raw read]: length = 2
0000: 02 28 .(
main, READ: TLSv1.2 Alert, length = 2
main, RECV TLSv1.2 ALERT: fatal, handshake_failure
%% Invalidated: [INssion-1, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256]
main, called closeSocket()
main, Exception while waiting for close javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
May 10, 2018 1:16:12 PM com.saurav.kumar.rest.impl.RestEasyClient sendRequest
INVERE: Error sending request
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2038)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1135)
答案 0 :(得分:0)
我的实施存在两个问题。
sudo /usr/java/default/bin/keytool -import -alias $file_name -file $file_name.crt -keystore keystore.jks -storepass changeit -noprompt
&#34;将证书安装到其中。当我尝试安装客户端证书时,它没有安装整个证书链。它不是整个证书链,而是在没有任何CA证书的情况下为我的应用程序安装证书,这就是客户端没有发送证书的原因,如下面的日志所示Warning: no suitable certificate found - continuing without client authentication *** Certificate chain <Empty> ***
org.apache.http.conn.ssl.StrictHostnameVerifier
类的IPv6验证的支持。我需要覆盖这个类,以便它能够正确处理IPv6地址并验证它。SEVERE:发送请求时出错 javax.net.ssl.SSLPeerUnverifiedException:主机名&#39; [IPv6-IP]&#39;不 与同行提供的证书主题不匹配 (CN_name_of_cert) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:465) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:395) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141) 在org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)