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