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 54cfc411e7SDavid Howells# We do it this way rather than having a boolean option for enabling an 55cfc411e7SDavid Howells# external private key, because 'make randconfig' might enable such a 56cfc411e7SDavid Howells# boolean option and we unfortunately can't make it depend on !RANDCONFIG. 57cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") 58ea35e0d5SStefan Berger 59e06a61a8SMasahiro Yamadakeytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 60ea35e0d5SStefan Berger 6154c8b517SMasahiro Yamadaquiet_cmd_gen_key = GENKEY $@ 6254c8b517SMasahiro Yamada cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 63*c537e4d0SMasahiro Yamada -batch -x509 -config $< \ 64*c537e4d0SMasahiro Yamada -outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1 6554c8b517SMasahiro Yamada 66e06a61a8SMasahiro Yamada$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE 67e06a61a8SMasahiro Yamada $(call if_changed,gen_key) 68e06a61a8SMasahiro Yamada 69e06a61a8SMasahiro Yamadatargets += signing_key.pem 70cfc411e7SDavid Howells 71f3a2ba44SMasahiro Yamadaquiet_cmd_copy_x509_config = COPY $@ 72f3a2ba44SMasahiro Yamada cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@ 73f3a2ba44SMasahiro Yamada 74f3a2ba44SMasahiro Yamada# You can provide your own config file. If not present, copy the default one. 75cfc411e7SDavid Howells$(obj)/x509.genkey: 76f3a2ba44SMasahiro Yamada $(call cmd,copy_x509_config) 77f3a2ba44SMasahiro Yamada 785ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG_KEY 79cfc411e7SDavid Howells 80cfc411e7SDavid Howells$(eval $(call config_filename,MODULE_SIG_KEY)) 81cfc411e7SDavid Howells 82cfc411e7SDavid Howells# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it 83cfc411e7SDavid Howellsifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) 84cfc411e7SDavid HowellsX509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) 85cfc411e7SDavid Howellsendif 86cfc411e7SDavid Howells 87cfc411e7SDavid Howells# GCC PR#66871 again. 88cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/signing_key.x509 89cfc411e7SDavid Howells 9062172c81SDavid Woodhousetargets += signing_key.x509 9162172c81SDavid Woodhouse$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE 9262172c81SDavid Woodhouse $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) 935ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG 94d1f04410SEric Snowberg 95d1f04410SEric Snowbergifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y) 96d1f04410SEric Snowberg 97d1f04410SEric Snowberg$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) 98d1f04410SEric Snowberg 99d1f04410SEric Snowberg$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list 100d1f04410SEric Snowberg 101d1f04410SEric Snowbergquiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) 102d1f04410SEric Snowberg cmd_extract_certs = scripts/extract-cert $(2) $@ 103d1f04410SEric Snowberg 104d1f04410SEric Snowbergtargets += x509_revocation_list 105d1f04410SEric Snowberg$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE 106d1f04410SEric Snowberg $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) 107d1f04410SEric Snowbergendif 108