wget TLS error from peer (alert code 40): handshake failure on TLS 1.2 and TLS 1.3 X25519 AES256-GCM
Hannasch, David Alexander
dahanna at sandia.gov
Tue Jan 11 18:34:38 UTC 2022
Sorry for the separate messages, but I said something wrong before. It's not quite a matter of TLS version per se, I don't think.
I tried with a host that supports only TLS 1.2, and busybox wget worked.
In this case, nmap showed:
$ nmap --script ssl-enum-ciphers -p 443 $INTERNAL_HOST
Starting Nmap 7.92 ( https://nmap.org<https://nmap.org/> ) at 2022-01-11 17:52 UTC
Nmap scan report for [MASKED]
Host is up (0.0011s latency).
PORT STATE SERVICE
443/tcp open https
| ssl-enum-ciphers:
| TLSv1.2:
| ciphers:
| TLS_DHE_RSA_WITH_AES_128_CBC_SHA (dh 2048) - A
| TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 (dh 2048) - A
| TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 (dh 2048) - A
| TLS_DHE_RSA_WITH_AES_256_CBC_SHA (dh 2048) - A
| TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 (dh 2048) - A
| TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 (dh 2048) - A
| TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (secp256r1) - A
| TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (secp256r1) - A
| TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A
| TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (secp256r1) - A
| TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (secp256r1) - A
| TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (secp256r1) - A
| TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
| TLS_RSA_WITH_AES_128_CBC_SHA256 (rsa 2048) - A
| TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 2048) - A
| TLS_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
| TLS_RSA_WITH_AES_256_CBC_SHA256 (rsa 2048) - A
| TLS_RSA_WITH_AES_256_GCM_SHA384 (rsa 2048) - A
| compressors:
| NULL
| cipher preference: client
|_ least strength: A
Nmap done: 1 IP address (1 host up) scanned in 0.85 seconds
And busybox:1.35.0 worked:
$ wget --proxy off http://$USERNAME:$PASSWORD@$INTERNAL_HOST<http://$USERNAME:$PASSWORD@%24internal_host/>
Connecting to [MASKED] (:80)
Connecting to [MASKED] (:443)
wget: note: TLS certificate validation not implemented
saving to 'index.html'
index.html 100% |********************************| 45427 0:00:00 ETA
'index.html' saved
I think maybe it's a particular cipher that busybox doesn't work with. This other host has TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (ecdh_x25519) but also has a lot of other things. I don't know how to tell which cipher busybox wget is actually using.
I haven't found any documentation on how the TLS is done, but I did find https://git.busybox.net/busybox/tree/networking/tls.c#n1503
//TODO: GCM_SHA384 ciphers can be supported, only need sha384-based PRF?
#if ALLOW_ECDHE_RSA_WITH_AES_128_GCM_SHA256
0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
#endif
// 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac"
This looks promising!
It looks like TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 is currently commented out of the function send_client_hello_and_alloc_hsd with a TODO noting that all it requires is a SHA384-based Pseudo-Random Function.
https://git.busybox.net/busybox/tree/networking/tls.c#n518
// RFC 5246:
// 5. HMAC and the Pseudorandom Function
//...
// In this section, we define one PRF, based on HMAC. This PRF with the
// SHA-256 hash function is used for all cipher suites defined in this
// document and in TLS documents published prior to this document when
// TLS 1.2 is negotiated.
// ^^^^^^^^^^^^^ IMPORTANT!
// PRF uses sha256 regardless of cipher for all ciphers
// defined by RFC 5246. It's not sha1 for AES_128_CBC_SHA!
// However, for _SHA384 ciphers, it's sha384. See RFC 5288,5289.
// RFC 5288:
// For cipher suites ending with _SHA256, the PRF is the TLS PRF
// with SHA-256 as the hash function.
// For cipher suites ending with _SHA384, the PRF is the TLS PRF
// with SHA-384 as the hash function.
static void prf_hmac_sha256(/*tls_state_t *tls,*/
It looks like that's where the SHA256 PRF is implemented.
I now *think* that it's a question of having a prf_hmac_sha384 and using it to enable TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 alongside TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256.
It looks like ecdh_x25519 is already supported:
https://git.busybox.net/busybox/tree/networking/tls.c#n1543
#if ALLOW_CURVE_X25519
0x00,0x1d, //curve_x25519 (RFC 7748)
#endif
(assuming the code is compiled with ALLOW_CURVE_X25519)
https://git.busybox.net/busybox/commit/?id=d4681c7293da6aeb901101b5bc239229f4963926
From: Hannasch, David Alexander
Sent: Monday, January 10, 2022 3:33 PM
To: busybox at busybox.net
Subject: wget TLS error from peer (alert code 40): handshake failure on TLS 1.2 and TLS 1.3 X25519 AES256-GCM
package: busybox
version: 1.35.0
When I execute busybox 'wget' it is unable to handshake with a TLS 1.3 X25519 AES256-GCM host.
I have not been able to build busybox from source, so I am using the busybox:1.35.0 container.
I have been using the following scripting:
test-busybox:
tags:
- docker
image: busybox:1.35.0
script:
- find / -name *libtls*
- find / -name *libretls*
- wget $TLS_13_URL
test-alpine:
tags:
- docker
image: alpine:3.15.0
script:
- find / -name *libtls* # /usr/lib/libtls.so.2.0.0
- find / -name *libretls*
- wget $TLS_13_URL
If you're not familiar with GitLab YAML, all that matters is the image name and the script. It's just loading busybox:1.35.0 and trying to wget.
Using Ubuntu, CentOS, or Alpine, wget works fine on this URL.
$ wget $TLS_13_URL
saving to 'index.html'
index.html 100% |********************************| 32211 0:00:00 ETA
'index.html' saved
Using busybox:1.35.0, wget fails.
$ wget $TLS_13_URL
wget: TLS error from peer (alert code 40): handshake failure
wget: error getting response: Connection reset by peer
(If it matters, 1.34.1 fails the same way.)
Unfortunately I do not know of a public-facing URL that supports only TLS 1.2 and 1.3, but I expect that wget will fail in the same way.
If desired, I have a great deal more information on the supported TLS below.
As mentioned, Ubuntu/CentOS/Alpine are all able to use wget just fine. Alpine is the most interesting, since Alpine actually uses BusyBox 1.34.1.
It looks like they rebuilt against a newer version of libtls.
https://gitlab.alpinelinux.org/alpine/aports/-/issues/11695
BusyBox doesn't appear (?) to be using libtls, or at least, I haven't found reference to it in the source, so I'm not sure whether a similar solution would work outside of Alpine.
Thank you,
David Hannasch
The promised details on the server are:
$ openssl s_client -connect $INTERNAL_HOST:443 -tls1_3
CONNECTED(00000003)
depth=2 C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
verify return:1
---
Certificate chain
...
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 6990 bytes and written 325 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 4096 bit
Secure Renegotiation IS NOT supported
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
DONE
$ openssl s_client -connect $INTERNAL_HOST:443 -tls1_2
CONNECTED(00000003)
depth=2 C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
verify return:1
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 6898 bytes and written 309 bytes
Verification: OK
---
New, TLSv1.2, Cipher is ECDHE-RSA-CHACHA20-POLY1305
Server public key is 4096 bit
Secure Renegotiation IS supported
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-CHACHA20-POLY1305
Verify return code: 0 (ok)
Extended master secret: yes
---
DONE
$ openssl s_client -connect $INTERNAL_HOST:443 -tls1_1 || echo "TLS 1.1 is not supported."
CONNECTED(00000003)
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 134 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.1
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1641851758
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
---
TLS 1.1 is not supported.
$ nmap --script ssl-enum-ciphers -p 443 $INTERNAL_HOST
Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-10 21:55 UTC
Host is up (0.0011s latency).
PORT STATE SERVICE
443/tcp open https
| ssl-enum-ciphers:
| TLSv1.2:
| ciphers:
| TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (ecdh_x25519) - A
| TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (ecdh_x25519) - A
| compressors:
| NULL
| cipher preference: server
| warnings:
| Key exchange (ecdh_x25519) of lower strength than certificate key
| TLSv1.3:
| ciphers:
| TLS_AKE_WITH_AES_256_GCM_SHA384 (ecdh_x25519) - A
| TLS_AKE_WITH_CHACHA20_POLY1305_SHA256 (ecdh_x25519) - A
| TLS_AKE_WITH_AES_128_GCM_SHA256 (ecdh_x25519) - A
| cipher preference: server
|_ least strength: A
Nmap done: 1 IP address (1 host up) scanned in 0.50 seconds
If there are some TLS's that BusyBox does not support, is that documented anywhere?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20220111/9d2505ec/attachment-0001.html>
More information about the busybox
mailing list