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 7*d1f04410SEric Snowbergobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o 8*d1f04410SEric 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 33*d1f04410SEric Snowbergclean-files := x509_certificate_list .x509.list x509_revocation_list 34cfc411e7SDavid Howells 35cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG),y) 36cfc411e7SDavid Howells############################################################################### 37cfc411e7SDavid Howells# 38cfc411e7SDavid Howells# If module signing is requested, say by allyesconfig, but a key has not been 39cfc411e7SDavid Howells# supplied, then one will need to be generated to make sure the build does not 40cfc411e7SDavid Howells# fail and that the kernel may be used afterwards. 41cfc411e7SDavid Howells# 42cfc411e7SDavid Howells############################################################################### 43cfc411e7SDavid Howellsifndef CONFIG_MODULE_SIG_HASH 44cfc411e7SDavid Howells$(error Could not determine digest type to use from kernel config) 45cfc411e7SDavid Howellsendif 46cfc411e7SDavid Howells 475d06ee20SArnd Bergmannredirect_openssl = 2>&1 485d06ee20SArnd Bergmannquiet_redirect_openssl = 2>&1 495d06ee20SArnd Bergmannsilent_redirect_openssl = 2>/dev/null 505d06ee20SArnd Bergmann 51cfc411e7SDavid Howells# We do it this way rather than having a boolean option for enabling an 52cfc411e7SDavid Howells# external private key, because 'make randconfig' might enable such a 53cfc411e7SDavid Howells# boolean option and we unfortunately can't make it depend on !RANDCONFIG. 54cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") 55cfc411e7SDavid Howells$(obj)/signing_key.pem: $(obj)/x509.genkey 565d06ee20SArnd Bergmann @$(kecho) "###" 575d06ee20SArnd Bergmann @$(kecho) "### Now generating an X.509 key pair to be used for signing modules." 585d06ee20SArnd Bergmann @$(kecho) "###" 595d06ee20SArnd Bergmann @$(kecho) "### If this takes a long time, you might wish to run rngd in the" 605d06ee20SArnd Bergmann @$(kecho) "### background to keep the supply of entropy topped up. It" 615d06ee20SArnd Bergmann @$(kecho) "### needs to be run as root, and uses a hardware random" 625d06ee20SArnd Bergmann @$(kecho) "### number generator if one is available." 635d06ee20SArnd Bergmann @$(kecho) "###" 645d06ee20SArnd Bergmann $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 65cfc411e7SDavid Howells -batch -x509 -config $(obj)/x509.genkey \ 66cfc411e7SDavid Howells -outform PEM -out $(obj)/signing_key.pem \ 675d06ee20SArnd Bergmann -keyout $(obj)/signing_key.pem \ 685d06ee20SArnd Bergmann $($(quiet)redirect_openssl) 695d06ee20SArnd Bergmann @$(kecho) "###" 705d06ee20SArnd Bergmann @$(kecho) "### Key pair generated." 715d06ee20SArnd Bergmann @$(kecho) "###" 72cfc411e7SDavid Howells 73cfc411e7SDavid Howells$(obj)/x509.genkey: 745d06ee20SArnd Bergmann @$(kecho) Generating X.509 key generation config 75cfc411e7SDavid Howells @echo >$@ "[ req ]" 76cfc411e7SDavid Howells @echo >>$@ "default_bits = 4096" 77cfc411e7SDavid Howells @echo >>$@ "distinguished_name = req_distinguished_name" 78cfc411e7SDavid Howells @echo >>$@ "prompt = no" 79cfc411e7SDavid Howells @echo >>$@ "string_mask = utf8only" 80cfc411e7SDavid Howells @echo >>$@ "x509_extensions = myexts" 81cfc411e7SDavid Howells @echo >>$@ 82cfc411e7SDavid Howells @echo >>$@ "[ req_distinguished_name ]" 83cfc411e7SDavid Howells @echo >>$@ "#O = Unspecified company" 84cfc411e7SDavid Howells @echo >>$@ "CN = Build time autogenerated kernel key" 85cfc411e7SDavid Howells @echo >>$@ "#emailAddress = unspecified.user@unspecified.company" 86cfc411e7SDavid Howells @echo >>$@ 87cfc411e7SDavid Howells @echo >>$@ "[ myexts ]" 88cfc411e7SDavid Howells @echo >>$@ "basicConstraints=critical,CA:FALSE" 89cfc411e7SDavid Howells @echo >>$@ "keyUsage=digitalSignature" 90cfc411e7SDavid Howells @echo >>$@ "subjectKeyIdentifier=hash" 91cfc411e7SDavid Howells @echo >>$@ "authorityKeyIdentifier=keyid" 925ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG_KEY 93cfc411e7SDavid Howells 94cfc411e7SDavid Howells$(eval $(call config_filename,MODULE_SIG_KEY)) 95cfc411e7SDavid Howells 96cfc411e7SDavid Howells# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it 97cfc411e7SDavid Howellsifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) 98cfc411e7SDavid HowellsX509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) 99cfc411e7SDavid Howellsendif 100cfc411e7SDavid Howells 101cfc411e7SDavid Howells# GCC PR#66871 again. 102cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/signing_key.x509 103cfc411e7SDavid Howells 10462172c81SDavid Woodhousetargets += signing_key.x509 10562172c81SDavid Woodhouse$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE 10662172c81SDavid Woodhouse $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) 1075ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG 108*d1f04410SEric Snowberg 109*d1f04410SEric Snowbergifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y) 110*d1f04410SEric Snowberg 111*d1f04410SEric Snowberg$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) 112*d1f04410SEric Snowberg 113*d1f04410SEric Snowberg$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list 114*d1f04410SEric Snowberg 115*d1f04410SEric Snowbergquiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) 116*d1f04410SEric Snowberg cmd_extract_certs = scripts/extract-cert $(2) $@ 117*d1f04410SEric Snowberg 118*d1f04410SEric Snowbergtargets += x509_revocation_list 119*d1f04410SEric Snowberg$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE 120*d1f04410SEric Snowberg $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) 121*d1f04410SEric Snowbergendif 122