Skip to content

Commit a4aed36

Browse files
stefanbergerjarkkojs
authored andcommitted
certs: Add support for using elliptic curve keys for signing modules
Add support for using elliptic curve keys for signing modules. It uses a NIST P384 (secp384r1) key if the user chooses an elliptic curve key and will have ECDSA support built into the kernel. Note: A developer choosing an ECDSA key for signing modules should still delete the signing key (rm certs/signing_key.*) when building an older version of a kernel that only supports RSA keys. Unless kbuild automati- cally detects and generates a new kernel module key, ECDSA-signed kernel modules will fail signature verification. Cc: David Howells <[email protected]> Cc: David Woodhouse <[email protected]> Signed-off-by: Stefan Berger <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent ea35e0d commit a4aed36

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

certs/Kconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@ config MODULE_SIG_KEY
1515
then the kernel will automatically generate the private key and
1616
certificate as described in Documentation/admin-guide/module-signing.rst
1717

18+
choice
19+
prompt "Type of module signing key to be generated"
20+
default MODULE_SIG_KEY_TYPE_RSA
21+
help
22+
The type of module signing key type to generate. This option
23+
does not apply if a #PKCS11 URI is used.
24+
25+
config MODULE_SIG_KEY_TYPE_RSA
26+
bool "RSA"
27+
depends on MODULE_SIG || (IMA_APPRAISE_MODSIG && MODULES)
28+
help
29+
Use an RSA key for module signing.
30+
31+
config MODULE_SIG_KEY_TYPE_ECDSA
32+
bool "ECDSA"
33+
select CRYPTO_ECDSA
34+
depends on MODULE_SIG || (IMA_APPRAISE_MODSIG && MODULES)
35+
help
36+
Use an elliptic curve key (NIST P384) for module signing. Consider
37+
using a strong hash like sha256 or sha384 for hashing modules.
38+
39+
Note: Remove all ECDSA signing keys, e.g. certs/signing_key.pem,
40+
when falling back to building Linux 5.14 and older kernels.
41+
42+
endchoice
43+
1844
config SYSTEM_TRUSTED_KEYRING
1945
bool "Provide system-wide ring of trusted keys"
2046
depends on KEYS

certs/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,21 @@ ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
6666

6767
ifeq ($(openssl_available),yes)
6868
X509TEXT=$(shell openssl x509 -in "certs/signing_key.pem" -text 2>/dev/null)
69+
endif
6970

71+
# Support user changing key type
72+
ifdef CONFIG_MODULE_SIG_KEY_TYPE_ECDSA
73+
keytype_openssl = -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
74+
ifeq ($(openssl_available),yes)
75+
$(if $(findstring id-ecPublicKey,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem"))
76+
endif
77+
endif # CONFIG_MODULE_SIG_KEY_TYPE_ECDSA
78+
79+
ifdef CONFIG_MODULE_SIG_KEY_TYPE_RSA
80+
ifeq ($(openssl_available),yes)
7081
$(if $(findstring rsaEncryption,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem"))
7182
endif
83+
endif # CONFIG_MODULE_SIG_KEY_TYPE_RSA
7284

7385
$(obj)/signing_key.pem: $(obj)/x509.genkey
7486
@$(kecho) "###"
@@ -83,6 +95,7 @@ $(obj)/signing_key.pem: $(obj)/x509.genkey
8395
-batch -x509 -config $(obj)/x509.genkey \
8496
-outform PEM -out $(obj)/signing_key.pem \
8597
-keyout $(obj)/signing_key.pem \
98+
$(keytype_openssl) \
8699
$($(quiet)redirect_openssl)
87100
@$(kecho) "###"
88101
@$(kecho) "### Key pair generated."

crypto/asymmetric_keys/pkcs7_parser.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ int pkcs7_sig_note_pkey_algo(void *context, size_t hdrlen,
269269
ctx->sinfo->sig->pkey_algo = "rsa";
270270
ctx->sinfo->sig->encoding = "pkcs1";
271271
break;
272+
case OID_id_ecdsa_with_sha1:
273+
case OID_id_ecdsa_with_sha224:
274+
case OID_id_ecdsa_with_sha256:
275+
case OID_id_ecdsa_with_sha384:
276+
case OID_id_ecdsa_with_sha512:
277+
ctx->sinfo->sig->pkey_algo = "ecdsa";
278+
ctx->sinfo->sig->encoding = "x962";
279+
break;
272280
default:
273281
printk("Unsupported pkey algo: %u\n", ctx->last_oid);
274282
return -ENOPKG;

0 commit comments

Comments
 (0)