1 # SPDX-License-Identifier: GPL-2.0
3 # Makefile for the linux kernel signature checking certificates.
6 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
7 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
8 obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
9 ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),)
11 $(obj)/blacklist_hashes.o: $(obj)/blacklist_hash_list
12 CFLAGS_blacklist_hashes.o := -I $(obj)
14 quiet_cmd_check_and_copy_blacklist_hash_list = GEN $@
15 cmd_check_and_copy_blacklist_hash_list = \
16 $(AWK) -f $(srctree)/scripts/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \
17 cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) > $@
19 $(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE
20 $(call if_changed,check_and_copy_blacklist_hash_list)
21 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
23 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
25 targets += blacklist_hash_list
27 quiet_cmd_extract_certs = CERT $@
28 cmd_extract_certs = $(obj)/extract-cert $(extract-cert-in) $@
29 extract-cert-in = $(or $(filter-out $(obj)/extract-cert, $(real-prereqs)),"")
31 $(obj)/system_certificates.o: $(obj)/x509_certificate_list
33 $(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE
34 $(call if_changed,extract_certs)
36 targets += x509_certificate_list
38 # If module signing is requested, say by allyesconfig, but a key has not been
39 # supplied, then one will need to be generated to make sure the build does not
40 # fail and that the kernel may be used afterwards.
42 # We do it this way rather than having a boolean option for enabling an
43 # external private key, because 'make randconfig' might enable such a
44 # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
45 ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem)
47 keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
49 quiet_cmd_gen_key = GENKEY $@
50 cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
51 -batch -x509 -config $< \
52 -outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1
54 $(obj)/signing_key.pem: $(obj)/x509.genkey FORCE
55 $(call if_changed,gen_key)
57 targets += signing_key.pem
59 quiet_cmd_copy_x509_config = COPY $@
60 cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@
62 # You can provide your own config file. If not present, copy the default one.
64 $(call cmd,copy_x509_config)
66 endif # CONFIG_MODULE_SIG_KEY
68 $(obj)/system_certificates.o: $(obj)/signing_key.x509
70 PKCS11_URI := $(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY))
72 $(obj)/signing_key.x509: extract-cert-in := $(PKCS11_URI)
75 $(obj)/signing_key.x509: $(filter-out $(PKCS11_URI),$(CONFIG_MODULE_SIG_KEY)) $(obj)/extract-cert FORCE
76 $(call if_changed,extract_certs)
78 targets += signing_key.x509
80 $(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
82 $(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE
83 $(call if_changed,extract_certs)
85 targets += x509_revocation_list
87 hostprogs := extract-cert
89 HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null)
90 HOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)