From: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
Subject: [gentoo-dev] [PATCH 2/3] kernel-build.eclass: check and fail early if key or cert in DER format
Date: Sun, 21 Jul 2024 10:59:23 +0200 [thread overview]
Message-ID: <20240721085924.11882-2-andrewammerlaan@gentoo.org> (raw)
In-Reply-To: <20240721085924.11882-1-andrewammerlaan@gentoo.org>
Bug: https://bugs.gentoo.org/936402
Signed-off-by: Andrew Ammerlaan <andrewammerlaan@gentoo.org>
---
eclass/kernel-build.eclass | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index cf060fa83766..fa01be28723f 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -133,8 +133,28 @@ kernel-build_pkg_setup() {
python-any-r1_pkg_setup
if [[ ${KERNEL_IUSE_MODULES_SIGN} ]]; then
secureboot_pkg_setup
- if [[ -e ${MODULES_SIGN_KEY} && ${MODULES_SIGN_KEY} != pkcs11:* ]]; then
- if [[ -e ${MODULES_SIGN_CERT} && ${MODULES_SIGN_CERT} != ${MODULES_SIGN_KEY} ]]; then
+
+ # Sanity check: fail early if key/cert in DER format or does not exist
+ local openssl_args=(
+ -noout -nocert
+ )
+ if [[ -n ${MODULES_SIGN_CERT} ]]; then
+ openssl_args+=( -inform PEM -in "${MODULES_SIGN_CERT}" )
+ else
+ # If no cert specified, we assume the pem key also contains the cert
+ openssl_args+=( -inform PEM -in "${MODULES_SIGN_KEY}" )
+ fi
+ if [[ ${MODULES_SIGN_KEY} == pkcs11:* ]]; then
+ openssl_args+=( -engine pkcs11 -keyform ENGINE -key "${MODULES_SIGN_KEY}" )
+ else
+ openssl_args+=( -keyform PEM -key "${MODULES_SIGN_KEY}" )
+ fi
+
+ openssl x509 "${openssl_args[@]}" ||
+ die "Kernel module signing certificate or key not found or not PEM format."
+
+ if [[ ${MODULES_SIGN_KEY} != pkcs11:* ]]; then
+ if [[ ${MODULES_SIGN_CERT} != ${MODULES_SIGN_KEY} ]]; then
MODULES_SIGN_KEY_CONTENTS="$(cat "${MODULES_SIGN_CERT}" "${MODULES_SIGN_KEY}" || die)"
else
MODULES_SIGN_KEY_CONTENTS="$(< "${MODULES_SIGN_KEY}")"
--
2.45.2
next prev parent reply other threads:[~2024-07-21 8:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-21 8:59 [gentoo-dev] [PATCH 1/3] secureboot.eclass: check and fail early if key or cert in DER format Andrew Ammerlaan
2024-07-21 8:59 ` Andrew Ammerlaan [this message]
2024-07-21 8:59 ` [gentoo-dev] [PATCH 3/3] kernel-build.eclass: don't check key/cert if merging binary Andrew Ammerlaan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240721085924.11882-2-andrewammerlaan@gentoo.org \
--to=andrewammerlaan@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox