certs: move scripts/extract-cert to certs/
[linux-2.6-block.git] / certs / Makefile
CommitLineData
b2441318 1# SPDX-License-Identifier: GPL-2.0
cfc411e7
DH
2#
3# Makefile for the linux kernel signature checking certificates.
4#
5
2565ca7f 6obj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o common.o
d1f04410
ES
7obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o common.o
8obj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o
129ab0d2 9ifneq ($(CONFIG_SYSTEM_BLACKLIST_HASH_LIST),)
734114f8
DH
10obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_hashes.o
11else
12obj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist_nohashes.o
13endif
cfc411e7 14
1c4bd9f7 15quiet_cmd_extract_certs = CERT $@
340a0253 16 cmd_extract_certs = $(obj)/extract-cert $(2) $@
1c4bd9f7 17
cfc411e7
DH
18$(obj)/system_certificates.o: $(obj)/x509_certificate_list
19
340a0253 20$(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE
b8c96a6b 21 $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_TRUSTED_KEYS),$<,""))
cfc411e7 22
5cca3606 23targets += x509_certificate_list
cfc411e7
DH
24
25ifeq ($(CONFIG_MODULE_SIG),y)
0165f4ca
NJ
26 SIGN_KEY = y
27endif
28
29ifeq ($(CONFIG_IMA_APPRAISE_MODSIG),y)
781a5739 30ifeq ($(CONFIG_MODULES),y)
0165f4ca
NJ
31 SIGN_KEY = y
32endif
781a5739 33endif
0165f4ca
NJ
34
35ifdef SIGN_KEY
cfc411e7
DH
36###############################################################################
37#
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.
41#
42###############################################################################
cfc411e7
DH
43
44# We do it this way rather than having a boolean option for enabling an
45# external private key, because 'make randconfig' might enable such a
46# boolean option and we unfortunately can't make it depend on !RANDCONFIG.
129ab0d2 47ifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem)
ea35e0d5 48
e06a61a8 49keytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1
ea35e0d5 50
54c8b517
MY
51quiet_cmd_gen_key = GENKEY $@
52 cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \
c537e4d0
MY
53 -batch -x509 -config $< \
54 -outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1
e06a61a8
MY
55
56$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE
57 $(call if_changed,gen_key)
54c8b517 58
e06a61a8 59targets += signing_key.pem
cfc411e7 60
f3a2ba44
MY
61quiet_cmd_copy_x509_config = COPY $@
62 cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@
63
64# You can provide your own config file. If not present, copy the default one.
cfc411e7 65$(obj)/x509.genkey:
f3a2ba44
MY
66 $(call cmd,copy_x509_config)
67
5ccbdbf9 68endif # CONFIG_MODULE_SIG_KEY
cfc411e7 69
cfc411e7 70# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
b8c96a6b
MY
71ifneq ($(filter-out pkcs11:%, %(CONFIG_MODULE_SIG_KEY)),)
72X509_DEP := $(CONFIG_MODULE_SIG_KEY)
cfc411e7
DH
73endif
74
cfc411e7
DH
75$(obj)/system_certificates.o: $(obj)/signing_key.x509
76
340a0253 77$(obj)/signing_key.x509: $(X509_DEP) $(obj)/extract-cert FORCE
b8c96a6b 78 $(call if_changed,extract_certs,$(if $(X509_DEP),$<,$(CONFIG_MODULE_SIG_KEY)))
5ccbdbf9 79endif # CONFIG_MODULE_SIG
d1f04410 80
5cca3606
MY
81targets += signing_key.x509
82
d1f04410
ES
83$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
84
340a0253 85$(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE
b8c96a6b 86 $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_REVOCATION_KEYS),$<,""))
5cca3606
MY
87
88targets += x509_revocation_list
340a0253
MY
89
90hostprogs := extract-cert
91
92HOSTCFLAGS_extract-cert.o = $(shell pkg-config --cflags libcrypto 2> /dev/null)
93HOSTLDLIBS_extract-cert = $(shell pkg-config --libs libcrypto 2> /dev/null || echo -lcrypto)