1 # SPDX-License-Identifier: GPL-2.0
3 # Makefile for the linux kernel signature checking certificates.
6 obj-
$(CONFIG_SYSTEM_TRUSTED_KEYRING
) += system_keyring.o system_certificates.o common.o
7 obj-
$(CONFIG_SYSTEM_BLACKLIST_KEYRING
) += blacklist.o common.o
8 obj-
$(CONFIG_SYSTEM_REVOCATION_LIST
) += revocation_certificates.o
9 ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST
),"")
10 obj-
$(CONFIG_SYSTEM_BLACKLIST_KEYRING
) += blacklist_hashes.o
12 obj-
$(CONFIG_SYSTEM_BLACKLIST_KEYRING
) += blacklist_nohashes.o
15 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING
),y
)
17 $(eval
$(call config_filename
,SYSTEM_TRUSTED_KEYS
))
19 # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
20 $(obj
)/system_certificates.o
: $(obj
)/x509_certificate_list
22 # Cope with signing_key.x509 existing in $(srctree) not $(objtree)
23 AFLAGS_system_certificates.o
:= -I
$(srctree
)
25 quiet_cmd_extract_certs
= EXTRACT_CERTS
$(patsubst "%",%,$(2))
26 cmd_extract_certs
= scripts
/extract-cert
$(2) $@
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
))
31 endif # CONFIG_SYSTEM_TRUSTED_KEYRING
33 clean-files
:= x509_certificate_list .x509.list x509_revocation_list
35 ifeq ($(CONFIG_MODULE_SIG
),y
)
36 ###############################################################################
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.
42 ###############################################################################
43 ifndef CONFIG_MODULE_SIG_HASH
44 $(error Could not determine digest type to use from kernel config
)
47 redirect_openssl
= 2>&1
48 quiet_redirect_openssl
= 2>&1
49 silent_redirect_openssl
= 2>/dev
/null
51 # We do it this way rather than having a boolean option for enabling an
52 # external private key, because 'make randconfig' might enable such a
53 # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
54 ifeq ($(CONFIG_MODULE_SIG_KEY
),"certs/signing_key.pem")
55 $(obj
)/signing_key.pem
: $(obj
)/x509.genkey
57 @
$(kecho
) "### Now generating an X.509 key pair to be used for signing modules."
59 @
$(kecho
) "### If this takes a long time, you might wish to run rngd in the"
60 @
$(kecho
) "### background to keep the supply of entropy topped up. It"
61 @
$(kecho
) "### needs to be run as root, and uses a hardware random"
62 @
$(kecho
) "### number generator if one is available."
64 $(Q
)openssl req
-new
-nodes
-utf8
-$(CONFIG_MODULE_SIG_HASH
) -days
36500 \
65 -batch
-x509
-config
$(obj
)/x509.genkey \
66 -outform PEM
-out
$(obj
)/signing_key.pem \
67 -keyout
$(obj
)/signing_key.pem \
68 $($(quiet
)redirect_openssl
)
70 @
$(kecho
) "### Key pair generated."
74 @
$(kecho
) Generating X
.509 key generation config
76 @echo
>>$@
"default_bits = 4096"
77 @echo
>>$@
"distinguished_name = req_distinguished_name"
78 @echo
>>$@
"prompt = no"
79 @echo
>>$@
"string_mask = utf8only"
80 @echo
>>$@
"x509_extensions = myexts"
82 @echo
>>$@
"[ req_distinguished_name ]"
83 @echo
>>$@
"#O = Unspecified company"
84 @echo
>>$@
"CN = Build time autogenerated kernel key"
85 @echo
>>$@
"#emailAddress = unspecified.user@unspecified.company"
87 @echo
>>$@
"[ myexts ]"
88 @echo
>>$@
"basicConstraints=critical,CA:FALSE"
89 @echo
>>$@
"keyUsage=digitalSignature"
90 @echo
>>$@
"subjectKeyIdentifier=hash"
91 @echo
>>$@
"authorityKeyIdentifier=keyid"
92 endif # CONFIG_MODULE_SIG_KEY
94 $(eval
$(call config_filename
,MODULE_SIG_KEY
))
96 # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
97 ifeq ($(patsubst pkcs11
:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME
))),$(firstword $(MODULE_SIG_KEY_FILENAME
)))
98 X509_DEP
:= $(MODULE_SIG_KEY_SRCPREFIX
)$(MODULE_SIG_KEY_FILENAME
)
101 # GCC PR#66871 again.
102 $(obj
)/system_certificates.o
: $(obj
)/signing_key.x509
104 targets
+= signing_key.x509
105 $(obj
)/signing_key.x509
: scripts
/extract-cert
$(X509_DEP
) FORCE
106 $(call if_changed
,extract_certs
,$(MODULE_SIG_KEY_SRCPREFIX
)$(CONFIG_MODULE_SIG_KEY
))
107 endif # CONFIG_MODULE_SIG
109 ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST
),y
)
111 $(eval
$(call config_filename
,SYSTEM_REVOCATION_KEYS
))
113 $(obj
)/revocation_certificates.o
: $(obj
)/x509_revocation_list
115 quiet_cmd_extract_certs
= EXTRACT_CERTS
$(patsubst "%",%,$(2))
116 cmd_extract_certs
= scripts
/extract-cert
$(2) $@
118 targets
+= x509_revocation_list
119 $(obj
)/x509_revocation_list
: scripts
/extract-cert
$(SYSTEM_REVOCATION_KEYS_SRCPREFIX
)$(SYSTEM_REVOCATION_KEYS_FILENAME
) FORCE
120 $(call if_changed
,extract_certs
,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX
)$(CONFIG_SYSTEM_REVOCATION_KEYS
))