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