🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.gentoo.dev
Article #238

[gentoo-dev] [PATCH 1/6] secureboot.eclass: support PKCS#11 keys with OpenSSL 4

#238
From: David Seifert
Date: Tue, 01 Dec 2026 16:00
68 lines
3612 bytes
OpenSSL 4 dropped the ENGINE API. Use pkcs11-provider for the key check
and systemd-sbsign, and sbsign's --provider option from
sbsigntools-0.9.5_p1 on.

Signed-off-by: David Seifert <soap@gentoo.org>
---
 eclass/secureboot.eclass | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/eclass/secureboot.eclass b/eclass/secureboot.eclass
index 15c86e58ffab0..a259ce362833f 100644
--- a/eclass/secureboot.eclass
+++ b/eclass/secureboot.eclass
@@ -65,7 +65,8 @@ BDEPEND="
 # @DEFAULT_UNSET
 # @DESCRIPTION:
 # Used with USE=secureboot.  Should be set to the path of the private
-# key in PEM format to use, or a PKCS#11 URI.
+# key in PEM format to use, or a PKCS#11 URI.  With OpenSSL 4, PKCS#11
+# URIs require dev-libs/pkcs11-provider.
 # If unspecified the following locations are tried in order:
 # - /etc/portage/secureboot.pem
 # - /var/lib/sbctl/keys/db/db.{key,pem} (from app-crypt/sbctl)
@@ -201,7 +202,12 @@ secureboot_pkg_setup() {
 			-noout -nocert
 		)
 		if [[ ${SECUREBOOT_SIGN_KEY} == pkcs11:* ]]; then
-			openssl_args+=( -engine pkcs11 -keyform ENGINE -key "${SECUREBOOT_SIGN_KEY}" )
+			# OpenSSL 4 removed the ENGINE API
+			if has_version -b ">=dev-libs/openssl-4"; then
+				openssl_args+=( -provider default -provider pkcs11 -key "${SECUREBOOT_SIGN_KEY}" )
+			else
+				openssl_args+=( -engine pkcs11 -keyform ENGINE -key "${SECUREBOOT_SIGN_KEY}" )
+			fi
 		else
 			openssl_args+=( -keyform PEM -key "${SECUREBOOT_SIGN_KEY}" )
 		fi
@@ -243,7 +249,13 @@ secureboot_sign_efi_file() {
 					"--cert=${SECUREBOOT_SIGN_CERT}"
 				)
 				if [[ ${SECUREBOOT_SIGN_KEY} == pkcs11:* ]]; then
-					args+=( "--engine=pkcs11" )
+					# 0.9.5_p1 replaced --engine with --provider
+					if has_version -b ">=app-crypt/sbsigntools-0.9.5_p1"; then
+						# sbsign loads the default provider before this one
+						args+=( "--provider=pkcs11" )
+					else
+						args+=( "--engine=pkcs11" )
+					fi
 				fi
 
 				"${EPREFIX}/usr/bin/sbsign" "${input_file}" "${args[@]}"
@@ -254,7 +266,12 @@ secureboot_sign_efi_file() {
 					"--certificate=${SECUREBOOT_SIGN_CERT}"
 				)
 				if [[ ${SECUREBOOT_SIGN_KEY} == pkcs11:* ]]; then
-					args+=( "--private-key-source=engine:pkcs11" )
+					# OpenSSL 4 removed the ENGINE API
+					if has_version -b ">=dev-libs/openssl-4"; then
+						args+=( "--private-key-source=provider:pkcs11" )
+					else
+						args+=( "--private-key-source=engine:pkcs11" )
+					fi
 				fi
 
 				"${EPREFIX}/usr/lib/systemd/systemd-sbsign" sign "${input_file}" "${args[@]}"
-- 
2.56.1
Technical Details
Message-ID: <O5yqR-fmyc-3@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!news.nntp4.net!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!news.nntp4.net!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: David Seifert <soap@gentoo.org>
Newsgroups: linux.gentoo.dev
Subject: [gentoo-dev] [PATCH 1/6] secureboot.eclass: support PKCS#11 keys with OpenSSL 4
Date: Tue, 01 Dec 2026 17:00:01 +0100
Message-ID: <O5yqR-fmyc-3@gated-at.bofh.it>
X-Original-To: gentoo-dev@lists.gentoo.org
X-Mailer: git-send-email 2.56.1
List-ID: Gentoo Linux mail <gentoo-dev.gentoo.org>
Reply-To: gentoo-dev@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Approved: robomod@news.nic.it
Lines: 68
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Cc: David Seifert <soap@gentoo.org>
X-Original-Date: Tue,  1 Dec 2026 16:49:19 +0100
X-Original-Message-ID: <20261201154924.70252-1-soap@gentoo.org>