Commit Graph

214 Commits

Author SHA1 Message Date
Anthony Ramine 56e9fef055 Add X509StoreContextRef::init_without_cleanup
As X509_STORE_CTX_init requires its arguments to outlive
the store context, we take ownership of all of them
and put them in the store context's ex data, ensuring
the soundness of the operation without the mandatory
call to X509_STORE_CTX_cleanup after a closure
is run.
2025-06-05 01:06:09 +01:00
Anthony Ramine 45f8589d48 Add mutable ex_data APIs for X509StoreContext 2025-06-05 01:06:09 +01:00
Anthony Ramine 15975ddde4
Ensure we call X509_STORE_CTX_cleanup on error path too (#360)
As X509_STORE_CTX_init may fail after setting some values
that should outlive the store context, we must ensure we
clean things up on its error path too.

We also know it's always ok to call X509_STORE_CTX_cleanupas X509_STORE_CTX_init starts with a call to it.
2025-06-02 16:40:44 +02:00
Anthony Ramine 6789a72fc0
Fix X509VerifyContextRef::set_verify_param (#358)
This method takes ownership of the given verify param.
2025-06-02 16:39:25 +02:00
Anthony Ramine 7a52fbbe99
Add X509VerifyParamRef::copy_from (#361) 2025-06-02 16:39:11 +02:00
James Larisch 2bc82e8d1c Add support for X509_STORE_CTX_get0_untrusted 2025-06-01 19:04:22 +01:00
James Larisch e99d162891 Add set_verify_param 2025-05-30 02:17:53 +02:00
Anthony Ramine 560925293b
Revert "feat(x509): Implement `Clone` for `X509Store` (#339)" (#353)
* Revert "feat(x509): Implement `Clone` for `X509Store` (#339)"

This reverts commit 49a8d0906a.

See <https://github.com/cloudflare/boring/pull/120>.

* Ensure Clone is not added to X509Store

* Add comment about why X509Store must not implement Clone

---------

Co-authored-by: Kornel <kornel@cloudflare.com>
2025-05-27 18:19:35 +02:00
James Larisch eefc7b7265 Add `X509_STORE_CTX_get0_cert` interface
This method reliably retrieves the certificate the `X509_STORE_CTX` is
verifying, unlike `X509_STORE_CTX_get_current_cert`, which may return
the "problematic" cert when verification fails.
2025-05-27 14:41:16 +01:00
0x676e67 6e35abb2cd boring(ssl): use `corresponds` macro in `add_certificate_compression_algorithm` 2025-05-26 08:51:37 -07:00
Kornel 23863ffd1b Clippy 2025-05-26 16:30:09 +01:00
Eric Rosenberg 9b34d3524b add SslCurve::X25519_MLKEM768 constant 2025-05-03 01:25:12 +09:00
Shih-Chiang Chien b29537e08f fix clippy error 2025-04-17 01:18:30 -07:00
Shih-Chiang Chien 220bedf239 expose SSL_set_compliance_policy 2025-04-17 01:18:30 -07:00
0x676e67 49a8d0906a
feat(x509): Implement `Clone` for `X509Store` (#339)
* boring(x509): impl Clone of X509Store
2025-04-07 18:05:27 +01:00
Rushil Mehra 721b6fca2e
Add fips-precompiled feature to support newer versions of FIPS (#338)
Newer versions of FIPS don't need any special casing in our bindings,
unlike the submoduled boringssl-fips. In addition, many users currently
use FIPS by precompiling BoringSSL with the proper build tools and
passing that in to the bindings.

Until we adopt the Update Stream pattern for FIPS, there are two main
use cases:

1. Passing an unmodified, precompiled FIPS validated version of
   boringssl (fips-precompiled)

2. Passing a custom source directory of boringssl meant to be linked
   with a FIPS validated bcm.o. This is mainly useful if you carry
   custom patches but still want to use a FIPS validated BoringCrypto.
   (fips-link-precompiled)

This commit introduces the `fips-precompiled` feature and removes the
`fips-no-compat` feature.
2025-03-31 12:34:29 -07:00
Felix Hanau d5bd85b3e5
Document linking to C++ standard library (#335)
This was added in #264, but not documented so far.
2025-03-18 10:16:43 -05:00
Rushil Mehra 11630058f0
Revert "Remove "fips-no-compat", decouple "fips-compat" from "fips"" (#334) 2025-03-17 21:37:14 -05:00
Christopher Patton d8975dc413 boring: Disable `SslCurve` API with "fips" feature
The "fips" feature implies use of a prebuilt boringSSL. The boringSSL
API consumed by `SslCurve` in incompatible with older versions of
boringSSL.

In the `ffi` bindings, the following symbols don't exist in older
builds:

* NID_X25519MLKEM768
* SSL_CURVE_X25519_MLKEM768
* NID_X25519Kyber768Draft00Old

The following symbols have been renamed:
* SSL_CURVE_P256KYBER768DRAFT00 => SSL_CURVE_P256_KYBER768_DRAFT00
* SSL_CURVE_X25519KYBER512DRAFT00 => SSL_CURVE_X25519_KYBER512_DRAFT00
* SSL_CURVE_X25519KYBER768DRAFT00OLD => SSL_CURVE_X25519_KYBER768_DRAFT00_OLD
* SSL_CURVE_P256KYBER768DRAFT00 => SSL_CURVE_P256_KYBER768_DRAFT00

Meanwhile, the `ssl_set_curves_list()` API is stable across these
versions of boringSSL.

These codepoints are added to the `SslCurve` API whenever
"pq-experimental" is enabled. Since this feature is no longer mutually
exclusive with prebuilt boringSSL (`boring-sys` just ignores patches),
we also need to disable this API whenever "fips" is enabled.
2025-03-16 08:45:01 +00:00
Christopher Patton 57307d739e Remove "fips-no-compat", decouple "fips-compat" from "fips"
Modify the "fips" feature so that it no longer implies "fips-compat".
The latter is no longer needed for recent builds of boringSSL; users who
need older builds will need to enable "fips-compat" explicitly.

Also, remove the "fipps-no-compat" feature, as it's now equivalent to
"fips".
2025-03-16 08:43:52 +00:00
Christopher Patton c774afc859 Add feature "fips-no-compat"
As of boringSSL commit a430310d6563c0734ddafca7731570dfb683dc19, we no
longer need to make exceptions for the types of BufLen, ProtosLen, and
ValueLen, which means the "fips-compat" feature is no longer needed for
"fips" users.

Currently "fips" implies "fips-compat". To allow users to upgrade
without breaking API compatibility with boring version 4, add a new
feature, "fips-no-compat", that does not imply "fips-compat".

In boring 5, we should remove "fips-no-compat" and decouple
"fips-compat" from "fips".
2025-03-14 22:22:41 +00:00
Christopher Patton dde4b9ccde
Advertise X25519MLKEM768 with "kx-client-pq-preferred" (#329)
This algorithm is advertised with "kx-client-pq-supported" but not with
"preferred". However the algorithm is wide spread enough that preferring
it is not a significant risk.
2025-03-10 11:30:56 -07:00
Yury Yarashevich 5268f63a77
Expose API to enable certificate compression. (#241) 2025-02-27 15:09:07 +00:00
Rushil Mehra 9ba00ea586 Fix lifetimes in ssl::select_next_proto
See https://github.com/sfackler/rust-openssl/pull/2360 and
https://nvd.nist.gov/vuln/detail/CVE-2025-24898. From the rust-openssl
PR:

`SSL_select_next_proto` can return a pointer into either the client or
server buffers, but the type signature of the function previously only
bound the output buffer to the client buffer. This can result in a UAF
in situations where the server slice does not point to a long-lived
allocation.

Thanks to Matt Mastracci for reporting this issue.
2025-02-23 20:19:10 +00:00
Rushil Mehra abaf06731b
Introduce a builder pattern for SslEchKeys + make set_ech_keys take a reference (#320)
Previously, set_ech_keys would consume the SslEchKeys struct to enforce
the requirement that the struct is immutable after initializing it on a
SSL_CTX. The problem with this is that it requires applications to
needlessly reallocate the SslEchKeys struct if they want to initialize
keys on multiple SSL_CTXs, which is a pretty common pattern. To work
around this, we introduce a builder (SslEchKeysBuilder) that requires
mutable access to add keys to the underlying struct. set_ech_keys takes
in a reference to SslEchKeys, which can only be made via consuming the
builder.
2025-02-21 14:33:59 -08:00
Rushil Mehra cbdf963464 Actually expose SslEchKeys 2025-02-21 10:40:33 +00:00
Rushil Mehra 3b5fa65860 Expose SSL_CTX_set1_ech_keys from SslContextRef
We currently expose this method on `SslContextBuilder`, which is fine
for bootstrapping an `SSL_CTX`, but subsequent attempts to set ECH keys
(like during key rotation) can only happen via `SslContextRef`. Also
update the method on the builder to take an immutable reference to self
because the API is thread safe.
2025-02-19 01:27:51 -08:00
Kornel bf0e21cec8 Use corresponds macro 2025-02-13 09:34:13 -08:00
Rushil Mehra 05270fa100 Expose SSL_set_enable_ech_grease 2025-02-13 11:27:18 +00:00
Rushil Mehra 24003a04e8 Clean up ECH tests 2025-02-13 11:27:18 +00:00
Rushil Mehra 5af82912df Expose client/server-side ECH
Resolves https://github.com/cloudflare/boring/issues/282
2025-02-12 17:07:17 +00:00
Rushil Mehra 2561bdf64d Expose EVP_HPKE_KEY 2025-02-12 17:07:17 +00:00
Kornel 3b36cb6c78 Detailed error codes 2025-02-11 23:53:46 +00:00
Evan Rittenhouse 3355ccca67 chore: Fix docs on SslRef::replace_ex_data 2025-02-04 15:10:41 +00:00
Alessandro Ghedini 76b592673f fix manual_c_str_literals clippy warning 2025-01-22 17:52:35 +00:00
Alessandro Ghedini af9df3765d replace once_cell with LazyLock
We can drop the once_cell dependency since the same functionality is
implemented in std now.

Requires bumping MSRV to 1.80.
2025-01-22 17:52:35 +00:00
Bas Westerbaan 6ca27a7738 RTG-3333 Support X25519MLKEM768 by default, but don't sent it as client
X25519MLKEM768 is the standardised successor of the preliminary
X25519Kyber768Draft00. Latest browsers have switched to X25519MLKEM768.
Cloudflare supports both on the edge.

We've had support for X25519MLKEM768 in this crate for a while, but
didn't enable by default. We're now enabling serverside support by
default. We also let clients advertise support when set
to kx-client-pq-supported.

We don't enable support by default yet for clients set to
kx-client-pq-preferred, as that would cause an extra round-trip due to
HelloRetryRequest if the server doesn't support X25519MLKEM768 yet.

BoringSSL against which we build must support X25519MLKEM768, otherwise
this will fail.
2025-01-13 18:10:32 +01:00
Leo Blöcher baede6c0af Remove INVALID_CALL from mid-handshake error message
Mid-handshake errors that occur before certificate verification
currently look like this:

```
TLS handshake failed: cert verification failed - Invalid certificate verification context [WRONG_VERSION_NUMBER]
```

Despite no certificate even being received yet, the error complains
about a failed verification. The cause here is that `cert verification
failed` is only omitted if the verification result is `OK`. The default
in BoringSSL before verification runs is `INVALID_CALL`, however.

`INVALID_CALL` is set/returned in these places:
- 44b3df6f03/src/ssl/internal.h (L3904)
- 44b3df6f03/src/ssl/ssl_session.cc (L396)
- 44b3df6f03/src/ssl/ssl_x509.cc (L713)

It is not used anywhere else as a verification result code. To improve
the error message, this commit adds `INVALID_CALL` as a verification
result for which no additional error is dislayed.
2025-01-06 16:12:05 +00:00
Rushil Mehra 33b511331b Fix bug with accessing memzero'd X509StoreContext in tests
As of https://boringssl-review.googlesource.com/c/boringssl/+/64141,
X509_STORE_CTX_cleanup will zero the memory allocated to the
X509_STORE_CTX. Because X509StoreContextRef::init invokes
X509_STORE_CTX_cleanup once the with_context closure has finished,
calling X509StoreContextRef::verify_result (or any API really) is going
to be invalid because memory has been zerod out. This is a pretty big
footgun, so maybe we should consider screaming a bit louder for this
case.
2025-01-06 16:08:33 +00:00
Kornel 57fbe0f594 Sync X509StoreBuilder with openssl 2024-11-28 11:48:09 -08:00
Kornel b26b78611b Sync X509VerifyFlags with openssl 2024-11-28 11:48:09 -08:00
Steven Fackler 6ef5c28239 More corresponds from openssl 2024-11-28 11:48:09 -08:00
Kornel 81e84c26a2 Clippy 2024-11-28 11:21:39 -08:00
Evan Rittenhouse c113ec5a0d Add bindings for SSL_CB_ACCEPT_EXIT and SSL_CB_CONNECT_EXIT 2024-11-20 08:17:44 -08:00
James Larisch bb373e5550 Add `set_cert_verify_callback` (`SSL_CTX_set_cert_verify`)
Add a wrapper for `SSL_CTX_set_cert_verify`, which allows consumers to
override the default certificate verification behavior.

The binding resembles `SSL_CTX_set_verify`'s.

See
https://docs.openssl.org/master/man3/SSL_CTX_set_cert_verify_callback/
for more details.
2024-10-22 00:05:57 -07:00
Alessandro Ghedini a57cb3a997
Add "fips-compat" feature (#286)
This adds a feature to build against a BoringSSL version compatible with
the current boringssl-fips, but _without_ actually enabling the `fips`
feature.

This can be useful to use with `fips-link-precompiled` while using a
custom BoringSSL version based on the older FIPS branch.
2024-10-17 09:58:02 -07:00
Bas Westerbaan b7eaa5bc95 Don't support X25519MLKEM768 by default (yet) 2024-09-18 22:36:04 +02:00
Bas Westerbaan 6d3639f173 Add post-quantum key agreement X25519MLKEM768
This is the successor of X25519Kyber768Draft00.

Spec:

https://datatracker.ietf.org/doc/draft-kwiatkowski-tls-ecdhe-mlkem/02/

IANA has assigned the codepoint.

https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8

Upstream BoringSSL support landed in.

7fb4d3da50

The version of BoringSSL we patch does not include it, so we add it manually.

Chrome and Firefox are planning to enable in October.

This PR is based on the IPD-Wing patch reviewed here:

https://github.com/cloudflare/boring/pull/243

There are two changes. First we simplify the patch a bit as we do not
need IPD-Wing. Secondly, we perform the encapsulation key check, which
was a last minute addition of NIST. We perform this check also for Kyber.
2024-09-18 12:00:27 +02:00
Bas Westerbaan 2c0a14253a Revert "PQ: fix timing sidechannels and add IPDWing"
For TLS, early adopters prefer X25519MLKEM768. Remove IPDWing in
preparation for adding X25519MLKEM768.

https://datatracker.ietf.org/doc/draft-kwiatkowski-tls-ecdhe-mlkem/

This reverts commit 4725a930d5.
2024-09-18 12:00:27 +02:00
Bas Westerbaan 4b37d88b80
Expose SSL(_CTX)_set1_curves_list (#270)
set_surves_list is similar to set_curves, but the curves are specified
by a string. This makes it convenient when the supported curves of
the underlying BoringSSL is not known at compile time.

Also fix a bug in checking return value of SSL_set1_curves_list.
2024-09-17 10:00:25 +02:00