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 | 2565ca7 | 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 | d1f0441 | 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 |
Masahiro Yamada | 129ab0d | 2021-12-14 11:53:53 +0900 | [diff] [blame] | 9 | ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),) |
David Howells | 734114f | 2017-04-03 16:07:24 +0100 | [diff] [blame] | 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 | |
Masahiro Yamada | 1c4bd9f | 2021-12-14 11:53:46 +0900 | [diff] [blame] | 15 | quiet_cmd_extract_certs = CERT $@ |
Masahiro Yamada | 340a025 | 2021-12-14 11:53:54 +0900 | [diff] [blame] | 16 | cmd_extract_certs = $(obj)/extract-cert $(2) $@ |
Masahiro Yamada | 1c4bd9f | 2021-12-14 11:53:46 +0900 | [diff] [blame] | 17 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 18 | $(obj)/system_certificates.o: $(obj)/x509_certificate_list |
| 19 | |
Masahiro Yamada | 340a025 | 2021-12-14 11:53:54 +0900 | [diff] [blame] | 20 | $(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE |
Masahiro Yamada | b8c96a6 | 2021-12-14 11:53:51 +0900 | [diff] [blame] | 21 | $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_TRUSTED_KEYS),$<,"")) |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 22 | |
Masahiro Yamada | 5cca360 | 2021-12-14 11:53:48 +0900 | [diff] [blame] | 23 | targets += x509_certificate_list |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 24 | |
| 25 | ifeq ($(CONFIG_MODULE_SIG),y) |
Nayna Jain | 0165f4c | 2021-04-09 10:35:06 -0400 | [diff] [blame] | 26 | SIGN_KEY = y |
| 27 | endif |
| 28 | |
| 29 | ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y) |
Nayna Jain | 781a573 | 2021-04-22 21:16:02 -0400 | [diff] [blame] | 30 | ifeq ($(CONFIG_MODULES),y) |
Nayna Jain | 0165f4c | 2021-04-09 10:35:06 -0400 | [diff] [blame] | 31 | SIGN_KEY = y |
| 32 | endif |
Nayna Jain | 781a573 | 2021-04-22 21:16:02 -0400 | [diff] [blame] | 33 | endif |
Nayna Jain | 0165f4c | 2021-04-09 10:35:06 -0400 | [diff] [blame] | 34 | |
| 35 | ifdef SIGN_KEY |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 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 | ############################################################################### |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 43 | |
| 44 | # We do it this way rather than having a boolean option for enabling an |
| 45 | # external private key, because 'make randconfig' might enable such a |
| 46 | # boolean option and we unfortunately can't make it depend on !RANDCONFIG. |
Masahiro Yamada | 129ab0d | 2021-12-14 11:53:53 +0900 | [diff] [blame] | 47 | ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem) |
Stefan Berger | ea35e0d | 2021-06-29 17:34:20 -0400 | [diff] [blame] | 48 | |
Masahiro Yamada | e06a61a | 2021-11-05 12:59:58 +0900 | [diff] [blame] | 49 | keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 |
Stefan Berger | ea35e0d | 2021-06-29 17:34:20 -0400 | [diff] [blame] | 50 | |
Masahiro Yamada | 54c8b51 | 2021-11-05 12:59:57 +0900 | [diff] [blame] | 51 | quiet_cmd_gen_key = GENKEY $@ |
| 52 | cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ |
Masahiro Yamada | c537e4d | 2021-12-14 11:53:45 +0900 | [diff] [blame] | 53 | -batch -x509 -config $< \ |
| 54 | -outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1 |
Masahiro Yamada | 54c8b51 | 2021-11-05 12:59:57 +0900 | [diff] [blame] | 55 | |
Masahiro Yamada | e06a61a | 2021-11-05 12:59:58 +0900 | [diff] [blame] | 56 | $(obj)/signing_key.pem: $(obj)/x509.genkey FORCE |
| 57 | $(call if_changed,gen_key) |
| 58 | |
| 59 | targets += signing_key.pem |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 60 | |
Masahiro Yamada | f3a2ba4 | 2021-11-05 12:59:55 +0900 | [diff] [blame] | 61 | quiet_cmd_copy_x509_config = COPY $@ |
| 62 | cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@ |
| 63 | |
| 64 | # You can provide your own config file. If not present, copy the default one. |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 65 | $(obj)/x509.genkey: |
Masahiro Yamada | f3a2ba4 | 2021-11-05 12:59:55 +0900 | [diff] [blame] | 66 | $(call cmd,copy_x509_config) |
| 67 | |
Jarkko Sakkinen | 5ccbdbf9 | 2017-07-13 13:16:49 +0100 | [diff] [blame] | 68 | endif # CONFIG_MODULE_SIG_KEY |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 69 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 70 | # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it |
Masahiro Yamada | ad29a2f | 2022-01-21 04:22:04 +0900 | [diff] [blame^] | 71 | ifneq ($(filter-out pkcs11:%, $(CONFIG_MODULE_SIG_KEY)),) |
Masahiro Yamada | b8c96a6 | 2021-12-14 11:53:51 +0900 | [diff] [blame] | 72 | X509_DEP := $(CONFIG_MODULE_SIG_KEY) |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 73 | endif |
| 74 | |
David Howells | cfc411e | 2015-08-14 15:20:41 +0100 | [diff] [blame] | 75 | $(obj)/system_certificates.o: $(obj)/signing_key.x509 |
| 76 | |
Masahiro Yamada | 340a025 | 2021-12-14 11:53:54 +0900 | [diff] [blame] | 77 | $(obj)/signing_key.x509: $(X509_DEP) $(obj)/extract-cert FORCE |
Masahiro Yamada | b8c96a6 | 2021-12-14 11:53:51 +0900 | [diff] [blame] | 78 | $(call if_changed,extract_certs,$(if $(X509_DEP),$<,$(CONFIG_MODULE_SIG_KEY))) |
Jarkko Sakkinen | 5ccbdbf9 | 2017-07-13 13:16:49 +0100 | [diff] [blame] | 79 | endif # CONFIG_MODULE_SIG |
Eric Snowberg | d1f0441 | 2021-01-22 13:10:53 -0500 | [diff] [blame] | 80 | |
Masahiro Yamada | 5cca360 | 2021-12-14 11:53:48 +0900 | [diff] [blame] | 81 | targets += signing_key.x509 |
| 82 | |
Eric Snowberg | d1f0441 | 2021-01-22 13:10:53 -0500 | [diff] [blame] | 83 | $(obj)/revocation_certificates.o: $(obj)/x509_revocation_list |
| 84 | |
Masahiro Yamada | 340a025 | 2021-12-14 11:53:54 +0900 | [diff] [blame] | 85 | $(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE |
Masahiro Yamada | b8c96a6 | 2021-12-14 11:53:51 +0900 | [diff] [blame] | 86 | $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_REVOCATION_KEYS),$<,"")) |
Masahiro Yamada | 5cca360 | 2021-12-14 11:53:48 +0900 | [diff] [blame] | 87 | |
| 88 | targets += x509_revocation_list |
Masahiro Yamada | 340a025 | 2021-12-14 11:53:54 +0900 | [diff] [blame] | 89 | |
| 90 | hostprogs := extract-cert |
| 91 | |
| 92 | HOSTCFLAGS_extract-cert.o = $(shell pkg-config --cflags libcrypto 2> /dev/null) |
| 93 | HOSTLDLIBS_extract-cert = $(shell pkg-config --libs libcrypto 2> /dev/null || echo -lcrypto) |