1.if empty(BEARSSL) 2.include "../libbearssl/Makefile.inc" 3.endif 4 5.if !target(_${__this}_) 6_${__this}_: 7 8libsecureboot_src:= ${.PARSEDIR} 9 10CFLAGS+= -I${libsecureboot_src}/h 11 12CFLAGS+= -DHAVE_BR_X509_TIME_CHECK 13 14.PATH: ${.PARSEDIR} 15 16SRCS+= \ 17 readfile.c \ 18 brf.c \ 19 vesigned.c \ 20 vets.c 21 22.if ${.CURDIR:M*libsecureboot*} != "" 23SRCS+= veta.c 24.endif 25 26CFLAGS+= ${XCFLAGS.${.TARGET:T:R}:U} 27 28# we use a couple of files from ${BEARSSL}/tools 29BRSSL_CFLAGS+= -I${BEARSSL}/tools 30BRSSL_SRCS+= \ 31 ${BEARSSL}/tools/xmem.c \ 32 ${BEARSSL}/tools/vector.c 33 34BRSSL_DEPS= \ 35 brf.c \ 36 vets.c \ 37 veta.c 38 39.if ${MK_LOADER_EFI_SECUREBOOT} != "no" 40BRSSL_DEPS+= \ 41 efi_init.c \ 42 efi_variables.c 43.endif 44 45# we do not need/want nested objdirs 46OBJS_SRCS_FILTER = T R 47 48SRCS+= ${BRSSL_SRCS} 49 50 51# extract the last cert from a chain (should be rootCA) 52_LAST_PEM_USE: .USE 53 sed "1,`grep -n .-END ${.ALLSRC:M*.pem} | tail -2 | head -1 | sed 's,:.*,,'`d" ${.ALLSRC:M*.pem} > ${.TARGET} 54 55# extract 2nd last cert from chain - we use this for self-test 56_2ndLAST_PEM_USE: .USE 57 sed -n "`grep -n .-BEGIN ${.ALLSRC:M*.pem} | tail -2 | \ 58 sed 's,:.*,,' | xargs | (read a b; echo $$a,$$(($$b - 1)))`p" ${.ALLSRC:M*.pem} > ${.TARGET} 59 60# rules to populate the [tv]*.pem files we use to generate ta.h 61# and can add/alter VE_*_LIST as desired. 62.-include "local.trust.mk" 63 64# list of hashes we support 65VE_HASH_LIST?= SHA256 66 67# list of signatures we support 68# some people don't trust ECDSA 69VE_SIGNATURE_LIST?= RSA 70 71# this list controls our search for signatures so will not be sorted 72# note: for X509 signatures we assume we can replace the trailing 73# "sig" with "certs" to find the certificate chain 74# eg. for manifest.esig we use manifest.ecerts 75VE_SIGNATURE_EXT_LIST?= sig 76 77# needs to be yes for FIPS 140-2 compliance 78VE_SELF_TESTS?= no 79 80# this is what we use as our trust anchor 81CFLAGS+= -I. -DTRUST_ANCHOR_STR=ta_PEM 82 83.if ${VE_SELF_TESTS} != "no" 84XCFLAGS.vets+= -DVERIFY_CERTS_STR=vc_PEM 85.endif 86 87# clean these up 88VE_HASH_LIST:= ${VE_HASH_LIST:tu:O:u} 89VE_SIGNATURE_LIST:= ${VE_SIGNATURE_LIST:tu:O:u} 90 91# define what we are supporting 92CFLAGS+= ${VE_HASH_LIST:@H@-DVE_$H_SUPPORT@} \ 93 ${VE_SIGNATURE_LIST:@S@-DVE_$S_SUPPORT@} 94 95.if ${VE_SIGNATURE_LIST:MOPENPGP} != "" 96.include "openpgp/Makefile.inc" 97.endif 98 99.if ${VE_SELF_TESTS} != "no" 100# The input used for hash KATs 101# we use a string by default so it is independent of any other test 102VE_HASH_KAT_STRLEN?= strlen 103.if ${VE_HASH_KAT_STRLEN} == "strlen" 104VE_HASH_KAT_STR?= self-tests-are-good 105VE_HASH_KAT_STR_INPUT= echo -n 106XCFLAGS.vets+= -DVE_HASH_KAT_STR=\"${VE_HASH_KAT_STR}\" 107.else 108VE_HASH_KAT_STR?= vc_PEM 109VE_HASH_KAT_STR_INPUT= cat 110VE_HASH_KAT_STRLEN= sizeof 111XCFLAGS.vets+= -DVE_HASH_KAT_STR=${VE_HASH_KAT_STR} 112.endif 113XCFLAGS.vets+= -DVE_HASH_KAT_STRLEN=${VE_HASH_KAT_STRLEN} 114.endif 115 116# this should be updated occassionally this is 2019-01-01Z 117SOURCE_DATE_EPOCH?= 1546329600 118.if ${MK_REPRODUCIBLE_BUILD} == "yes" 119BUILD_UTC?= ${SOURCE_DATE_EPOCH} 120.endif 121# BUILD_UTC provides a basis for the loader's notion of time 122# By default we use the mtime of BUILD_UTC_FILE 123.if empty(BUILD_UTC_FILE) 124BUILD_UTC_FILE:= ${.PARSEDIR:tA}/${.PARSEFILE} 125.endif 126# you can of course set BUILD_UTC to any value you like 127.if ${MAKE_VERSION} > 20230509 128BUILD_UTC?= ${BUILD_UTC_FILE:mtime} 129.else 130BUILD_UTC?= ${${STAT:Ustat} -L -f %m ${BUILD_UTC_FILE}:L:sh} 131.endif 132 133# Generate ta.h containing one or more PEM encoded trust anchors in ta_PEM. 134# 135# If we are doing self-tests, we define another arrary vc_PEM 136# containing certificates that we can verify for each trust anchor. 137# This is typically a subordinate CA cert. 138# Finally we generate a hash of VE_HASH_KAT_STR 139# using each supported hash method 140# to use as a Known Answer Test (needed for FIPS 140-2) 141# 142TA_PEM_LIST ?= ${.ALLSRC:N*crl*:Mt*.pem} 143VC_PEM_LIST ?= ${.ALLSRC:N*crl*:Mv*.pem} 144vets.o vets.po vets.pico: ta.h 145ta.h: 146 @( echo '/* Autogenerated - DO NOT EDIT!!! */'; echo; \ 147 cat ${TA_PEM_LIST:O:u} /dev/null | \ 148 file2c -sx 'static const char ta_PEM[] = {' '};'; \ 149 echo "${.newline}${VE_HASH_LIST:O:u:@H@static char vh_$H[] = \"`${VE_HASH_KAT_STR_INPUT} ${VE_HASH_KAT_STR} | ${$H:U${H:tl}}`\";${.newline}@}"; ) > ${.TARGET} 150.if ${VE_SELF_TESTS} != "no" 151 ( cat ${VC_PEM_LIST:O:u} /dev/null | \ 152 file2c -sx 'static const char vc_PEM[] = {' '};'; echo ) >> ${.TARGET} 153.endif 154 echo '#define BUILD_UTC ${BUILD_UTC}' >> ${.TARGET} ${.OODATE:MNOMETA_CMP} 155 156# This header records our preference for signature extensions. 157vesigned.o vesigned.po vesigned.pico: vse.h 158vse.h: 159 @( echo '/* Autogenerated - DO NOT EDIT!!! */'; echo; \ 160 echo "static const char *signature_exts[] = {"; \ 161 echo '${VE_SIGNATURE_EXT_LIST:O:u:@e@"$e",${.newline}@}'; \ 162 echo 'NULL };' ) > ${.TARGET} 163 164 165.for s in ${BRSSL_SRCS} ${BRSSL_DEPS} 166.ifdef BRSSL_SED 167$s: brssl.h 168.endif 169XCFLAGS.${s:R}+= ${BRSSL_CFLAGS} 170.endfor 171 172.endif 173