Skip to content

Commit e06a61a

Browse files
committed
certs: use if_changed to re-generate the key when the key type is changed
If the key type of the existing signing key does not match to CONFIG_MODULE_SIG_KEY_TYPE_*, the Makefile removes it so that it is re-generated. Use if_changed so that the key is re-generated when the key type is changed (that is, the openssl command line is changed). Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 54c8b51 commit e06a61a

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

certs/Makefile

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,23 @@ ifdef SIGN_KEY
5151
#
5252
###############################################################################
5353

54-
openssl_available = $(shell openssl help 2>/dev/null && echo yes)
55-
5654
# We do it this way rather than having a boolean option for enabling an
5755
# external private key, because 'make randconfig' might enable such a
5856
# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
5957
ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
6058

61-
ifeq ($(openssl_available),yes)
62-
X509TEXT=$(shell openssl x509 -in "certs/signing_key.pem" -text 2>/dev/null)
63-
endif
64-
65-
# Support user changing key type
66-
ifdef CONFIG_MODULE_SIG_KEY_TYPE_ECDSA
67-
keytype_openssl = -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
68-
ifeq ($(openssl_available),yes)
69-
$(if $(findstring id-ecPublicKey,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem"))
70-
endif
71-
endif # CONFIG_MODULE_SIG_KEY_TYPE_ECDSA
72-
73-
ifdef CONFIG_MODULE_SIG_KEY_TYPE_RSA
74-
ifeq ($(openssl_available),yes)
75-
$(if $(findstring rsaEncryption,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem"))
76-
endif
77-
endif # CONFIG_MODULE_SIG_KEY_TYPE_RSA
59+
keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
7860

7961
quiet_cmd_gen_key = GENKEY $@
8062
cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
8163
-batch -x509 -config $(obj)/x509.genkey \
8264
-outform PEM -out $(obj)/signing_key.pem \
83-
-keyout $(obj)/signing_key.pem \
84-
$(keytype_openssl) \
85-
2>&1
65+
-keyout $(obj)/signing_key.pem $(keytype-y) 2>&1
66+
67+
$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE
68+
$(call if_changed,gen_key)
8669

87-
$(obj)/signing_key.pem: $(obj)/x509.genkey
88-
$(call cmd,gen_key)
70+
targets += signing_key.pem
8971

9072
quiet_cmd_copy_x509_config = COPY $@
9173
cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@

0 commit comments

Comments
 (0)