首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用java但不使用curl的已完成部分中的握手失败

问使用java但不使用curl的已完成部分中的握手失败
EN

Stack Overflow用户
提问于 2020-04-09 23:05:29
回答 1查看 328关注 0票数 0

我正在尝试用java实现双向认证客户端。我已经用我的客户端证书链和私钥生成了身份密钥库。我已经生成了带有服务器证书的信任密钥库。所有的握手会话看起来都是正常的,但是在完成部分我收到一个错误。我尝试了java8和java11,得到了相同的结果,但是使用curl,一切都没问题。

代码语言:javascript
复制
...
*** 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,并且也返回了错误:

代码语言:javascript
复制
>>> ??? [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工作得很好:

代码语言:javascript
复制
* 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
...
EN

回答 1

Stack Overflow用户

发布于 2020-04-20 17:26:45

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

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

代码语言:javascript
复制
openssl genrsa -out ca.private 3072
openssl req -new -x509 -days 365 -key ca.private -out ca.crt

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

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
openssl req -newkey rsa:2048 -new -x509 -sha256 -days 365 -out ca.crt -keyout ca.key -nodes

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

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61124250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档