1#!/bin/bash -eux 2# Copyright 2015 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6ME="${0##*/}" 7TMP="${ME}.tmp" 8 9# Set to 1 to update the expected output 10UPDATE_MODE=0 11 12# Work in scratch directory 13cd "${OUTDIR}" 14 15# Test 'futility vbutil_key' against expected output 16VBUTIL_KEY_FILES=" 17 tests/devkeys/root_key.vbpubk 18 tests/devkeys/root_key.vbprivk 19" 20 21for file in ${VBUTIL_KEY_FILES}; do 22 outfile="vbutil_key.${file//\//_}" 23 gotfile="${OUTDIR}/${outfile}" 24 wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}" 25 ( cd "${SRCDIR}" && "${FUTILITY}" vbutil_key --unpack "${file}" ) \ 26 | tee "${gotfile}" 27 28 [[ "${UPDATE_MODE}" -gt 0 ]] && cp "${gotfile}" "${wantfile}" 29 30 diff "${wantfile}" "${gotfile}" 31done 32 33 34# Test 'futility vbutil_keyblock' against expected output 35file="tests/devkeys/kernel.keyblock" 36outfile="vbutil_keyblock.${file//\//_}" 37gotfile="${OUTDIR}/${outfile}" 38wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}" 39( cd "${SRCDIR}" && "${FUTILITY}" vbutil_keyblock --unpack "${file}" \ 40 --signpubkey "tests/devkeys/kernel_subkey.vbpubk" ) \ 41 | tee "${gotfile}" 42 43[[ "${UPDATE_MODE}" -gt 0 ]] && cp "${gotfile}" "${wantfile}" 44 45diff "${wantfile}" "${gotfile}" 46 47 48# Test 'futility vbutil_firmware' against expected output 49KEYDIR="${SRCDIR}/tests/devkeys" 50outfile="vbutil_firmware.verify" 51gotfile="${OUTDIR}/${outfile}" 52wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}" 53 54# Create a firmware blob and vblock. Version and flags are just 55# arbitrary non-zero numbers so we can verify they're printed 56# properly. 57dd bs=1024 count=16 if=/dev/urandom of="${TMP}.fw_main" 58"${FUTILITY}" vbutil_firmware --vblock "${TMP}.vblock.old" \ 59 --keyblock "${KEYDIR}/firmware.keyblock" \ 60 --signprivate "${KEYDIR}/firmware_data_key.vbprivk" \ 61 --version 12 \ 62 --fv "${TMP}.fw_main" \ 63 --kernelkey "${KEYDIR}/kernel_subkey.vbpubk" \ 64 --flags 42 65 66# Verify 67"${FUTILITY}" vbutil_firmware --verify "${TMP}.vblock.old" \ 68 --signpubkey "${KEYDIR}/root_key.vbpubk" \ 69 --fv "${TMP}.fw_main" | tee "${gotfile}" 70 71[[ "${UPDATE_MODE}" -gt 0 ]] && cp "${gotfile}" "${wantfile}" 72 73diff "${wantfile}" "${gotfile}" 74 75 76# cleanup 77rm -rf "${TMP}"* 78exit 0 79