Fix compilation with openssl 4.0

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2026-04-14 19:02:46 +02:00
commit 7d16ad00bd
2 changed files with 84 additions and 0 deletions

81
41639.patch Normal file
View file

@ -0,0 +1,81 @@
From 92c93fc9cc0012c3596e312167b054facafc216f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@amutable.com>
Date: Tue, 14 Apr 2026 18:59:07 +0200
Subject: [PATCH] various: fix compilation with openssl-4.0.0-beta1
Various types have been made opaque, so we need to use some accessor
functions.
---
src/sbsign/sbsign.c | 6 ++++--
src/shared/pkcs11-util.c | 16 +++++++++-------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/sbsign/sbsign.c b/src/sbsign/sbsign.c
index d13dc5e326..2453ebb3ea 100644
--- a/src/sbsign/sbsign.c
+++ b/src/sbsign/sbsign.c
@@ -262,8 +262,10 @@ static int spc_indirect_data_content_new(const void *digest, size_t digestsz, ui
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to get SpcPeImageData object: %s",
ERR_error_string(ERR_get_error(), NULL));
- idc->data->value->value.sequence->data = TAKE_PTR(peidraw);
- idc->data->value->value.sequence->length = peidrawsz;
+ if (!ASN1_STRING_set(idc->data->value->value.sequence, peidraw, peidrawsz))
+ return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to set ASN1_STRING data.");
+ TAKE_PTR(peidraw);
+
idc->messageDigest->digestAlgorithm->algorithm = OBJ_nid2obj(NID_sha256);
if (!idc->messageDigest->digestAlgorithm->algorithm)
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to get SHA256 object: %s",
diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c
index 3062bcc554..693445eb41 100644
--- a/src/shared/pkcs11-util.c
+++ b/src/shared/pkcs11-util.c
@@ -553,8 +553,13 @@ int pkcs11_token_read_public_key(
if (EVP_PKEY_fromdata_init(ctx) != 1)
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Failed to init an EVP_PKEY_CTX for EC.");
+
OSSL_PARAM ec_params[8] = {
- OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY, os->data, os->length)
+ /* We need to drop the const from the data param, because ec_params is
+ * modified below. But we'll not modify ec_params[0]. */
+ OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_PUB_KEY,
+ (unsigned char *) ASN1_STRING_get0_data(os),
+ ASN1_STRING_length(os)),
};
_cleanup_free_ void *order = NULL, *p = NULL, *a = NULL, *b = NULL, *generator = NULL;
@@ -657,13 +662,10 @@ int pkcs11_token_read_x509_certificate(
CK_OBJECT_HANDLE object,
X509 **ret_cert) {
- _cleanup_free_ char *t = NULL;
CK_ATTRIBUTE attribute = {
.type = CKA_VALUE
};
CK_RV rv;
- _cleanup_(X509_freep) X509 *x509 = NULL;
- X509_NAME *name = NULL;
int r;
r = dlopen_p11kit();
@@ -687,15 +689,15 @@ int pkcs11_token_read_x509_certificate(
"Failed to read X.509 certificate data off token: %s", sym_p11_kit_strerror(rv));
const unsigned char *p = attribute.pValue;
- x509 = d2i_X509(NULL, &p, attribute.ulValueLen);
+ _cleanup_(X509_freep) X509 *x509 = d2i_X509(NULL, &p, attribute.ulValueLen);
if (!x509)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Failed to parse X.509 certificate.");
- name = X509_get_subject_name(x509);
+ const X509_NAME *name = X509_get_subject_name(x509);
if (!name)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Failed to acquire X.509 subject name.");
- t = X509_NAME_oneline(name, NULL, 0);
+ _cleanup_free_ char *t = X509_NAME_oneline(name, NULL, 0);
if (!t)
return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Failed to format X.509 subject name as string.");

View file

@ -152,6 +152,9 @@ Patch: 38769.patch
# Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=2415701
Patch: 0002-machined-continue-without-resolve.hook-socket.patch
# Fix compilation with openssl 4.0
Patch: https://github.com/systemd/systemd/pull/41639.patch
%endif
%ifarch %{ix86} x86_64 aarch64 riscv64