Sync `Detailed error codes` and `Clean up boring_sys::init()` (#47)

* 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.

* 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.

* fix manual_c_str_literals clippy warning

* chore: Fix docs on SslRef::replace_ex_data

* Detailed error codes

* Clean up boring_sys::init()

We don't need the workaround that was initially introduced for a bug in
openssl, and OPENSSL_init_ssl always calls into CRYPTO_library_init on
boringssl, so just call it explicitly.

---------

Co-authored-by: Bas Westerbaan <bas@cloudflare.com>
Co-authored-by: Alessandro Ghedini <alessandro@cloudflare.com>
Co-authored-by: Evan Rittenhouse <erittenhouse@cloudflare.com>
Co-authored-by: Kornel <kornel@cloudflare.com>
Co-authored-by: Rushil Mehra <rmehra@cloudflare.com>
This commit is contained in:
0x676e67 2025-02-12 22:49:09 +08:00 committed by GitHub
parent 2e17f2bc16
commit dded5d4e8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 14 deletions

View File

@ -48,18 +48,7 @@ pub const fn ERR_GET_REASON(l: c_uint) -> c_int {
} }
pub fn init() { pub fn init() {
use std::ptr; unsafe {
use std::sync::Once; CRYPTO_library_init();
}
// explicitly initialize to work around https://github.com/openssl/openssl/issues/3505
static INIT: Once = Once::new();
let init_options = OPENSSL_INIT_LOAD_SSL_STRINGS;
INIT.call_once(|| {
assert_eq!(
unsafe { OPENSSL_init_ssl(init_options.try_into().unwrap(), ptr::null_mut()) },
1
)
});
} }

View File

@ -182,6 +182,12 @@ impl Error {
} }
} }
/// Returns the raw OpenSSL error constant for the library reporting the
/// error.
pub fn library_code(&self) -> libc::c_int {
ffi::ERR_GET_LIB(self.code)
}
/// Returns the name of the function reporting the error. /// Returns the name of the function reporting the error.
pub fn function(&self) -> Option<&'static str> { pub fn function(&self) -> Option<&'static str> {
unsafe { unsafe {
@ -206,6 +212,11 @@ impl Error {
} }
} }
/// Returns the raw OpenSSL error constant for the reason for the error.
pub fn reason_code(&self) -> libc::c_int {
ffi::ERR_GET_REASON(self.code)
}
/// Returns the name of the source file which encountered the error. /// Returns the name of the source file which encountered the error.
pub fn file(&self) -> &'static str { pub fn file(&self) -> &'static str {
unsafe { unsafe {
@ -235,12 +246,14 @@ impl fmt::Debug for Error {
if let Some(library) = self.library() { if let Some(library) = self.library() {
builder.field("library", &library); builder.field("library", &library);
} }
builder.field("library_code", &self.library_code());
if let Some(function) = self.function() { if let Some(function) = self.function() {
builder.field("function", &function); builder.field("function", &function);
} }
if let Some(reason) = self.reason() { if let Some(reason) = self.reason() {
builder.field("reason", &reason); builder.field("reason", &reason);
} }
builder.field("reason_code", &self.reason_code());
builder.field("file", &self.file()); builder.field("file", &self.file());
builder.field("line", &self.line()); builder.field("line", &self.line());
if let Some(data) = self.data() { if let Some(data) = self.data() {