xref: /openbmc/linux/certs/Makefile (revision f3a2ba44)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2cfc411e7SDavid Howells#
3cfc411e7SDavid Howells# Makefile for the linux kernel signature checking certificates.
4cfc411e7SDavid Howells#
5cfc411e7SDavid Howells
62565ca7fSEric Snowbergobj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
7d1f04410SEric Snowbergobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o
8d1f04410SEric Snowbergobj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
9734114f8SDavid Howellsifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
10734114f8SDavid Howellsobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
11734114f8SDavid Howellselse
12734114f8SDavid Howellsobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
13734114f8SDavid Howellsendif
14cfc411e7SDavid Howells
15cfc411e7SDavid Howellsifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
16cfc411e7SDavid Howells
17cfc411e7SDavid Howells$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
18cfc411e7SDavid Howells
19cfc411e7SDavid Howells# GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
20cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/x509_certificate_list
21cfc411e7SDavid Howells
22cfc411e7SDavid Howells# Cope with signing_key.x509 existing in $(srctree) not $(objtree)
23cfc411e7SDavid HowellsAFLAGS_system_certificates.o := -I$(srctree)
24cfc411e7SDavid Howells
25cfc411e7SDavid Howellsquiet_cmd_extract_certs  = EXTRACT_CERTS   $(patsubst "%",%,$(2))
26172caf19SMasahiro Yamada      cmd_extract_certs  = scripts/extract-cert $(2) $@
27cfc411e7SDavid Howells
28cfc411e7SDavid Howellstargets += x509_certificate_list
29cfc411e7SDavid Howells$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
30cfc411e7SDavid Howells	$(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
315ccbdbf9SJarkko Sakkinenendif # CONFIG_SYSTEM_TRUSTED_KEYRING
32cfc411e7SDavid Howells
33d1f04410SEric Snowbergclean-files := x509_certificate_list .x509.list x509_revocation_list
34cfc411e7SDavid Howells
35cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG),y)
360165f4caSNayna Jain	SIGN_KEY = y
370165f4caSNayna Jainendif
380165f4caSNayna Jain
390165f4caSNayna Jainifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y)
40781a5739SNayna Jainifeq ($(CONFIG_MODULES),y)
410165f4caSNayna Jain	SIGN_KEY = y
420165f4caSNayna Jainendif
43781a5739SNayna Jainendif
440165f4caSNayna Jain
450165f4caSNayna Jainifdef SIGN_KEY
46cfc411e7SDavid Howells###############################################################################
47cfc411e7SDavid Howells#
48cfc411e7SDavid Howells# If module signing is requested, say by allyesconfig, but a key has not been
49cfc411e7SDavid Howells# supplied, then one will need to be generated to make sure the build does not
50cfc411e7SDavid Howells# fail and that the kernel may be used afterwards.
51cfc411e7SDavid Howells#
52cfc411e7SDavid Howells###############################################################################
53cfc411e7SDavid Howells
545d06ee20SArnd Bergmannredirect_openssl	= 2>&1
555d06ee20SArnd Bergmannquiet_redirect_openssl	= 2>&1
565d06ee20SArnd Bergmannsilent_redirect_openssl = 2>/dev/null
57ea35e0d5SStefan Bergeropenssl_available       = $(shell openssl help 2>/dev/null && echo yes)
585d06ee20SArnd Bergmann
59cfc411e7SDavid Howells# We do it this way rather than having a boolean option for enabling an
60cfc411e7SDavid Howells# external private key, because 'make randconfig' might enable such a
61cfc411e7SDavid Howells# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
62cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
63ea35e0d5SStefan Berger
64ea35e0d5SStefan Bergerifeq ($(openssl_available),yes)
65ea35e0d5SStefan BergerX509TEXT=$(shell openssl x509 -in "certs/signing_key.pem" -text 2>/dev/null)
66a4aed36eSStefan Bergerendif
67ea35e0d5SStefan Berger
68a4aed36eSStefan Berger# Support user changing key type
69a4aed36eSStefan Bergerifdef CONFIG_MODULE_SIG_KEY_TYPE_ECDSA
70a4aed36eSStefan Bergerkeytype_openssl = -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
71a4aed36eSStefan Bergerifeq ($(openssl_available),yes)
72a4aed36eSStefan Berger$(if $(findstring id-ecPublicKey,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem"))
73a4aed36eSStefan Bergerendif
74a4aed36eSStefan Bergerendif # CONFIG_MODULE_SIG_KEY_TYPE_ECDSA
75a4aed36eSStefan Berger
76a4aed36eSStefan Bergerifdef CONFIG_MODULE_SIG_KEY_TYPE_RSA
77a4aed36eSStefan Bergerifeq ($(openssl_available),yes)
78ea35e0d5SStefan Berger$(if $(findstring rsaEncryption,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem"))
79ea35e0d5SStefan Bergerendif
80a4aed36eSStefan Bergerendif # CONFIG_MODULE_SIG_KEY_TYPE_RSA
81ea35e0d5SStefan Berger
82cfc411e7SDavid Howells$(obj)/signing_key.pem: $(obj)/x509.genkey
835d06ee20SArnd Bergmann	@$(kecho) "###"
845d06ee20SArnd Bergmann	@$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
855d06ee20SArnd Bergmann	@$(kecho) "###"
865d06ee20SArnd Bergmann	@$(kecho) "### If this takes a long time, you might wish to run rngd in the"
875d06ee20SArnd Bergmann	@$(kecho) "### background to keep the supply of entropy topped up.  It"
885d06ee20SArnd Bergmann	@$(kecho) "### needs to be run as root, and uses a hardware random"
895d06ee20SArnd Bergmann	@$(kecho) "### number generator if one is available."
905d06ee20SArnd Bergmann	@$(kecho) "###"
915d06ee20SArnd Bergmann	$(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
92cfc411e7SDavid Howells		-batch -x509 -config $(obj)/x509.genkey \
93cfc411e7SDavid Howells		-outform PEM -out $(obj)/signing_key.pem \
945d06ee20SArnd Bergmann		-keyout $(obj)/signing_key.pem \
95a4aed36eSStefan Berger		$(keytype_openssl) \
965d06ee20SArnd Bergmann		$($(quiet)redirect_openssl)
975d06ee20SArnd Bergmann	@$(kecho) "###"
985d06ee20SArnd Bergmann	@$(kecho) "### Key pair generated."
995d06ee20SArnd Bergmann	@$(kecho) "###"
100cfc411e7SDavid Howells
101*f3a2ba44SMasahiro Yamadaquiet_cmd_copy_x509_config = COPY    $@
102*f3a2ba44SMasahiro Yamada      cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@
103*f3a2ba44SMasahiro Yamada
104*f3a2ba44SMasahiro Yamada# You can provide your own config file. If not present, copy the default one.
105cfc411e7SDavid Howells$(obj)/x509.genkey:
106*f3a2ba44SMasahiro Yamada	$(call cmd,copy_x509_config)
107*f3a2ba44SMasahiro Yamada
1085ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG_KEY
109cfc411e7SDavid Howells
110cfc411e7SDavid Howells$(eval $(call config_filename,MODULE_SIG_KEY))
111cfc411e7SDavid Howells
112cfc411e7SDavid Howells# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
113cfc411e7SDavid Howellsifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
114cfc411e7SDavid HowellsX509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
115cfc411e7SDavid Howellsendif
116cfc411e7SDavid Howells
117cfc411e7SDavid Howells# GCC PR#66871 again.
118cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/signing_key.x509
119cfc411e7SDavid Howells
12062172c81SDavid Woodhousetargets += signing_key.x509
12162172c81SDavid Woodhouse$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
12262172c81SDavid Woodhouse	$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
1235ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG
124d1f04410SEric Snowberg
125d1f04410SEric Snowbergifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y)
126d1f04410SEric Snowberg
127d1f04410SEric Snowberg$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS))
128d1f04410SEric Snowberg
129d1f04410SEric Snowberg$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
130d1f04410SEric Snowberg
131d1f04410SEric Snowbergquiet_cmd_extract_certs  = EXTRACT_CERTS   $(patsubst "%",%,$(2))
132d1f04410SEric Snowberg      cmd_extract_certs  = scripts/extract-cert $(2) $@
133d1f04410SEric Snowberg
134d1f04410SEric Snowbergtargets += x509_revocation_list
135d1f04410SEric Snowberg$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE
136d1f04410SEric Snowberg	$(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS))
137d1f04410SEric Snowbergendif
138