From 77e2d668b67861807d9d47e561adf7f9306cf006 Mon Sep 17 00:00:00 2001 From: Andrew Galloni Date: Wed, 14 Oct 2026 16:45:06 +0100 Subject: [PATCH 01/20] Add crates.io trusted publishing (#535) --- .github/workflows/publish.yml | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..bb56df0a4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,63 @@ +name: Publish to crates.io + +permissions: + contents: read + id-token: write + +on: + push: + tags: + - "v*.*.*" + +concurrency: + group: crates-io-publish + cancel-in-progress: false + +defaults: + run: + shell: bash + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + environment: crates-io + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + submodules: "recursive" + + - name: Verify tag is on master + run: | + git fetch --no-tags origin +refs/heads/master:refs/remotes/origin/master + if ! git merge-base --is-ancestor "${GITHUB_REF_NAME}" origin/master; then + echo "Tag ${GITHUB_REF_NAME} is not reachable from origin/master. Refusing to publish." >&2 + exit 1 + fi + + workspace_version="$( + sed -n '/^\[workspace\.package\]$/,/^\[/ { + s/^version = "\([^"]*\)"$/\1/p + }' Cargo.toml + )" + tag_version="${GITHUB_REF_NAME#v}" + if [[ -z "${workspace_version}" || "${tag_version}" != "${workspace_version}" ]]; then + echo "Tag version ${tag_version} does not match workspace version ${workspace_version}." >&2 + exit 1 + fi + + - uses: rust-lang/crates-io-auth-action@v1 + id: auth + + - name: Publish crates + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + run: | + cargo publish -p boring-sys + sleep 20 + cargo publish -p boring + sleep 20 + cargo publish -p tokio-boring + sleep 20 + cargo publish -p hyper-boring From 0bbd1b74d29682bcc18feb42fc2b75607176b594 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 04:33:37 +0000 Subject: [PATCH 02/20] BN_is_odd --- boring/src/bn.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/boring/src/bn.rs b/boring/src/bn.rs index 545eb3487..07f65da94 100644 --- a/boring/src/bn.rs +++ b/boring/src/bn.rs @@ -292,6 +292,18 @@ impl BigNumRef { unsafe { BN_is_negative(self.as_ptr()) == 1 } } + #[corresponds(BN_is_odd)] + #[must_use] + pub fn is_odd(&self) -> bool { + unsafe { ffi::BN_is_odd(self.as_ptr()) == 1 } + } + + #[corresponds(BN_is_even)] + #[must_use] + pub fn is_even(&self) -> bool { + !self.is_odd() + } + /// Returns the number of significant bits in `self`. #[corresponds(BN_num_bits)] #[must_use] From fb97b2a91cff13d77ad84fc3efff9081e505e87a Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 12:22:29 +0000 Subject: [PATCH 03/20] BN_mod_sqrt --- boring/src/bn.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/boring/src/bn.rs b/boring/src/bn.rs index 07f65da94..f25047f78 100644 --- a/boring/src/bn.rs +++ b/boring/src/bn.rs @@ -807,6 +807,32 @@ impl BigNumRef { } } + /// Places into `self` the modular square root of `a` such that `self^2 = a (mod p)`. + /// + /// Returns an error or if `a` is not a square mod `p`. In the latter case, it will add + /// `BN_R_NOT_A_SQUARE` to the error queue. If `a` is a square and `p` > 2, there are two + /// possible square roots; this function may return either. + /// + /// This function only works if `p` is a prime. If `p` is composite, it may fail or return an + /// arbitrary value. Callers should not pass attacker-controlled values of `p`. + #[corresponds(BN_mod_sqrt)] + pub fn mod_sqrt( + &mut self, + a: &BigNumRef, + p: &BigNumRef, + ctx: &mut BigNumContextRef, + ) -> Result<(), ErrorStack> { + unsafe { + cvt_p(ffi::BN_mod_sqrt( + self.as_ptr(), + a.as_ptr(), + p.as_ptr(), + ctx.as_ptr(), + )) + .map(|_| ()) + } + } + /// Returns an `Asn1Integer` containing the value of `self`. #[corresponds(BN_to_ASN1_INTEGER)] pub fn to_asn1_integer(&self) -> Result { @@ -1189,4 +1215,25 @@ mod tests { assert!(p.is_prime(100, &mut ctx).unwrap()); assert!(p.is_prime_fasttest(100, &mut ctx, true).unwrap()); } + + #[test] + fn test_mod_sqrt() { + let mut ctx = BigNumContext::new().unwrap(); + + // 2 is a quadratic residue mod 0x7DEB1 (a prime) + let s = BigNum::from_hex_str("2").unwrap(); + let p = BigNum::from_hex_str("7DEB1").unwrap(); + let mut sqrt = BigNum::new().unwrap(); + let mut out = BigNum::new().unwrap(); + + // Square the root since there are two possible roots; verify the square equals s mod p + sqrt.mod_sqrt(&s, &p, &mut ctx).unwrap(); + out.mod_sqr(&sqrt, &p, &mut ctx).unwrap(); + assert_eq!(out, s); + + // 3 is not a quadratic residue mod 5, so mod_sqrt must fail + let non_residue = BigNum::from_hex_str("3").unwrap(); + let p5 = BigNum::from_hex_str("5").unwrap(); + assert!(out.mod_sqrt(&non_residue, &p5, &mut ctx).is_err()); + } } From 56fc12d4e0e50b4757731fdc90058204b7843744 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 12:22:58 +0000 Subject: [PATCH 04/20] BN_bin2bn --- boring/src/bn.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/boring/src/bn.rs b/boring/src/bn.rs index f25047f78..d4d77c33d 100644 --- a/boring/src/bn.rs +++ b/boring/src/bn.rs @@ -888,10 +888,6 @@ impl BigNum { /// Creates a new `BigNum` from an unsigned, big-endian encoded number of arbitrary length. /// - /// OpenSSL documentation at [`BN_bin2bn`] - /// - /// [`BN_bin2bn`]: https://www.openssl.org/docs/man1.1.0/crypto/BN_bin2bn.html - /// /// ``` /// # use boring::bn::BigNum; /// let bignum = BigNum::from_slice(&[0x12, 0x00, 0x34]).unwrap(); @@ -906,6 +902,15 @@ impl BigNum { cvt_p(ffi::BN_bin2bn(n.as_ptr(), n.len(), ptr::null_mut())).map(|p| BigNum::from_ptr(p)) } } + + /// Copies data from a big-endian byte slice into `self`, overwriting its current value. + #[corresponds(BN_bin2bn)] + pub fn copy_from_slice(&mut self, n: &[u8]) -> Result<(), ErrorStack> { + unsafe { + cvt_p(ffi::BN_bin2bn(n.as_ptr(), n.len(), self.as_ptr()))?; + Ok(()) + } + } } impl fmt::Debug for BigNumRef { @@ -1167,11 +1172,15 @@ mod tests { #[test] fn test_to_from_slice() { - let v0 = BigNum::from_u32(10_203_004).unwrap(); + let mut v0 = BigNum::from_u32(10_203_004).unwrap(); let vec = v0.to_vec(); let v1 = BigNum::from_slice(&vec).unwrap(); - assert_eq!(v0, v1); + + v0.copy_from_slice(&[0x12, 0, 0x34]).unwrap(); + assert_eq!(v0, BigNum::from_u32(0x12_0034).unwrap()); + v0.copy_from_slice(&[0xff]).unwrap(); + assert_eq!(v0, BigNum::from_u32(0xff).unwrap()); } #[test] From 22caa9bd65c17d7c435a47041b5d238bd2be8ee7 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 04:33:32 +0000 Subject: [PATCH 05/20] ASN1_INTEGER_cmp/dup --- boring/src/asn1.rs | 122 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 110 insertions(+), 12 deletions(-) diff --git a/boring/src/asn1.rs b/boring/src/asn1.rs index 8acc2c40e..5ccb4aea0 100644 --- a/boring/src/asn1.rs +++ b/boring/src/asn1.rs @@ -450,6 +450,7 @@ impl fmt::Debug for Asn1StringRef { foreign_type_and_impl_send_sync! { type CType = ffi::ASN1_INTEGER; fn drop = ffi::ASN1_INTEGER_free; + fn clone = ffi::ASN1_INTEGER_dup; /// Numeric representation /// @@ -476,24 +477,88 @@ impl Asn1Integer { } } +impl Ord for Asn1IntegerRef { + #[corresponds(ASN1_INTEGER_cmp)] + fn cmp(&self, other: &Self) -> Ordering { + let res = unsafe { ffi::ASN1_INTEGER_cmp(self.as_ptr(), other.as_ptr()) }; + res.cmp(&0) + } +} + +impl PartialOrd for Asn1IntegerRef { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialOrd for Asn1IntegerRef { + fn partial_cmp(&self, other: &Asn1Integer) -> Option { + Some(self.cmp(&**other)) + } +} + +impl Eq for Asn1IntegerRef {} + +impl PartialEq for Asn1IntegerRef { + #[corresponds(ASN1_INTEGER_cmp)] + fn eq(&self, other: &Self) -> bool { + self.cmp(other) == Ordering::Equal + } +} + +impl PartialEq for Asn1IntegerRef { + fn eq(&self, other: &Asn1Integer) -> bool { + self.eq(&**other) + } +} + +impl Ord for Asn1Integer { + fn cmp(&self, other: &Self) -> Ordering { + Asn1IntegerRef::cmp(self, other) + } +} + +impl PartialOrd for Asn1Integer { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl PartialOrd for Asn1Integer { + fn partial_cmp(&self, other: &Asn1IntegerRef) -> Option { + (**self).partial_cmp(other) + } +} + +impl Eq for Asn1Integer {} + +impl PartialEq for Asn1Integer { + fn eq(&self, other: &Self) -> bool { + Asn1IntegerRef::eq(self, other) + } +} + +impl PartialEq for Asn1Integer { + fn eq(&self, other: &Asn1IntegerRef) -> bool { + Asn1IntegerRef::eq(self, other) + } +} + impl Asn1IntegerRef { #[allow(clippy::unnecessary_cast)] #[allow(missing_docs)] #[deprecated(since = "0.10.6", note = "use to_bn instead")] #[must_use] pub fn get(&self) -> i64 { - unsafe { crate::ffi::ASN1_INTEGER_get(self.as_ptr()) as i64 } + unsafe { ffi::ASN1_INTEGER_get(self.as_ptr()) as i64 } } /// Converts the integer to a `BigNum`. #[corresponds(ASN1_INTEGER_to_BN)] pub fn to_bn(&self) -> Result { unsafe { - cvt_p(crate::ffi::ASN1_INTEGER_to_BN( - self.as_ptr(), - ptr::null_mut(), - )) - .map(|p| BigNum::from_ptr(p)) + cvt_p(ffi::ASN1_INTEGER_to_BN(self.as_ptr(), ptr::null_mut())) + .map(|p| BigNum::from_ptr(p)) } } @@ -503,12 +568,7 @@ impl Asn1IntegerRef { /// [`bn`]: ../bn/struct.BigNumRef.html#method.to_asn1_integer #[corresponds(ASN1_INTEGER_set)] pub fn set(&mut self, value: i32) -> Result<(), ErrorStack> { - unsafe { - cvt(crate::ffi::ASN1_INTEGER_set( - self.as_ptr(), - c_long::from(value), - )) - } + unsafe { cvt(ffi::ASN1_INTEGER_set(self.as_ptr(), c_long::from(value))) } } } @@ -723,4 +783,42 @@ mod tests { .map(|object| object.to_string()) .expect_err("parsing invalid OID should fail"); } + + #[test] + fn integer_eq_ord() { + let make = |n: u32| Asn1Integer::from_bn(&BigNum::from_u32(n).unwrap()).unwrap(); + + let a = make(1); + let b = make(1); + let c = make(2); + + assert!(a == b); + assert!(a.as_ref() == b.as_ref()); + assert!(a != c); + assert!(*a == *b); + assert!(*a != *c); + assert!(a == *b); + assert!(*a == b); + assert!(a <= b); + assert!(a >= b); + assert!(a < c); + assert!(c > a); + assert!(*a <= *b); + assert!(*a >= *b); + assert!(*a < *c); + assert!(*c > *a); + assert!(*a <= b); + assert!(*c > a); + } + + #[test] + fn integer_to_owned() { + let bn = BigNum::from_dec_str("1234567890").unwrap(); + let orig = Asn1Integer::from_bn(&bn).unwrap(); + let copy = orig.clone(); + assert!( + orig == copy, + "duplicated Asn1Integer should be equal to the original" + ); + } } From 5c1e0f5a73774af409cc854ff6080af32455c839 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 11:21:06 +0000 Subject: [PATCH 06/20] ASN1_GENERALIZEDTIME_set_string + FromStr --- boring/src/asn1.rs | 125 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 111 insertions(+), 14 deletions(-) diff --git a/boring/src/asn1.rs b/boring/src/asn1.rs index 5ccb4aea0..6001902d8 100644 --- a/boring/src/asn1.rs +++ b/boring/src/asn1.rs @@ -61,6 +61,40 @@ foreign_type_and_impl_send_sync! { pub struct Asn1GeneralizedTime; } +impl Asn1GeneralizedTime { + #[corresponds(ASN1_GENERALIZEDTIME_new)] + fn new() -> Result { + ffi::init(); + + unsafe { + let handle = cvt_p(ffi::ASN1_GENERALIZEDTIME_new())?; + Ok(Self::from_ptr(handle)) + } + } +} + +impl str::FromStr for Asn1GeneralizedTime { + type Err = ErrorStack; + + /// Creates a new `Asn1GeneralizedTime` corresponding to the specified ASN1 + /// time string. + /// + /// The string must be a valid GeneralizedTime. Returns an error if the + /// string is not valid. + #[corresponds(ASN1_GENERALIZEDTIME_set_string)] + fn from_str(s: &str) -> Result { + let time = Asn1GeneralizedTime::new()?; + let s = CString::new(s).map_err(ErrorStack::internal_error)?; + unsafe { + cvt(ffi::ASN1_GENERALIZEDTIME_set_string( + time.as_ptr(), + s.as_ptr(), + ))?; + Ok(time) + } + } +} + impl fmt::Display for Asn1GeneralizedTimeRef { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let bio = MemBio::new().ok(); @@ -323,18 +357,41 @@ impl Asn1Time { } } + /// Creates a new time corresponding to the specified X509 time string. + /// + /// Behaves like [`Asn1Time::from_str`] except it additionally converts + /// GeneralizedTime to UTCTime if it is in the range where UTCTime is used. + /// See RFC 5280, section 4.1.2.5. + #[corresponds(ASN1_TIME_set_string_X509)] + pub fn from_str_x509(s: &str) -> Result { + let time = Asn1Time::new()?; + let s = CString::new(s).map_err(ErrorStack::internal_error)?; + unsafe { + cvt(ffi::ASN1_TIME_set_string_X509(time.as_ptr(), s.as_ptr()))?; + } + Ok(time) + } + /// Creates a new time corresponding to the specified ASN1 time string. #[corresponds(ASN1_TIME_set_string)] #[allow(clippy::should_implement_trait)] pub fn from_str(s: &str) -> Result { - unsafe { - let s = CString::new(s).map_err(ErrorStack::internal_error)?; + s.parse() + } +} - let time = Asn1Time::new()?; - cvt(ffi::ASN1_TIME_set_string(time.as_ptr(), s.as_ptr()))?; +impl str::FromStr for Asn1Time { + type Err = ErrorStack; - Ok(time) + /// Creates a new time corresponding to the specified ASN1 time string. + #[corresponds(ASN1_TIME_set_string)] + fn from_str(s: &str) -> Result { + let time = Asn1Time::new()?; + let s = CString::new(s).map_err(ErrorStack::internal_error)?; + unsafe { + cvt(ffi::ASN1_TIME_set_string(time.as_ptr(), s.as_ptr()))?; } + Ok(time) } } @@ -421,7 +478,13 @@ impl Asn1StringRef { #[corresponds(ASN1_STRING_get0_data)] #[must_use] pub fn as_slice(&self) -> &[u8] { - unsafe { slice::from_raw_parts(ASN1_STRING_get0_data(self.as_ptr()), self.len()) } + unsafe { + let ptr = ffi::ASN1_STRING_get0_data(self.as_ptr().cast()); + if ptr.is_null() { + return &[]; + } + slice::from_raw_parts(ptr, self.len()) + } } /// Returns the number of bytes in the string. @@ -590,7 +653,7 @@ impl Asn1BitStringRef { #[must_use] pub fn as_slice(&self) -> &[u8] { unsafe { - let ptr = ASN1_STRING_get0_data(self.as_ptr().cast()); + let ptr = ffi::ASN1_STRING_get0_data(self.as_ptr().cast()); if ptr.is_null() { return &[]; } @@ -648,10 +711,21 @@ impl Asn1Object { #[corresponds(OBJ_txt2obj)] #[allow(clippy::should_implement_trait)] pub fn from_str(txt: &str) -> Result { + txt.parse() + } +} + +impl str::FromStr for Asn1Object { + type Err = ErrorStack; + + /// Constructs an ASN.1 Object Identifier from a string representation of the OID. + #[corresponds(OBJ_txt2obj)] + fn from_str(txt: &str) -> Result { + ffi::init(); + + let txt = CString::new(txt).map_err(ErrorStack::internal_error)?; unsafe { - ffi::init(); - let txt = CString::new(txt).map_err(ErrorStack::internal_error)?; - let obj: *mut ffi::ASN1_OBJECT = cvt_p(ffi::OBJ_txt2obj(txt.as_ptr(), 0))?; + let obj = cvt_p(ffi::OBJ_txt2obj(txt.as_ptr(), 0))?; Ok(Asn1Object::from_ptr(obj)) } } @@ -690,8 +764,6 @@ impl fmt::Debug for Asn1ObjectRef { } } -use crate::ffi::ASN1_STRING_get0_data; - #[cfg(test)] mod tests { use super::*; @@ -716,6 +788,31 @@ mod tests { #[test] fn time_from_str() { Asn1Time::from_str("99991231235959Z").unwrap(); + + let time: Asn1GeneralizedTime = "20250101120000Z".parse().unwrap(); + let display = time.to_string(); + assert!( + display.contains("2025"), + "expected year in display: {display}" + ); + + assert!( + ::from_str("not a time").is_err(), + "should fail for invalid input", + ); + + // GeneralizedTime that falls in UTCTime range should be accepted + let time = Asn1Time::from_str_x509("20250101120000Z").unwrap(); + let display = time.to_string(); + assert!( + display.contains("2025"), + "expected year in display: {display}" + ); + + assert!( + Asn1Time::from_str_x509("not a time").is_err(), + "should fail for invalid input", + ); } #[test] @@ -728,7 +825,7 @@ mod tests { fn time_eq() { let a = Asn1Time::from_str("99991231235959Z").unwrap(); let b = Asn1Time::from_str("99991231235959Z").unwrap(); - let c = Asn1Time::from_str("99991231235958Z").unwrap(); + let c = "99991231235958Z".parse::().unwrap(); let a_ref = a.as_ref(); let b_ref = b.as_ref(); let c_ref = c.as_ref(); @@ -745,7 +842,7 @@ mod tests { #[test] fn time_ord() { let a = Asn1Time::from_str("99991231235959Z").unwrap(); - let b = Asn1Time::from_str("99991231235959Z").unwrap(); + let b = ::from_str("99991231235959Z").unwrap(); let c = Asn1Time::from_str("99991231235958Z").unwrap(); let a_ref = a.as_ref(); let b_ref = b.as_ref(); From c3de08abb8e9ccd46b5cc4bb3c533be86deb41db Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 04:33:20 +0000 Subject: [PATCH 07/20] X509_NAME_cmp --- boring/src/x509/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/boring/src/x509/mod.rs b/boring/src/x509/mod.rs index 7a6d1d2db..feb754d7c 100644 --- a/boring/src/x509/mod.rs +++ b/boring/src/x509/mod.rs @@ -1192,6 +1192,16 @@ impl X509NameRef { to_der, ffi::i2d_X509_NAME } + + /// Compares `self` and `other`'s canonicalized forms. + #[corresponds(X509_NAME_cmp)] + pub fn try_cmp(&self, other: &X509NameRef) -> Result { + let r = unsafe { ffi::X509_NAME_cmp(self.as_ptr(), other.as_ptr()) }; + if r == -2 { + return Err(ErrorStack::get()); + } + Ok(r.cmp(&0)) + } } impl fmt::Debug for X509NameRef { From 243011bd2981780b8e53254dea28b8ac4bb0be20 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 04:37:00 +0000 Subject: [PATCH 08/20] EC_GROUP_get_asn1_flag --- boring/src/ec.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/boring/src/ec.rs b/boring/src/ec.rs index aac0230fa..d7a49db0a 100644 --- a/boring/src/ec.rs +++ b/boring/src/ec.rs @@ -204,11 +204,19 @@ impl EcGroupRef { } } - /// Sets the flag determining if the group corresponds to a named curve or must be explicitly - /// parameterized. - /// - /// This defaults to `EXPLICIT_CURVE` in OpenSSL 1.0.1 and 1.0.2, but `NAMED_CURVE` in OpenSSL - /// 1.1.0. + /// Returns [`Asn1Flag::NAMED_CURVE`]. + #[doc(hidden)] + #[deprecated(note = "BoringSSL always returns `OPENSSL_EC_NAMED_CURVE`")] + #[corresponds(EC_GROUP_get_asn1_flag)] + #[must_use] + pub fn asn1_flag(&self) -> Asn1Flag { + unsafe { Asn1Flag(ffi::EC_GROUP_get_asn1_flag(self.as_ptr())) } + } + + /// No-op + #[doc(hidden)] + #[deprecated(note = "Ignored in BoringSSL")] + #[corresponds(EC_GROUP_set_asn1_flag)] pub fn set_asn1_flag(&mut self, flag: Asn1Flag) { unsafe { ffi::EC_GROUP_set_asn1_flag(self.as_ptr(), flag.0); From 8e666916a1cb003782ce1bcdca120c396c4df46f Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 04:39:01 +0000 Subject: [PATCH 09/20] EC_POINT_get_affine_coordinates --- boring/src/ec.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/boring/src/ec.rs b/boring/src/ec.rs index d7a49db0a..81313b16b 100644 --- a/boring/src/ec.rs +++ b/boring/src/ec.rs @@ -411,6 +411,7 @@ impl EcPointRef { /// Place affine coordinates of a curve over a prime field in the provided /// `x` and `y` `BigNum`s + #[doc(alias = "affine_coordinates")] #[corresponds(EC_POINT_get_affine_coordinates_GFp)] pub fn affine_coordinates_gfp( &self, @@ -429,6 +430,28 @@ impl EcPointRef { )) } } + + /// An alias for [`affine_coordinates_gfp`](Self::affine_coordinates_gfp). + #[corresponds(EC_POINT_get_affine_coordinates)] + #[doc(hidden)] + pub fn affine_coordinates( + &self, + group: &EcGroupRef, + x: &mut BigNumRef, + y: &mut BigNumRef, + ctx: &mut BigNumContextRef, + ) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::EC_POINT_get_affine_coordinates( + group.as_ptr(), + self.as_ptr(), + x.as_ptr(), + y.as_ptr(), + ctx.as_ptr(), + )) + } + } + } impl EcPoint { From 68f93c34e45f5db6170713de899115b3ef7ef0bc Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 04:39:25 +0000 Subject: [PATCH 10/20] EC_POINT_is_at_infinity --- boring/src/ec.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/boring/src/ec.rs b/boring/src/ec.rs index 81313b16b..e224ef0f0 100644 --- a/boring/src/ec.rs +++ b/boring/src/ec.rs @@ -452,6 +452,31 @@ impl EcPointRef { } } + /// Returns `true` if `self` is the point at infinity and `false` otherwise. + #[corresponds(EC_POINT_is_at_infinity)] + #[must_use] + pub fn is_infinity(&self, group: &EcGroupRef) -> bool { + unsafe { ffi::EC_POINT_is_at_infinity(group.as_ptr(), self.as_ptr()) == 1 } + } + + /// Returns `Ok(true)` if `self` is an element of `group` and `Ok(false)` otherwise. + /// `ctx` is ignored. This method exists for rust-openssl interoperability. + #[corresponds(EC_POINT_is_on_curve)] + #[doc(hidden)] + pub fn is_on_curve( + &self, + group: &EcGroupRef, + ctx: &mut BigNumContextRef, + ) -> Result { + unsafe { + let res = cvt_n(ffi::EC_POINT_is_on_curve( + group.as_ptr(), + self.as_ptr(), + ctx.as_ptr(), + ))?; + Ok(res == 1) + } + } } impl EcPoint { From 23dd17fd6943252ee15791a658706678f6359451 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Mar 2026 11:56:36 +0000 Subject: [PATCH 11/20] Constants for rust-openssl --- boring/src/nid.rs | 9 +++++++++ boring/src/pkey.rs | 6 ++++++ boring/src/srtp.rs | 2 ++ 3 files changed, 17 insertions(+) diff --git a/boring/src/nid.rs b/boring/src/nid.rs index 15cfe4eb9..9dc0bee74 100644 --- a/boring/src/nid.rs +++ b/boring/src/nid.rs @@ -1057,6 +1057,15 @@ impl Nid { pub const AUTH_ECDSA: Nid = Nid(ffi::NID_auth_ecdsa); pub const AUTH_PSK: Nid = Nid(ffi::NID_auth_psk); pub const AUTH_ANY: Nid = Nid(ffi::NID_auth_any); + pub const BRAINPOOL_P256R1: Nid = Nid(ffi::NID_brainpoolP256r1); + pub const BRAINPOOL_P256T1: Nid = Nid(ffi::NID_brainpoolP256t1); + pub const BRAINPOOL_P320R1: Nid = Nid(ffi::NID_brainpoolP320r1); + pub const BRAINPOOL_P320T1: Nid = Nid(ffi::NID_brainpoolP320t1); + pub const BRAINPOOL_P384R1: Nid = Nid(ffi::NID_brainpoolP384r1); + pub const BRAINPOOL_P384T1: Nid = Nid(ffi::NID_brainpoolP384t1); + pub const BRAINPOOL_P512R1: Nid = Nid(ffi::NID_brainpoolP512r1); + pub const BRAINPOOL_P512T1: Nid = Nid(ffi::NID_brainpoolP512t1); + pub const CHACHA20_POLY1305: Nid = Nid(ffi::NID_chacha20_poly1305); } #[cfg(test)] diff --git a/boring/src/pkey.rs b/boring/src/pkey.rs index bc5214e3a..97b8134dc 100644 --- a/boring/src/pkey.rs +++ b/boring/src/pkey.rs @@ -74,7 +74,12 @@ pub struct Id(c_int); impl Id { pub const RSA: Id = Id(ffi::EVP_PKEY_RSA); + /// RSA-PSS key type + #[doc(alias = "RSA_PSS")] pub const RSAPSS: Id = Id(ffi::EVP_PKEY_RSA_PSS); + /// rust-openssl alias + #[doc(hidden)] + pub const RSA_PSS: Id = Self::RSAPSS; pub const DSA: Id = Id(ffi::EVP_PKEY_DSA); pub const DH: Id = Id(ffi::EVP_PKEY_DH); pub const EC: Id = Id(ffi::EVP_PKEY_EC); @@ -82,6 +87,7 @@ impl Id { pub const ED448: Id = Id(ffi::EVP_PKEY_ED448); pub const X25519: Id = Id(ffi::EVP_PKEY_X25519); pub const X448: Id = Id(ffi::EVP_PKEY_X448); + pub const HKDF: Id = Id(ffi::EVP_PKEY_HKDF); /// Creates a `Id` from an integer representation. #[must_use] diff --git a/boring/src/srtp.rs b/boring/src/srtp.rs index 7dffc436e..1508b26ce 100644 --- a/boring/src/srtp.rs +++ b/boring/src/srtp.rs @@ -48,6 +48,8 @@ impl SrtpProfileId { SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_32 as _); pub const SRTP_NULL_SHA1_80: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_80 as _); pub const SRTP_NULL_SHA1_32: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_32 as _); + pub const SRTP_AEAD_AES_128_GCM: SrtpProfileId = SrtpProfileId(ffi::SRTP_AEAD_AES_128_GCM as _); + pub const SRTP_AEAD_AES_256_GCM: SrtpProfileId = SrtpProfileId(ffi::SRTP_AEAD_AES_256_GCM as _); /// Creates a `SrtpProfileId` from an integer representation. #[must_use] From 1d63370ab198185bee486b2b077a7eb0fb025272 Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 14 Oct 2026 20:22:28 +0100 Subject: [PATCH 12/20] Report real key_index error --- hyper-boring/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hyper-boring/src/lib.rs b/hyper-boring/src/lib.rs index c43d48456..fa262a3d2 100644 --- a/hyper-boring/src/lib.rs +++ b/hyper-boring/src/lib.rs @@ -15,8 +15,9 @@ mod v1; pub use self::v1::*; fn key_index() -> Result, ErrorStack> { - static IDX: LazyLock> = LazyLock::new(|| Ssl::new_ex_index().unwrap()); - Ok(*IDX) + static IDX: LazyLock, ErrorStack>> = + LazyLock::new(Ssl::new_ex_index); + IDX.clone() } /// Settings for [`HttpsLayer`] From d18291d97d893859edd3e7ccd142c49f536a0801 Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 14 Oct 2026 20:08:43 +0100 Subject: [PATCH 13/20] Changelog --- RELEASE_NOTES | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index bb0372b92..235d64691 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,3 +1,16 @@ +5.3.0 +- 2026-10-14 Add action-aware certificate selection callbacks +- 2026-10-14 Back-compat shims for v4 +- 2026-10-14 Add X509Ref::check_host_with_flags (fixes #530) +- 2026-10-09 boring-sys: exclude non-BoringSSL symbols from bindings +- 2026-09-30 Fix tests failures related to upstream X509_V_FLAG_TRUSTED_FIRST change +- 2026-09-30 Update to boringssl 0.20260929.0 +- 2026-08-28 RTG-5132 Enable X25519MLKEM768 in FIPS compliance profile +- 2026-08-20 RTG-5132 Bump BoringSSL +- 2026-09-22 Add native HKDF bindings +- 2026-08-14 Semver compat for nonce mutability issue +- 2026-06-25 aead: require &mut self for seal/open and add TLS AEAD variants + 5.2.0 - 2026-10-14 Add action-aware certificate selection callbacks, including ECH fallback - 2026-05-21 Export `DEP_BORINGSSL_VERSION_MAJOR` var From da1240dd22cf87f5dbdb7fb64d6e5e23515b43cd Mon Sep 17 00:00:00 2001 From: Kornel Date: Wed, 14 Oct 2026 20:28:24 +0100 Subject: [PATCH 14/20] Clippy --- boring/src/asn1.rs | 14 +++++++------- boring/src/ssl/mod.rs | 14 +++++++------- boring/src/ssl/test/mod.rs | 16 ++++++++-------- tokio-boring/examples/simple-async.rs | 2 +- tokio-boring/src/lib.rs | 8 ++++---- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/boring/src/asn1.rs b/boring/src/asn1.rs index 6001902d8..67f2036f0 100644 --- a/boring/src/asn1.rs +++ b/boring/src/asn1.rs @@ -96,7 +96,7 @@ impl str::FromStr for Asn1GeneralizedTime { } impl fmt::Display for Asn1GeneralizedTimeRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let bio = MemBio::new().ok(); let msg = bio .as_ref() @@ -295,7 +295,7 @@ impl PartialOrd for &Asn1TimeRef { } impl fmt::Display for Asn1TimeRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { unsafe { let mem_bio = match MemBio::new() { Err(_) => return f.write_str("error"), @@ -304,14 +304,14 @@ impl fmt::Display for Asn1TimeRef { let print_result = cvt(ffi::ASN1_TIME_print(mem_bio.as_ptr(), self.as_ptr())); match print_result { Err(_) => f.write_str("error"), - Ok(_) => f.write_str(str::from_utf8_unchecked(mem_bio.get_buf())), + Ok(()) => f.write_str(str::from_utf8_unchecked(mem_bio.get_buf())), } } } } impl fmt::Debug for Asn1TimeRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } } @@ -502,7 +502,7 @@ impl Asn1StringRef { } impl fmt::Debug for Asn1StringRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.as_utf8() { Ok(openssl_string) => openssl_string.fmt(fmt), Err(_) => fmt.write_str("error"), @@ -740,7 +740,7 @@ impl Asn1ObjectRef { } impl fmt::Display for Asn1ObjectRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { unsafe { let mut buf = [0u8; 80]; let len = ffi::OBJ_obj2txt( @@ -759,7 +759,7 @@ impl fmt::Display for Asn1ObjectRef { } impl fmt::Debug for Asn1ObjectRef { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, fmt) } } diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index 62eee9f90..e0f358d6e 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -1199,7 +1199,7 @@ impl SslContextBuilder { self.ctx.replace_ex_data(callback_index, callback); let callback = self.ctx.ex_data(callback_index).unwrap(); - let arg = std::ptr::from_ref(callback).cast_mut().cast(); + let arg = ptr::from_ref(callback).cast_mut().cast(); ffi::SSL_CTX_set_tlsext_servername_arg(self.as_ptr(), arg); ffi::SSL_CTX_set_tlsext_servername_callback(self.as_ptr(), Some(raw_sni::)); } @@ -4763,20 +4763,20 @@ pub trait CertificateCompressor: Send + Sync + 'static { /// Perform compression of `input` buffer and write compressed data to `output`. #[allow(unused_variables)] - fn compress(&self, input: &[u8], output: &mut W) -> std::io::Result<()> + fn compress(&self, input: &[u8], output: &mut W) -> io::Result<()> where - W: std::io::Write, + W: Write, { - Err(std::io::Error::other("not implemented")) + Err(io::Error::other("not implemented")) } /// Perform decompression of `input` buffer and write compressed data to `output`. #[allow(unused_variables)] - fn decompress(&self, input: &[u8], output: &mut W) -> std::io::Result<()> + fn decompress(&self, input: &[u8], output: &mut W) -> io::Result<()> where - W: std::io::Write, + W: Write, { - Err(std::io::Error::other("not implemented")) + Err(io::Error::other("not implemented")) } } diff --git a/boring/src/ssl/test/mod.rs b/boring/src/ssl/test/mod.rs index 3e5fed9e4..4ee5d0aef 100644 --- a/boring/src/ssl/test/mod.rs +++ b/boring/src/ssl/test/mod.rs @@ -467,7 +467,7 @@ fn test_select_cert_disable_ech_without_ech_fails() { #[test] fn test_select_cert_unknown_extension() { let mut server = Server::builder(); - let unknown_extension = std::sync::Arc::new(std::sync::Mutex::new(Some(vec![]))); + let unknown_extension = Arc::new(std::sync::Mutex::new(Some(vec![]))); server.ctx().set_select_certificate_callback({ let unknown = unknown_extension.clone(); @@ -491,7 +491,7 @@ fn test_select_cert_unknown_extension() { #[test] fn test_select_cert_alpn_extension() { let mut server = Server::builder(); - let alpn_extension = std::sync::Arc::new(std::sync::Mutex::new(None)); + let alpn_extension = Arc::new(std::sync::Mutex::new(None)); server.ctx().set_select_certificate_callback({ let alpn = alpn_extension.clone(); move |client_hello| { @@ -1390,7 +1390,7 @@ fn peer_signature_algorithm_mtls_server_sees_client() { // Observe from a server-side HANDSHAKE_DONE info callback so the capture // happens synchronously during the server's accept, before the client's // connect() returns. - let captured = std::sync::Arc::new(AtomicBool::new(false)); + let captured = Arc::new(AtomicBool::new(false)); let mut server_builder = Server::builder(); { @@ -1401,7 +1401,7 @@ fn peer_signature_algorithm_mtls_server_sees_client() { .set_verify_cert_store(store.build()) .unwrap(); server_builder.ctx().set_verify(SslVerifyMode::PEER); - let captured_cb = std::sync::Arc::clone(&captured); + let captured_cb = Arc::clone(&captured); server_builder .ctx() .set_info_callback(move |ssl, mode, _value| { @@ -1436,11 +1436,11 @@ fn peer_signature_algorithm_mtls_server_sees_client() { fn signature_algorithm_used_server_default() { // BoringSSL only retains signature_algorithm_used during the handshake, so we // capture it from a HANDSHAKE_DONE info callback. - let captured = std::sync::Arc::new(AtomicBool::new(false)); + let captured = Arc::new(AtomicBool::new(false)); let mut server_builder = Server::builder(); { - let captured_cb = std::sync::Arc::clone(&captured); + let captured_cb = Arc::clone(&captured); server_builder .ctx() .set_info_callback(move |ssl, mode, _value| { @@ -1489,8 +1489,8 @@ fn signature_algorithm_used_mtls_client() { } let server = server_builder.build(); - let captured = std::sync::Arc::new(AtomicBool::new(false)); - let captured_cb = std::sync::Arc::clone(&captured); + let captured = Arc::new(AtomicBool::new(false)); + let captured_cb = Arc::clone(&captured); let mut client_builder = server.client_with_root_ca(); client_builder diff --git a/tokio-boring/examples/simple-async.rs b/tokio-boring/examples/simple-async.rs index c51368bd1..d75fcedab 100644 --- a/tokio-boring/examples/simple-async.rs +++ b/tokio-boring/examples/simple-async.rs @@ -7,7 +7,7 @@ async fn main() -> anyhow::Result<()> { let (tcp_stream, _addr) = listener.accept().await?; let server = ssl::SslMethod::tls(); - let mut ssl_builder = boring::ssl::SslAcceptor::mozilla_modern(server)?; + let mut ssl_builder = ssl::SslAcceptor::mozilla_modern(server)?; ssl_builder.set_default_verify_paths()?; ssl_builder.set_verify(ssl::SslVerifyMode::PEER); let acceptor = ssl_builder.build(); diff --git a/tokio-boring/src/lib.rs b/tokio-boring/src/lib.rs index b5ebe0c2b..42ca7588c 100644 --- a/tokio-boring/src/lib.rs +++ b/tokio-boring/src/lib.rs @@ -203,7 +203,7 @@ where fn poll_read( mut self: Pin<&mut Self>, ctx: &mut Context<'_>, - buf: &mut ReadBuf, + buf: &mut ReadBuf<'_>, ) -> Poll> { self.run_in_context(ctx, |s| { // SAFETY: read_uninit does not de-initialize the buffer. @@ -227,17 +227,17 @@ where { fn poll_write( mut self: Pin<&mut Self>, - ctx: &mut Context, + ctx: &mut Context<'_>, buf: &[u8], ) -> Poll> { self.run_in_context(ctx, |s| cvt(s.write(buf))) } - fn poll_flush(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll> { self.run_in_context(ctx, |s| cvt(s.flush())) } - fn poll_shutdown(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll> { + fn poll_shutdown(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll> { match self.run_in_context(ctx, |s| s.shutdown()) { Ok(ShutdownResult::Sent | ShutdownResult::Received) => {} Err(ref e) if e.code() == ErrorCode::ZERO_RETURN => {} From fdb42cd69fc1821cd9f5c5e06a41f727f48e9ae4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine <123095+nox@users.noreply.github.com> Date: Mon, 19 Oct 2026 16:14:59 +0200 Subject: [PATCH 15/20] Make crates.io publishing a guarded manual release (#541) --- .github/workflows/publish.yml | 476 ++++++++++++++++++++++++++++++++-- README.md | 12 + 2 files changed, 460 insertions(+), 28 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bb56df0a4..8fedda243 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,13 +1,18 @@ name: Publish to crates.io -permissions: - contents: read - id-token: write +permissions: {} on: - push: - tags: - - "v*.*.*" + workflow_dispatch: + inputs: + pr_number: + description: "Merged release PR number (write access required to run)" + required: true + type: number + expected_version: + description: "Version to release, without the v prefix" + required: true + type: string concurrency: group: crates-io-publish @@ -18,46 +23,461 @@ defaults: shell: bash jobs: + validate: + name: Validate release + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + outputs: + merge_commit_sha: ${{ steps.release-pr.outputs.merge_commit_sha }} + is_prerelease: ${{ steps.release-pr.outputs.is_prerelease }} + env: + EXPECTED_VERSION: ${{ inputs.expected_version }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + ref: refs/heads/master + fetch-depth: 0 + submodules: "recursive" + persist-credentials: false + + - name: Verify release PR + id: release-pr + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ inputs.pr_number }} + EXPECTED_VERSION: ${{ inputs.expected_version }} + run: | + if [[ "${GITHUB_REF}" != "refs/heads/master" ]]; then + echo "Release workflow must be run from the master branch, not ${GITHUB_REF}." >&2 + exit 1 + fi + + if [[ ! "${PR_NUMBER}" =~ ^[1-9][0-9]*$ ]]; then + echo "PR number must be a positive integer." >&2 + exit 1 + fi + + if [[ ! "${EXPECTED_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then + echo "Expected version must be a valid semver version." >&2 + exit 1 + fi + version_without_build="${EXPECTED_VERSION%%+*}" + is_prerelease=false + if [[ "${version_without_build}" == *-* ]]; then + is_prerelease=true + fi + + pr="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}")" + state="$(jq -r '.state' <<<"${pr}")" + merged_at="$(jq -r '.merged_at // empty' <<<"${pr}")" + base_ref="$(jq -r '.base.ref' <<<"${pr}")" + merge_commit_sha="$(jq -r '.merge_commit_sha // empty' <<<"${pr}")" + + if [[ "${state}" != "closed" || -z "${merged_at}" ]]; then + echo "PR #${PR_NUMBER} is not merged." >&2 + exit 1 + fi + if [[ "${base_ref}" != "master" ]]; then + echo "PR #${PR_NUMBER} targets ${base_ref}, not master." >&2 + exit 1 + fi + if [[ -z "${merge_commit_sha}" ]]; then + echo "PR #${PR_NUMBER} has no recorded merge commit." >&2 + exit 1 + fi + + pr_commits="$(gh api \ + "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits?per_page=2")" + commit_count="$(jq 'length' <<<"${pr_commits}")" + if [[ "${commit_count}" != "1" ]]; then + echo "PR #${PR_NUMBER} must contain exactly one commit; found ${commit_count}." >&2 + exit 1 + fi + + git fetch --no-tags origin +refs/heads/master:refs/remotes/origin/master "${merge_commit_sha}" + master_sha="$(git rev-parse refs/remotes/origin/master)" + if ! git merge-base --is-ancestor "${merge_commit_sha}" "${master_sha}"; then + echo "PR #${PR_NUMBER}'s merge commit is not reachable from master." >&2 + exit 1 + fi + + merged_parent_sha="$(git rev-parse "${merge_commit_sha}^1")" + if [[ -z "${merged_parent_sha}" ]]; then + echo "Could not determine the parent of the merged release commit." >&2 + exit 1 + fi + + version_from_cargo() { + sed -n '/^\[workspace\.package\]$/,/^\[/ { + s/^version = "\([^"]*\)"$/\1/p + }' <<<"${1}" + } + + base_cargo="$(git show "${merged_parent_sha}:Cargo.toml")" + pr_cargo="$(git show "${merge_commit_sha}:Cargo.toml")" + base_version="$(version_from_cargo "${base_cargo}")" + pr_version="$(version_from_cargo "${pr_cargo}")" + + if [[ -z "${base_version}" || -z "${pr_version}" || "${base_version}" == "${pr_version}" ]]; then + echo "PR #${PR_NUMBER} does not change the workspace version." >&2 + exit 1 + fi + if [[ "${pr_version}" != "${EXPECTED_VERSION}" ]]; then + echo "PR #${PR_NUMBER} changes the version to ${pr_version}, not ${EXPECTED_VERSION}." >&2 + exit 1 + fi + if ! git diff --unified=0 "${merged_parent_sha}" "${merge_commit_sha}" -- Cargo.toml \ + | grep -Eq '^[+-]version = "'; then + echo "PR #${PR_NUMBER} does not contain a Cargo.toml version change." >&2 + exit 1 + fi + echo "MERGE_COMMIT_SHA=${merge_commit_sha}" >>"${GITHUB_ENV}" + echo "merge_commit_sha=${merge_commit_sha}" >>"${GITHUB_OUTPUT}" + echo "is_prerelease=${is_prerelease}" >>"${GITHUB_OUTPUT}" + + - name: Verify master and crate versions + env: + EXPECTED_VERSION: ${{ inputs.expected_version }} + run: | + git fetch --no-tags origin +refs/heads/master:refs/remotes/origin/master "${MERGE_COMMIT_SHA}" + master_sha="$(git rev-parse refs/remotes/origin/master)" + if ! git merge-base --is-ancestor "${MERGE_COMMIT_SHA}" "${master_sha}"; then + echo "The merged release commit is no longer reachable from master." >&2 + exit 1 + fi + git checkout --detach "${MERGE_COMMIT_SHA}" + git submodule update --init --recursive + + workspace_version="$(sed -n '/^\[workspace\.package\]$/,/^\[/ { + s/^version = "\([^"]*\)"$/\1/p + }' Cargo.toml)" + if [[ "${workspace_version}" != "${EXPECTED_VERSION}" ]]; then + echo "Workspace version ${workspace_version} does not match ${EXPECTED_VERSION}." >&2 + exit 1 + fi + + metadata="$(mktemp)" + trap 'rm -f "${metadata}"' EXIT + cargo metadata --no-deps --format-version 1 >"${metadata}" + + for package in boring-sys boring tokio-boring hyper-boring; do + package_version="$(jq -r --arg package "${package}" \ + '[.packages[] | select(.name == $package) | .version] | if length == 1 then .[0] else empty end' \ + "${metadata}")" + if [[ "${package_version}" != "${EXPECTED_VERSION}" ]]; then + echo "${package} has version ${package_version}, expected ${EXPECTED_VERSION}." >&2 + exit 1 + fi + done + + release_tag="v${EXPECTED_VERSION}" + existing_tag_sha="$(git ls-remote origin "refs/tags/${release_tag}^{}" | awk 'NR == 1 { print $1 }')" + if [[ -z "${existing_tag_sha}" ]]; then + existing_tag_sha="$(git ls-remote origin "refs/tags/${release_tag}" | awk 'NR == 1 { print $1 }')" + fi + if [[ -n "${existing_tag_sha}" && "${existing_tag_sha}" != "${MERGE_COMMIT_SHA}" ]]; then + echo "Tag ${release_tag} already exists at ${existing_tag_sha}, not ${MERGE_COMMIT_SHA}." >&2 + exit 1 + fi + publish: name: Publish + needs: validate runs-on: ubuntu-latest + # The crates-io environment policy permits master; this workflow creates the v* tag before publishing. environment: crates-io + permissions: + contents: write + id-token: write + env: + MERGE_COMMIT_SHA: ${{ needs.validate.outputs.merge_commit_sha }} + EXPECTED_VERSION: ${{ inputs.expected_version }} + IS_PRERELEASE: ${{ needs.validate.outputs.is_prerelease }} steps: - - uses: actions/checkout@v7 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: + ref: ${{ needs.validate.outputs.merge_commit_sha }} fetch-depth: 0 submodules: "recursive" + persist-credentials: false - - name: Verify tag is on master + - name: Verify release commit is still on master run: | - git fetch --no-tags origin +refs/heads/master:refs/remotes/origin/master - if ! git merge-base --is-ancestor "${GITHUB_REF_NAME}" origin/master; then - echo "Tag ${GITHUB_REF_NAME} is not reachable from origin/master. Refusing to publish." >&2 + git fetch --no-tags origin +refs/heads/master:refs/remotes/origin/master "${MERGE_COMMIT_SHA}" + master_sha="$(git rev-parse refs/remotes/origin/master)" + if ! git merge-base --is-ancestor "${MERGE_COMMIT_SHA}" "${master_sha}"; then + echo "The merged release commit is no longer reachable from master." >&2 exit 1 fi - workspace_version="$( - sed -n '/^\[workspace\.package\]$/,/^\[/ { - s/^version = "\([^"]*\)"$/\1/p - }' Cargo.toml - )" - tag_version="${GITHUB_REF_NAME#v}" - if [[ -z "${workspace_version}" || "${tag_version}" != "${workspace_version}" ]]; then - echo "Tag version ${tag_version} does not match workspace version ${workspace_version}." >&2 + - name: Prepare release tag and GitHub Release + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ inputs.pr_number }} + run: | + release_tag="v${EXPECTED_VERSION}" + git fetch --no-tags origin +refs/heads/master:refs/remotes/origin/master "${MERGE_COMMIT_SHA}" + master_sha="$(git rev-parse refs/remotes/origin/master)" + if ! git merge-base --is-ancestor "${MERGE_COMMIT_SHA}" "${master_sha}"; then + echo "The merged release commit is no longer reachable from master." >&2 exit 1 fi - - uses: rust-lang/crates-io-auth-action@v1 + existing_tag_sha="$(git ls-remote origin "refs/tags/${release_tag}^{}" | awk 'NR == 1 { print $1 }')" + if [[ -z "${existing_tag_sha}" ]]; then + existing_tag_sha="$(git ls-remote origin "refs/tags/${release_tag}" | awk 'NR == 1 { print $1 }')" + fi + if [[ -n "${existing_tag_sha}" && "${existing_tag_sha}" != "${MERGE_COMMIT_SHA}" ]]; then + echo "Tag ${release_tag} already exists at ${existing_tag_sha}, not ${MERGE_COMMIT_SHA}." >&2 + exit 1 + fi + + if [[ -z "${existing_tag_sha}" ]]; then + tag_object_sha="$(gh api --method POST \ + "repos/${GITHUB_REPOSITORY}/git/tags" \ + -f "tag=${release_tag}" \ + -f "message=Release ${EXPECTED_VERSION}" \ + -f "object=${MERGE_COMMIT_SHA}" \ + -f "type=commit" \ + --jq '.sha')" + gh api --method POST \ + "repos/${GITHUB_REPOSITORY}/git/refs" \ + -f "ref=refs/tags/${release_tag}" \ + -f "sha=${tag_object_sha}" >/dev/null + fi + + + - name: Prepare publishing helpers + run: | + cat >"${RUNNER_TEMP}/publish-crate.sh" <<'SCRIPT' + #!/usr/bin/env bash + set -euo pipefail + + package="${1}" + + crate_status() { + curl --silent --show-error --retry 3 --retry-all-errors \ + --output /dev/null --write-out '%{http_code}' \ + "https://crates.io/api/v1/crates/${1}/${EXPECTED_VERSION}" + } + + crate_info() { + curl --silent --show-error --retry 3 --retry-all-errors \ + "https://crates.io/api/v1/crates/${1}/${EXPECTED_VERSION}" + } + + package_checksum() { + local package="${1}" archive + # --no-verify packages without running build scripts while the registry token is present. + cargo package --no-verify -p "${package}" >/dev/null + archive="target/package/${package}-${EXPECTED_VERSION}.crate" + if [[ ! -f "${archive}" ]]; then + echo "Cargo did not create ${archive}." >&2 + return 1 + fi + sha256sum "${archive}" | awk '{print $1}' + } + + wait_for_crate() { + local delay status + for delay in 0 5 10 20 40; do + status="$(crate_status "${1}")" + if [[ "${status}" == "200" ]]; then + return 0 + fi + sleep "${delay}" + done + echo "${1} ${EXPECTED_VERSION} did not appear in the crates.io API." >&2 + return 1 + } + + verify_checksum() { + local package="${1}" expected_checksum="${2}" info actual_checksum + info="$(crate_info "${package}")" + if ! jq -e '.version.yanked == false' <<<"${info}" >/dev/null; then + echo "${package} ${EXPECTED_VERSION} is yanked or has no yanked status." >&2 + return 1 + fi + actual_checksum="$(jq -r '.version.checksum // empty' <<<"${info}")" + if [[ -z "${actual_checksum}" || "${actual_checksum}" != "${expected_checksum}" ]]; then + echo "Checksum mismatch for ${package} ${EXPECTED_VERSION}." >&2 + return 1 + fi + } + + crate_index_path() { + local name="${1}" + case "${#name}" in + 1) printf '1/%s' "${name}" ;; + 2) printf '2/%s' "${name}" ;; + 3) printf '3/%s/%s' "${name:0:1}" "${name}" ;; + *) printf '%s/%s/%s' "${name:0:2}" "${name:2:2}" "${name}" ;; + esac + } + + wait_for_index() { + local delay index_path + index_path="$(crate_index_path "${1}")" + for delay in 0 5 10 20 40; do + if curl --silent --show-error --retry 3 --retry-all-errors \ + "https://index.crates.io/${index_path}" \ + | jq -s -e --arg version "${EXPECTED_VERSION}" "any(.[]; .vers == \$version)" >/dev/null; then + return 0 + fi + sleep "${delay}" + done + echo "${1} ${EXPECTED_VERSION} did not appear in the crates.io index." >&2 + return 1 + } + + case "$(crate_status "${package}")" in + 200) + expected_checksum="$(package_checksum "${package}")" + verify_checksum "${package}" "${expected_checksum}" + wait_for_index "${package}" + ;; + 404) + expected_checksum="$(package_checksum "${package}")" + cargo publish --no-verify -p "${package}" + wait_for_crate "${package}" + verify_checksum "${package}" "${expected_checksum}" + ;; + *) + echo "Unexpected crates.io response for ${package} ${EXPECTED_VERSION}." >&2 + exit 1 + ;; + esac + SCRIPT + chmod +x "${RUNNER_TEMP}/publish-crate.sh" + + cat >"${RUNNER_TEMP}/update-release.sh" <<'SCRIPT' + #!/usr/bin/env bash + set -euo pipefail + + package="${1}" + body="$(gh api "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" --jq .body)" + link="https://crates.io/crates/${package}/${EXPECTED_VERSION}" + line="- ${package}: [published](${link})" + if grep -Eq "^- ${package}:" <<<"${body}"; then + body="$(printf '%s\n' "${body}" | sed "s|^- ${package}:.*$|${line}|")" + else + body="${body}"$'\n'"${line}" + fi + gh api --method PATCH "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \ + -f "body=${body}" >/dev/null + SCRIPT + chmod +x "${RUNNER_TEMP}/update-release.sh" + + - uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5 id: auth - - name: Publish crates + - name: Publish boring-sys env: CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + run: '"${RUNNER_TEMP}/publish-crate.sh" boring-sys' + + - name: Create or publish GitHub Release + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ inputs.pr_number }} run: | - cargo publish -p boring-sys - sleep 20 - cargo publish -p boring - sleep 20 - cargo publish -p tokio-boring - sleep 20 - cargo publish -p hyper-boring + release_tag="v${EXPECTED_VERSION}" + releases="$(gh api --paginate \ + "repos/${GITHUB_REPOSITORY}/releases?per_page=100" \ + --jq '.[]')" + release_json="$(jq -s --arg tag "${release_tag}" \ + 'map(select(.tag_name == $tag)) | if length == 0 then null elif length == 1 then .[0] else error("multiple releases for tag") end' \ + <<<"${releases}")" + + if [[ "${release_json}" != "null" ]]; then + release_id="$(jq -r '.id' <<<"${release_json}")" + body="$(jq -r '.body // ""' <<<"${release_json}")" + gh api --method PATCH "repos/${GITHUB_REPOSITORY}/releases/${release_id}" \ + -F draft=false \ + -F "prerelease=${IS_PRERELEASE}" \ + -f "make_latest=false" \ + -f "body=${body}" >/dev/null + else + release_body="$(printf 'Release %s\n\nPR: #%s\nCommit: \x60%s\x60\n\n- boring-sys: [published](https://crates.io/crates/boring-sys/%s)\n- boring: publishing\n- tokio-boring: publishing\n- hyper-boring: publishing\n\nStatus: Incomplete\n' \ + "${release_tag}" "${PR_NUMBER}" "${MERGE_COMMIT_SHA}" "${EXPECTED_VERSION}")" + release_id="$(gh api --method POST \ + "repos/${GITHUB_REPOSITORY}/releases" \ + -f "tag_name=${release_tag}" \ + -f "target_commitish=${MERGE_COMMIT_SHA}" \ + -f "name=Release ${release_tag}" \ + -f "body=${release_body}" \ + -F draft=false \ + -F "prerelease=${IS_PRERELEASE}" \ + -f "make_latest=false" \ + --jq '.id')" + fi + echo "RELEASE_ID=${release_id}" >>"${GITHUB_ENV}" + + - name: Mark boring-sys published + env: + GH_TOKEN: ${{ github.token }} + run: '"${RUNNER_TEMP}/update-release.sh" boring-sys' + + - name: Publish boring + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + run: '"${RUNNER_TEMP}/publish-crate.sh" boring' + + - name: Mark boring published + env: + GH_TOKEN: ${{ github.token }} + run: '"${RUNNER_TEMP}/update-release.sh" boring' + + - name: Publish tokio-boring + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + run: '"${RUNNER_TEMP}/publish-crate.sh" tokio-boring' + + - name: Mark tokio-boring published + env: + GH_TOKEN: ${{ github.token }} + run: '"${RUNNER_TEMP}/update-release.sh" tokio-boring' + + - name: Publish hyper-boring + env: + CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} + run: '"${RUNNER_TEMP}/publish-crate.sh" hyper-boring' + + - name: Mark hyper-boring published + env: + GH_TOKEN: ${{ github.token }} + run: '"${RUNNER_TEMP}/update-release.sh" hyper-boring' + + - name: Finalize GitHub Release + env: + GH_TOKEN: ${{ github.token }} + run: | + body="$(gh api "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" --jq .body)" + body="$(printf '%s\n' "${body}" | sed -E 's/^Status: (Incomplete|Publishing)$/Status: Published/')" + make_latest=false + if [[ "${IS_PRERELEASE}" == "false" ]]; then + make_latest=true + latest_error="${RUNNER_TEMP}/latest-release-error" + if ! latest_release="$(gh api "repos/${GITHUB_REPOSITORY}/releases/latest" 2>"${latest_error}")"; then + if ! grep -q 'HTTP 404' "${latest_error}"; then + cat "${latest_error}" >&2 + exit 1 + fi + latest_release="" + fi + if [[ -n "${latest_release}" ]]; then + latest_version="$(jq -r '.tag_name' <<<"${latest_release}")" + latest_version="${latest_version#v}" + highest_version="$(printf '%s\n%s\n' "${EXPECTED_VERSION}" "${latest_version}" | sort -V | tail -n 1)" + if [[ "${latest_version}" == "${highest_version}" && "${latest_version}" != "${EXPECTED_VERSION}" ]]; then + make_latest=legacy + fi + fi + fi + gh api --method PATCH "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \ + -F draft=false \ + -F "prerelease=${IS_PRERELEASE}" \ + -f "make_latest=${make_latest}" \ + -f "body=${body}" >/dev/null diff --git a/README.md b/README.md index 49ea529f4..514715803 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,18 @@ and [Raw Public Key](https://docs.rs/boring/latest/boring/ssl/struct.SslRef.html - hyper HTTPS connector: - FFI bindings: +## crates.io releases + +A release PR contains exactly one commit that changes the workspace version, with all four published crates resolving to that version. The PR is merged into `master` using the repository's rebase-and-merge strategy, and its post-rebase merge commit must remain reachable from `master` when the release is started. + +The release workflow is run from `master` through **Actions → Publish to crates.io** with the merged PR number and expected version, without the `v` prefix. It verifies the PR, merge commit, and crate versions before creating the immutable tag and publishing `boring-sys`. Once the first crate succeeds, it creates or reuses a non-latest GitHub Release and publishes `boring`, `tokio-boring`, and `hyper-boring` in dependency order. The GitHub Release is updated after each crate succeeds with a link to its crates.io version. + +The annotated `v` tag is created before publication as the release's immutable anchor. A partially completed release remains a non-latest GitHub Release and can be rerun with the same inputs; already-published crates remain linked in the Release body. After all crates publish successfully, the GitHub Release becomes the latest release. Pushing a tag alone does not publish a release. The `crates-io` environment policy permits `master` and retains its required reviewers. + +On a rerun, an existing non-yanked crate version is accepted only when its crates.io checksum matches the archive generated from the release commit. A checksum mismatch stops the release rather than associating an artifact from another source with this release. + +Versions with a prerelease component, such as `5.4.0-rc.1`, are marked as GitHub prereleases and never become the repository's Latest release. + # Upgrading from `boring` v4 * First update to boring 4.22 and ensure it builds without any deprecation warnings. From 3d73b843af897c280766641786055b462accb4be Mon Sep 17 00:00:00 2001 From: Adrian Maceiras Date: Fri, 23 Oct 2026 13:23:56 -0500 Subject: [PATCH 16/20] Add Asn1IntegerRef::to_der_contents --- boring/src/asn1.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/boring/src/asn1.rs b/boring/src/asn1.rs index 67f2036f0..31aeccd1c 100644 --- a/boring/src/asn1.rs +++ b/boring/src/asn1.rs @@ -625,6 +625,15 @@ impl Asn1IntegerRef { } } + to_der! { + /// Serializes the integer as DER contents, excluding the tag and length. + /// + /// The result is a minimal, big-endian two's complement encoding. + #[corresponds(i2c_ASN1_INTEGER)] + to_der_contents, + ffi::i2c_ASN1_INTEGER + } + /// Sets the ASN.1 value to the value of a signed 32-bit integer, for larger numbers /// see [`bn`]. /// @@ -918,4 +927,27 @@ mod tests { "duplicated Asn1Integer should be equal to the original" ); } + + #[test] + fn integer_to_der_contents() { + let cases: &[(&str, &[u8])] = &[ + ("0", &[0x00]), + ("127", &[0x7f]), + ("128", &[0x00, 0x80]), + ("255", &[0x00, 0xff]), + ("256", &[0x01, 0x00]), + ("-1", &[0xff]), + ("-128", &[0x80]), + ("-129", &[0xff, 0x7f]), + ("-255", &[0xff, 0x01]), + ("-256", &[0xff, 0x00]), + ("18446744073709551616", &[0x01, 0, 0, 0, 0, 0, 0, 0, 0]), + ("-18446744073709551616", &[0xff, 0, 0, 0, 0, 0, 0, 0, 0]), + ]; + for &(value, expected) in cases { + let bn = BigNum::from_dec_str(value).unwrap(); + let integer = Asn1Integer::from_bn(&bn).unwrap(); + assert_eq!(integer.to_der_contents().unwrap(), expected, "{value}"); + } + } } From 7a80a796bfdda516bca1cef285682369d1640e09 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 28 Oct 2026 17:08:11 +0100 Subject: [PATCH 17/20] Update to boringssl 0.20261020.0 with ML-DSA by default Includes upstream commits dd682072b ("Block a handful of intermediate certificates") and e52f12bcd ("crypto/x509 MTC: Update to draft -07"). ML-DSA was previously already enabled by default for TLS 1.3 servers. Now boring-pq.patch also enables ML-DSA for TLS 1.3 clients by default and in the fips202205 and fips202609 profiles. The PQ kex patch rebase conflicted due to e52f12bcd ("crypto/x509 MTC: Update to draft -07") changing and renumbering OIDs. To reduce future conflicts, I now picked NID 959 which was previously used by CECPQ2. A trivial conflict in the `SSL_CTX_use_second_keyshare` addition was resolved as some definitions moved to a private openssl/ssl_deprecated.h header since 5509db769 ("ssl: Move deprecated APIs out"). Update the outdated boring crate docs, we don't support the old FIPS 140-2 validated module. --- boring-sys/deps/boringssl | 2 +- boring-sys/patches/boring-pq.patch | 433 +++++++++++++++++++++++------ boring/src/lib.rs | 25 +- 3 files changed, 363 insertions(+), 97 deletions(-) diff --git a/boring-sys/deps/boringssl b/boring-sys/deps/boringssl index 427ec40cc..d3bf4795a 160000 --- a/boring-sys/deps/boringssl +++ b/boring-sys/deps/boringssl @@ -1 +1 @@ -Subproject commit 427ec40cc8edc545253289232e885708c409e5ea +Subproject commit d3bf4795ad5b79d646cddf2fec687da5b9b502db diff --git a/boring-sys/patches/boring-pq.patch b/boring-sys/patches/boring-pq.patch index 29bcc5121..d3c621831 100644 --- a/boring-sys/patches/boring-pq.patch +++ b/boring-sys/patches/boring-pq.patch @@ -36,55 +36,55 @@ This patch adds: ssl/internal.h | 12 +- ssl/ssl_key_share.cc | 257 +++++++++++++++++++++ ssl/ssl_lib.cc | 16 +- - ssl/ssl_test.cc | 28 ++- + ssl/ssl_test.cc | 22 +- ssl/test/runner/compliance_policy_tests.go | 2 + tool/client.cc | 9 + - 13 files changed, 370 insertions(+), 20 deletions(-) + 13 files changed, 366 insertions(+), 18 deletions(-) diff --git a/crypto/obj/obj_dat.h b/crypto/obj/obj_dat.h -index ced3582f9..f35a79e0b 100644 +index 0e7d4c2d0..dbbb9df08 100644 --- a/crypto/obj/obj_dat.h +++ b/crypto/obj/obj_dat.h -@@ -8865,7 +8865,8 @@ static const ASN1_OBJECT kObjects[NUM_NID] = { - 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, - {"X-Wing", "X-Wing", NID_X_Wing, 0, NULL, 0}, +@@ -8842,7 +8842,8 @@ static const ASN1_OBJECT kObjects[NUM_NID] = { + {"AuthPSK", "auth-psk", NID_auth_psk, 0, NULL, 0}, + {"KxANY", "kx-any", NID_kx_any, 0, NULL, 0}, + {"AuthANY", "auth-any", NID_auth_any, 0, NULL, 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, + {"P256Kyber768Draft00", "P256Kyber768Draft00", NID_P256Kyber768Draft00, 0, + NULL, 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, - {NULL, NULL, NID_undef, 0, NULL, 0}, - {"alg-mtcProof-draft", "alg-mtcProof-draft", NID_alg_mtcProof_draft, 10, -@@ -9012,6 +9013,7 @@ static const uint16_t kNIDsInShortNameOrder[] = { + {"ED448", "ED448", NID_ED448, 3, &kObjectData[6181], 0}, + {"X448", "X448", NID_X448, 3, &kObjectData[6184], 0}, + {"SHA512-256", "sha512-256", NID_sha512_256, 9, &kObjectData[6187], 0}, +@@ -9004,6 +9005,7 @@ static const uint16_t kNIDsInShortNameOrder[] = { 18 /* OU */, 749 /* Oakley-EC2N-3 */, 750 /* Oakley-EC2N-4 */, -+ 973 /* P256Kyber768Draft00 */, ++ 959 /* P256Kyber768Draft00 */, 9 /* PBE-MD2-DES */, 168 /* PBE-MD2-RC2-64 */, 10 /* PBE-MD5-DES */, -@@ -9942,6 +9944,7 @@ static const uint16_t kNIDsInLongNameOrder[] = { +@@ -9934,6 +9936,7 @@ static const uint16_t kNIDsInLongNameOrder[] = { 366 /* OCSP Nonce */, 371 /* OCSP Service Locator */, 180 /* OCSP Signing */, -+ 973 /* P256Kyber768Draft00 */, ++ 959 /* P256Kyber768Draft00 */, 161 /* PBES2 */, 69 /* PBKDF2 */, 162 /* PBMAC1 */, diff --git a/crypto/obj/obj_mac.num b/crypto/obj/obj_mac.num -index 582412081..4a0e651dc 100644 +index fa39c2933..cee6214dd 100644 --- a/crypto/obj/obj_mac.num +++ b/crypto/obj/obj_mac.num -@@ -959,6 +959,7 @@ ML_DSA_65 968 - ML_DSA_87 969 - ML_KEM_768 970 - X_Wing 972 -+P256Kyber768Draft00 973 - alg_mtcProof_draft 976 - rdna_trustAnchorID_draft 977 - pe_mtcCertificationAuthority_draft 978 +@@ -947,6 +947,7 @@ auth_ecdsa 955 + auth_psk 956 + kx_any 957 + auth_any 958 ++P256Kyber768Draft00 959 + ED448 960 + X448 961 + sha512_256 962 diff --git a/crypto/obj/objects.txt b/crypto/obj/objects.txt -index fa4bd648c..32ae303c7 100644 +index 3fdc316e4..a646f0acc 100644 --- a/crypto/obj/objects.txt +++ b/crypto/obj/objects.txt @@ -1343,6 +1343,7 @@ secg-scheme 14 3 : dhSinglePass-cofactorDH-sha512kdf-scheme @@ -96,32 +96,32 @@ index fa4bd648c..32ae303c7 100644 # NIDs for PQ/T hybrid KEMs (no corresponding OIDs). diff --git a/include/openssl/nid.h b/include/openssl/nid.h -index 9ca8e6707..584d139f9 100644 +index 38e5dc86d..39b406ecd 100644 --- a/include/openssl/nid.h +++ b/include/openssl/nid.h -@@ -5511,6 +5511,9 @@ extern "C" { - #define SN_X_Wing "X-Wing" - #define NID_X_Wing 972 +@@ -5452,6 +5452,9 @@ extern "C" { + #define LN_auth_any "auth-any" + #define NID_auth_any 958 +#define SN_P256Kyber768Draft00 "P256Kyber768Draft00" -+#define NID_P256Kyber768Draft00 973 ++#define NID_P256Kyber768Draft00 959 + - #define SN_alg_mtcProof_draft "alg-mtcProof-draft" - #define NID_alg_mtcProof_draft 976 - #define OBJ_alg_mtcProof_draft 1L, 3L, 6L, 1L, 4L, 1L, 44363L, 47L, 0L + #define SN_ED448 "ED448" + #define NID_ED448 960 + #define OBJ_ED448 1L, 3L, 101L, 113L diff --git a/include/openssl/prefix_symbols.h b/include/openssl/prefix_symbols.h -index f59abe8b9..e41c0eb55 100644 +index 42f766ade..4e33e5051 100644 --- a/include/openssl/prefix_symbols.h +++ b/include/openssl/prefix_symbols.h -@@ -2112,6 +2112,7 @@ +@@ -2128,6 +2128,7 @@ #pragma redefine_extname SSL_CTX_use_certificate_chain_file BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_use_certificate_chain_file) #pragma redefine_extname SSL_CTX_use_certificate_file BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_use_certificate_file) #pragma redefine_extname SSL_CTX_use_psk_identity_hint BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_use_psk_identity_hint) +#pragma redefine_extname SSL_CTX_use_second_keyshare BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_CTX_use_second_keyshare) #pragma redefine_extname SSL_ECH_KEYS_add BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_add) + #pragma redefine_extname SSL_ECH_KEYS_dup_ref BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_dup_ref) #pragma redefine_extname SSL_ECH_KEYS_free BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_free) - #pragma redefine_extname SSL_ECH_KEYS_has_duplicate_config_id BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_ECH_KEYS_has_duplicate_config_id) -@@ -2463,6 +2464,7 @@ +@@ -2481,6 +2482,7 @@ #pragma redefine_extname SSL_use_certificate_ASN1 BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_use_certificate_ASN1) #pragma redefine_extname SSL_use_certificate_file BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_use_certificate_file) #pragma redefine_extname SSL_use_psk_identity_hint BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_use_psk_identity_hint) @@ -129,15 +129,15 @@ index f59abe8b9..e41c0eb55 100644 #pragma redefine_extname SSL_used_hello_retry_request BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_used_hello_retry_request) #pragma redefine_extname SSL_version BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_version) #pragma redefine_extname SSL_want BORINGSSL_ADD_USER_LABEL_AND_PREFIX(SSL_want) -@@ -5264,6 +5266,7 @@ +@@ -5299,6 +5301,7 @@ #define SSL_CTX_use_certificate_chain_file BORINGSSL_ADD_PREFIX(SSL_CTX_use_certificate_chain_file) #define SSL_CTX_use_certificate_file BORINGSSL_ADD_PREFIX(SSL_CTX_use_certificate_file) #define SSL_CTX_use_psk_identity_hint BORINGSSL_ADD_PREFIX(SSL_CTX_use_psk_identity_hint) +#define SSL_CTX_use_second_keyshare BORINGSSL_ADD_PREFIX(SSL_CTX_use_second_keyshare) #define SSL_ECH_KEYS_add BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_add) + #define SSL_ECH_KEYS_dup_ref BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_dup_ref) #define SSL_ECH_KEYS_free BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_free) - #define SSL_ECH_KEYS_has_duplicate_config_id BORINGSSL_ADD_PREFIX(SSL_ECH_KEYS_has_duplicate_config_id) -@@ -5615,6 +5618,7 @@ +@@ -5652,6 +5655,7 @@ #define SSL_use_certificate_ASN1 BORINGSSL_ADD_PREFIX(SSL_use_certificate_ASN1) #define SSL_use_certificate_file BORINGSSL_ADD_PREFIX(SSL_use_certificate_file) #define SSL_use_psk_identity_hint BORINGSSL_ADD_PREFIX(SSL_use_psk_identity_hint) @@ -146,10 +146,10 @@ index f59abe8b9..e41c0eb55 100644 #define SSL_version BORINGSSL_ADD_PREFIX(SSL_version) #define SSL_want BORINGSSL_ADD_PREFIX(SSL_want) diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h -index ca1c2d50b..a13db1400 100644 +index e42a0ac08..67b653784 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h -@@ -2725,7 +2725,9 @@ OPENSSL_EXPORT size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx); +@@ -2731,7 +2731,9 @@ OPENSSL_EXPORT size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx); #define SSL_GROUP_SECP521R1 25 #define SSL_GROUP_X25519 29 #define SSL_GROUP_X25519_MLKEM768 0x11ec @@ -159,17 +159,9 @@ index ca1c2d50b..a13db1400 100644 // SSL_CTX_set1_group_ids sets the preferred groups for `ctx` to `group_ids`. // Each element of `group_ids` should be a unique one of the `SSL_GROUP_*` -@@ -6388,6 +6390,7 @@ OPENSSL_EXPORT int SSL_CTX_set_tlsext_status_arg(SSL_CTX *ctx, void *arg); - #define SSL_CURVE_SECP384R1 SSL_GROUP_SECP384R1 - #define SSL_CURVE_SECP521R1 SSL_GROUP_SECP521R1 - #define SSL_CURVE_X25519 SSL_GROUP_X25519 -+#define SSL_CURVE_X25519_KYBER768_DRAFT00 SSL_GROUP_X25519_KYBER768_DRAFT00 - - // SSL_get_curve_id calls `SSL_get_group_id`. - OPENSSL_EXPORT uint16_t SSL_get_curve_id(const SSL *ssl); -@@ -6412,6 +6415,20 @@ OPENSSL_EXPORT int SSL_CTX_set1_curves_list(SSL_CTX *ctx, const char *curves); - // SSL_set1_curves_list calls `SSL_set1_groups_list`. - OPENSSL_EXPORT int SSL_set1_curves_list(SSL *ssl, const char *curves); +@@ -5723,6 +5725,21 @@ OPENSSL_EXPORT void SSL_set_jdk11_workaround(SSL *ssl, int enable); + OPENSSL_EXPORT int SSL_parse_client_hello(const SSL *ssl, SSL_CLIENT_HELLO *out, + const uint8_t *in, size_t len); +// By default, a client will send both a non post-quantum and a post-quantum +// keyshare if available. @@ -185,11 +177,12 @@ index ca1c2d50b..a13db1400 100644 +// a client using |ctx| will only send one keyshare. +OPENSSL_EXPORT void SSL_CTX_use_second_keyshare(SSL_CTX *ctx, int enabled); + - // TLSEXT_nid_unknown is a constant used in OpenSSL for - // `SSL_get_negotiated_group` to return an unrecognized group. BoringSSL never - // returns this value, but we define this constant for compatibility. ++ + // Compliance policy configurations + // + // A TLS connection has a large number of different parameters. Some are well diff --git a/ssl/extensions.cc b/ssl/extensions.cc -index ab32bb93f..2677314d0 100644 +index db650c8bf..87b2ea23f 100644 --- a/ssl/extensions.cc +++ b/ssl/extensions.cc @@ -107,7 +107,15 @@ static bool tls1_check_duplicate_extensions(const CBS *cbs) { @@ -243,7 +236,7 @@ index ab32bb93f..2677314d0 100644 selected_key_shares.emplace(default_key_shares); } diff --git a/ssl/internal.h b/ssl/internal.h -index 8efc21e06..57fffadde 100644 +index bff133b11..0872532eb 100644 --- a/ssl/internal.h +++ b/ssl/internal.h @@ -952,7 +952,7 @@ struct NamedGroup { @@ -255,7 +248,7 @@ index 8efc21e06..57fffadde 100644 // DefaultSupportedGroupIds returns the list of IDs for the default groups that // are supported when the caller hasn't explicitly configured supported groups. -@@ -3642,6 +3642,11 @@ struct SSL_CONFIG { +@@ -3576,6 +3576,11 @@ struct SSL_CONFIG { // permute_extensions is whether to permute extensions when sending messages. bool permute_extensions : 1; @@ -267,7 +260,7 @@ index 8efc21e06..57fffadde 100644 // alps_use_new_codepoint if set indicates we use new ALPS extension codepoint // to negotiate and convey application settings. bool alps_use_new_codepoint : 1; -@@ -4263,6 +4268,11 @@ class SSLContext : public ssl_ctx_st, public RefCounted { +@@ -4192,6 +4197,11 @@ class SSLContext : public ssl_ctx_st, public RefCounted { // permute_extensions is whether to permute extensions when sending messages. bool permute_extensions : 1; @@ -580,18 +573,18 @@ index 84394b247..2f006e982 100644 return nullptr; } diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc -index b59029f54..33cc42dde 100644 +index 4a53066c1..b09363e37 100644 --- a/ssl/ssl_lib.cc +++ b/ssl/ssl_lib.cc -@@ -383,6 +383,7 @@ bssl::SSLContext::SSLContext(const SSL_METHOD *ssl_method) +@@ -370,6 +370,7 @@ bssl::SSLContext::SSLContext(const SSL_METHOD *ssl_method) + channel_id_enabled(false), grease_enabled(false), - grease_sigalgs_enabled(false), permute_extensions(false), + disable_second_keyshare(false), allow_unknown_alpn_protos(false), false_start_allowed_without_alpn(false), - handoff(false), -@@ -515,6 +516,7 @@ SSL *SSL_new(SSL_CTX *ctx) { + enable_early_data(false), +@@ -508,6 +509,7 @@ SSL *SSL_new(SSL_CTX *ctx) { ssl->config->retain_only_sha256_of_client_certs = ctx_impl->retain_only_sha256_of_client_certs; ssl->config->permute_extensions = ctx_impl->permute_extensions; @@ -599,7 +592,7 @@ index b59029f54..33cc42dde 100644 ssl->config->compliance_policy = ctx_impl->compliance_policy; if (!ssl->config->tls13_cipher_list.CopyFrom(ctx_impl->tls13_cipher_list)) { -@@ -583,6 +585,7 @@ SSL_CONFIG::SSL_CONFIG(SSLImpl *ssl_arg) +@@ -574,6 +576,7 @@ SSL_CONFIG::SSL_CONFIG(SSLImpl *ssl_arg) jdk11_workaround(false), quic_use_legacy_codepoint(false), permute_extensions(false), @@ -607,7 +600,7 @@ index b59029f54..33cc42dde 100644 alps_use_new_codepoint(true), server_padding_enabled(false) { assert(ssl); -@@ -3577,6 +3580,15 @@ int SSL_set1_curves_list(SSL *ssl, const char *curves) { +@@ -3558,6 +3561,15 @@ int SSL_set1_curves_list(SSL *ssl, const char *curves) { return SSL_set1_groups_list(ssl, curves); } @@ -623,7 +616,7 @@ index b59029f54..33cc42dde 100644 namespace fips202205 { // (References are to SP 800-52r2): -@@ -3588,7 +3600,9 @@ namespace fips202205 { +@@ -3569,7 +3581,9 @@ namespace fips202205 { // Section 3.3.1 // "The server shall be configured to only use cipher suites that are // composed entirely of NIST approved algorithms" @@ -635,10 +628,10 @@ index b59029f54..33cc42dde 100644 static const uint16_t kSigAlgs[] = { SSL_SIGN_RSA_PKCS1_SHA256, diff --git a/ssl/ssl_test.cc b/ssl/ssl_test.cc -index 25d0ca38b..36b1d6ba7 100644 +index c24997daf..3a0bc99c3 100644 --- a/ssl/ssl_test.cc +++ b/ssl/ssl_test.cc -@@ -495,6 +495,10 @@ static const CurveTest kCurveTests[] = { +@@ -520,6 +520,10 @@ static const CurveTest kCurveTests[] = { "P-256", {SSL_GROUP_SECP256R1}, }, @@ -649,7 +642,7 @@ index 25d0ca38b..36b1d6ba7 100644 { "P-256:X25519MLKEM768", {SSL_GROUP_SECP256R1, SSL_GROUP_X25519_MLKEM768}, -@@ -507,6 +511,14 @@ static const CurveTest kCurveTests[] = { +@@ -532,6 +536,14 @@ static const CurveTest kCurveTests[] = { "MLKEM1024:X25519MLKEM768", {SSL_GROUP_MLKEM1024, SSL_GROUP_X25519_MLKEM768}, }, @@ -664,7 +657,7 @@ index 25d0ca38b..36b1d6ba7 100644 { "P-256:P-384:P-521:X25519", -@@ -686,8 +698,10 @@ TEST(SSLTest, CurveRules) { +@@ -711,8 +723,10 @@ TEST(SSLTest, CurveRules) { } TEST(SSLTest, DefaultCurves) { @@ -677,7 +670,7 @@ index 25d0ca38b..36b1d6ba7 100644 // Test the group ID APIs. { -@@ -2224,7 +2238,9 @@ TEST(SSLTest, SetGroupIdsWithEqualPreference) { +@@ -2249,7 +2263,9 @@ TEST(SSLTest, SetGroupIdsWithEqualPreference) { // (i.e. using the default groups). TEST(SSLTest, SetGroupIdsWithFlags_DefaultGroups) { const uint16_t kDefaultGroups[] = {SSL_GROUP_X25519_MLKEM768, @@ -688,19 +681,6 @@ index 25d0ca38b..36b1d6ba7 100644 SSL_GROUP_SECP384R1}; const uint32_t kBogusFlags[] = {SSL_GROUP_FLAG_EQUAL_PREFERENCE_WITH_NEXT, SSL_GROUP_FLAG_EQUAL_PREFERENCE_WITH_NEXT, 0}; -@@ -7411,8 +7427,10 @@ TEST(SSLTest, ApplyHandoffRemovesUnsupportedCurves) { - - // The default list of groups is used before applying the handoff. - EXPECT_THAT(FromOpaque(server.get())->config->supported_group_list, -- ElementsAreArray({SSL_GROUP_X25519_MLKEM768, SSL_GROUP_X25519, -- SSL_GROUP_SECP256R1, SSL_GROUP_SECP384R1})); -+ ElementsAreArray({SSL_GROUP_X25519_MLKEM768, -+ SSL_GROUP_P256_KYBER768_DRAFT00, -+ SSL_GROUP_X25519, SSL_GROUP_SECP256R1, -+ SSL_GROUP_SECP384R1})); - ASSERT_TRUE(SSL_apply_handoff(server.get(), handoff)); - EXPECT_EQ(1u, FromOpaque(server.get())->config->supported_group_list.size()); - EXPECT_EQ(SSL_GROUP_SECP256R1, diff --git a/ssl/test/runner/compliance_policy_tests.go b/ssl/test/runner/compliance_policy_tests.go index 3e97718b8..269fbcca6 100644 --- a/ssl/test/runner/compliance_policy_tests.go @@ -741,3 +721,286 @@ index 1f2b19965..6cf555433 100644 // Configure accepted roots. if (args_map.count("-root-certs") != 0) { if (!SSL_CTX_load_verify_locations( +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Wu +Date: Tue, 27 Oct 2026 20:01:41 +0100 +Subject: [PATCH] Limit advertising ML-DSA support to TLS 1.3 + +ML-DSA is only supported with TLS 1.3, do not advertise it when TLS 1.2 +is the maximum version (for clients) or the negotiated version (for +servers requesting client auth). This also prevents SSLTest.ClientHello +test failures when ML-DSA is enabled by default. + +Thanks David for the ExpectPeerSignatureAlgorithmPreferences change. + +Change-Id: Idb8fe38ff189d037ff32673c499b95050cb1e7ce +--- + ssl/extensions.cc | 10 +++++ + ssl/test/runner/common.go | 4 ++ + ssl/test/runner/handshake_client.go | 23 +++++++--- + ssl/test/runner/handshake_server.go | 6 +++ + ssl/test/runner/signature_algorithm_tests.go | 44 ++++++++++++++++++++ + 5 files changed, 81 insertions(+), 6 deletions(-) + +diff --git a/ssl/extensions.cc b/ssl/extensions.cc +index 69e02fd7e..8426f22ac 100644 +--- a/ssl/extensions.cc ++++ b/ssl/extensions.cc +@@ -118,6 +118,11 @@ static bool is_post_quantum_group(uint16_t id) { + } + } + ++static bool is_post_quantum_sigalg(uint16_t sigalg) { ++ return sigalg == SSL_SIGN_ML_DSA_44 || sigalg == SSL_SIGN_ML_DSA_65 || ++ sigalg == SSL_SIGN_ML_DSA_87; ++} ++ + bool ssl_parse_client_hello_with_trailing_data(const SSLImpl *ssl, CBS *cbs, + SSL_CLIENT_HELLO *out) { + OPENSSL_memset(out, 0, sizeof(*out)); +@@ -347,7 +352,12 @@ static Span tls12_get_verify_sigalgs(const SSL_HANDSHAKE *hs) { + } + + bool tls12_add_verify_sigalgs(const SSL_HANDSHAKE *hs, CBB *out) { ++ uint16_t max_version = ++ hs->ssl->server ? ssl_protocol_version(hs->ssl) : hs->max_version; + for (uint16_t sigalg : tls12_get_verify_sigalgs(hs)) { ++ if (is_post_quantum_sigalg(sigalg) && max_version < TLS1_3_VERSION) { ++ continue; ++ } + if (!CBB_add_u16(out, sigalg)) { + return false; + } +diff --git a/ssl/test/runner/common.go b/ssl/test/runner/common.go +index 514dd7c57..e8c3e6467 100644 +--- a/ssl/test/runner/common.go ++++ b/ssl/test/runner/common.go +@@ -1507,6 +1507,10 @@ type ProtocolBugs struct { + // signature algorithm preferences to be ignored. + IgnorePeerSignatureAlgorithmPreferences bool + ++ // ExpectPeerSignatureAlgorithmPreferences, if not nil, asserts that the ++ // peer's signature algorithm preferences were the specified list. ++ ExpectPeerSignatureAlgorithmPreferences []signatureAlgorithm ++ + // IgnorePeerCurvePreferences, if true, causes the peer's curve + // preferences to be ignored. + IgnorePeerCurvePreferences bool +diff --git a/ssl/test/runner/handshake_client.go b/ssl/test/runner/handshake_client.go +index df9816a2f..23f32a413 100644 +--- a/ssl/test/runner/handshake_client.go ++++ b/ssl/test/runner/handshake_client.go +@@ -1294,10 +1294,9 @@ func (hs *clientHandshakeState) doTLS13Handshake(msg any) error { + } + + hs.writeServerHash(certReq.marshal()) +- + credential = c.config.Credential +- if credential != nil && c.config.Bugs.IgnorePeerSignatureAlgorithmPreferences { +- certReq.signatureAlgorithms = credential.signatureAlgorithms() ++ if err := hs.handleCertificateRequest(certReq, credential); err != nil { ++ return err + } + + msg, err = c.readHandshake() +@@ -1776,10 +1775,9 @@ func (hs *clientHandshakeState) doFullHandshake() error { + if ok { + certRequested = true + hs.writeServerHash(certReq.marshal()) +- + credential = c.config.Credential +- if credential != nil && c.config.Bugs.IgnorePeerSignatureAlgorithmPreferences { +- certReq.signatureAlgorithms = credential.signatureAlgorithms() ++ if err := hs.handleCertificateRequest(certReq, credential); err != nil { ++ return err + } + + msg, err = c.readHandshake() +@@ -2662,3 +2660,16 @@ func (hs *clientHandshakeState) generatePSKBinders(hello *clientHelloMsg, firstC + // Clear the cached encoding. + hello.raw = nil + } ++ ++func (hs *clientHandshakeState) handleCertificateRequest(certReq *certificateRequestMsg, credential *Credential) error { ++ c := hs.c ++ if expected := c.config.Bugs.ExpectPeerSignatureAlgorithmPreferences; expected != nil { ++ if !slices.Equal(expected, certReq.signatureAlgorithms) { ++ return fmt.Errorf("tls: server offered signature algorithms %v, but expected %v", certReq.signatureAlgorithms, expected) ++ } ++ } ++ if credential != nil && c.config.Bugs.IgnorePeerSignatureAlgorithmPreferences { ++ certReq.signatureAlgorithms = credential.signatureAlgorithms() ++ } ++ return nil ++} +diff --git a/ssl/test/runner/handshake_server.go b/ssl/test/runner/handshake_server.go +index c4ef197a7..66209af18 100644 +--- a/ssl/test/runner/handshake_server.go ++++ b/ssl/test/runner/handshake_server.go +@@ -453,6 +453,12 @@ func (hs *serverHandshakeState) readClientHello() error { + } + } + ++ if expected := c.config.Bugs.ExpectPeerSignatureAlgorithmPreferences; expected != nil { ++ if !slices.Equal(expected, hs.clientHello.signatureAlgorithms) { ++ return fmt.Errorf("tls: client offered signature algorithms %v, but expected %v", hs.clientHello.signatureAlgorithms, expected) ++ } ++ } ++ + applyBugsToClientHello(hs.clientHello, config) + + return nil +diff --git a/ssl/test/runner/signature_algorithm_tests.go b/ssl/test/runner/signature_algorithm_tests.go +index bb93eb47d..08e27a345 100644 +--- a/ssl/test/runner/signature_algorithm_tests.go ++++ b/ssl/test/runner/signature_algorithm_tests.go +@@ -998,6 +998,50 @@ func addSignatureAlgorithmTests() { + expectedError: ":WRONG_SIGNATURE_TYPE:", + }) + ++ // Test that ML-DSA is not advertised by clients below TLS 1.3, even ++ // when explicitly configured. ++ testCases = append(testCases, testCase{ ++ testType: clientTest, ++ name: "VerifyPreferences-MLDSANotAdvertised-TLS12", ++ config: Config{ ++ Credential: &rsaCertificate, ++ Bugs: ProtocolBugs{ ++ ExpectPeerSignatureAlgorithmPreferences: []signatureAlgorithm{signatureRSAPSSWithSHA256}, ++ }, ++ }, ++ flags: []string{ ++ // The client sends ClientHello before it learns the negotiated ++ // version, so filtering out ML-DSA depends on the shim's max ++ // version. ++ "-max-version", strconv.Itoa(VersionTLS12), ++ "-verify-prefs", strconv.Itoa(int(signatureMLDSA44)), ++ "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), ++ }, ++ }) ++ ++ // Test that ML-DSA is not offered by a server in a CertificateVerify ++ // when explicitly configured with TLS 1.2. ++ testCases = append(testCases, testCase{ ++ testType: serverTest, ++ name: "VerifyPreferences-MLDSANotAdvertised-ClientAuth-TLS12", ++ config: Config{ ++ // The server sends CertificateVerify after it negotiates a ++ // version, so filtering out ML-DSA should happen even if the ++ // shim supported TLS 1.3. ++ MaxVersion: VersionTLS12, ++ Credential: &rsaCertificate, ++ Bugs: ProtocolBugs{ ++ ExpectPeerSignatureAlgorithmPreferences: []signatureAlgorithm{signatureRSAPSSWithSHA256}, ++ }, ++ }, ++ shimCertificate: &rsaCertificate, ++ flags: []string{ ++ "-verify-prefs", strconv.Itoa(int(signatureMLDSA44)), ++ "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)), ++ "-require-any-client-certificate", ++ }, ++ }) ++ + // Test that configuring verify preferences changes what the client + // advertises. + testCases = append(testCases, testCase{ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Wu +Date: Tue, 27 Oct 2026 16:14:58 +0100 +Subject: [PATCH] Enable ML-DSA for TLS clients by default + +Servers already support ML-DSA by default, enable it in clients as well. +This also enables verification of ML-DSA mTLS certs for servers. + +Change-Id: I7ea112e7a80e886bdb1a0e8f6871dbb67eea536b +--- + ssl/extensions.cc | 5 +++++ + ssl/test/runner/signature_algorithm_tests.go | 2 +- + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/ssl/extensions.cc b/ssl/extensions.cc +index 8426f22ac..0f1a84017 100644 +--- a/ssl/extensions.cc ++++ b/ssl/extensions.cc +@@ -297,6 +297,11 @@ bool tls1_check_group_id(const SSL_HANDSHAKE *hs, uint16_t group_id) { + // kVerifySignatureAlgorithms is the default list of accepted signature + // algorithms for verifying. + static const uint16_t kVerifySignatureAlgorithms[] = { ++ // CF: prefer PQ ML-DSA over others by default. ++ SSL_SIGN_ML_DSA_44, ++ SSL_SIGN_ML_DSA_65, ++ SSL_SIGN_ML_DSA_87, ++ + // List our preferred algorithms first. + SSL_SIGN_ECDSA_SECP256R1_SHA256, + SSL_SIGN_RSA_PSS_RSAE_SHA256, +diff --git a/ssl/test/runner/signature_algorithm_tests.go b/ssl/test/runner/signature_algorithm_tests.go +index 08e27a345..56d13f1d0 100644 +--- a/ssl/test/runner/signature_algorithm_tests.go ++++ b/ssl/test/runner/signature_algorithm_tests.go +@@ -124,7 +124,7 @@ func addSignatureAlgorithmTests() { + + // By default, BoringSSL does not accept these algorithms. + verifyDefault := !shouldFail +- if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 || alg.id == signatureEd25519 || isTLS13PKCS1 || isMLDSA { ++ if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 || alg.id == signatureEd25519 || isTLS13PKCS1 { + verifyDefault = false + } + +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Peter Wu +Date: Tue, 27 Oct 2026 22:01:23 +0100 +Subject: [PATCH] Enable ML-DSA for FIPS compliance policies + +Keep ML-DSA enabled with fips202205 and fips202609 compliance policies. +We already extended the fips202205 profile with X25519MLKEM768 support +("Add additional post-quantum key agreement"), and now add ML-DSA. +--- + ssl/ssl_lib.cc | 10 ++++++++++ + ssl/test/runner/compliance_policy_tests.go | 4 ++++ + 2 files changed, 14 insertions(+) + +diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc +index b09363e37..78b8778e1 100644 +--- a/ssl/ssl_lib.cc ++++ b/ssl/ssl_lib.cc +@@ -3586,6 +3586,11 @@ static const uint16_t kGroups[] = { + SSL_GROUP_SECP256R1, SSL_GROUP_SECP384R1}; + + static const uint16_t kSigAlgs[] = { ++ // CF: prefer PQ ML-DSA over others. ++ SSL_SIGN_ML_DSA_44, ++ SSL_SIGN_ML_DSA_65, ++ SSL_SIGN_ML_DSA_87, ++ + SSL_SIGN_RSA_PKCS1_SHA256, + SSL_SIGN_RSA_PKCS1_SHA384, + SSL_SIGN_RSA_PKCS1_SHA512, +@@ -3673,6 +3678,11 @@ static const uint32_t kGroupsFlags[] = { + static const uint32_t kOptions = SSL_OP_CIPHER_SERVER_PREFERENCE; + + static const uint16_t kSigAlgs[] = { ++ // CF: prefer PQ ML-DSA over others. ++ SSL_SIGN_ML_DSA_44, ++ SSL_SIGN_ML_DSA_65, ++ SSL_SIGN_ML_DSA_87, ++ + SSL_SIGN_RSA_PKCS1_SHA256, + SSL_SIGN_RSA_PKCS1_SHA384, + SSL_SIGN_RSA_PKCS1_SHA512, +diff --git a/ssl/test/runner/compliance_policy_tests.go b/ssl/test/runner/compliance_policy_tests.go +index 269fbcca6..64b3c50b9 100644 +--- a/ssl/test/runner/compliance_policy_tests.go ++++ b/ssl/test/runner/compliance_policy_tests.go +@@ -304,6 +304,10 @@ func addCompliancePolicyTests() { + signatureRSAPSSWithSHA384, + signatureRSAPSSWithSHA512: + isFIPSSigAlg = true ++ case signatureMLDSA44, ++ signatureMLDSA65, ++ signatureMLDSA87: ++ isFIPSSigAlg = true + } + + var isWPASigAlg bool diff --git a/boring/src/lib.rs b/boring/src/lib.rs index 8c4a3af33..2bc791f39 100644 --- a/boring/src/lib.rs +++ b/boring/src/lib.rs @@ -14,8 +14,8 @@ //! ## BoringSSL version //! //! By default, the crate statically links against a pinned BoringSSL revision, vendored as a -//! submodule at `boring-sys/deps/boringssl`. The current pin is upstream tag `0.20260929.0`. -//! *Note*: any BoringSSL revision bumps will be released as a major version update of all crates. +//! submodule at `boring-sys/deps/boringssl`. The current pin is upstream tag `0.20261020.0`. +//! *Note*: any BoringSSL revision bumps will be released as a minor version update of all crates. //! //! # Compilation and linking options //! @@ -27,7 +27,8 @@ //! ## Support for pre-built binaries or custom source //! //! While this crate can build BoringSSL on its own, you may want to provide pre-built binaries instead. -//! To do so, specify the environment variable `BORING_BSSL{,_FIPS}_PATH` with the path to the binaries. +//! To do so, specify the environment variable `BORING_BSSL_PATH` or `BORING_BSSL_FIPS_PATH` with +//! the path to the binaries. //! //! You can also provide specific headers by setting `BORING_BSSL{,_FIPS}_INCLUDE_PATH`. //! @@ -40,11 +41,11 @@ //! _Warning_: When providing a different version of BoringSSL make sure to use a compatible one, the //! crate relies on the presence of certain functions. //! -//! ## Building with a FIPS-validated module +//! ## FIPS 140-3 //! -//! Only BoringCrypto module version `853ca1ea1168dff08011e5d42d94609cc0ca2e27`, as certified with -//! [FIPS 140-2 certificate 4407](https://csrc.nist.gov/projects/cryptographic-module-validation-program/certificate/4407) -//! is supported by this crate. Support is enabled by this crate's `fips` feature. +//! Use the `fips` feature to enable building the BoringCrypto FIPS module in FIPS mode. The +//! vendored BoringSSL sources are the [update stream of a validated +//! module](https://github.com/google/boringssl/blob/main/crypto/fipsmodule/FIPS.md#update-stream). //! //! `boring-sys` comes with a test that FIPS is enabled/disabled depending on the feature flag. You can run it as follows: //! @@ -82,15 +83,17 @@ //! post-quantum key agreement from RFC 10024, by default. The `pq-experimental` //! feature is a no-op kept only for backwards compatibility. //! -//! We patch BpringSSL to additionally support - +//! We patch BoringSSL to additionally support these key agreements, they will be removed in the +//! future: +//! //! - `X25519Kyber768Draft00`, under codepoint `0x6399`. This is the pre-standard predecessor of //! `X25519MLKEM768`. Not recommended; it's being phased out. //! - `P256Kyber768Draft00`, under codepoint `0xfe32`, which uses P-256 as the classical part. //! In the past we needed this for compliance reasons. Not recommended; it's being phased out. //! -//! Presently all these key agreements are deployed by Cloudflare. We only support `X25519MLKEM768` -//! long term. +//! Upstream BoringSSL supports ML-DSA for authentication in TLS 1.3, but only enables it for +//! servers by default. We patch BoringSSL to enable ML-DSA for clients by default as well, and +//! enable ML-DSA for both in the fips202205 and fips202609 compliance profiles. #[macro_use] extern crate bitflags; From c4e23932cb25a70cfab15bcea6bd54beb143736b Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Mon, 19 Oct 2026 06:22:46 +0000 Subject: [PATCH 18/20] boring-sys: clear repository-local git env vars in build script A build started from a git hook inherits GIT_DIR and related variables, so the build script's git init and git apply ran against the caller's repository instead of the copied BoringSSL sources. From a worktree this writes core.bare = true into the main checkout's config. Fixes #527 --- boring-sys/build/main.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/boring-sys/build/main.rs b/boring-sys/build/main.rs index a34270cc6..709e4949e 100644 --- a/boring-sys/build/main.rs +++ b/boring-sys/build/main.rs @@ -158,7 +158,7 @@ fn get_boringssl_source_path(config: &Config) -> &Path { println!("cargo:warning=fetching boringssl git submodule"); run_command( - Command::new("git") + git_command() .args(["submodule", "update", "--init", "--recursive"]) .arg(&submodule_path), ) @@ -497,7 +497,7 @@ fn ensure_patches_applied(config: &Config) -> io::Result<()> { // NOTE: init git in the copied files, so we can apply patches if !has_git { - run_command(Command::new("git").arg("init").current_dir(src_path))?; + run_command(git_command().arg("init").current_dir(src_path))?; } if config.features.allow_crl_extensions_bad_version { @@ -549,7 +549,7 @@ fn apply_patch(config: &Config, patch_name: &str) -> io::Result<()> { } run_command( - Command::new("git") + git_command() .args(&args) .arg(cmd_path) .current_dir(src_path), @@ -558,6 +558,36 @@ fn apply_patch(config: &Config, patch_name: &str) -> io::Result<()> { Ok(()) } +/// Repository-local variables, as listed by `git rev-parse --local-env-vars`. +/// +/// Git sets these when it runs hooks, so a build started from a hook would +/// otherwise run `git` against the caller's repository instead of the BoringSSL sources. +const GIT_LOCAL_ENV_VARS: &[&str] = &[ + "GIT_ALTERNATE_OBJECT_DIRECTORIES", + "GIT_CONFIG", + "GIT_CONFIG_PARAMETERS", + "GIT_CONFIG_COUNT", + "GIT_OBJECT_DIRECTORY", + "GIT_DIR", + "GIT_WORK_TREE", + "GIT_IMPLICIT_WORK_TREE", + "GIT_GRAFT_FILE", + "GIT_INDEX_FILE", + "GIT_NO_REPLACE_OBJECTS", + "GIT_REPLACE_REF_BASE", + "GIT_PREFIX", + "GIT_SHALLOW_FILE", + "GIT_COMMON_DIR", +]; + +fn git_command() -> Command { + let mut command = Command::new("git"); + for var in GIT_LOCAL_ENV_VARS { + command.env_remove(var); + } + command +} + fn run_command(command: &mut Command) -> io::Result { let out = command.output().map_err(|e| { io::Error::new( From fa5efdca1280f9437b199bda9eac9dd43eca4658 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 30 Oct 2026 10:25:50 +0100 Subject: [PATCH 19/20] Add unchecked DER certificate setters `SslRef::set_certificate_der_unchecked` and `SslContextBuilder::set_certificate_der_unchecked` allow callers to preserve certificate DER that cannot be represented by a parsed `X509Ref`. The impl of `AsRef` for `Asn1TimeRef` lets callers inspect encoded time bytes without direct FFI. Documentation notes that the unchecked setters bypass full X.509 parsing, and tests cover both setters. --- boring/src/asn1.rs | 17 +++++++++++++++ boring/src/ssl/mod.rs | 42 ++++++++++++++++++++++++++++++++++++++ boring/src/ssl/test/mod.rs | 36 ++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/boring/src/asn1.rs b/boring/src/asn1.rs index 31aeccd1c..134907ac8 100644 --- a/boring/src/asn1.rs +++ b/boring/src/asn1.rs @@ -252,6 +252,14 @@ impl Asn1TimeRef { } } +impl AsRef for Asn1TimeRef { + fn as_ref(&self) -> &Asn1StringRef { + // SAFETY: `ASN1_TIME` is a typedef of `ASN1_STRING`, and the returned + // reference is bounded by the lifetime of `self`. + unsafe { Asn1StringRef::from_ptr(self.as_ptr().cast()) } + } +} + impl PartialEq for Asn1TimeRef { fn eq(&self, other: &Asn1TimeRef) -> bool { self.diff(other) @@ -830,6 +838,15 @@ mod tests { assert_eq!("Jan 1 00:00:00 1970 GMT", t.to_string()); } + #[test] + fn time_as_asn1_string() { + let time = Asn1Time::from_str("99991231235959Z").unwrap(); + let time_ref: &Asn1TimeRef = time.as_ref(); + let string_ref: &Asn1StringRef = time_ref.as_ref(); + + assert_eq!(string_ref.as_slice(), b"99991231235959Z"); + } + #[test] fn time_eq() { let a = Asn1Time::from_str("99991231235959Z").unwrap(); diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index e0f358d6e..7062fc927 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -1475,6 +1475,27 @@ impl SslContextBuilder { unsafe { cvt(ffi::SSL_CTX_use_certificate(self.as_ptr(), cert.as_ptr())) } } + /// Sets the leaf certificate from its DER encoding without fully parsing it. + /// + /// BoringSSL copies `der` and performs only the checks needed to extract a + /// supported public key. Other malformed certificate fields may be accepted. + /// + /// # Warning + /// + /// Callers should normally parse the DER with [`X509::from_der`] and use + /// [`Self::set_certificate`]. This method is intended for cases that must + /// preserve certificate DER which cannot be represented by an [`X509Ref`]. + #[corresponds(SSL_CTX_use_certificate_ASN1)] + pub fn set_certificate_der_unchecked(&mut self, der: &[u8]) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::SSL_CTX_use_certificate_ASN1( + self.as_ptr(), + der.len(), + der.as_ptr(), + )) + } + } + /// Appends a certificate to the certificate chain. /// /// This chain should contain all certificates necessary to go from the certificate specified by @@ -3876,6 +3897,27 @@ impl SslRef { Ok(()) } + /// Sets the leaf certificate from its DER encoding without fully parsing it. + /// + /// BoringSSL copies `der` and performs only the checks needed to extract a + /// supported public key. Other malformed certificate fields may be accepted. + /// + /// # Warning + /// + /// Callers should normally parse the DER with [`X509::from_der`] and use + /// [`Self::set_certificate`]. This method is intended for cases that must + /// preserve certificate DER which cannot be represented by an [`X509Ref`]. + #[corresponds(SSL_use_certificate_ASN1)] + pub fn set_certificate_der_unchecked(&mut self, der: &[u8]) -> Result<(), ErrorStack> { + unsafe { + cvt(ffi::SSL_use_certificate_ASN1( + self.as_ptr(), + der.as_ptr(), + der.len(), + )) + } + } + /// Sets the list of CA names sent to the client. /// /// The CA certificates must still be added to the trust root - they are not automatically set diff --git a/boring/src/ssl/test/mod.rs b/boring/src/ssl/test/mod.rs index 4ee5d0aef..a3d42bfb7 100644 --- a/boring/src/ssl/test/mod.rs +++ b/boring/src/ssl/test/mod.rs @@ -8,6 +8,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::Arc; use std::thread; +use crate::asn1::Asn1StringRef; use crate::error::ErrorStack; use crate::hash::MessageDigest; use crate::pkey::PKey; @@ -40,6 +41,41 @@ static CERT: &[u8] = include_bytes!("../../../test/cert.pem"); static KEY: &[u8] = include_bytes!("../../../test/key.pem"); const TEST_CERT_DIGEST: &str = "585e3a58acfd3b4e5e2825659407244ddd93539c"; +fn malformed_certificate_der() -> Vec { + const MALFORMED_TIME: &[u8] = b"250231000000Z"; + + let cert = X509::from_pem(CERT).unwrap(); + let time: &Asn1StringRef = cert.not_before().as_ref(); + let original = time.as_slice(); + assert_eq!(original.len(), MALFORMED_TIME.len()); + + let mut der = cert.to_der().unwrap(); + let offset = der + .windows(original.len()) + .position(|window| window == original) + .unwrap(); + der[offset..offset + MALFORMED_TIME.len()].copy_from_slice(MALFORMED_TIME); + assert!(X509::from_der(&der).is_err()); + + der +} + +#[test] +fn set_context_certificate_der_unchecked() { + let mut context = SslContext::builder(SslMethod::tls()).unwrap(); + context + .set_certificate_der_unchecked(&malformed_certificate_der()) + .unwrap(); +} + +#[test] +fn set_certificate_der_unchecked() { + let context = SslContext::builder(SslMethod::tls()).unwrap().build(); + let mut ssl = Ssl::new(&context).unwrap(); + ssl.set_certificate_der_unchecked(&malformed_certificate_der()) + .unwrap(); +} + #[test] fn get_ctx_options() { let ctx = SslContext::builder(SslMethod::tls()).unwrap(); From 309bf35b9eb97fc21040915a5f4a886941965c47 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 30 Oct 2026 10:58:15 +0000 Subject: [PATCH 20/20] Release 5.4.0 --- Cargo.toml | 8 ++++---- RELEASE_NOTES | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b2a823118..88364d939 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ resolver = "2" [workspace.package] -version = "5.3.0" +version = "5.4.0" rust-version = "1.85" repository = "https://github.com/cloudflare/boring" edition = "2021" @@ -20,9 +20,9 @@ tag-prefix = "" publish = false [workspace.dependencies] -boring-sys = { version = "5.3.0", path = "./boring-sys", default-features = false } -boring = { version = "5.3.0", path = "./boring", default-features = false } -tokio-boring = { version = "5.3.0", path = "./tokio-boring", default-features = false } +boring-sys = { version = "5.4.0", path = "./boring-sys", default-features = false } +boring = { version = "5.4.0", path = "./boring", default-features = false } +tokio-boring = { version = "5.4.0", path = "./tokio-boring", default-features = false } bindgen = { version = "0.72.0", default-features = false, features = ["runtime"] } bitflags = "2.9" diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 235d64691..dd2937724 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -1,3 +1,12 @@ +5.4.0 +- 2026-10-30 Add unchecked DER certificate setters +- 2026-10-28 Update to boringssl 0.20261020.0 with ML-DSA by default +- 2026-10-23 Add Asn1IntegerRef::to_der_contents +- 2026-10-19 Make crates.io publishing a guarded manual release (#541) +- 2026-03-27 Constants for rust-openssl compat +- 2026-03-27 `ASN1_INTEGER_*`, `BN_*` functions +- 2026-10-14 Add crates.io trusted publishing (#535) + 5.3.0 - 2026-10-14 Add action-aware certificate selection callbacks - 2026-10-14 Back-compat shims for v4