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 common.o 8 obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revoca 8 obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o >> 9 ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"") >> 10 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o >> 11 else >> 12 obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o >> 13 endif 9 14 10 $(obj)/blacklist_hashes.o: $(obj)/blacklist_ha !! 15 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) 11 CFLAGS_blacklist_hashes.o := -I $(obj) << 12 16 13 quiet_cmd_check_and_copy_blacklist_hash_list = !! 17 $(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 18 >> 19 # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871) 29 $(obj)/system_certificates.o: $(obj)/x509_cert 20 $(obj)/system_certificates.o: $(obj)/x509_certificate_list 30 21 31 $(obj)/x509_certificate_list: $(CONFIG_SYSTEM_ !! 22 # Cope with signing_key.x509 existing in $(srctree) not $(objtree) 32 $(call if_changed,extract_certs) !! 23 AFLAGS_system_certificates.o := -I$(srctree) >> 24 >> 25 quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) >> 26 cmd_extract_certs = scripts/extract-cert $(2) $@ 33 27 34 targets += x509_certificate_list 28 targets += x509_certificate_list >> 29 $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE >> 30 $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS)) >> 31 endif # CONFIG_SYSTEM_TRUSTED_KEYRING >> 32 >> 33 clean-files := x509_certificate_list .x509.list x509_revocation_list >> 34 >> 35 ifeq ($(CONFIG_MODULE_SIG),y) >> 36 SIGN_KEY = y >> 37 endif >> 38 >> 39 ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y) >> 40 ifeq ($(CONFIG_MODULES),y) >> 41 SIGN_KEY = y >> 42 endif >> 43 endif 35 44 >> 45 ifdef SIGN_KEY >> 46 ############################################################################### >> 47 # 36 # If module signing is requested, say by allye 48 # If module signing is requested, say by allyesconfig, but a key has not been 37 # supplied, then one will need to be generated 49 # 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 50 # fail and that the kernel may be used afterwards. 39 # 51 # >> 52 ############################################################################### >> 53 ifndef CONFIG_MODULE_SIG_HASH >> 54 $(error Could not determine digest type to use from kernel config) >> 55 endif >> 56 >> 57 redirect_openssl = 2>&1 >> 58 quiet_redirect_openssl = 2>&1 >> 59 silent_redirect_openssl = 2>/dev/null >> 60 openssl_available = $(shell openssl help 2>/dev/null && echo yes) >> 61 40 # We do it this way rather than having a boole 62 # We do it this way rather than having a boolean option for enabling an 41 # external private key, because 'make randconf 63 # external private key, because 'make randconfig' might enable such a 42 # boolean option and we unfortunately can't ma 64 # boolean option and we unfortunately can't make it depend on !RANDCONFIG. 43 ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_k !! 65 ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") 44 66 45 keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := !! 67 ifeq ($(openssl_available),yes) 46 !! 68 X509TEXT=$(shell openssl x509 -in "certs/signing_key.pem" -text 2>/dev/null) 47 quiet_cmd_gen_key = GENKEY $@ !! 69 endif 48 cmd_gen_key = openssl req -new -nodes -u << 49 -batch -x509 -config $< \ << 50 -outform PEM -out $@ -keyout $ << 51 70 52 $(obj)/signing_key.pem: $(obj)/x509.genkey FOR !! 71 # Support user changing key type 53 $(call if_changed,gen_key) !! 72 ifdef CONFIG_MODULE_SIG_KEY_TYPE_ECDSA >> 73 keytype_openssl = -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 >> 74 ifeq ($(openssl_available),yes) >> 75 $(if $(findstring id-ecPublicKey,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem")) >> 76 endif >> 77 endif # CONFIG_MODULE_SIG_KEY_TYPE_ECDSA 54 78 55 targets += signing_key.pem !! 79 ifdef CONFIG_MODULE_SIG_KEY_TYPE_RSA >> 80 ifeq ($(openssl_available),yes) >> 81 $(if $(findstring rsaEncryption,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem")) >> 82 endif >> 83 endif # CONFIG_MODULE_SIG_KEY_TYPE_RSA 56 84 57 quiet_cmd_copy_x509_config = COPY $@ !! 85 $(obj)/signing_key.pem: $(obj)/x509.genkey 58 cmd_copy_x509_config = cat $(src)/defaul !! 86 @$(kecho) "###" >> 87 @$(kecho) "### Now generating an X.509 key pair to be used for signing modules." >> 88 @$(kecho) "###" >> 89 @$(kecho) "### If this takes a long time, you might wish to run rngd in the" >> 90 @$(kecho) "### background to keep the supply of entropy topped up. It" >> 91 @$(kecho) "### needs to be run as root, and uses a hardware random" >> 92 @$(kecho) "### number generator if one is available." >> 93 @$(kecho) "###" >> 94 $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ >> 95 -batch -x509 -config $(obj)/x509.genkey \ >> 96 -outform PEM -out $(obj)/signing_key.pem \ >> 97 -keyout $(obj)/signing_key.pem \ >> 98 $(keytype_openssl) \ >> 99 $($(quiet)redirect_openssl) >> 100 @$(kecho) "###" >> 101 @$(kecho) "### Key pair generated." >> 102 @$(kecho) "###" 59 103 60 # You can provide your own config file. If not << 61 $(obj)/x509.genkey: 104 $(obj)/x509.genkey: 62 $(call cmd,copy_x509_config) !! 105 @$(kecho) Generating X.509 key generation config 63 !! 106 @echo >$@ "[ req ]" >> 107 @echo >>$@ "default_bits = 4096" >> 108 @echo >>$@ "distinguished_name = req_distinguished_name" >> 109 @echo >>$@ "prompt = no" >> 110 @echo >>$@ "string_mask = utf8only" >> 111 @echo >>$@ "x509_extensions = myexts" >> 112 @echo >>$@ >> 113 @echo >>$@ "[ req_distinguished_name ]" >> 114 @echo >>$@ "#O = Unspecified company" >> 115 @echo >>$@ "CN = Build time autogenerated kernel key" >> 116 @echo >>$@ "#emailAddress = unspecified.user@unspecified.company" >> 117 @echo >>$@ >> 118 @echo >>$@ "[ myexts ]" >> 119 @echo >>$@ "basicConstraints=critical,CA:FALSE" >> 120 @echo >>$@ "keyUsage=digitalSignature" >> 121 @echo >>$@ "subjectKeyIdentifier=hash" >> 122 @echo >>$@ "authorityKeyIdentifier=keyid" 64 endif # CONFIG_MODULE_SIG_KEY 123 endif # CONFIG_MODULE_SIG_KEY 65 124 66 $(obj)/system_certificates.o: $(obj)/signing_k !! 125 $(eval $(call config_filename,MODULE_SIG_KEY)) 67 126 68 PKCS11_URI := $(filter pkcs11:%, $(CONFIG_MODU !! 127 # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it 69 ifdef PKCS11_URI !! 128 ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) 70 $(obj)/signing_key.x509: extract-cert-in := $( !! 129 X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) 71 endif 130 endif 72 131 73 $(obj)/signing_key.x509: $(filter-out $(PKCS11 !! 132 # GCC PR#66871 again. 74 $(call if_changed,extract_certs) !! 133 $(obj)/system_certificates.o: $(obj)/signing_key.x509 75 134 76 targets += signing_key.x509 135 targets += signing_key.x509 >> 136 $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE >> 137 $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) >> 138 endif # CONFIG_MODULE_SIG 77 139 78 $(obj)/revocation_certificates.o: $(obj)/x509_ !! 140 ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y) 79 141 80 $(obj)/x509_revocation_list: $(CONFIG_SYSTEM_R !! 142 $(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) 81 $(call if_changed,extract_certs) << 82 143 83 targets += x509_revocation_list !! 144 $(obj)/revocation_certificates.o: $(obj)/x509_revocation_list 84 145 85 hostprogs := extract-cert !! 146 quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) >> 147 cmd_extract_certs = scripts/extract-cert $(2) $@ 86 148 87 HOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_ !! 149 targets += x509_revocation_list 88 HOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CO !! 150 $(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE >> 151 $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) >> 152 endif
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.