Commit | Line | Data |
---|---|---|
b2441318 | 1 | # SPDX-License-Identifier: GPL-2.0 |
cfc411e7 DH |
2 | # |
3 | # Makefile for the linux kernel signature checking certificates. | |
4 | # | |
5 | ||
2565ca7f | 6 | obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o |
d1f04410 ES |
7 | obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o |
8 | obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o | |
734114f8 DH |
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 | |
cfc411e7 | 14 | |
cfc411e7 DH |
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)) | |
172caf19 | 26 | cmd_extract_certs = scripts/extract-cert $(2) $@ |
cfc411e7 DH |
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)) | |
5ccbdbf9 | 31 | endif # CONFIG_SYSTEM_TRUSTED_KEYRING |
cfc411e7 | 32 | |
d1f04410 | 33 | clean-files := x509_certificate_list .x509.list x509_revocation_list |
cfc411e7 DH |
34 | |
35 | ifeq ($(CONFIG_MODULE_SIG),y) | |
0165f4ca NJ |
36 | SIGN_KEY = y |
37 | endif | |
38 | ||
39 | ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y) | |
781a5739 | 40 | ifeq ($(CONFIG_MODULES),y) |
0165f4ca NJ |
41 | SIGN_KEY = y |
42 | endif | |
781a5739 | 43 | endif |
0165f4ca NJ |
44 | |
45 | ifdef SIGN_KEY | |
cfc411e7 DH |
46 | ############################################################################### |
47 | # | |
48 | # If module signing is requested, say by allyesconfig, but a key has not been | |
49 | # supplied, then one will need to be generated to make sure the build does not | |
50 | # fail and that the kernel may be used afterwards. | |
51 | # | |
52 | ############################################################################### | |
53 | ifndef CONFIG_MODULE_SIG_HASH | |
54 | $(error Could not determine digest type to use from kernel config) | |
55 | endif | |
56 | ||
5d06ee20 AB |
57 | redirect_openssl = 2>&1 |
58 | quiet_redirect_openssl = 2>&1 | |
59 | silent_redirect_openssl = 2>/dev/null | |
ea35e0d5 | 60 | openssl_available = $(shell openssl help 2>/dev/null && echo yes) |
5d06ee20 | 61 | |
cfc411e7 DH |
62 | # We do it this way rather than having a boolean option for enabling an |
63 | # external private key, because 'make randconfig' might enable such a | |
64 | # boolean option and we unfortunately can't make it depend on !RANDCONFIG. | |
65 | ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem") | |
ea35e0d5 SB |
66 | |
67 | ifeq ($(openssl_available),yes) | |
68 | X509TEXT=$(shell openssl x509 -in "certs/signing_key.pem" -text 2>/dev/null) | |
a4aed36e | 69 | endif |
ea35e0d5 | 70 | |
a4aed36e SB |
71 | # Support user changing key type |
72 | ifdef CONFIG_MODULE_SIG_KEY_TYPE_ECDSA | |
73 | keytype_openssl = -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 | |
74 | ifeq ($(openssl_available),yes) | |
75 | $(if $(findstring id-ecPublicKey,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem")) | |
76 | endif | |
77 | endif # CONFIG_MODULE_SIG_KEY_TYPE_ECDSA | |
78 | ||
79 | ifdef CONFIG_MODULE_SIG_KEY_TYPE_RSA | |
80 | ifeq ($(openssl_available),yes) | |
ea35e0d5 SB |
81 | $(if $(findstring rsaEncryption,$(X509TEXT)),,$(shell rm -f "certs/signing_key.pem")) |
82 | endif | |
a4aed36e | 83 | endif # CONFIG_MODULE_SIG_KEY_TYPE_RSA |
ea35e0d5 | 84 | |
cfc411e7 | 85 | $(obj)/signing_key.pem: $(obj)/x509.genkey |
5d06ee20 AB |
86 | @$(kecho) "###" |
87 | @$(kecho) "### Now generating an X.509 key pair to be used for signing modules." | |
88 | @$(kecho) "###" | |
89 | @$(kecho) "### If this takes a long time, you might wish to run rngd in the" | |
90 | @$(kecho) "### background to keep the supply of entropy topped up. It" | |
91 | @$(kecho) "### needs to be run as root, and uses a hardware random" | |
92 | @$(kecho) "### number generator if one is available." | |
93 | @$(kecho) "###" | |
94 | $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ | |
cfc411e7 DH |
95 | -batch -x509 -config $(obj)/x509.genkey \ |
96 | -outform PEM -out $(obj)/signing_key.pem \ | |
5d06ee20 | 97 | -keyout $(obj)/signing_key.pem \ |
a4aed36e | 98 | $(keytype_openssl) \ |
5d06ee20 AB |
99 | $($(quiet)redirect_openssl) |
100 | @$(kecho) "###" | |
101 | @$(kecho) "### Key pair generated." | |
102 | @$(kecho) "###" | |
cfc411e7 DH |
103 | |
104 | $(obj)/x509.genkey: | |
5d06ee20 | 105 | @$(kecho) Generating X.509 key generation config |
cfc411e7 DH |
106 | @echo >$@ "[ req ]" |
107 | @echo >>$@ "default_bits = 4096" | |
108 | @echo >>$@ "distinguished_name = req_distinguished_name" | |
109 | @echo >>$@ "prompt = no" | |
110 | @echo >>$@ "string_mask = utf8only" | |
111 | @echo >>$@ "x509_extensions = myexts" | |
112 | @echo >>$@ | |
113 | @echo >>$@ "[ req_distinguished_name ]" | |
114 | @echo >>$@ "#O = Unspecified company" | |
115 | @echo >>$@ "CN = Build time autogenerated kernel key" | |
116 | @echo >>$@ "#emailAddress = unspecified.user@unspecified.company" | |
117 | @echo >>$@ | |
118 | @echo >>$@ "[ myexts ]" | |
119 | @echo >>$@ "basicConstraints=critical,CA:FALSE" | |
120 | @echo >>$@ "keyUsage=digitalSignature" | |
121 | @echo >>$@ "subjectKeyIdentifier=hash" | |
122 | @echo >>$@ "authorityKeyIdentifier=keyid" | |
5ccbdbf9 | 123 | endif # CONFIG_MODULE_SIG_KEY |
cfc411e7 DH |
124 | |
125 | $(eval $(call config_filename,MODULE_SIG_KEY)) | |
126 | ||
127 | # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it | |
128 | ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) | |
129 | X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) | |
130 | endif | |
131 | ||
132 | # GCC PR#66871 again. | |
133 | $(obj)/system_certificates.o: $(obj)/signing_key.x509 | |
134 | ||
62172c81 DW |
135 | targets += signing_key.x509 |
136 | $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE | |
137 | $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) | |
5ccbdbf9 | 138 | endif # CONFIG_MODULE_SIG |
d1f04410 ES |
139 | |
140 | ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y) | |
141 | ||
142 | $(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) | |
143 | ||
144 | $(obj)/revocation_certificates.o: $(obj)/x509_revocation_list | |
145 | ||
146 | quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2)) | |
147 | cmd_extract_certs = scripts/extract-cert $(2) $@ | |
148 | ||
149 | targets += x509_revocation_list | |
150 | $(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE | |
151 | $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) | |
152 | endif |