Commit Graph

1916 Commits

Author SHA1 Message Date
Daniel Stenberg
a8bef39036
openssl: remove code handling default version
Since it is no longer actually kept as default internally, that's just
dead code.

Follow-up to 9d8998c994
Closes #19354
2025-11-05 14:14:58 +01:00
x2018
2db36f11b8
gtls: add return checks and optimize the code
This commit does the following things:

1. Update the description of gtls_init()

2. In gtls_client_init(), check the invaild SSLVERSION at first. Note
   that this part refactors the duplicate/incompatible checks and removes
   the useless local variable `sni`.

3. Check the return value of gnutls_ocsp_resp_init(). Although the
   original code is safe because gnutls_ocsp_resp_import() will check
   the validity of `ocsp_resp`, it is better to catch the error in time
   and record the proper message to output log.

Closes #19366
2025-11-05 14:09:34 +01:00
x2018
dd71f61ea2
lib: cleanup for some typos about spaces and code style
Closes #19370
2025-11-05 14:07:28 +01:00
x2018
8d4530537a
gtls: check the return value of gnutls_pubkey_init()
Closes #19362
2025-11-04 17:00:52 +01:00
Joshua Rogers
0d5e24281d
vtls: check final cfilter node in find_ssl_filter
find_ssl_filter used while(cf && cf->next) and skipped the last node.
If the SSL filter was last, channel binding lookup failed and we returned
CURLE_BAD_FUNCTION_ARGUMENT. Switch to while(cf) so the tail is examined.

This bug was found with ZeroPath.

Closes #19229
2025-11-03 18:21:57 +01:00
Stefan Eissing
cccc65f051
openssl: check CURL_SSLVERSION_MAX_DEFAULT properly
The definition of these constants does not give a numeric ordering
and MAX_DEFAULT needs to be checked in addition of ciphers and QUIC
checks to apply correctly.

Fixes #19340
Reported-by: Peter Piekarski
Closes #19341
2025-11-03 16:31:22 +01:00
x2018
e2a12fcbdb
vtls: properly handle SSL shutdown timeout
Closes #19323
2025-11-01 23:28:40 +01:00
x2018
27f55383fb
schannel: properly close the certfile on error
Closes #19304
2025-10-31 23:27:06 +01:00
Daniel Stenberg
d4d7139e70
openssl: combine all the x509-store flags
... intead of overwriting the previous ones in ossl_populate_x509_store()

Pointed out by ZeroPath

Closes #19306
2025-10-31 23:24:38 +01:00
Stefan Eissing
b4630ed8fa
sectrust: fix verifystatus via sectrust
When openssl does not verify the certificate, but apple sectrust
does, we also pass it the ocsp stapled response when configured and
available.

When openssl does not verify the cert chain, it will also not be able
to verify the ocsp stapling. Do not call it if sectrust is the
verifier of the cert chain.

Fixes #19307
Reported-by: Harry Sintonen
Closes #19308
2025-10-31 23:10:35 +01:00
Daniel Stenberg
d646d5a130
openssl: fix the ocsp len arg to Curl_vtls_apple_verify
If it has no data, pass in a zero.

Fixes #19303
Reported-by: Harry Sintonen
Closes #19305
2025-10-31 23:09:05 +01:00
Daniel Stenberg
80258309b2
lib: reduce memcpy calls
socks_gssapi: the malloc + memcpy was superflous and can be skipped

cleartext: avoid malloc + three memcpy with aprintf()

digest_sspi: use memdup0 instead of malloc + memcpy

vtls: use memdup0 instead of malloc + memcpy

Closes #19282
2025-10-30 15:40:21 +01:00
Stefan Eissing
c82a70628d ssl-session-cache: check use on config and availability
Replace the check if a ssl session cache is configured with
a function checking if it is configured *and* if an ssl session
cache is available.

During normal operations, a session cache is always there, however
for "connect-only" transfers this might not be the case. When such
transfers receive new sessions/tickets, they need to silently
discard those and not fail.

Reported-by: Marc Aldorasi

Fixes https://github.com/curl/curl/issues/18983
Closes https://github.com/curl/curl/pull/19251
2025-10-29 03:07:59 -04:00
Daniel Stenberg
875ea98c36
schannel: handle Curl_conn_cf_send() errors better
Avoid a resource leak in the error path.

Reported-by: Joshua Rogers

Closes #19265
2025-10-28 23:26:33 +01:00
Stefan Eissing
692c7f133e
TLS: IP address verification, extend test
Change the test certificate to carry a altname 'dns:127.0.0.1' which
should *not* match in test_17_05_bad_ip_addr.

wolfSSL: since `wolfSSL_check_domain_name()` does not differentiate
between DNS and IP names, use if only for DNS names. For IP addresses,
get the peer certificate after the handshake and check that using
wolfSSL_X509_check_ip_asc().

Unfortunately, this succeeds where it should not, as wolfSSL internally
used the same check code for both cases. So, skip the test case until
wolfSSL fixes that.

Reported-by: Joshua Rogers
Closes #19252
2025-10-27 17:22:17 +01:00
Daniel Stenberg
3e12ed955b
schannel: lower the maximum allowed time to block to 7 seconds
During TLS renegotiation, the schannel_recv_renegotiate() function is
allowed to block for a short while. Reduce the maximum allowed time to
block from 10 minutes down to 7 seconds.

Closes #19205
2025-10-25 17:52:29 +02:00
Viktor Szakats
a13d811044
lib: delete unused header includes
`escape.h`, `getinfo.h`, `strdup.h`.

Tested OK with full non-unity CI run.

Closes #19231
2025-10-25 00:19:00 +02:00
Viktor Szakats
3fc727751f
lib: delete unused crypto header includes
Tested OK with full non-unity CI run.

Closes #19225
2025-10-24 22:53:26 +02:00
Viktor Szakats
833da09b53
vtls: drop duplicate CURL_SHA256_DIGEST_LENGTH definition
Closes #19224
2025-10-24 19:16:53 +02:00
Viktor Szakats
207a74206b
mbedtls: fix building with sha-256 missing from PSA
Fixing:
```
lib/vtls/mbedtls.c:1505:10: error: call to undeclared function 'Curl_sha256it'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 1505 |   return Curl_sha256it(sha256sum, input, inputlen);
      |          ^
1 error generated.
```

with mbedTLS configuration:
```
tf-psa-crypto/scripts/config.py unset PSA_WANT_ALG_SHA_256
tf-psa-crypto/scripts/config.py unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
tf-psa-crypto/scripts/config.py unset MBEDTLS_LMS_C
```

Follow-up to 3a305831d1 #19077

Closes #19223
2025-10-24 19:14:28 +02:00
Viktor Szakats
4a6fbd5e1d
NTLM: disable if DES support missing from OpenSSL or mbedTLS
Make autotools and cmake detect DES support in OpenSSL and mbedTLS.
Forward feature macros to C and omit NTLM from the feature preview list.
Use the feature macros in source. This ensure that `-V` output matches
the preview.

OpenSSL doesn't support DES when built with `no-des` or `no-deprecated`.
mbedTLS 4.x no longer supports it, and it's possible to disable it in
<4 with `scripts/config.py unset MBEDTLS_DES_C`.

Before this patch this worked for
mbedTLS 4 only, and with a regression for pending PR #16973.

Also:

- drop NTLM feature check from `curl_setup.h` in favour of autotools/
  cmake feature macros. This makes `curl_setup.h` no longer need
  to include an mbedTLS header, which in turn makes tests/server build
  without depending on mbedTLS.
  Fixing, in #16973:
  ```
  In file included from tests/server/first.h:40,
                   from bld/tests/server/servers.c:3:
  lib/curl_setup.h:741:10: fatal error: mbedtls/version.h: No such file or directory
    741 | #include <mbedtls/version.h>
        |          ^~~~~~~~~~~~~~~~~~~
  ```
  Ref: https://github.com/curl/curl/actions/runs/18689537893/job/53291322012?pr=16973
  Ref: #19181 (initial fix idea)
  Follow-up to 3a305831d1 #19077

- move back mbedTLS header include and version check from
  `curl_setup.h` to each source which consumes mbedTLS.

- GHA/http3-linux: drop workaround that disabled NTLM for
  `no-deprecated` OpenSSL builds.
  Follow-up to 006977859d #12384

- curl_ntlm_core: drop pointless macro `CURL_NTLM_NOT_SUPPORTED`.
  Follow-up to 006977859d #12384

Closes #19206
2025-10-24 12:12:20 +02:00
Viktor Szakats
1de4a9a5fb
mbedtls: fix building with <3.6.1
```
lib/vtls/mbedtls.c:786:3: error: call to undeclared function 'mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  786 |   mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets(&backend->config,
      |   ^
lib/vtls/mbedtls.c:787:5: error: use of undeclared identifier 'MBEDTLS_SSL_TLS1_3_SIGNAL_NEW_SESSION_TICKETS_ENABLED'; did you mean 'MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH'?
  787 |     MBEDTLS_SSL_TLS1_3_SIGNAL_NEW_SESSION_TICKETS_ENABLED);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH
dep/mbedtls-3.4.0/_pkg/include/mbedtls/ssl.h:700:5: note: 'MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH' declared here
  700 |     MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH,
      |     ^
2 errors generated.
```

Regression from d63e40f8e6 #18271 (8.16.0)

Closes #19208
2025-10-24 12:12:20 +02:00
Daniel Stenberg
3692cd837e
schannel: replace a run-time condition with an assert
For detecting a bad function argument that probably also would cause a
compiler warning.

Closes #19203
2025-10-23 22:52:02 +02:00
Theo Buehler
2edce44065
vtls: remove call to PKCS12_PBE_add()
Curl is one of the last callers of PKCS12_PBE_add(). It has been a noop
since OpenSSL 0.9.8k (2006) stubbed it out when moving the built-in PBE
algorithms to a static table:
b8f702a0af

Closes #19201
2025-10-23 14:13:26 +02:00
x2018
6032b8f2a2
vtls: unify the error handling in ssl_cf_connect().
Check preference at first, then init peer and do connect. Also fixes
CF_DATA_RESTORE.

Closes #19196
2025-10-23 08:23:44 +02:00
Daniel Stenberg
9e15b07638
openssl: only try engine/provider if a certificate file/name is provided
Bug: https://issues.oss-fuzz.com/issues/435278402

Closes #19197
2025-10-23 07:54:34 +02:00
Stefan Eissing
fcae0733a7
gnutls: fix re-handshake comments
With GnuTLS, a GNUTLS_E_REHANDSHAKE can be a renegotiate in TLSv1.2 or a
key update in TLSv1.3. This had been made non-blocking in
a1850ad7de but the comment warning about a
blocking call was not updated.

Closes #19187
2025-10-22 11:40:00 +02:00
Daniel Stenberg
00cb679c04
openssl: remove dead code
A condition in infof_certstack() would always equal true after a
previous change.

Follow-up to e2a4de8a60

Pointed out by Coverity
Closes #19142
2025-10-19 23:48:28 +02:00
Daniel Stenberg
d3b2ba92c7
rustls: exit on error
In init_config_builder_verifier() the call to
rustls_root_cert_store_builder_build() set result on failure but did not
return.

Pointed out by ZeroPath
Closes #19125
2025-10-19 23:47:47 +02:00
Yedaya Katsman
55e0526566
openssl: fix unable do typo in failf() calls
Closes #19149
2025-10-19 23:42:54 +02:00
Daniel Stenberg
6550dd0f3d
wolfssl: clear variable to avoid uninitialized use
Pointed out by ZeroPath
Closes #19126
2025-10-19 11:08:14 +02:00
Joshua Rogers
66e3ff5d0e schannel: fix memory leak
- Do not leak memory on failed setting algorithm cipher list.

Discovered by ZeroPath.


- Do not free backend->cred after failed AcquireCredentialsHandle.

backend->cred is always freed later, during cleanup.


Closes https://github.com/curl/curl/pull/19118
2025-10-19 02:23:36 -04:00
Joshua Rogers
bff9679a01
schannel_verify: do not call infof with an appended \n
Discovered by ZeroPath
Closes #19123
2025-10-18 22:15:26 +02:00
Daniel Stenberg
8de898414c
openssl: free UI_METHOD on exit path
In providercheck(), when failing to open the "store", the exit path
would not previously free the created UI_METHOD and instead leak this
resource.

Pointed out by ZeroPath

Closes #19114
2025-10-18 12:54:19 +02:00
Daniel Stenberg
b9b8a7a5df
openssl: fix resource leak in provider error path
Pointed out by ZeroPath

Closes #19111
2025-10-18 00:40:13 +02:00
Daniel Stenberg
c921f6d052
wolfssl: fix resource leak in verify_pinned error paths
Pointed out by ZeroPath

Closes #19110
2025-10-17 23:34:04 +02:00
Daniel Stenberg
e29706d6e2
mbedtls: move the crypto init into the vtls init function
Follow-up to 3a305831d1

Closes #19108
2025-10-17 23:33:12 +02:00
Daniel Stenberg
e9455ea523
rustls: make read_file_into not reject good files
For files with sizes using an exact multiple of 256 bytes, the final
successful read(s) filled the buffer(s) and the subsequent fread
returned 0 for EOF, which caused read_file_into to fail.

Now, it needs to return 0 and not be EOF to be an error.

Follow-up to dd95a49d49

Pointed out by ZeroPath
Closes #19104
2025-10-17 17:44:14 +02:00
Daniel Stenberg
fbff1d5b90
openssl: avoid overwriting 'result' after error
Follow-up to eefd03c572

Pointed out by ZeroPath https://zeropath.com/
Closes #19099
2025-10-17 15:48:47 +02:00
Daniel Stenberg
3df71e6dc2
openssl: fail if more than MAX_ALLOWED_CERT_AMOUNT certs
Detect and prevent abuse or mistakes. Limit set to 100.

Closes #19091
2025-10-17 13:36:57 +02:00
Daniel Stenberg
e2a4de8a60
openssl: better return code checks when logging cert data
Pointed out by ZeroPath

Closes #19094
2025-10-17 12:41:04 +02:00
Daniel Stenberg
c4db9eb491
rustls: limit snprintf proper in cr_keylog_log_cb()
It should limit the size to the size of the target array, not the
incoming data.

Pointed out by ZeroPath
Closes #19095
2025-10-17 12:38:36 +02:00
Viktor Szakats
3a305831d1
mbedtls: add support for 4.0.0
After this patch libcurl requires (as already documented)
the `curl_global_init()` call when using the `curl_formadd()` API with
mbedTLS.

Note: NTLM is not supported with mbedTLS 4+, because it lacks
the necessary crypto primitive: DES.

Also:
- lib: de-dupe mbedTLS minimum version checks into `curl_setup.h`.
- lib: initialize PSA Crypto as part of `curl_global_init()`.
  For MD5, SHA-256, `curl_formadd()`, and MultiSSL builds with mbedTLS
  but where mbedTLS isn't the default backend.
- lib1308: fix to call `curl_global_init()` (for the Form API).
- curl_ntlm_core: disable with mbedTLS 4+.
- md4: disable mbedTLS implementation when building against 4.x.
- md5: use mbedTLS PSA Crypto API when available, otherwise use
  the default local implementation.
- sha256: use mbedTLS PSA Crypto API when available, otherwise use
  the default local implementation.
- vtls/mbedtls: drop PSA Crypto initialization in favor of
  `curl_global_init()`.
- vtls/mbedtls: use PSA Crypto random API with all mbedTLS versions.
- vtls/mbedtls: do the same for the SHA-256 callback.
- autotools: detect mbedTLS 4+, and disable NTLM for 3.x.
- cmake: disable NTLM for mbedTLS 3.x.
- GHA/linux: keep building mbedTLS 3.x manually and use it in
  an existing job, while also enabling pytest in it.
- GHA/linux: bump to mbedTLS 4.0.0.
  Closes #19075
  Closes #19074

Refs:
https://github.com/Mbed-TLS/mbedtls/releases/tag/mbedtls-4.0.0
https://github.com/Mbed-TLS/mbedtls/blob/mbedtls-4.0.0/docs/4.0-migration-guide.md
https://github.com/Mbed-TLS/mbedtls/blob/mbedtls-4.0.0/tf-psa-crypto/docs/1.0-migration-guide.md [404]
https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/tf-psa-crypto-1.0.0/docs/1.0-migration-guide.md
https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/tf-psa-crypto-1.0.0/docs/psa-transition.md
627f727bbe/docs/4.0-migration-guide

Closes #19077
2025-10-17 11:50:48 +02:00
Stefan Eissing
c37ed9a11e
apple sectrust: add to features
It should be visible in the feature list that libcurl is build with
Apple SecTrust enabled.

Closes #19057
2025-10-16 10:58:45 +02:00
Stefan Eissing
4cc476b37f
gnutls: check conversion of peer cert chain
Check the result when converting the peer certificate chain
into gnutls internal x590 data structure for errors.

Reported-by: Joshua Rogers
Closes #18964
2025-10-10 23:41:31 +02:00
Daniel Stenberg
1e6d507de7
schannel_verify: fix mem-leak in Curl_verify_host
Reported-by: Stanislav Fort
Closes #18972
2025-10-09 21:55:28 +02:00
Stefan Eissing
d1d5855689
openssl: add comments regarding OCSP verification
To allow future reviewers of "security" reports to more easily find out
why code is this way.

Closes #18962
2025-10-09 14:44:28 +02:00
Stefan Eissing
83bed97ad8
rustls: pass the correct result to rustls_failf
Reported-by: Joshua Rogers
Closes #18961
2025-10-09 14:43:14 +02:00
Daniel Stenberg
1ce6dff01a
openssl: fix peer certificate leak in channel binding
Reported-by: Stanislav Fort
Bug: https://hackerone.com/reports/3373640
Closes #18917
2025-10-09 09:10:37 +02:00
Stefan Eissing
0f02744c41
apple sectrust: check correct result on old OS versions
On ancient Apple OS versions where SecTrustEvaluateWithError() is not
available, the deprected SecTrustEvaluate() is used. In that code
branch, the code checked the wong variable for the verified result.

Closes #18929
2025-10-08 23:16:50 +02:00