blob: f4c25b67aad90b5833f1e390e2cf0ae303412fbd [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
David Howellscfc411e2015-08-14 15:20:41 +01002#
3# Makefile for the linux kernel signature checking certificates.
4#
5
6obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
David Howells734114f2017-04-03 16:07:24 +01007obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
8ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
9obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
10else
11obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
12endif
David Howellscfc411e2015-08-14 15:20:41 +010013
David Howellscfc411e2015-08-14 15:20:41 +010014ifeq ($(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)
22AFLAGS_system_certificates.o := -I$(srctree)
23
24quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
Masahiro Yamada172caf12018-12-31 17:24:08 +090025 cmd_extract_certs = scripts/extract-cert $(2) $@
David Howellscfc411e2015-08-14 15:20:41 +010026
27targets += x509_certificate_list
28$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
29 $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
Jarkko Sakkinen5ccbdbf92017-07-13 13:16:49 +010030endif # CONFIG_SYSTEM_TRUSTED_KEYRING
David Howellscfc411e2015-08-14 15:20:41 +010031
32clean-files := x509_certificate_list .x509.list
33
34ifeq ($(CONFIG_MODULE_SIG),y)
35###############################################################################
36#
37# If module signing is requested, say by allyesconfig, but a key has not been
38# supplied, then one will need to be generated to make sure the build does not
39# fail and that the kernel may be used afterwards.
40#
41###############################################################################
42ifndef CONFIG_MODULE_SIG_HASH
43$(error Could not determine digest type to use from kernel config)
44endif
45
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010046redirect_openssl = 2>&1
47quiet_redirect_openssl = 2>&1
48silent_redirect_openssl = 2>/dev/null
49
David Howellscfc411e2015-08-14 15:20:41 +010050# We do it this way rather than having a boolean option for enabling an
51# external private key, because 'make randconfig' might enable such a
52# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
53ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
54$(obj)/signing_key.pem: $(obj)/x509.genkey
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010055 @$(kecho) "###"
56 @$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
57 @$(kecho) "###"
58 @$(kecho) "### If this takes a long time, you might wish to run rngd in the"
59 @$(kecho) "### background to keep the supply of entropy topped up. It"
60 @$(kecho) "### needs to be run as root, and uses a hardware random"
61 @$(kecho) "### number generator if one is available."
62 @$(kecho) "###"
63 $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
David Howellscfc411e2015-08-14 15:20:41 +010064 -batch -x509 -config $(obj)/x509.genkey \
65 -outform PEM -out $(obj)/signing_key.pem \
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010066 -keyout $(obj)/signing_key.pem \
67 $($(quiet)redirect_openssl)
68 @$(kecho) "###"
69 @$(kecho) "### Key pair generated."
70 @$(kecho) "###"
David Howellscfc411e2015-08-14 15:20:41 +010071
72$(obj)/x509.genkey:
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010073 @$(kecho) Generating X.509 key generation config
David Howellscfc411e2015-08-14 15:20:41 +010074 @echo >$@ "[ req ]"
75 @echo >>$@ "default_bits = 4096"
76 @echo >>$@ "distinguished_name = req_distinguished_name"
77 @echo >>$@ "prompt = no"
78 @echo >>$@ "string_mask = utf8only"
79 @echo >>$@ "x509_extensions = myexts"
80 @echo >>$@
81 @echo >>$@ "[ req_distinguished_name ]"
82 @echo >>$@ "#O = Unspecified company"
83 @echo >>$@ "CN = Build time autogenerated kernel key"
84 @echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
85 @echo >>$@
86 @echo >>$@ "[ myexts ]"
87 @echo >>$@ "basicConstraints=critical,CA:FALSE"
88 @echo >>$@ "keyUsage=digitalSignature"
89 @echo >>$@ "subjectKeyIdentifier=hash"
90 @echo >>$@ "authorityKeyIdentifier=keyid"
Jarkko Sakkinen5ccbdbf92017-07-13 13:16:49 +010091endif # CONFIG_MODULE_SIG_KEY
David Howellscfc411e2015-08-14 15:20:41 +010092
93$(eval $(call config_filename,MODULE_SIG_KEY))
94
95# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
96ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
97X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
98endif
99
100# GCC PR#66871 again.
101$(obj)/system_certificates.o: $(obj)/signing_key.x509
102
David Woodhouse62172c82015-08-14 15:33:56 +0100103targets += signing_key.x509
104$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
105 $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
Jarkko Sakkinen5ccbdbf92017-07-13 13:16:49 +0100106endif # CONFIG_MODULE_SIG