xref: /openbmc/linux/certs/Makefile (revision 7ae5c03a)
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for the linux kernel signature checking certificates.
4#
5
6obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
7obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
8obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
9ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),)
10
11$(obj)/blacklist_hashes.o: $(obj)/blacklist_hash_list
12CFLAGS_blacklist_hashes.o := -I $(obj)
13
14quiet_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) > $@
18
19$(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE
20	$(call if_changed,check_and_copy_blacklist_hash_list)
21obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
22else
23obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
24endif
25targets += blacklist_hash_list
26
27quiet_cmd_extract_certs  = CERT    $@
28      cmd_extract_certs  = $(obj)/extract-cert $(extract-cert-in) $@
29extract-cert-in = $(or $(filter-out $(obj)/extract-cert, $(real-prereqs)),"")
30
31$(obj)/system_certificates.o: $(obj)/x509_certificate_list
32
33$(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE
34	$(call if_changed,extract_certs)
35
36targets += x509_certificate_list
37
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.
41#
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.
45ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem)
46
47keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
48
49quiet_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
53
54$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE
55	$(call if_changed,gen_key)
56
57targets += signing_key.pem
58
59quiet_cmd_copy_x509_config = COPY    $@
60      cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@
61
62# You can provide your own config file. If not present, copy the default one.
63$(obj)/x509.genkey:
64	$(call cmd,copy_x509_config)
65
66endif # CONFIG_MODULE_SIG_KEY
67
68$(obj)/system_certificates.o: $(obj)/signing_key.x509
69
70PKCS11_URI := $(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY))
71ifdef PKCS11_URI
72$(obj)/signing_key.x509: extract-cert-in := $(PKCS11_URI)
73endif
74
75$(obj)/signing_key.x509: $(filter-out $(PKCS11_URI),$(CONFIG_MODULE_SIG_KEY)) $(obj)/extract-cert FORCE
76	$(call if_changed,extract_certs)
77
78targets += signing_key.x509
79
80$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
81
82$(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE
83	$(call if_changed,extract_certs)
84
85targets += x509_revocation_list
86
87hostprogs := extract-cert
88
89HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null)
90HOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
91