1# $FreeBSD$ 2 3.if empty(BEARSSL) 4.include "../libbearssl/Makefile.inc" 5.endif 6 7.if !target(_${__this}_) 8_${__this}_: 9 10libsecureboot_src:= ${.PARSEDIR} 11 12CFLAGS+= -I${libsecureboot_src}/h 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# list of hashes we support 61VE_HASH_LIST?= SHA256 62 63# list of signatures we support 64# some people don't trust ECDSA 65VE_SIGNATURE_LIST?= RSA 66 67# this list controls our search for signatures so will not be sorted 68# note: for X509 signatures we assume we can replace the trailing 69# "sig" with "certs" to find the certificate chain 70# eg. for manifest.esig we use manifest.ecerts 71VE_SIGNATURE_EXT_LIST?= sig 72 73# needs to be yes for FIPS 140-2 compliance 74VE_SELF_TESTS?= no 75 76# rules to populate the [tv]*.pem files we use to generate ta.h 77# and can add/alter VE_*_LIST as desired. 78.-include "local.trust.mk" 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 101VE_HASH_KAT_STR?= vc_PEM 102 103XCFLAGS.vets+= -DVE_HASH_KAT_STR=${VE_HASH_KAT_STR} 104.endif 105 106# this should be updated occassionally this is 2019-01-01Z 107SOURCE_DATE_EPOCH?= 1546329600 108.if ${MK_REPRODUCIBLE_BUILD} == "yes" 109BUILD_UTC?= ${SOURCE_DATE_EPOCH} 110.endif 111# BUILD_UTC provides a basis for the loader's notion of time 112# By default we use the mtime of BUILD_UTC_FILE 113.if empty(BUILD_UTC_FILE) 114BUILD_UTC_FILE:= ${.PARSEDIR:tA}/${.PARSEFILE} 115.endif 116# you can of course set BUILD_UTC to any value you like 117BUILD_UTC?= ${${STAT:Ustat} -f %m ${BUILD_UTC_FILE}:L:sh} 118 119# Generate ta.h containing one or more PEM encoded trust anchors in ta_PEM. 120# 121# If we are doing self-tests, we define another arrary vc_PEM 122# containing certificates that we can verify for each trust anchor. 123# This is typically a subordinate CA cert. 124# Finally we generate a hash of vc_PEM using each supported hash method 125# to use as a Known Answer Test (needed for FIPS 140-2) 126# 127vets.o vets.po vets.pico: ta.h 128ta.h: ${.ALLTARGETS:M[tv]*pem:O:u} 129 @( echo '/* Autogenerated - DO NOT EDIT!!! */'; echo; \ 130 cat ${.ALLSRC:N*crl*:Mt*.pem} /dev/null | \ 131 file2c -sx 'static const char ta_PEM[] = {' '};'; \ 132 echo "${.newline}${VE_HASH_LIST:@H@static char vh_$H[] = \"`cat ${.ALLSRC:N*crl*:Mv*.pem} | ${$H:U${H:tl}}`\";${.newline}@}"; ) > ${.TARGET} 133.if ${VE_SELF_TESTS} != "no" 134 ( cat ${.ALLSRC:N*crl*:Mv*.pem} /dev/null | \ 135 file2c -sx 'static const char vc_PEM[] = {' '};'; echo ) >> ${.TARGET} 136.endif 137 echo '#define BUILD_UTC ${BUILD_UTC}' >> ${.TARGET} ${.OODATE:MNOMETA_CMP} 138 139# This header records our preference for signature extensions. 140vesigned.o vesigned.po vesigned.pico: vse.h 141vse.h: 142 @( echo '/* Autogenerated - DO NOT EDIT!!! */'; echo; \ 143 echo "static const char *signature_exts[] = {"; \ 144 echo '${VE_SIGNATURE_EXT_LIST:@e@"$e",${.newline}@}'; \ 145 echo 'NULL };' ) > ${.TARGET} 146 147 148.for s in ${BRSSL_SRCS} ${BRSSL_DEPS} 149.ifdef BRSSL_SED 150$s: brssl.h 151.endif 152XCFLAGS.${s:R}+= ${BRSSL_CFLAGS} 153.endfor 154 155.endif 156