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 | |
| 6 | obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 7 | obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o |
| 8 | ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"") |
| 9 | obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o |
| 10 | else |
| 11 | obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o |
| 12 | endif |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 13 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 14 | ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) |
| 15 | |
| 16 | $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS)) |
| 17 | |
| 18 | # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871) |
| 19 | $(obj)/system_certificates.o: $(obj)/x509_certificate_list |
| 20 | |
| 21 | # Cope with signing_key.x509 existing in $(srctree) not $(objtree) |
| 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) $@ || ( rm $@; exit 1) |
| 26 | |
Jeevan Shriram | 9e5ed82 | 2017-02-16 17:58:04 -0800 | [diff] [blame] | 27 | ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYS),"verity.x509.pem") |
| 28 | SYSTEM_TRUSTED_KEYS_SRCPREFIX := $(srctree)/certs/ |
| 29 | endif |
| 30 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 31 | targets += x509_certificate_list |
| 32 | $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE |
| 33 | $(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] | 34 | endif # CONFIG_SYSTEM_TRUSTED_KEYRING |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 35 | |
| 36 | clean-files := x509_certificate_list .x509.list |
| 37 | |
| 38 | ifeq ($(CONFIG_MODULE_SIG),y) |
| 39 | ############################################################################### |
| 40 | # |
| 41 | # If module signing is requested, say by allyesconfig, but a key has not been |
| 42 | # supplied, then one will need to be generated to make sure the build does not |
| 43 | # fail and that the kernel may be used afterwards. |
| 44 | # |
| 45 | ############################################################################### |
| 46 | ifndef CONFIG_MODULE_SIG_HASH |
| 47 | $(error Could not determine digest type to use from kernel config) |
| 48 | endif |
| 49 | |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 50 | redirect_openssl = 2>&1 |
| 51 | quiet_redirect_openssl = 2>&1 |
| 52 | silent_redirect_openssl = 2>/dev/null |
| 53 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 54 | # We do it this way rather than having a boolean option for enabling an |
| 55 | # external private key, because 'make randconfig' might enable such a |
| 56 | # boolean option and we unfortunately can't make it depend on !RANDCONFIG. |
| 57 | ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") |
| 58 | $(obj)/signing_key.pem: $(obj)/x509.genkey |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 59 | @$(kecho) "###" |
| 60 | @$(kecho) "### Now generating an X.509 key pair to be used for signing modules." |
| 61 | @$(kecho) "###" |
| 62 | @$(kecho) "### If this takes a long time, you might wish to run rngd in the" |
| 63 | @$(kecho) "### background to keep the supply of entropy topped up. It" |
| 64 | @$(kecho) "### needs to be run as root, and uses a hardware random" |
| 65 | @$(kecho) "### number generator if one is available." |
| 66 | @$(kecho) "###" |
| 67 | $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 68 | -batch -x509 -config $(obj)/x509.genkey \ |
| 69 | -outform PEM -out $(obj)/signing_key.pem \ |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 70 | -keyout $(obj)/signing_key.pem \ |
| 71 | $($(quiet)redirect_openssl) |
| 72 | @$(kecho) "###" |
| 73 | @$(kecho) "### Key pair generated." |
| 74 | @$(kecho) "###" |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 75 | |
| 76 | $(obj)/x509.genkey: |
Arnd Bergmann | 5d06ee2 | 2016-02-25 17:31:32 +0100 | [diff] [blame] | 77 | @$(kecho) Generating X.509 key generation config |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 78 | @echo >$@ "[ req ]" |
| 79 | @echo >>$@ "default_bits = 4096" |
| 80 | @echo >>$@ "distinguished_name = req_distinguished_name" |
| 81 | @echo >>$@ "prompt = no" |
| 82 | @echo >>$@ "string_mask = utf8only" |
| 83 | @echo >>$@ "x509_extensions = myexts" |
| 84 | @echo >>$@ |
| 85 | @echo >>$@ "[ req_distinguished_name ]" |
| 86 | @echo >>$@ "#O = Unspecified company" |
| 87 | @echo >>$@ "CN = Build time autogenerated kernel key" |
| 88 | @echo >>$@ "#emailAddress = unspecified.user@unspecified.company" |
| 89 | @echo >>$@ |
| 90 | @echo >>$@ "[ myexts ]" |
| 91 | @echo >>$@ "basicConstraints=critical,CA:FALSE" |
| 92 | @echo >>$@ "keyUsage=digitalSignature" |
| 93 | @echo >>$@ "subjectKeyIdentifier=hash" |
| 94 | @echo >>$@ "authorityKeyIdentifier=keyid" |
Jarkko Sakkinen | 5ccbdbf9 | 2017-07-13 13:16:49 +0100 | [diff] [blame] | 95 | endif # CONFIG_MODULE_SIG_KEY |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 96 | |
| 97 | $(eval $(call config_filename,MODULE_SIG_KEY)) |
| 98 | |
| 99 | # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it |
| 100 | ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) |
| 101 | X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) |
| 102 | endif |
| 103 | |
| 104 | # GCC PR#66871 again. |
| 105 | $(obj)/system_certificates.o: $(obj)/signing_key.x509 |
| 106 | |
David Woodhouse | 62172c8 | 2015-08-14 15:33:56 +0100 | [diff] [blame] | 107 | targets += signing_key.x509 |
| 108 | $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE |
| 109 | $(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] | 110 | endif # CONFIG_MODULE_SIG |