blob: 359239a0ee9e32b7bd11cfa08a9f1224f2a3156b [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
Eric Snowberg2565ca72021-01-22 13:10:52 -05006obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
Eric Snowbergd1f04412021-01-22 13:10:53 -05007obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o
8obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
David Howells734114f2017-04-03 16:07:24 +01009ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
10obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
11else
12obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
13endif
David Howellscfc411e2015-08-14 15:20:41 +010014
David Howellscfc411e2015-08-14 15:20:41 +010015ifeq ($(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)
23AFLAGS_system_certificates.o := -I$(srctree)
24
25quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
Masahiro Yamada172caf12018-12-31 17:24:08 +090026 cmd_extract_certs = scripts/extract-cert $(2) $@
David Howellscfc411e2015-08-14 15:20:41 +010027
28targets += 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))
Jarkko Sakkinen5ccbdbf92017-07-13 13:16:49 +010031endif # CONFIG_SYSTEM_TRUSTED_KEYRING
David Howellscfc411e2015-08-14 15:20:41 +010032
Eric Snowbergd1f04412021-01-22 13:10:53 -050033clean-files := x509_certificate_list .x509.list x509_revocation_list
David Howellscfc411e2015-08-14 15:20:41 +010034
35ifeq ($(CONFIG_MODULE_SIG),y)
Nayna Jain0165f4c2021-04-09 10:35:06 -040036 SIGN_KEY = y
37endif
38
39ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y)
Nayna Jain781a5732021-04-22 21:16:02 -040040ifeq ($(CONFIG_MODULES),y)
Nayna Jain0165f4c2021-04-09 10:35:06 -040041 SIGN_KEY = y
42endif
Nayna Jain781a5732021-04-22 21:16:02 -040043endif
Nayna Jain0165f4c2021-04-09 10:35:06 -040044
45ifdef SIGN_KEY
David Howellscfc411e2015-08-14 15:20:41 +010046###############################################################################
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###############################################################################
53ifndef CONFIG_MODULE_SIG_HASH
54$(error Could not determine digest type to use from kernel config)
55endif
56
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010057redirect_openssl = 2>&1
58quiet_redirect_openssl = 2>&1
59silent_redirect_openssl = 2>/dev/null
60
David Howellscfc411e2015-08-14 15:20:41 +010061# We do it this way rather than having a boolean option for enabling an
62# external private key, because 'make randconfig' might enable such a
63# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
64ifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
65$(obj)/signing_key.pem: $(obj)/x509.genkey
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010066 @$(kecho) "###"
67 @$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
68 @$(kecho) "###"
69 @$(kecho) "### If this takes a long time, you might wish to run rngd in the"
70 @$(kecho) "### background to keep the supply of entropy topped up. It"
71 @$(kecho) "### needs to be run as root, and uses a hardware random"
72 @$(kecho) "### number generator if one is available."
73 @$(kecho) "###"
74 $(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
David Howellscfc411e2015-08-14 15:20:41 +010075 -batch -x509 -config $(obj)/x509.genkey \
76 -outform PEM -out $(obj)/signing_key.pem \
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010077 -keyout $(obj)/signing_key.pem \
78 $($(quiet)redirect_openssl)
79 @$(kecho) "###"
80 @$(kecho) "### Key pair generated."
81 @$(kecho) "###"
David Howellscfc411e2015-08-14 15:20:41 +010082
83$(obj)/x509.genkey:
Arnd Bergmann5d06ee22016-02-25 17:31:32 +010084 @$(kecho) Generating X.509 key generation config
David Howellscfc411e2015-08-14 15:20:41 +010085 @echo >$@ "[ req ]"
86 @echo >>$@ "default_bits = 4096"
87 @echo >>$@ "distinguished_name = req_distinguished_name"
88 @echo >>$@ "prompt = no"
89 @echo >>$@ "string_mask = utf8only"
90 @echo >>$@ "x509_extensions = myexts"
91 @echo >>$@
92 @echo >>$@ "[ req_distinguished_name ]"
93 @echo >>$@ "#O = Unspecified company"
94 @echo >>$@ "CN = Build time autogenerated kernel key"
95 @echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
96 @echo >>$@
97 @echo >>$@ "[ myexts ]"
98 @echo >>$@ "basicConstraints=critical,CA:FALSE"
99 @echo >>$@ "keyUsage=digitalSignature"
100 @echo >>$@ "subjectKeyIdentifier=hash"
101 @echo >>$@ "authorityKeyIdentifier=keyid"
Jarkko Sakkinen5ccbdbf92017-07-13 13:16:49 +0100102endif # CONFIG_MODULE_SIG_KEY
David Howellscfc411e2015-08-14 15:20:41 +0100103
104$(eval $(call config_filename,MODULE_SIG_KEY))
105
106# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
107ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
108X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
109endif
110
111# GCC PR#66871 again.
112$(obj)/system_certificates.o: $(obj)/signing_key.x509
113
David Woodhouse62172c82015-08-14 15:33:56 +0100114targets += signing_key.x509
115$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
116 $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
Jarkko Sakkinen5ccbdbf92017-07-13 13:16:49 +0100117endif # CONFIG_MODULE_SIG
Eric Snowbergd1f04412021-01-22 13:10:53 -0500118
119ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y)
120
121$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS))
122
123$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
124
125quiet_cmd_extract_certs = EXTRACT_CERTS $(patsubst "%",%,$(2))
126 cmd_extract_certs = scripts/extract-cert $(2) $@
127
128targets += x509_revocation_list
129$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE
130 $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS))
131endif