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
7 obj-
$(CONFIG_SYSTEM_BLACKLIST_KEYRING
) += blacklist.o
8 ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST
),"")
9 obj-
$(CONFIG_SYSTEM_BLACKLIST_KEYRING
) += blacklist_hashes.o
11 obj-
$(CONFIG_SYSTEM_BLACKLIST_KEYRING
) += blacklist_nohashes.o
13 obj-
$(CONFIG_EFI_SIGNATURE_LIST_PARSER
) += efi_parser.o
15 obj-
$(CONFIG_LOAD_UEFI_KEYS
) += load_uefi.o
16 $(obj
)/load_uefi.o
: KBUILD_CFLAGS
+= -fshort-wchar
19 ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING
),y
)
21 $(eval
$(call config_filename
,SYSTEM_TRUSTED_KEYS
))
23 # GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
24 $(obj
)/system_certificates.o
: $(obj
)/x509_certificate_list
26 # Cope with signing_key.x509 existing in $(srctree) not $(objtree)
27 AFLAGS_system_certificates.o
:= -I
$(srctree
)
29 quiet_cmd_extract_certs
= EXTRACT_CERTS
$(patsubst "%",%,$(2))
30 cmd_extract_certs
= scripts
/extract-cert
$(2) $@ ||
( rm $@
; exit
1)
32 targets
+= x509_certificate_list
33 $(obj
)/x509_certificate_list
: scripts
/extract-cert
$(SYSTEM_TRUSTED_KEYS_SRCPREFIX
)$(SYSTEM_TRUSTED_KEYS_FILENAME
) FORCE
34 $(call if_changed
,extract_certs
,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX
)$(CONFIG_SYSTEM_TRUSTED_KEYS
))
35 endif # CONFIG_SYSTEM_TRUSTED_KEYRING
37 clean-files
:= x509_certificate_list .x509.list
39 ifeq ($(CONFIG_MODULE_SIG
),y
)
40 ###############################################################################
42 # If module signing is requested, say by allyesconfig, but a key has not been
43 # supplied, then one will need to be generated to make sure the build does not
44 # fail and that the kernel may be used afterwards.
46 ###############################################################################
47 ifndef CONFIG_MODULE_SIG_HASH
48 $(error Could not determine digest type to use from kernel config
)
51 redirect_openssl
= 2>&1
52 quiet_redirect_openssl
= 2>&1
53 silent_redirect_openssl
= 2>/dev
/null
55 # We do it this way rather than having a boolean option for enabling an
56 # external private key, because 'make randconfig' might enable such a
57 # boolean option and we unfortunately can't make it depend on !RANDCONFIG.
58 ifeq ($(CONFIG_MODULE_SIG_KEY
),"certs/signing_key.pem")
59 $(obj
)/signing_key.pem
: $(obj
)/x509.genkey
61 @
$(kecho
) "### Now generating an X.509 key pair to be used for signing modules."
63 @
$(kecho
) "### If this takes a long time, you might wish to run rngd in the"
64 @
$(kecho
) "### background to keep the supply of entropy topped up. It"
65 @
$(kecho
) "### needs to be run as root, and uses a hardware random"
66 @
$(kecho
) "### number generator if one is available."
68 $(Q
)openssl req
-new
-nodes
-utf8
-$(CONFIG_MODULE_SIG_HASH
) -days
36500 \
69 -batch
-x509
-config
$(obj
)/x509.genkey \
70 -outform PEM
-out
$(obj
)/signing_key.pem \
71 -keyout
$(obj
)/signing_key.pem \
72 $($(quiet
)redirect_openssl
)
74 @
$(kecho
) "### Key pair generated."
78 @
$(kecho
) Generating X
.509 key generation config
80 @echo
>>$@
"default_bits = 4096"
81 @echo
>>$@
"distinguished_name = req_distinguished_name"
82 @echo
>>$@
"prompt = no"
83 @echo
>>$@
"string_mask = utf8only"
84 @echo
>>$@
"x509_extensions = myexts"
86 @echo
>>$@
"[ req_distinguished_name ]"
87 @echo
>>$@
"#O = Unspecified company"
88 @echo
>>$@
"CN = Build time autogenerated kernel key"
89 @echo
>>$@
"#emailAddress = unspecified.user@unspecified.company"
91 @echo
>>$@
"[ myexts ]"
92 @echo
>>$@
"basicConstraints=critical,CA:FALSE"
93 @echo
>>$@
"keyUsage=digitalSignature"
94 @echo
>>$@
"subjectKeyIdentifier=hash"
95 @echo
>>$@
"authorityKeyIdentifier=keyid"
96 endif # CONFIG_MODULE_SIG_KEY
98 $(eval
$(call config_filename
,MODULE_SIG_KEY
))
100 # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
101 ifeq ($(patsubst pkcs11
:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME
))),$(firstword $(MODULE_SIG_KEY_FILENAME
)))
102 X509_DEP
:= $(MODULE_SIG_KEY_SRCPREFIX
)$(MODULE_SIG_KEY_FILENAME
)
105 # GCC PR#66871 again.
106 $(obj
)/system_certificates.o
: $(obj
)/signing_key.x509
108 targets
+= signing_key.x509
109 $(obj
)/signing_key.x509
: scripts
/extract-cert
$(X509_DEP
) FORCE
110 $(call if_changed
,extract_certs
,$(MODULE_SIG_KEY_SRCPREFIX
)$(CONFIG_MODULE_SIG_KEY
))
111 endif # CONFIG_MODULE_SIG