xref: /openbmc/linux/certs/Makefile (revision 2565ca7f)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2cfc411e7SDavid Howells#
3cfc411e7SDavid Howells# Makefile for the linux kernel signature checking certificates.
4cfc411e7SDavid Howells#
5cfc411e7SDavid Howells
6*2565ca7fSEric Snowbergobj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
7734114f8SDavid Howellsobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o
8734114f8SDavid Howellsifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),"")
9734114f8SDavid Howellsobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
10734114f8SDavid Howellselse
11734114f8SDavid Howellsobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
12734114f8SDavid Howellsendif
13cfc411e7SDavid Howells
14cfc411e7SDavid Howellsifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
15cfc411e7SDavid Howells
16cfc411e7SDavid Howells$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
17cfc411e7SDavid Howells
18cfc411e7SDavid Howells# GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
19cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/x509_certificate_list
20cfc411e7SDavid Howells
21cfc411e7SDavid Howells# Cope with signing_key.x509 existing in $(srctree) not $(objtree)
22cfc411e7SDavid HowellsAFLAGS_system_certificates.o := -I$(srctree)
23cfc411e7SDavid Howells
24cfc411e7SDavid Howellsquiet_cmd_extract_certs  = EXTRACT_CERTS   $(patsubst "%",%,$(2))
25172caf19SMasahiro Yamada      cmd_extract_certs  = scripts/extract-cert $(2) $@
26cfc411e7SDavid Howells
27cfc411e7SDavid Howellstargets += x509_certificate_list
28cfc411e7SDavid Howells$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
29cfc411e7SDavid Howells	$(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
305ccbdbf9SJarkko Sakkinenendif # CONFIG_SYSTEM_TRUSTED_KEYRING
31cfc411e7SDavid Howells
32cfc411e7SDavid Howellsclean-files := x509_certificate_list .x509.list
33cfc411e7SDavid Howells
34cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG),y)
35cfc411e7SDavid Howells###############################################################################
36cfc411e7SDavid Howells#
37cfc411e7SDavid Howells# If module signing is requested, say by allyesconfig, but a key has not been
38cfc411e7SDavid Howells# supplied, then one will need to be generated to make sure the build does not
39cfc411e7SDavid Howells# fail and that the kernel may be used afterwards.
40cfc411e7SDavid Howells#
41cfc411e7SDavid Howells###############################################################################
42cfc411e7SDavid Howellsifndef CONFIG_MODULE_SIG_HASH
43cfc411e7SDavid Howells$(error Could not determine digest type to use from kernel config)
44cfc411e7SDavid Howellsendif
45cfc411e7SDavid Howells
465d06ee20SArnd Bergmannredirect_openssl	= 2>&1
475d06ee20SArnd Bergmannquiet_redirect_openssl	= 2>&1
485d06ee20SArnd Bergmannsilent_redirect_openssl = 2>/dev/null
495d06ee20SArnd Bergmann
50cfc411e7SDavid Howells# We do it this way rather than having a boolean option for enabling an
51cfc411e7SDavid Howells# external private key, because 'make randconfig' might enable such a
52cfc411e7SDavid Howells# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
53cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
54cfc411e7SDavid Howells$(obj)/signing_key.pem: $(obj)/x509.genkey
555d06ee20SArnd Bergmann	@$(kecho) "###"
565d06ee20SArnd Bergmann	@$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
575d06ee20SArnd Bergmann	@$(kecho) "###"
585d06ee20SArnd Bergmann	@$(kecho) "### If this takes a long time, you might wish to run rngd in the"
595d06ee20SArnd Bergmann	@$(kecho) "### background to keep the supply of entropy topped up.  It"
605d06ee20SArnd Bergmann	@$(kecho) "### needs to be run as root, and uses a hardware random"
615d06ee20SArnd Bergmann	@$(kecho) "### number generator if one is available."
625d06ee20SArnd Bergmann	@$(kecho) "###"
635d06ee20SArnd Bergmann	$(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
64cfc411e7SDavid Howells		-batch -x509 -config $(obj)/x509.genkey \
65cfc411e7SDavid Howells		-outform PEM -out $(obj)/signing_key.pem \
665d06ee20SArnd Bergmann		-keyout $(obj)/signing_key.pem \
675d06ee20SArnd Bergmann		$($(quiet)redirect_openssl)
685d06ee20SArnd Bergmann	@$(kecho) "###"
695d06ee20SArnd Bergmann	@$(kecho) "### Key pair generated."
705d06ee20SArnd Bergmann	@$(kecho) "###"
71cfc411e7SDavid Howells
72cfc411e7SDavid Howells$(obj)/x509.genkey:
735d06ee20SArnd Bergmann	@$(kecho) Generating X.509 key generation config
74cfc411e7SDavid Howells	@echo  >$@ "[ req ]"
75cfc411e7SDavid Howells	@echo >>$@ "default_bits = 4096"
76cfc411e7SDavid Howells	@echo >>$@ "distinguished_name = req_distinguished_name"
77cfc411e7SDavid Howells	@echo >>$@ "prompt = no"
78cfc411e7SDavid Howells	@echo >>$@ "string_mask = utf8only"
79cfc411e7SDavid Howells	@echo >>$@ "x509_extensions = myexts"
80cfc411e7SDavid Howells	@echo >>$@
81cfc411e7SDavid Howells	@echo >>$@ "[ req_distinguished_name ]"
82cfc411e7SDavid Howells	@echo >>$@ "#O = Unspecified company"
83cfc411e7SDavid Howells	@echo >>$@ "CN = Build time autogenerated kernel key"
84cfc411e7SDavid Howells	@echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
85cfc411e7SDavid Howells	@echo >>$@
86cfc411e7SDavid Howells	@echo >>$@ "[ myexts ]"
87cfc411e7SDavid Howells	@echo >>$@ "basicConstraints=critical,CA:FALSE"
88cfc411e7SDavid Howells	@echo >>$@ "keyUsage=digitalSignature"
89cfc411e7SDavid Howells	@echo >>$@ "subjectKeyIdentifier=hash"
90cfc411e7SDavid Howells	@echo >>$@ "authorityKeyIdentifier=keyid"
915ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG_KEY
92cfc411e7SDavid Howells
93cfc411e7SDavid Howells$(eval $(call config_filename,MODULE_SIG_KEY))
94cfc411e7SDavid Howells
95cfc411e7SDavid Howells# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
96cfc411e7SDavid Howellsifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
97cfc411e7SDavid HowellsX509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
98cfc411e7SDavid Howellsendif
99cfc411e7SDavid Howells
100cfc411e7SDavid Howells# GCC PR#66871 again.
101cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/signing_key.x509
102cfc411e7SDavid Howells
10362172c81SDavid Woodhousetargets += signing_key.x509
10462172c81SDavid Woodhouse$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
10562172c81SDavid Woodhouse	$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
1065ccbdbf9SJarkko Sakkinenendif # CONFIG_MODULE_SIG
107