1 # SPDX-License-Identifier: GPL-2.0 << 2 # 1 # 3 # Makefile for the linux kernel signature chec 2 # Makefile for the linux kernel signature checking certificates. 4 # 3 # 5 4 6 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system 5 obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o 7 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blac << 8 obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revoca << 9 6 10 $(obj)/blacklist_hashes.o: $(obj)/blacklist_ha !! 7 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) 11 CFLAGS_blacklist_hashes.o := -I $(obj) << 12 8 13 quiet_cmd_check_and_copy_blacklist_hash_list = !! 9 $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS)) 14 cmd_check_and_copy_blacklist_hash_list = << 15 $(if $(CONFIG_SYSTEM_BLACKLIST_HASH_LI << 16 $(AWK) -f $(src)/check-blacklist-hashe << 17 { cat $(CONFIG_SYSTEM_BLACKLIST_HASH_L << 18 echo NULL > $@) << 19 << 20 $(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BL << 21 $(call if_changed,check_and_copy_black << 22 << 23 targets += blacklist_hash_list << 24 << 25 quiet_cmd_extract_certs = CERT $@ << 26 cmd_extract_certs = $(obj)/extract-cert << 27 extract-cert-in = $(filter-out $(obj)/extract- << 28 10 >> 11 # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871) 29 $(obj)/system_certificates.o: $(obj)/x509_cert 12 $(obj)/system_certificates.o: $(obj)/x509_certificate_list 30 13 31 $(obj)/x509_certificate_list: $(CONFIG_SYSTEM_ !! 14 # Cope with signing_key.x509 existing in $(srctree) not $(objtree) 32 $(call if_changed,extract_certs) !! 15 AFLAGS_system_certificates.o := -I$(srctree) >> 16 >> 17 quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) >> 18 cmd_extract_certs = scripts/extract-cert $(2) $@ || ( rm $@; exit 1) 33 19 34 targets += x509_certificate_list 20 targets += x509_certificate_list >> 21 $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE >> 22 $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS)) >> 23 endif >> 24 >> 25 clean-files := x509_certificate_list .x509.list 35 26 >> 27 ifeq ($(CONFIG_MODULE_SIG),y) >> 28 ############################################################################### >> 29 # 36 # If module signing is requested, say by allye 30 # If module signing is requested, say by allyesconfig, but a key has not been 37 # supplied, then one will need to be generated 31 # supplied, then one will need to be generated to make sure the build does not 38 # fail and that the kernel may be used afterwa 32 # fail and that the kernel may be used afterwards. 39 # 33 # >> 34 ############################################################################### >> 35 ifndef CONFIG_MODULE_SIG_HASH >> 36 $(error Could not determine digest type to use from kernel config) >> 37 endif >> 38 >> 39 redirect_openssl = 2>&1 >> 40 quiet_redirect_openssl = 2>&1 >> 41 silent_redirect_openssl = 2>/dev/null >> 42 40 # We do it this way rather than having a boole 43 # We do it this way rather than having a boolean option for enabling an 41 # external private key, because 'make randconf 44 # external private key, because 'make randconfig' might enable such a 42 # boolean option and we unfortunately can't ma 45 # boolean option and we unfortunately can't make it depend on !RANDCONFIG. 43 ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_k !! 46 ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") 44 !! 47 $(obj)/signing_key.pem: $(obj)/x509.genkey 45 keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := !! 48 @$(kecho) "###" 46 !! 49 @$(kecho) "### Now generating an X.509 key pair to be used for signing modules." 47 quiet_cmd_gen_key = GENKEY $@ !! 50 @$(kecho) "###" 48 cmd_gen_key = openssl req -new -nodes -u !! 51 @$(kecho) "### If this takes a long time, you might wish to run rngd in the" 49 -batch -x509 -config $< \ !! 52 @$(kecho) "### background to keep the supply of entropy topped up. It" 50 -outform PEM -out $@ -keyout $ !! 53 @$(kecho) "### needs to be run as root, and uses a hardware random" 51 !! 54 @$(kecho) "### number generator if one is available." 52 $(obj)/signing_key.pem: $(obj)/x509.genkey FOR !! 55 @$(kecho) "###" 53 $(call if_changed,gen_key) !! 56 $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 54 !! 57 -batch -x509 -config $(obj)/x509.genkey \ 55 targets += signing_key.pem !! 58 -outform PEM -out $(obj)/signing_key.pem \ >> 59 -keyout $(obj)/signing_key.pem \ >> 60 $($(quiet)redirect_openssl) >> 61 @$(kecho) "###" >> 62 @$(kecho) "### Key pair generated." >> 63 @$(kecho) "###" 56 64 57 quiet_cmd_copy_x509_config = COPY $@ << 58 cmd_copy_x509_config = cat $(src)/defaul << 59 << 60 # You can provide your own config file. If not << 61 $(obj)/x509.genkey: 65 $(obj)/x509.genkey: 62 $(call cmd,copy_x509_config) !! 66 @$(kecho) Generating X.509 key generation config 63 !! 67 @echo >$@ "[ req ]" 64 endif # CONFIG_MODULE_SIG_KEY !! 68 @echo >>$@ "default_bits = 4096" >> 69 @echo >>$@ "distinguished_name = req_distinguished_name" >> 70 @echo >>$@ "prompt = no" >> 71 @echo >>$@ "string_mask = utf8only" >> 72 @echo >>$@ "x509_extensions = myexts" >> 73 @echo >>$@ >> 74 @echo >>$@ "[ req_distinguished_name ]" >> 75 @echo >>$@ "#O = Unspecified company" >> 76 @echo >>$@ "CN = Build time autogenerated kernel key" >> 77 @echo >>$@ "#emailAddress = unspecified.user@unspecified.company" >> 78 @echo >>$@ >> 79 @echo >>$@ "[ myexts ]" >> 80 @echo >>$@ "basicConstraints=critical,CA:FALSE" >> 81 @echo >>$@ "keyUsage=digitalSignature" >> 82 @echo >>$@ "subjectKeyIdentifier=hash" >> 83 @echo >>$@ "authorityKeyIdentifier=keyid" >> 84 endif 65 85 66 $(obj)/system_certificates.o: $(obj)/signing_k !! 86 $(eval $(call config_filename,MODULE_SIG_KEY)) 67 87 68 PKCS11_URI := $(filter pkcs11:%, $(CONFIG_MODU !! 88 # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it 69 ifdef PKCS11_URI !! 89 ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) 70 $(obj)/signing_key.x509: extract-cert-in := $( !! 90 X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) 71 endif 91 endif 72 92 73 $(obj)/signing_key.x509: $(filter-out $(PKCS11 !! 93 # GCC PR#66871 again. 74 $(call if_changed,extract_certs) !! 94 $(obj)/system_certificates.o: $(obj)/signing_key.x509 75 95 76 targets += signing_key.x509 96 targets += signing_key.x509 77 !! 97 $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE 78 $(obj)/revocation_certificates.o: $(obj)/x509_ !! 98 $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) 79 !! 99 endif 80 $(obj)/x509_revocation_list: $(CONFIG_SYSTEM_R << 81 $(call if_changed,extract_certs) << 82 << 83 targets += x509_revocation_list << 84 << 85 hostprogs := extract-cert << 86 << 87 HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_ << 88 HOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CO <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.