Skip to content

Commit

Permalink
Prepare Rust for the next libcrypto bump
Browse files Browse the repository at this point in the history
X509V3_EXT_add_alias() will go away and X509_PURPOSE_get0() will return
a const pointer. This breaks the build of the vendored rust-openssl crate.
Fix this by pulling in (parts of) the following upstream PRs:

sfackler/rust-openssl#2121
sfackler/rust-openssl#2124

ok semarie (maintainer)
  • Loading branch information
botovq committed Dec 12, 2023
1 parent b8c4974 commit aedb68b
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lang/rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COMMENT-src = Rust source component

V = 1.74.0
DISTNAME = rustc-${V}-src
REVISION = 0
REVISION = 1

# rustc bootstrap version
BV-aarch64 = 1.74.0-20231115
Expand Down
15 changes: 15 additions & 0 deletions lang/rust/patches/patch-vendor_openssl-sys_build_cfgs_rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
https://github.com/sfackler/rust-openssl/pull/2124

Index: vendor/openssl-sys/build/cfgs.rs
--- vendor/openssl-sys/build/cfgs.rs.orig
+++ vendor/openssl-sys/build/cfgs.rs
@@ -53,6 +53,9 @@ pub fn get(openssl_version: Option<u64>, libressl_vers
if libressl_version >= 0x3_07_00_00_0 {
cfgs.push("libressl370");
}
+ if libressl_version >= 0x3_09_00_00_0 {
+ cfgs.push("libressl390");
+ }
} else {
let openssl_version = openssl_version.unwrap();

17 changes: 17 additions & 0 deletions lang/rust/patches/patch-vendor_openssl-sys_src_handwritten_x509_rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
https://github.com/sfackler/rust-openssl/pull/2124

Index: vendor/openssl-sys/src/handwritten/x509.rs
--- vendor/openssl-sys/src/handwritten/x509.rs.orig
+++ vendor/openssl-sys/src/handwritten/x509.rs
@@ -700,10 +700,8 @@ pub struct X509_PURPOSE {
const_ptr_api! {
extern "C" {
pub fn X509_PURPOSE_get_by_sname(sname: #[const_ptr_if(any(ossl110, libressl280))] c_char) -> c_int;
+ pub fn X509_PURPOSE_get0(idx: c_int) -> #[const_ptr_if(libressl390)] X509_PURPOSE;
}
-}
-extern "C" {
- pub fn X509_PURPOSE_get0(idx: c_int) -> *mut X509_PURPOSE;
}

extern "C" {
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
https://github.com/sfackler/rust-openssl/pull/2124

Index: vendor/openssl-sys/src/handwritten/x509v3.rs
--- vendor/openssl-sys/src/handwritten/x509v3.rs.orig
+++ vendor/openssl-sys/src/handwritten/x509v3.rs
@@ -84,6 +84,7 @@ const_ptr_api! {
}

extern "C" {
+ #[cfg(not(libressl390))]
pub fn X509V3_EXT_add_alias(nid_to: c_int, nid_from: c_int) -> c_int;
pub fn X509V3_EXT_d2i(ext: *mut X509_EXTENSION) -> *mut c_void;
pub fn X509V3_EXT_i2d(ext_nid: c_int, crit: c_int, ext: *mut c_void) -> *mut X509_EXTENSION;
15 changes: 15 additions & 0 deletions lang/rust/patches/patch-vendor_openssl_build_rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
https://github.com/sfackler/rust-openssl/pull/2124

Index: vendor/openssl/build.rs
--- vendor/openssl/build.rs.orig
+++ vendor/openssl/build.rs
@@ -73,6 +73,9 @@ fn main() {
for var in vars.split(',') {
println!("cargo:rustc-cfg=osslconf=\"{}\"", var);
}
+ if version >= 0x3_09_00_00_0 {
+ println!("cargo:rustc-cfg=libressl390");
+ }
}

if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") {
21 changes: 21 additions & 0 deletions lang/rust/patches/patch-vendor_openssl_src_lib_rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Part of https://github.com/sfackler/rust-openssl/pull/2121

Index: vendor/openssl/src/lib.rs
--- vendor/openssl/src/lib.rs.orig
+++ vendor/openssl/src/lib.rs
@@ -204,6 +204,15 @@ fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
}

#[inline]
+fn cvt_p_const<T>(r: *const T) -> Result<*const T, ErrorStack> {
+ if r.is_null() {
+ Err(ErrorStack::get())
+ } else {
+ Ok(r)
+ }
+}
+
+#[inline]
fn cvt(r: c_int) -> Result<c_int, ErrorStack> {
if r <= 0 {
Err(ErrorStack::get())
34 changes: 34 additions & 0 deletions lang/rust/patches/patch-vendor_openssl_src_x509_mod_rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From https://github.com/sfackler/rust-openssl/pull/2121
and https://github.com/sfackler/rust-openssl/pull/2124

Index: vendor/openssl/src/x509/mod.rs
--- vendor/openssl/src/x509/mod.rs.orig
+++ vendor/openssl/src/x509/mod.rs
@@ -38,7 +38,7 @@ use crate::ssl::SslRef;
use crate::stack::{Stack, StackRef, Stackable};
use crate::string::OpensslString;
use crate::util::{ForeignTypeExt, ForeignTypeRefExt};
-use crate::{cvt, cvt_n, cvt_p};
+use crate::{cvt, cvt_n, cvt_p, cvt_p_const};
use openssl_macros::corresponds;

#[cfg(any(ossl102, libressl261))]
@@ -1022,6 +1022,7 @@ impl X509Extension {
/// # Safety
///
/// This method modifies global state without locking and therefore is not thread safe
+ #[cfg(not(libressl390))]
#[corresponds(X509V3_EXT_add_alias)]
#[deprecated(
note = "Use x509::extension types or new_from_der and then this is not necessary",
@@ -2511,8 +2512,8 @@ impl X509PurposeRef {
#[corresponds(X509_PURPOSE_get0)]
pub fn from_idx(idx: c_int) -> Result<&'static X509PurposeRef, ErrorStack> {
unsafe {
- let ptr = cvt_p(ffi::X509_PURPOSE_get0(idx))?;
- Ok(X509PurposeRef::from_ptr(ptr))
+ let ptr = cvt_p_const(ffi::X509_PURPOSE_get0(idx))?;
+ Ok(X509PurposeRef::from_const_ptr(ptr))
}
}

0 comments on commit aedb68b

Please sign in to comment.