aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2015-08-14 10:20:41 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2015-08-14 11:06:13 -0400
commitcfc411e7fff3e15cd6354ff69773907e2c9d1c0c (patch)
treec67e679c1c2bbe4a657ce58d60e995c63535952b
parent0e38c35815f50e5a347977d76fb5eb4c3bf020b5 (diff)
Move certificate handling to its own directory
Move certificate handling out of the kernel/ directory and into a certs/ directory to get all the weird stuff in one place and move the generated signing keys into this directory. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: David Woodhouse <David.Woodhouse@intel.com>
-rw-r--r--Documentation/module-signing.txt18
-rw-r--r--MAINTAINERS9
-rw-r--r--Makefile4
-rw-r--r--certs/Kconfig42
-rw-r--r--certs/Makefile147
-rw-r--r--certs/system_certificates.S (renamed from kernel/system_certificates.S)4
-rw-r--r--certs/system_keyring.c (renamed from kernel/system_keyring.c)0
-rw-r--r--crypto/Kconfig1
-rw-r--r--init/Kconfig39
-rw-r--r--kernel/Makefile143
10 files changed, 212 insertions, 195 deletions
diff --git a/Documentation/module-signing.txt b/Documentation/module-signing.txt
index 02a9baf1c72f..a78bf1ffa68c 100644
--- a/Documentation/module-signing.txt
+++ b/Documentation/module-signing.txt
@@ -92,13 +92,13 @@ This has a number of options available:
92 (4) "File name or PKCS#11 URI of module signing key" (CONFIG_MODULE_SIG_KEY) 92 (4) "File name or PKCS#11 URI of module signing key" (CONFIG_MODULE_SIG_KEY)
93 93
94 Setting this option to something other than its default of 94 Setting this option to something other than its default of
95 "signing_key.pem" will disable the autogeneration of signing keys and 95 "certs/signing_key.pem" will disable the autogeneration of signing keys
96 allow the kernel modules to be signed with a key of your choosing. 96 and allow the kernel modules to be signed with a key of your choosing.
97 The string provided should identify a file containing both a private 97 The string provided should identify a file containing both a private key
98 key and its corresponding X.509 certificate in PEM form, or — on 98 and its corresponding X.509 certificate in PEM form, or — on systems where
99 systems where the OpenSSL ENGINE_pkcs11 is functional — a PKCS#11 URI 99 the OpenSSL ENGINE_pkcs11 is functional — a PKCS#11 URI as defined by
100 as defined by RFC7512. In the latter case, the PKCS#11 URI should 100 RFC7512. In the latter case, the PKCS#11 URI should reference both a
101 reference both a certificate and a private key. 101 certificate and a private key.
102 102
103 If the PEM file containing the private key is encrypted, or if the 103 If the PEM file containing the private key is encrypted, or if the
104 PKCS#11 token requries a PIN, this can be provided at build time by 104 PKCS#11 token requries a PIN, this can be provided at build time by
@@ -130,12 +130,12 @@ Under normal conditions, when CONFIG_MODULE_SIG_KEY is unchanged from its
130default, the kernel build will automatically generate a new keypair using 130default, the kernel build will automatically generate a new keypair using
131openssl if one does not exist in the file: 131openssl if one does not exist in the file:
132 132
133 signing_key.pem 133 certs/signing_key.pem
134 134
135during the building of vmlinux (the public part of the key needs to be built 135during the building of vmlinux (the public part of the key needs to be built
136into vmlinux) using parameters in the: 136into vmlinux) using parameters in the:
137 137
138 x509.genkey 138 certs/x509.genkey
139 139
140file (which is also generated if it does not already exist). 140file (which is also generated if it does not already exist).
141 141
diff --git a/MAINTAINERS b/MAINTAINERS
index bde2e3f5a10b..294dc59ed5e1 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2589,6 +2589,15 @@ S: Supported
2589F: Documentation/filesystems/ceph.txt 2589F: Documentation/filesystems/ceph.txt
2590F: fs/ceph/ 2590F: fs/ceph/
2591 2591
2592CERTIFICATE HANDLING:
2593M: David Howells <dhowells@redhat.com>
2594M: David Woodhouse <dwmw2@infradead.org>
2595L: keyrings@linux-nfs.org
2596S: Maintained
2597F: Documentation/module-signing.txt
2598F: certs/
2599F: scripts/extract-cert.c
2600
2592CERTIFIED WIRELESS USB (WUSB) SUBSYSTEM: 2601CERTIFIED WIRELESS USB (WUSB) SUBSYSTEM:
2593L: linux-usb@vger.kernel.org 2602L: linux-usb@vger.kernel.org
2594S: Orphan 2603S: Orphan
diff --git a/Makefile b/Makefile
index 6ab99d8cc23c..2341942feb85 100644
--- a/Makefile
+++ b/Makefile
@@ -871,7 +871,7 @@ INITRD_COMPRESS-$(CONFIG_RD_LZ4) := lz4
871 871
872ifdef CONFIG_MODULE_SIG_ALL 872ifdef CONFIG_MODULE_SIG_ALL
873MODSECKEY = $(CONFIG_MODULE_SIG_KEY) 873MODSECKEY = $(CONFIG_MODULE_SIG_KEY)
874MODPUBKEY = ./signing_key.x509 874MODPUBKEY = certs/signing_key.x509
875export MODPUBKEY 875export MODPUBKEY
876mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY) 876mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)
877else 877else
@@ -881,7 +881,7 @@ export mod_sign_cmd
881 881
882 882
883ifeq ($(KBUILD_EXTMOD),) 883ifeq ($(KBUILD_EXTMOD),)
884core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ 884core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
885 885
886vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ 886vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
887 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ 887 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
diff --git a/certs/Kconfig b/certs/Kconfig
new file mode 100644
index 000000000000..b030b9c7ed34
--- /dev/null
+++ b/certs/Kconfig
@@ -0,0 +1,42 @@
1menu "Certificates for signature checking"
2
3config MODULE_SIG_KEY
4 string "File name or PKCS#11 URI of module signing key"
5 default "certs/signing_key.pem"
6 depends on MODULE_SIG
7 help
8 Provide the file name of a private key/certificate in PEM format,
9 or a PKCS#11 URI according to RFC7512. The file should contain, or
10 the URI should identify, both the certificate and its corresponding
11 private key.
12
13 If this option is unchanged from its default "certs/signing_key.pem",
14 then the kernel will automatically generate the private key and
15 certificate as described in Documentation/module-signing.txt
16
17config SYSTEM_TRUSTED_KEYRING
18 bool "Provide system-wide ring of trusted keys"
19 depends on KEYS
20 help
21 Provide a system keyring to which trusted keys can be added. Keys in
22 the keyring are considered to be trusted. Keys may be added at will
23 by the kernel from compiled-in data and from hardware key stores, but
24 userspace may only add extra keys if those keys can be verified by
25 keys already in the keyring.
26
27 Keys in this keyring are used by module signature checking.
28
29config SYSTEM_TRUSTED_KEYS
30 string "Additional X.509 keys for default system keyring"
31 depends on SYSTEM_TRUSTED_KEYRING
32 help
33 If set, this option should be the filename of a PEM-formatted file
34 containing trusted X.509 certificates to be included in the default
35 system keyring. Any certificate used for module signing is implicitly
36 also trusted.
37
38 NOTE: If you previously provided keys for the system keyring in the
39 form of DER-encoded *.x509 files in the top-level build directory,
40 those are no longer used. You will need to set this option instead.
41
42endmenu
diff --git a/certs/Makefile b/certs/Makefile
new file mode 100644
index 000000000000..5d33486d3b20
--- /dev/null
+++ b/certs/Makefile
@@ -0,0 +1,147 @@
1#
2# Makefile for the linux kernel signature checking certificates.
3#
4
5obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
6
7###############################################################################
8#
9# When a Kconfig string contains a filename, it is suitable for
10# passing to shell commands. It is surrounded by double-quotes, and
11# any double-quotes or backslashes within it are escaped by
12# backslashes.
13#
14# This is no use for dependencies or $(wildcard). We need to strip the
15# surrounding quotes and the escaping from quotes and backslashes, and
16# we *do* need to escape any spaces in the string. So, for example:
17#
18# Usage: $(eval $(call config_filename,FOO))
19#
20# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option,
21# transformed as described above to be suitable for use within the
22# makefile.
23#
24# Also, if the filename is a relative filename and exists in the source
25# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to
26# be prefixed to *both* command invocation and dependencies.
27#
28# Note: We also print the filenames in the quiet_cmd_foo text, and
29# perhaps ought to have a version specially escaped for that purpose.
30# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good
31# enough. It'll strip the quotes in the common case where there's no
32# space and it's a simple filename, and it'll retain the quotes when
33# there's a space. There are some esoteric cases in which it'll print
34# the wrong thing, but we don't really care. The actual dependencies
35# and commands *do* get it right, with various combinations of single
36# and double quotes, backslashes and spaces in the filenames.
37#
38###############################################################################
39#
40quote := $(firstword " ")
41space :=
42space +=
43space_escape := %%%SPACE%%%
44#
45define config_filename
46ifneq ($$(CONFIG_$(1)),"")
47$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1)))))))
48ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME)))
49else
50ifeq ($$(wildcard $$($(1)_FILENAME)),)
51ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),)
52$(1)_SRCPREFIX := $(srctree)/
53endif
54endif
55endif
56endif
57endef
58#
59###############################################################################
60
61ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
62
63$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
64
65# GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
66$(obj)/system_certificates.o: $(obj)/x509_certificate_list
67
68# Cope with signing_key.x509 existing in $(srctree) not $(objtree)
69AFLAGS_system_certificates.o := -I$(srctree)
70
71quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
72 cmd_extract_certs = scripts/extract-cert $(2) $@ || ( rm $@; exit 1)
73
74targets += x509_certificate_list
75$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
76 $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
77endif
78
79clean-files := x509_certificate_list .x509.list
80
81ifeq ($(CONFIG_MODULE_SIG),y)
82###############################################################################
83#
84# If module signing is requested, say by allyesconfig, but a key has not been
85# supplied, then one will need to be generated to make sure the build does not
86# fail and that the kernel may be used afterwards.
87#
88###############################################################################
89ifndef CONFIG_MODULE_SIG_HASH
90$(error Could not determine digest type to use from kernel config)
91endif
92
93# We do it this way rather than having a boolean option for enabling an
94# external private key, because 'make randconfig' might enable such a
95# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
96ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
97$(obj)/signing_key.pem: $(obj)/x509.genkey
98 @echo "###"
99 @echo "### Now generating an X.509 key pair to be used for signing modules."
100 @echo "###"
101 @echo "### If this takes a long time, you might wish to run rngd in the"
102 @echo "### background to keep the supply of entropy topped up. It"
103 @echo "### needs to be run as root, and uses a hardware random"
104 @echo "### number generator if one is available."
105 @echo "###"
106 openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
107 -batch -x509 -config $(obj)/x509.genkey \
108 -outform PEM -out $(obj)/signing_key.pem \
109 -keyout $(obj)/signing_key.pem 2>&1
110 @echo "###"
111 @echo "### Key pair generated."
112 @echo "###"
113
114$(obj)/x509.genkey:
115 @echo Generating X.509 key generation config
116 @echo >$@ "[ req ]"
117 @echo >>$@ "default_bits = 4096"
118 @echo >>$@ "distinguished_name = req_distinguished_name"
119 @echo >>$@ "prompt = no"
120 @echo >>$@ "string_mask = utf8only"
121 @echo >>$@ "x509_extensions = myexts"
122 @echo >>$@
123 @echo >>$@ "[ req_distinguished_name ]"
124 @echo >>$@ "#O = Unspecified company"
125 @echo >>$@ "CN = Build time autogenerated kernel key"
126 @echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
127 @echo >>$@
128 @echo >>$@ "[ myexts ]"
129 @echo >>$@ "basicConstraints=critical,CA:FALSE"
130 @echo >>$@ "keyUsage=digitalSignature"
131 @echo >>$@ "subjectKeyIdentifier=hash"
132 @echo >>$@ "authorityKeyIdentifier=keyid"
133endif
134
135$(eval $(call config_filename,MODULE_SIG_KEY))
136
137# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
138ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
139X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
140endif
141
142# GCC PR#66871 again.
143$(obj)/system_certificates.o: $(obj)/signing_key.x509
144
145$(obj)/signing_key.x509: scripts/extract-cert include/config/module/sig/key.h $(X509_DEP)
146 $(call cmd,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
147endif
diff --git a/kernel/system_certificates.S b/certs/system_certificates.S
index 6ba2f75e7ba5..9216e8c81764 100644
--- a/kernel/system_certificates.S
+++ b/certs/system_certificates.S
@@ -8,9 +8,9 @@
8VMLINUX_SYMBOL(system_certificate_list): 8VMLINUX_SYMBOL(system_certificate_list):
9__cert_list_start: 9__cert_list_start:
10#ifdef CONFIG_MODULE_SIG 10#ifdef CONFIG_MODULE_SIG
11 .incbin "signing_key.x509" 11 .incbin "certs/signing_key.x509"
12#endif 12#endif
13 .incbin "kernel/x509_certificate_list" 13 .incbin "certs/x509_certificate_list"
14__cert_list_end: 14__cert_list_end:
15 15
16 .align 8 16 .align 8
diff --git a/kernel/system_keyring.c b/certs/system_keyring.c
index 2570598b784d..2570598b784d 100644
--- a/kernel/system_keyring.c
+++ b/certs/system_keyring.c
diff --git a/crypto/Kconfig b/crypto/Kconfig
index b4cfc5754033..51b01de7c0ae 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1601,5 +1601,6 @@ config CRYPTO_HASH_INFO
1601 1601
1602source "drivers/crypto/Kconfig" 1602source "drivers/crypto/Kconfig"
1603source crypto/asymmetric_keys/Kconfig 1603source crypto/asymmetric_keys/Kconfig
1604source certs/Kconfig
1604 1605
1605endif # if CRYPTO 1606endif # if CRYPTO
diff --git a/init/Kconfig b/init/Kconfig
index 5d1a703663ad..5526dfaac628 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1740,31 +1740,6 @@ config MMAP_ALLOW_UNINITIALIZED
1740 1740
1741 See Documentation/nommu-mmap.txt for more information. 1741 See Documentation/nommu-mmap.txt for more information.
1742 1742
1743config SYSTEM_TRUSTED_KEYRING
1744 bool "Provide system-wide ring of trusted keys"
1745 depends on KEYS
1746 help
1747 Provide a system keyring to which trusted keys can be added. Keys in
1748 the keyring are considered to be trusted. Keys may be added at will
1749 by the kernel from compiled-in data and from hardware key stores, but
1750 userspace may only add extra keys if those keys can be verified by
1751 keys already in the keyring.
1752
1753 Keys in this keyring are used by module signature checking.
1754
1755config SYSTEM_TRUSTED_KEYS
1756 string "Additional X.509 keys for default system keyring"
1757 depends on SYSTEM_TRUSTED_KEYRING
1758 help
1759 If set, this option should be the filename of a PEM-formatted file
1760 containing trusted X.509 certificates to be included in the default
1761 system keyring. Any certificate used for module signing is implicitly
1762 also trusted.
1763
1764 NOTE: If you previously provided keys for the system keyring in the
1765 form of DER-encoded *.x509 files in the top-level build directory,
1766 those are no longer used. You will need to set this option instead.
1767
1768config SYSTEM_DATA_VERIFICATION 1743config SYSTEM_DATA_VERIFICATION
1769 def_bool n 1744 def_bool n
1770 select SYSTEM_TRUSTED_KEYRING 1745 select SYSTEM_TRUSTED_KEYRING
@@ -1965,20 +1940,6 @@ config MODULE_SIG_HASH
1965 default "sha384" if MODULE_SIG_SHA384 1940 default "sha384" if MODULE_SIG_SHA384
1966 default "sha512" if MODULE_SIG_SHA512 1941 default "sha512" if MODULE_SIG_SHA512
1967 1942
1968config MODULE_SIG_KEY
1969 string "File name or PKCS#11 URI of module signing key"
1970 default "signing_key.pem"
1971 depends on MODULE_SIG
1972 help
1973 Provide the file name of a private key/certificate in PEM format,
1974 or a PKCS#11 URI according to RFC7512. The file should contain, or
1975 the URI should identify, both the certificate and its corresponding
1976 private key.
1977
1978 If this option is unchanged from its default "signing_key.pem",
1979 then the kernel will automatically generate the private key and
1980 certificate as described in Documentation/module-signing.txt
1981
1982config MODULE_COMPRESS 1943config MODULE_COMPRESS
1983 bool "Compress modules on installation" 1944 bool "Compress modules on installation"
1984 depends on MODULES 1945 depends on MODULES
diff --git a/kernel/Makefile b/kernel/Makefile
index 65ef3846fbe8..1aa153a1be21 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -45,7 +45,6 @@ ifneq ($(CONFIG_SMP),y)
45obj-y += up.o 45obj-y += up.o
46endif 46endif
47obj-$(CONFIG_UID16) += uid16.o 47obj-$(CONFIG_UID16) += uid16.o
48obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
49obj-$(CONFIG_MODULES) += module.o 48obj-$(CONFIG_MODULES) += module.o
50obj-$(CONFIG_MODULE_SIG) += module_signing.o 49obj-$(CONFIG_MODULE_SIG) += module_signing.o
51obj-$(CONFIG_KALLSYMS) += kallsyms.o 50obj-$(CONFIG_KALLSYMS) += kallsyms.o
@@ -111,145 +110,3 @@ $(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
111targets += config_data.h 110targets += config_data.h
112$(obj)/config_data.h: $(obj)/config_data.gz FORCE 111$(obj)/config_data.h: $(obj)/config_data.gz FORCE
113 $(call filechk,ikconfiggz) 112 $(call filechk,ikconfiggz)
114
115###############################################################################
116#
117# When a Kconfig string contains a filename, it is suitable for
118# passing to shell commands. It is surrounded by double-quotes, and
119# any double-quotes or backslashes within it are escaped by
120# backslashes.
121#
122# This is no use for dependencies or $(wildcard). We need to strip the
123# surrounding quotes and the escaping from quotes and backslashes, and
124# we *do* need to escape any spaces in the string. So, for example:
125#
126# Usage: $(eval $(call config_filename,FOO))
127#
128# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option,
129# transformed as described above to be suitable for use within the
130# makefile.
131#
132# Also, if the filename is a relative filename and exists in the source
133# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to
134# be prefixed to *both* command invocation and dependencies.
135#
136# Note: We also print the filenames in the quiet_cmd_foo text, and
137# perhaps ought to have a version specially escaped for that purpose.
138# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good
139# enough. It'll strip the quotes in the common case where there's no
140# space and it's a simple filename, and it'll retain the quotes when
141# there's a space. There are some esoteric cases in which it'll print
142# the wrong thing, but we don't really care. The actual dependencies
143# and commands *do* get it right, with various combinations of single
144# and double quotes, backslashes and spaces in the filenames.
145#
146###############################################################################
147#
148quote := $(firstword " ")
149space :=
150space +=
151space_escape := %%%SPACE%%%
152#
153define config_filename
154ifneq ($$(CONFIG_$(1)),"")
155$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1)))))))
156ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME)))
157else
158ifeq ($$(wildcard $$($(1)_FILENAME)),)
159ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),)
160$(1)_SRCPREFIX := $(srctree)/
161endif
162endif
163endif
164endif
165endef
166#
167###############################################################################
168
169ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
170
171$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
172
173# GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
174$(obj)/system_certificates.o: $(obj)/x509_certificate_list
175
176# Cope with signing_key.x509 existing in $(srctree) not $(objtree)
177AFLAGS_system_certificates.o := -I$(srctree)
178
179quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
180 cmd_extract_certs = scripts/extract-cert $(2) $@ || ( rm $@; exit 1)
181
182targets += x509_certificate_list
183$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
184 $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
185endif
186
187clean-files := x509_certificate_list .x509.list
188
189ifeq ($(CONFIG_MODULE_SIG),y)
190###############################################################################
191#
192# If module signing is requested, say by allyesconfig, but a key has not been
193# supplied, then one will need to be generated to make sure the build does not
194# fail and that the kernel may be used afterwards.
195#
196###############################################################################
197ifndef CONFIG_MODULE_SIG_HASH
198$(error Could not determine digest type to use from kernel config)
199endif
200
201# We do it this way rather than having a boolean option for enabling an
202# external private key, because 'make randconfig' might enable such a
203# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
204ifeq ($(CONFIG_MODULE_SIG_KEY),"signing_key.pem")
205signing_key.pem: x509.genkey
206 @echo "###"
207 @echo "### Now generating an X.509 key pair to be used for signing modules."
208 @echo "###"
209 @echo "### If this takes a long time, you might wish to run rngd in the"
210 @echo "### background to keep the supply of entropy topped up. It"
211 @echo "### needs to be run as root, and uses a hardware random"
212 @echo "### number generator if one is available."
213 @echo "###"
214 openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
215 -batch -x509 -config x509.genkey \
216 -outform PEM -out signing_key.pem \
217 -keyout signing_key.pem 2>&1
218 @echo "###"
219 @echo "### Key pair generated."
220 @echo "###"
221
222x509.genkey:
223 @echo Generating X.509 key generation config
224 @echo >x509.genkey "[ req ]"
225 @echo >>x509.genkey "default_bits = 4096"
226 @echo >>x509.genkey "distinguished_name = req_distinguished_name"
227 @echo >>x509.genkey "prompt = no"
228 @echo >>x509.genkey "string_mask = utf8only"
229 @echo >>x509.genkey "x509_extensions = myexts"
230 @echo >>x509.genkey
231 @echo >>x509.genkey "[ req_distinguished_name ]"
232 @echo >>x509.genkey "#O = Unspecified company"
233 @echo >>x509.genkey "CN = Build time autogenerated kernel key"
234 @echo >>x509.genkey "#emailAddress = unspecified.user@unspecified.company"
235 @echo >>x509.genkey
236 @echo >>x509.genkey "[ myexts ]"
237 @echo >>x509.genkey "basicConstraints=critical,CA:FALSE"
238 @echo >>x509.genkey "keyUsage=digitalSignature"
239 @echo >>x509.genkey "subjectKeyIdentifier=hash"
240 @echo >>x509.genkey "authorityKeyIdentifier=keyid"
241endif
242
243$(eval $(call config_filename,MODULE_SIG_KEY))
244
245# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
246ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
247X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
248endif
249
250# GCC PR#66871 again.
251$(obj)/system_certificates.o: signing_key.x509
252
253signing_key.x509: scripts/extract-cert include/config/module/sig/key.h $(X509_DEP)
254 $(call cmd,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
255endif