162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci# 362306a36Sopenharmony_ci# Makefile for the linux kernel signature checking certificates. 462306a36Sopenharmony_ci# 562306a36Sopenharmony_ci 662306a36Sopenharmony_ciobj-$(CONFIG_SYSTEM_TRUSTED_KEYRING) += system_keyring.o system_certificates.o 762306a36Sopenharmony_ciobj-$(CONFIG_SYSTEM_BLACKLIST_KEYRING) += blacklist.o blacklist_hashes.o 862306a36Sopenharmony_ciobj-$(CONFIG_SYSTEM_REVOCATION_LIST) += revocation_certificates.o 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci$(obj)/blacklist_hashes.o: $(obj)/blacklist_hash_list 1162306a36Sopenharmony_ciCFLAGS_blacklist_hashes.o := -I $(obj) 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciquiet_cmd_check_and_copy_blacklist_hash_list = GEN $@ 1462306a36Sopenharmony_ci cmd_check_and_copy_blacklist_hash_list = \ 1562306a36Sopenharmony_ci $(if $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST), \ 1662306a36Sopenharmony_ci $(AWK) -f $(srctree)/$(src)/check-blacklist-hashes.awk $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) >&2; \ 1762306a36Sopenharmony_ci { cat $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST); echo $(comma) NULL; } > $@, \ 1862306a36Sopenharmony_ci echo NULL > $@) 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci$(obj)/blacklist_hash_list: $(CONFIG_SYSTEM_BLACKLIST_HASH_LIST) FORCE 2162306a36Sopenharmony_ci $(call if_changed,check_and_copy_blacklist_hash_list) 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_citargets += blacklist_hash_list 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ciquiet_cmd_extract_certs = CERT $@ 2662306a36Sopenharmony_ci cmd_extract_certs = $(obj)/extract-cert "$(extract-cert-in)" $@ 2762306a36Sopenharmony_ciextract-cert-in = $(filter-out $(obj)/extract-cert, $(real-prereqs)) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci$(obj)/system_certificates.o: $(obj)/x509_certificate_list 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci$(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) $(obj)/extract-cert FORCE 3262306a36Sopenharmony_ci $(call if_changed,extract_certs) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_citargets += x509_certificate_list 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci# If module signing is requested, say by allyesconfig, but a key has not been 3762306a36Sopenharmony_ci# supplied, then one will need to be generated to make sure the build does not 3862306a36Sopenharmony_ci# fail and that the kernel may be used afterwards. 3962306a36Sopenharmony_ci# 4062306a36Sopenharmony_ci# We do it this way rather than having a boolean option for enabling an 4162306a36Sopenharmony_ci# external private key, because 'make randconfig' might enable such a 4262306a36Sopenharmony_ci# boolean option and we unfortunately can't make it depend on !RANDCONFIG. 4362306a36Sopenharmony_ciifeq ($(CONFIG_MODULE_SIG_KEY),certs/signing_key.pem) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cikeytype-$(CONFIG_MODULE_SIG_KEY_TYPE_ECDSA) := -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciquiet_cmd_gen_key = GENKEY $@ 4862306a36Sopenharmony_ci cmd_gen_key = openssl req -new -nodes -utf8 -$(CONFIG_MODULE_SIG_HASH) -days 36500 \ 4962306a36Sopenharmony_ci -batch -x509 -config $< \ 5062306a36Sopenharmony_ci -outform PEM -out $@ -keyout $@ $(keytype-y) 2>&1 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci$(obj)/signing_key.pem: $(obj)/x509.genkey FORCE 5362306a36Sopenharmony_ci $(call if_changed,gen_key) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_citargets += signing_key.pem 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciquiet_cmd_copy_x509_config = COPY $@ 5862306a36Sopenharmony_ci cmd_copy_x509_config = cat $(srctree)/$(src)/default_x509.genkey > $@ 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci# You can provide your own config file. If not present, copy the default one. 6162306a36Sopenharmony_ci$(obj)/x509.genkey: 6262306a36Sopenharmony_ci $(call cmd,copy_x509_config) 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciendif # CONFIG_MODULE_SIG_KEY 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci$(obj)/system_certificates.o: $(obj)/signing_key.x509 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciPKCS11_URI := $(filter pkcs11:%, $(CONFIG_MODULE_SIG_KEY)) 6962306a36Sopenharmony_ciifdef PKCS11_URI 7062306a36Sopenharmony_ci$(obj)/signing_key.x509: extract-cert-in := $(PKCS11_URI) 7162306a36Sopenharmony_ciendif 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci$(obj)/signing_key.x509: $(filter-out $(PKCS11_URI),$(CONFIG_MODULE_SIG_KEY)) $(obj)/extract-cert FORCE 7462306a36Sopenharmony_ci $(call if_changed,extract_certs) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_citargets += signing_key.x509 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci$(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) $(obj)/extract-cert FORCE 8162306a36Sopenharmony_ci $(call if_changed,extract_certs) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_citargets += x509_revocation_list 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_cihostprogs := extract-cert 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ciHOSTCFLAGS_extract-cert.o = $(shell $(HOSTPKG_CONFIG) --cflags libcrypto 2> /dev/null) 8862306a36Sopenharmony_ciHOSTLDLIBS_extract-cert = $(shell $(HOSTPKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto) 89