Commit Graph

69 Commits

Author SHA1 Message Date
Rushil Mehra 646ae33c61 X509Builder::append_extension2 -> X509Builder::append_extension 2025-09-26 17:38:53 +01:00
Alessandro Ghedini 4cb7e260a8 Clean-up legacy FIPS options
Per BoringSSL's FIPS policy, its `main` branch is the "update branch"
for FedRAMP compliance's purposes.

This means that we can stop using a specific BoringSSL branch when
enabling FIPS, as well as a number of hacks that allowed us to build
more recent BoringSSL versions with an older pre-compiled FIPS modules.

This also required slightly updating the main BoringSSL submodule, as
the previous version had an issue when building with the FIPS option
enabled. This is turn required some changes to the PQ patch as well as
some APIs that don't seem to be exposed publicly, as well as changing
some paths in the other patches.

In order to allow a smooth upgrade of internal projects, the `fips-compat`
feature is reduced in scope and renamed to `legacy-compat-deprecated` so
that we can incrementally upgrade internal BoringSSL forks. In practice
this shouldn't really be something anyone else would need, since in
order to work it requires a specific mix of BoringSSL version and
backported patches.
2025-09-26 17:12:23 +01:00
Kornel 9bad96e48b Style nits 2025-09-26 13:33:19 +01:00
Kornel 79338a99ea CStr UTF-8 improvements 2025-09-26 10:55:46 +01:00
Evan Rittenhouse 963425eb82 Add binding for X509_check_ip_asc
The binding corresponds to
https://boringssl.googlesource.com/boringssl.git/+/refs/heads/master/include/openssl/x509.h#4690.

To see the SANs covered by the specified cert, use:

```shell
❯ openssl x509 -in ./boring/test/alt_name_cert.pem -noout -text | grep -A1 "Subject Alternative Name"
            X509v3 Subject Alternative Name:
                DNS:example.com, IP Address:127.0.0.1, IP Address:0:0:0:0:0:0:0:1, email:test@example.com, URI:http://www.example.com
```
2025-09-05 10:23:00 +01:00
Kornel 50fa2e672f Use ERR_clear_error 2025-09-03 17:24:30 +01:00
Kornel 3de1385660 Fix doc links 2025-09-03 17:24:22 +01:00
Kornel 5fa9c81c88
Sprinkle #[must_use] (#368) 2025-06-05 20:40:35 +01:00
Kornel 5d57b3a057 Make X509Store shareable between contexts
#362
2025-06-05 14:45:40 +01:00
Kornel 4d178a7f9f Clippy 2025-06-05 10:16:08 +01:00
Kornel bcec9462af Don't unwrap when Result can be returned instead 2025-06-05 10:14:54 +01:00
Kornel 05f798adc4 Rename to reset_with_context_data 2025-06-05 01:06:09 +01:00
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 49a8d0906a
feat(x509): Implement `Clone` for `X509Store` (#339)
* boring(x509): impl Clone of X509Store
2025-04-07 18:05:27 +01:00
Kornel bf0e21cec8 Use corresponds macro 2025-02-13 09:34:13 -08: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
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
Rushil Mehra 7324db2b75 Use ForeignType::into_ptr wherever applicable 2024-09-04 04:04:30 -07:00
Rushil Mehra ef8146be7c Add tests for X509Ref::subject_key_id, X509Ref::authority_key_id, and X509NameRef::print_ex 2024-08-15 15:09:02 -07:00
Rushil Mehra 96981dd6c6 Expose X509NameRef::print_ex 2024-08-15 15:09:02 -07:00
Rushil Mehra fae2f7fbf1 Introduce `corresponds` macro from openssl-macros
Our rustdocs are miserably broken. We manually link to openssl docs in
most binding definitions, and openssl keeps changing their documentation
URL, so in order to fix everything I'd have to touch every single
binding definition in every single file. Instead, we should use the
`corresponds` macro from the openssl-macros crate which nicely adds a
link to the openssl documentation on our behalf. If the openssl
documentation url ever changes again in the future, a simple dependency
bump should solve the issue.
2024-08-15 15:09:02 -07:00
Rushil Mehra 2be6e100b6 Introduce ForeignTypeExt and ForeignTypeRefExt
`ForeignTypeExt` and `ForeignTypeRefExt` are inspired by
https://github.com/sfackler/rust-openssl/pull/1345, which make dealing
with FFI safer and more ergonomic. The new APIs (e.g.
from_const_ptr_opt`) also allow for gracefully handling instances where
the initial API call results in `NULL`. Instead of crashing the program,
`None` will be returned.
2024-08-15 15:09:02 -07:00
Rushil Mehra 1b5ae3251f Expose mTLS related APIs 2024-08-15 15:09:02 -07:00
Evan Rittenhouse 07bfd55a4d Fix x509_check_host return value
The [x509_check_host docs](https://www.openssl.org/docs/man1.1.1/man3/X509_check_host.html)
state:
> The functions return 1 for a successful match, 0 for a failed match
and -1 for an internal error: typically a memory allocation failure or
an ASN.1 decoding error.
All functions can also return -2 if the input is malformed. For example,
X509_check_host() returns -2 if the provided name contains embedded
NULs.

The current implementation will return `true` for 1, -1, and -2,
therefore returning an incorrect value if any of the above error cases
are hit.
2024-07-31 11:20:47 -07:00
Rushil Mehra 924f452130 clippy: *::max_value() -> *::MAX 2024-06-26 16:13:58 +01:00
Rushil Mehra 884c91e770 Expose X509_check_host 2024-06-26 16:13:58 +01:00
Anthony Ramine 20f9991c18 Fix support for fips-link-precompiled
This feature expects a recent boringssl checkout (such as the one
found in boring-sys/deps/boringssl), so it should not be using
the same bindings as the fips feature, which are based on
boring-sys/deps/boringssl-fips, which is older and with a different
API.
2024-01-08 14:37:55 +01:00
Anthony Ramine dfd49f4fef Introduce X509Flags
For now it has a single associated constant, X509Flags::TRUSTED_FIRST.
2024-01-03 19:37:59 +01:00
Anthony Ramine 94457340ac Move x509 tests to a subdirectory 2024-01-03 19:37:59 +01:00
Anthony Ramine 1321ded678 Rearrange imports in x509 module 2024-01-03 19:37:59 +01:00
Anthony Ramine a8dea4a22c Introduce X509CheckFlags::UNDERSCORE_WILDCARDS 2024-01-02 15:37:36 +01:00
Anthony Ramine 72f4bf5724 Introduce set_custom_verify_callback and set_async_custom_verify_callback 2023-12-14 16:31:09 +01:00
Anthony Ramine 84a80c1916 Change X509VerifyResult to Result<(), X509VerifyError>
This commit separates X509VerifyResult::OK from the rest
of the codes that actually represent errors, using
a Result type as usual.
2023-10-11 14:42:59 +02:00
Anthony Ramine ad4239d59c Introduce bindings for all X509_V_ERR_* constants 2023-10-11 14:42:59 +02:00
Ivan Nikulin 011d500460 Separate `fips` and `fips-link-precompiled` features.
Make the later compatible with `rpk` feature.
2023-08-30 11:41:20 +01:00
Anthony Ramine 6e751e85cb Revert "Merge pull request #108 from nox/store-clone"
This reverts commit 1c1af4b38b, reversing
changes made to da32be1fa9.

SslContextBuilder::cert_store_mut returns a &mut X509StoreBuilder
backed by a X509Store that is already shared with an existing SslContext.
2023-05-15 15:36:17 +02:00
Anthony Ramine ad2517f797 Fix build 2023-05-15 15:36:17 +02:00
Ivan Nikulin 1c1af4b38b
Merge pull request #108 from nox/store-clone
Implement ToOwned for X509StoreRef and Clone for X509Store
2023-05-11 16:25:11 +01:00