gpt4 book ai didi

java - java 的 Finished 部分握手失败,但curl 则不然

转载 作者:行者123 更新时间:2023-12-01 17:30:49 25 4
gpt4 key购买 nike

我正在尝试使用 java 实现相互身份验证客户端。我已经使用我的客户端证书和私钥链生成了身份 keystore 。我已经使用服务器证书生成了信任 keystore 。所有握手 session 似乎都正常,但在“完成”部分我收到错误。我尝试使用 java 8 和 java 11 得到相同的结果,但是使用curl,一切正常。

...
*** Finished
verify_data: { 228, 83, 92, 58, 53, 18, 245, 6, 218, 90, 45, 85 }
***
update handshake state: finished[20]
upcoming handshake states: server change_cipher_spec[-1]
upcoming handshake states: server finished[20]
[write] MD5 and SHA1 hashes: len = 16
0000: 14 00 00 0C E4 53 5C 3A 35 12 F5 06 DA 5A 2D 55 .....S\:5....Z-U
Padded plaintext before ENCRYPTION: len = 16
0000: 14 00 00 0C E4 53 5C 3A 35 12 F5 06 DA 5A 2D 55 .....S\:5....Z-U
Thread-1, WRITE: TLSv1.2 Handshake, length = 40
[Raw write]: length = 45
0000: 16 03 03 00 28 00 00 00 00 00 00 00 00 BF F7 75 ....(..........u
0010: 39 43 10 6F 28 84 04 A2 E8 25 F4 70 F1 3E 77 7C 9C.o(....%.p.>w.
0020: 73 75 28 75 22 30 BE CA 1A 64 53 1B 12 su(u"0...dS..
[Raw read]: length = 5
0000: 15 03 03 00 02 .....
[Raw read]: length = 2
0000: 02 28 .(
Thread-1, READ: TLSv1.2 Alert, length = 2
Thread-1, RECV TLSv1.2 ALERT: fatal, handshake_failure
%% Invalidated: [Session-1, TLS_RSA_WITH_AES_128_GCM_SHA256]
Thread-1, called closeSocket()
Thread-1, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

服务已开启https://vps.integrazioneweb.com:8890/oauth/token

这里是ssl的调试信息。你能帮我理解问题吗?

handshake debug info

我还使用了 openssl s_client 并返回错误:

>>> ??? [length 0005]
14 03 03 00 01
>>> TLS 1.2 ChangeCipherSpec [length 0001]
01
write to 0x270a6f0 [0x2719770] (6 bytes => 6 (0x6))
0000 - 14 03 03 00 01 01 ......
>>> ??? [length 0005]
16 03 03 00 28
>>> TLS 1.2 Handshake [length 0010], Finished
14 00 00 0c a4 a4 2c 75 7f ba b7 be 92 74 d3 06
write to 0x270a6f0 [0x2719770] (45 bytes => 45 (0x2D))
0000 - 16 03 03 00 28 66 2e 8c-30 e1 c5 6e fe b4 dc 5b ....(f..0..n...[
0010 - ca fd 1d 73 ca e2 eb 37-96 fc 89 47 6c 1d 07 aa ...s...7...Gl...
0020 - 12 62 81 96 5b 7f 8d 8b-4f 1b 7d 97 3c .b..[...O.}.<
read from 0x270a6f0 [0x270fcd3] (5 bytes => 5 (0x5))
0000 - 15 03 03 00 02 .....
<<< ??? [length 0005]
15 03 03 00 02
read from 0x270a6f0 [0x270fcd8] (2 bytes => 2 (0x2))
0000 - 02 28 .(
<<< TLS 1.2 Alert [length 0002], fatal handshake_failure
02 28
140663681992592:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:s3_pkt.c:1493:SSL alert number 40
140663681992592:error:1409E0E5:SSL routines:ssl3_write_bytes:ssl handshake failure:s3_pkt.c:659:

但是,curl 工作得很好:

* SOCKS5 communication to vps.integrazioneweb.com:8890
* SOCKS5 request granted.
* Connected to proxy (xx.xx.xx.xx) port xxxx (#0)
* schannel: SSL/TLS connection with vps.integrazioneweb.com port 8890 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 188 bytes...
* schannel: sent initial handshake data: sent 188 bytes
* schannel: SSL/TLS connection with vps.integrazioneweb.com port 8890 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with vps.integrazioneweb.com port 8890 (step 2/3)
* schannel: encrypted data got 1283
* schannel: encrypted data buffer: offset 1283 length 4096
* schannel: a client certificate has been requested
* schannel: SSL/TLS connection with vps.integrazioneweb.com port 8890 (step 2/3)
* schannel: encrypted data buffer: offset 1283 length 4096
* schannel: sending next handshake data: sending 325 bytes...
* schannel: SSL/TLS connection with vps.integrazioneweb.com port 8890 (step 2/3)
* schannel: encrypted data got 258
* schannel: encrypted data buffer: offset 258 length 4096
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with vps.integrazioneweb.com port 8890 (step 3/3)
* schannel: stored credential handle in session cache
* Server auth using Basic with user 'enrico.musella@st.com'
> POST /oauth/token HTTP/1.1
> Host: vps.integrazioneweb.com:8890
> Authorization: Basic xxxxx
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Length: 61
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 61 out of 61 bytes
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 1528
* schannel: encrypted data buffer: offset 1528 length 103424
* schannel: decrypted data length: 1228
* schannel: decrypted data added: 1228
* schannel: decrypted data cached: offset 1228 length 102400
* schannel: encrypted data length: 271
* schannel: encrypted data cached: offset 271 length 103424
* schannel: decrypted data length: 33
* schannel: decrypted data added: 33
* schannel: decrypted data cached: offset 1261 length 102400
* schannel: encrypted data length: 209
* schannel: encrypted data cached: offset 209 length 103424
* schannel: decrypted data length: 31
* schannel: decrypted data added: 31
* schannel: decrypted data cached: offset 1292 length 102400
* schannel: encrypted data length: 149
* schannel: encrypted data cached: offset 149 length 103424
* schannel: decrypted data length: 51
* schannel: decrypted data added: 51
* schannel: decrypted data cached: offset 1343 length 102400
* schannel: encrypted data length: 69
* schannel: encrypted data cached: offset 69 length 103424
* schannel: decrypted data length: 6
* schannel: decrypted data added: 6
* schannel: decrypted data cached: offset 1349 length 102400
* schannel: encrypted data length: 34
* schannel: encrypted data cached: offset 34 length 103424
* schannel: decrypted data length: 5
* schannel: decrypted data added: 5
* schannel: decrypted data cached: offset 1354 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 1354 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 1354
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 200
< Pragma: no-cache
...

最佳答案

我解决了使用其他步骤重新生成 key 集和证书的问题,但我还需要知道第一种情况下问题出在哪里。

在第一种情况(有问题)中生成我使用的 ca 文件:

openssl genrsa -out ca.private 3072
openssl req -new -x509 -days 365 -key ca.private -out ca.crt

生成我使用的客户端文件:

openssl genrsa -out client.private 3072
openssl req -new -key client.private -out client.csr
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.private -CAcreateserial -out client.crt

在第二种情况下(没有问题)生成我使用的 ca 文件:

openssl req -newkey rsa:2048 -new -x509 -sha256 -days 365 -out ca.crt -keyout ca.key -nodes

生成我使用的客户端文件:

openssl req -newkey rsa:2048 -new -sha256 -out client.csr -keyout client.key -nodes
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 -sha256

关于java - java 的 Finished 部分握手失败,但curl 则不然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61124250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com