xref: /openbmc/linux/certs/Makefile (revision 5d06ee20)
1cfc411e7SDavid Howells#
2cfc411e7SDavid Howells# Makefile for the linux kernel signature checking certificates.
3cfc411e7SDavid Howells#
4cfc411e7SDavid Howells
5cfc411e7SDavid Howellsobj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o
6cfc411e7SDavid Howells
7cfc411e7SDavid Howellsifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
8cfc411e7SDavid Howells
9cfc411e7SDavid Howells$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
10cfc411e7SDavid Howells
11cfc411e7SDavid Howells# GCC doesn't include .incbin files in -MD generated dependencies (PR#66871)
12cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/x509_certificate_list
13cfc411e7SDavid Howells
14cfc411e7SDavid Howells# Cope with signing_key.x509 existing in $(srctree) not $(objtree)
15cfc411e7SDavid HowellsAFLAGS_system_certificates.o := -I$(srctree)
16cfc411e7SDavid Howells
17cfc411e7SDavid Howellsquiet_cmd_extract_certs  = EXTRACT_CERTS   $(patsubst "%",%,$(2))
18cfc411e7SDavid Howells      cmd_extract_certs  = scripts/extract-cert $(2) $@ || ( rm $@; exit 1)
19cfc411e7SDavid Howells
20cfc411e7SDavid Howellstargets += x509_certificate_list
21cfc411e7SDavid Howells$(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE
22cfc411e7SDavid Howells	$(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS))
23cfc411e7SDavid Howellsendif
24cfc411e7SDavid Howells
25cfc411e7SDavid Howellsclean-files := x509_certificate_list .x509.list
26cfc411e7SDavid Howells
27cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG),y)
28cfc411e7SDavid Howells###############################################################################
29cfc411e7SDavid Howells#
30cfc411e7SDavid Howells# If module signing is requested, say by allyesconfig, but a key has not been
31cfc411e7SDavid Howells# supplied, then one will need to be generated to make sure the build does not
32cfc411e7SDavid Howells# fail and that the kernel may be used afterwards.
33cfc411e7SDavid Howells#
34cfc411e7SDavid Howells###############################################################################
35cfc411e7SDavid Howellsifndef CONFIG_MODULE_SIG_HASH
36cfc411e7SDavid Howells$(error Could not determine digest type to use from kernel config)
37cfc411e7SDavid Howellsendif
38cfc411e7SDavid Howells
395d06ee20SArnd Bergmannredirect_openssl	= 2>&1
405d06ee20SArnd Bergmannquiet_redirect_openssl	= 2>&1
415d06ee20SArnd Bergmannsilent_redirect_openssl = 2>/dev/null
425d06ee20SArnd Bergmann
43cfc411e7SDavid Howells# We do it this way rather than having a boolean option for enabling an
44cfc411e7SDavid Howells# external private key, because 'make randconfig' might enable such a
45cfc411e7SDavid Howells# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
46cfc411e7SDavid Howellsifeq ($(CONFIG_MODULE_SIG_KEY),"certs/signing_key.pem")
47cfc411e7SDavid Howells$(obj)/signing_key.pem: $(obj)/x509.genkey
485d06ee20SArnd Bergmann	@$(kecho) "###"
495d06ee20SArnd Bergmann	@$(kecho) "### Now generating an X.509 key pair to be used for signing modules."
505d06ee20SArnd Bergmann	@$(kecho) "###"
515d06ee20SArnd Bergmann	@$(kecho) "### If this takes a long time, you might wish to run rngd in the"
525d06ee20SArnd Bergmann	@$(kecho) "### background to keep the supply of entropy topped up.  It"
535d06ee20SArnd Bergmann	@$(kecho) "### needs to be run as root, and uses a hardware random"
545d06ee20SArnd Bergmann	@$(kecho) "### number generator if one is available."
555d06ee20SArnd Bergmann	@$(kecho) "###"
565d06ee20SArnd Bergmann	$(Q)openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
57cfc411e7SDavid Howells		-batch -x509 -config $(obj)/x509.genkey \
58cfc411e7SDavid Howells		-outform PEM -out $(obj)/signing_key.pem \
595d06ee20SArnd Bergmann		-keyout $(obj)/signing_key.pem \
605d06ee20SArnd Bergmann		$($(quiet)redirect_openssl)
615d06ee20SArnd Bergmann	@$(kecho) "###"
625d06ee20SArnd Bergmann	@$(kecho) "### Key pair generated."
635d06ee20SArnd Bergmann	@$(kecho) "###"
64cfc411e7SDavid Howells
65cfc411e7SDavid Howells$(obj)/x509.genkey:
665d06ee20SArnd Bergmann	@$(kecho) Generating X.509 key generation config
67cfc411e7SDavid Howells	@echo  >$@ "[ req ]"
68cfc411e7SDavid Howells	@echo >>$@ "default_bits = 4096"
69cfc411e7SDavid Howells	@echo >>$@ "distinguished_name = req_distinguished_name"
70cfc411e7SDavid Howells	@echo >>$@ "prompt = no"
71cfc411e7SDavid Howells	@echo >>$@ "string_mask = utf8only"
72cfc411e7SDavid Howells	@echo >>$@ "x509_extensions = myexts"
73cfc411e7SDavid Howells	@echo >>$@
74cfc411e7SDavid Howells	@echo >>$@ "[ req_distinguished_name ]"
75cfc411e7SDavid Howells	@echo >>$@ "#O = Unspecified company"
76cfc411e7SDavid Howells	@echo >>$@ "CN = Build time autogenerated kernel key"
77cfc411e7SDavid Howells	@echo >>$@ "#emailAddress = unspecified.user@unspecified.company"
78cfc411e7SDavid Howells	@echo >>$@
79cfc411e7SDavid Howells	@echo >>$@ "[ myexts ]"
80cfc411e7SDavid Howells	@echo >>$@ "basicConstraints=critical,CA:FALSE"
81cfc411e7SDavid Howells	@echo >>$@ "keyUsage=digitalSignature"
82cfc411e7SDavid Howells	@echo >>$@ "subjectKeyIdentifier=hash"
83cfc411e7SDavid Howells	@echo >>$@ "authorityKeyIdentifier=keyid"
84cfc411e7SDavid Howellsendif
85cfc411e7SDavid Howells
86cfc411e7SDavid Howells$(eval $(call config_filename,MODULE_SIG_KEY))
87cfc411e7SDavid Howells
88cfc411e7SDavid Howells# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
89cfc411e7SDavid Howellsifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
90cfc411e7SDavid HowellsX509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
91cfc411e7SDavid Howellsendif
92cfc411e7SDavid Howells
93cfc411e7SDavid Howells# GCC PR#66871 again.
94cfc411e7SDavid Howells$(obj)/system_certificates.o: $(obj)/signing_key.x509
95cfc411e7SDavid Howells
9662172c81SDavid Woodhousetargets += signing_key.x509
9762172c81SDavid Woodhouse$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
9862172c81SDavid Woodhouse	$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
99cfc411e7SDavid Howellsendif
100