Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 2 | # |
| 3 | # Makefile for the linux kernel signature checking certificates. |
| 4 | # |
| 5 | |
Eric Snowberg | 72d6f5d | 2021-01-22 13:10:52 -0500 | [diff] [blame] | 6 | obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o |
Eric Snowberg | c6ae6f8 | 2021-01-22 13:10:53 -0500 | [diff] [blame] | 7 | obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o |
| 8 | obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 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 |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 14 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 15 | ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) |
| 16 | |
| 17 | $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS)) |
| 18 | |
| 19 | # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871) |
| 20 | $(obj)/system_certificates.o: $(obj)/x509_certificate_list |
| 21 | |
| 22 | # Cope with signing_key.x509 existing in $(srctree) not $(objtree) |
| 23 | AFLAGS_system_certificates.o := -I$(srctree) |
| 24 | |
| 25 | quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) |
Masahiro Yamada | 172caf1 | 2018-12-31 17:24:08 +0900 | [diff] [blame] | 26 | cmd_extract_certs = scripts/extract-cert $(2) $@ |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 27 | |
| 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)) |
Jarkko Sakkinen | 5ccbdbf9 | 2017-07-13 13:16:49 +0100 | [diff] [blame] | 31 | endif # CONFIG_SYSTEM_TRUSTED_KEYRING |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 32 | |
Eric Snowberg | c6ae6f8 | 2021-01-22 13:10:53 -0500 | [diff] [blame] | 33 | clean-files := x509_certificate_list .x509.list x509_revocation_list |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 34 | |
| 35 | ifeq ($(CONFIG_MODULE_SIG),y) |
| 36 | ############################################################################### |
| 37 | # |
| 38 | # If module signing is requested, say by allyesconfig, but a key has not been |
| 39 | # supplied, then one will need to be generated to make sure the build does not |
| 40 | # fail and that the kernel may be used afterwards. |
| 41 | # |
| 42 | ############################################################################### |
| 43 | ifndef CONFIG_MODULE_SIG_HASH |
| 44 | $(error Could not determine digest type to use from kernel config) |
| 45 | endif |
| 46 | |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 47 | redirect_openssl = 2>&1 |
| 48 | quiet_redirect_openssl = 2>&1 |
| 49 | silent_redirect_openssl = 2>/dev/null |
Stefan Berger | bd2028e | 2021-06-29 17:34:20 -0400 | [diff] [blame] | 50 | openssl_available = $(shell openssl help 2>/dev/null && echo yes) |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 51 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 52 | # We do it this way rather than having a boolean option for enabling an |
| 53 | # external private key, because 'make randconfig' might enable such a |
| 54 | # boolean option and we unfortunately can't make it depend on !RANDCONFIG. |
| 55 | ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") |
Stefan Berger | bd2028e | 2021-06-29 17:34:20 -0400 | [diff] [blame] | 56 | |
| 57 | ifeq ($(openssl_available),yes) |
| 58 | X509TEXT=$(shell openssl x509 -in "certs/signing_key.pem" -text 2>/dev/null) |
| 59 | |
| 60 | $(if $(findstring rsaEncryption,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem")) |
| 61 | endif |
| 62 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 63 | $(obj)/signing_key.pem: $(obj)/x509.genkey |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 64 | @$(kecho) "###" |
| 65 | @$(kecho) "### Now generating an X.509 key pair to be used for signing modules." |
| 66 | @$(kecho) "###" |
| 67 | @$(kecho) "### If this takes a long time, you might wish to run rngd in the" |
| 68 | @$(kecho) "### background to keep the supply of entropy topped up. It" |
| 69 | @$(kecho) "### needs to be run as root, and uses a hardware random" |
| 70 | @$(kecho) "### number generator if one is available." |
| 71 | @$(kecho) "###" |
| 72 | $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 73 | -batch -x509 -config $(obj)/x509.genkey \ |
| 74 | -outform PEM -out $(obj)/signing_key.pem \ |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 75 | -keyout $(obj)/signing_key.pem \ |
| 76 | $($(quiet)redirect_openssl) |
| 77 | @$(kecho) "###" |
| 78 | @$(kecho) "### Key pair generated." |
| 79 | @$(kecho) "###" |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 80 | |
| 81 | $(obj)/x509.genkey: |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 82 | @$(kecho) Generating X.509 key generation config |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 83 | @echo >$@ "[ req ]" |
| 84 | @echo >>$@ "default_bits = 4096" |
| 85 | @echo >>$@ "distinguished_name = req_distinguished_name" |
| 86 | @echo >>$@ "prompt = no" |
| 87 | @echo >>$@ "string_mask = utf8only" |
| 88 | @echo >>$@ "x509_extensions = myexts" |
| 89 | @echo >>$@ |
| 90 | @echo >>$@ "[ req_distinguished_name ]" |
| 91 | @echo >>$@ "#O = Unspecified company" |
| 92 | @echo >>$@ "CN = Build time autogenerated kernel key" |
| 93 | @echo >>$@ "#emailAddress = unspecified.user@unspecified.company" |
| 94 | @echo >>$@ |
| 95 | @echo >>$@ "[ myexts ]" |
| 96 | @echo >>$@ "basicConstraints=critical,CA:FALSE" |
| 97 | @echo >>$@ "keyUsage=digitalSignature" |
| 98 | @echo >>$@ "subjectKeyIdentifier=hash" |
| 99 | @echo >>$@ "authorityKeyIdentifier=keyid" |
Jarkko Sakkinen | 5ccbdbf9 | 2017-07-13 13:16:49 +0100 | [diff] [blame] | 100 | endif # CONFIG_MODULE_SIG_KEY |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 101 | |
| 102 | $(eval $(call config_filename,MODULE_SIG_KEY)) |
| 103 | |
| 104 | # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it |
| 105 | ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) |
| 106 | X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) |
| 107 | endif |
| 108 | |
| 109 | # GCC PR#66871 again. |
| 110 | $(obj)/system_certificates.o: $(obj)/signing_key.x509 |
| 111 | |
David Woodhouse | 62172c8 | 2015-08-14 15:33:56 +0100 | [diff] [blame] | 112 | targets += signing_key.x509 |
| 113 | $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE |
| 114 | $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) |
Jarkko Sakkinen | 5ccbdbf9 | 2017-07-13 13:16:49 +0100 | [diff] [blame] | 115 | endif # CONFIG_MODULE_SIG |
Eric Snowberg | c6ae6f8 | 2021-01-22 13:10:53 -0500 | [diff] [blame] | 116 | |
| 117 | ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y) |
| 118 | |
| 119 | $(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) |
| 120 | |
| 121 | $(obj)/revocation_certificates.o: $(obj)/x509_revocation_list |
| 122 | |
| 123 | quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) |
| 124 | cmd_extract_certs = scripts/extract-cert $(2) $@ |
| 125 | |
| 126 | targets += x509_revocation_list |
| 127 | $(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE |
| 128 | $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) |
| 129 | endif |