xref: /linux/certs/Makefile (revision b1c3d2be)
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
660050ffeSDavid Howellsobj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
731f6d95cSMasahiro Yamadaobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o blacklist_hashes.o
8d1f04410SEric Snowbergobj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
9addf4663SMickaël Salaün
1027b5b22dSMasahiro Yamada$(obj)/blacklist_hashes.o: $(obj)/blacklist_hash_list
1127b5b22dSMasahiro YamadaCFLAGS_blacklist_hashes.o := -I $(obj)
12addf4663SMickaël Salaün
1327b5b22dSMasahiro Yamadaquiet_cmd_check_and_copy_blacklist_hash_list = GEN     $@
1427b5b22dSMasahiro Yamada      cmd_check_and_copy_blacklist_hash_list = \
1531f6d95cSMasahiro Yamada	$(if $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST), \
169008a676SMasahiro Yamada	$(AWK) -f $(srctree)/$(src)/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \
1731f6d95cSMasahiro Yamada	{ cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST); echo $(comma) NULL; } > $@, \
1831f6d95cSMasahiro Yamada	echo NULL > $@)
19addf4663SMickaël Salaün
2027b5b22dSMasahiro Yamada$(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE
2127b5b22dSMasahiro Yamada	$(call if_changed,check_and_copy_blacklist_hash_list)
2231f6d95cSMasahiro Yamada
2327b5b22dSMasahiro Yamadatargets += blacklist_hash_list
24cfc411e7SDavid Howells
251c4bd9f7SMasahiro Yamadaquiet_cmd_extract_certs  = CERT    $@
26*b1c3d2beSJan Luebbe      cmd_extract_certs  = $(obj)/extract-cert "$(extract-cert-in)" $@
27*b1c3d2beSJan Luebbeextract-cert-in = $(filter-out $(obj)/extract-cert, $(real-prereqs))
281c4bd9f7SMasahiro Yamada
29cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/x509_certificate_list
30cfc411e7SDavid Howells
31340a0253SMasahiro Yamada$(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE
32f44b645fSMasahiro Yamada	$(call if_changed,extract_certs)
33cfc411e7SDavid Howells
3427b5b22dSMasahiro Yamadatargets += x509_certificate_list
35cfc411e7SDavid Howells
36cfc411e7SDavid Howells# If module signing is requested, say by allyesconfig, but a key has not been
37cfc411e7SDavid Howells# supplied, then one will need to be generated to make sure the build does not
38cfc411e7SDavid Howells# fail and that the kernel may be used afterwards.
39cfc411e7SDavid Howells#
40cfc411e7SDavid Howells# We do it this way rather than having a boolean option for enabling an
41cfc411e7SDavid Howells# external private key, because 'make randconfig' might enable such a
42cfc411e7SDavid Howells# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
43129ab0d2SMasahiro Yamadaifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem)
44ea35e0d5SStefan Berger
45e06a61a8SMasahiro Yamadakeytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
46ea35e0d5SStefan Berger
4754c8b517SMasahiro Yamadaquiet_cmd_gen_key = GENKEY  $@
4854c8b517SMasahiro Yamada      cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
49c537e4d0SMasahiro Yamada		-batch -x509 -config $< \
50c537e4d0SMasahiro Yamada		-outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1
5154c8b517SMasahiro Yamada
52e06a61a8SMasahiro Yamada$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE
53e06a61a8SMasahiro Yamada	$(call if_changed,gen_key)
54e06a61a8SMasahiro Yamada
55e06a61a8SMasahiro Yamadatargets += signing_key.pem
56cfc411e7SDavid Howells
57f3a2ba44SMasahiro Yamadaquiet_cmd_copy_x509_config = COPY    $@
58f3a2ba44SMasahiro Yamada      cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@
59f3a2ba44SMasahiro Yamada
60f3a2ba44SMasahiro Yamada# You can provide your own config file. If not present, copy the default one.
61cfc411e7SDavid Howells$(obj)/x509.genkey:
62f3a2ba44SMasahiro Yamada	$(call cmd,copy_x509_config)
63f3a2ba44SMasahiro Yamada
645ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG_KEY
65cfc411e7SDavid Howells
66cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/signing_key.x509
67cfc411e7SDavid Howells
68f44b645fSMasahiro YamadaPKCS11_URI := $(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY))
69f44b645fSMasahiro Yamadaifdef PKCS11_URI
70f44b645fSMasahiro Yamada$(obj)/signing_key.x509: extract-cert-in := $(PKCS11_URI)
71f44b645fSMasahiro Yamadaendif
72f44b645fSMasahiro Yamada
73f44b645fSMasahiro Yamada$(obj)/signing_key.x509: $(filter-out $(PKCS11_URI),$(CONFIG_MODULE_SIG_KEY)) $(obj)/extract-cert FORCE
74f44b645fSMasahiro Yamada	$(call if_changed,extract_certs)
75d1f04410SEric Snowberg
765cca3606SMasahiro Yamadatargets += signing_key.x509
775cca3606SMasahiro Yamada
78d1f04410SEric Snowberg$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
79d1f04410SEric Snowberg
80340a0253SMasahiro Yamada$(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE
81f44b645fSMasahiro Yamada	$(call if_changed,extract_certs)
825cca3606SMasahiro Yamada
835cca3606SMasahiro Yamadatargets += x509_revocation_list
84340a0253SMasahiro Yamada
85340a0253SMasahiro Yamadahostprogs := extract-cert
86340a0253SMasahiro Yamada
87d5ea4fecSChun-Tse ShaoHOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null)
88d5ea4fecSChun-Tse ShaoHOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto)
89