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 common.o 7obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o 8obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o 9ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),) 10obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o 11else 12obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o 13endif 14 15quiet_cmd_extract_certs = CERT $@ 16 cmd_extract_certs = $(obj)/extract-cert $(2) $@ 17 18$(obj)/system_certificates.o: $(obj)/x509_certificate_list 19 20$(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE 21 $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_TRUSTED_KEYS),$<,"")) 22 23targets += x509_certificate_list 24 25# If module signing is requested, say by allyesconfig, but a key has not been 26# supplied, then one will need to be generated to make sure the build does not 27# fail and that the kernel may be used afterwards. 28# 29# We do it this way rather than having a boolean option for enabling an 30# external private key, because 'make randconfig' might enable such a 31# boolean option and we unfortunately can't make it depend on !RANDCONFIG. 32ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem) 33 34keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 35 36quiet_cmd_gen_key = GENKEY $@ 37 cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 38 -batch -x509 -config $< \ 39 -outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1 40 41$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE 42 $(call if_changed,gen_key) 43 44targets += signing_key.pem 45 46quiet_cmd_copy_x509_config = COPY $@ 47 cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@ 48 49# You can provide your own config file. If not present, copy the default one. 50$(obj)/x509.genkey: 51 $(call cmd,copy_x509_config) 52 53endif # CONFIG_MODULE_SIG_KEY 54 55# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it 56ifneq ($(filter-out pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),) 57X509_DEP := $(CONFIG_MODULE_SIG_KEY) 58endif 59 60$(obj)/system_certificates.o: $(obj)/signing_key.x509 61 62$(obj)/signing_key.x509: $(X509_DEP) $(obj)/extract-cert FORCE 63 $(call if_changed,extract_certs,$(if $(CONFIG_MODULE_SIG_KEY),$(if $(X509_DEP),$<,$(CONFIG_MODULE_SIG_KEY)),"")) 64 65targets += signing_key.x509 66 67$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list 68 69$(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE 70 $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_REVOCATION_KEYS),$<,"")) 71 72targets += x509_revocation_list 73 74hostprogs := extract-cert 75 76HOSTCFLAGS_extract-cert.o = $(shell pkg-config --cflags libcrypto 2> /dev/null) 77HOSTLDLIBS_extract-cert = $(shell pkg-config --libs libcrypto 2> /dev/null || echo -lcrypto) 78