1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
#!/bin/bash -u
#
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Quick test of vbutil_kernel args, to make sure we can pack and unpack
# less-than-full-sized components.
#
# Load common constants and variables for tests.
. "$(dirname "$0")/common.sh"
# directories
DEVKEYS="${ROOT_DIR}/tests/devkeys"
DATA_DIR="${SCRIPT_DIR}/preamble_tests/data"
TMPDIR="${TEST_DIR}/vbutil_kernel_arg_tests_dir"
[ -d "${TMPDIR}" ] || mkdir -p "${TMPDIR}"
# Arbitrarily chosen keys and config file.
KEYBLOCK="${DATA_DIR}/kb_0_0.keyblock"
SIGNPRIVATE="${DATA_DIR}/data_0.vbprivk"
SIGNPUBLIC="${DATA_DIR}/root_0.vbpubk"
CONFIG="${DATA_DIR}/dummy_config.txt"
# Create some big and little files for the kernel and bootloader
BIG="${TMPDIR}/big.bin"
dd if=/dev/urandom bs=32768 count=1 of="${BIG}" 2>/dev/null
SMALL="${TMPDIR}/small.bin"
dd if=/dev/urandom bs=16 count=1 of="${SMALL}" 2>/dev/null
declare -a KERN_VALS
declare -a BOOT_VALS
KERN_VALS=("--vmlinuz=${BIG}" "--vmlinuz=${SMALL}")
BOOT_VALS=("--bootloader=${BIG}" "--bootloader=${SMALL}")
tests=0
errs=0
# Pack a bunch of stuff
k=0
while [ "$k" -lt "${#KERN_VALS[*]}" ]; do
b=0
while [ "$b" -lt "${#BOOT_VALS[*]}" ]; do
echo -n "pack kern_${k}_${b}.vblock ... "
: $(( tests++ ))
if ! "${FUTILITY}" vbutil_kernel \
--pack "${TMPDIR}/kern_${k}_${b}.vblock" \
--keyblock "${KEYBLOCK}" \
--signprivate "${SIGNPRIVATE}" \
--version 1 \
--arch arm \
--config "${CONFIG}" \
"${KERN_VALS[$k]}" \
"${BOOT_VALS[$k]}" >/dev/null
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
: $(( b++ ))
done
: $(( k++ ))
done
# Now unpack it
for v in "${TMPDIR}"/kern_*.vblock; do
: $(( tests++ ))
vv=$(basename "$v")
echo -n "verify $vv ... "
if ! "${FUTILITY}" vbutil_kernel --verify "$v" >/dev/null
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
: $(( tests++ ))
echo -n "verify $vv signed ... "
if ! "${FUTILITY}" vbutil_kernel --verify "$v" \
--signpubkey "${SIGNPUBLIC}" >/dev/null
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
done
# Test repacking a USB image for the SSD, the way the installer does.
set -e
# Pack for USB
USB_KERN="${TMPDIR}/usb_kern.bin"
USB_KEYBLOCK="${DEVKEYS}/recovery_kernel.keyblock"
USB_SIGNPRIVATE="${DEVKEYS}/recovery_kernel_data_key.vbprivk"
USB_SIGNPUBKEY="${DEVKEYS}/recovery_key.vbpubk"
echo -n "pack USB kernel ... "
: $(( tests++ ))
if ! "${FUTILITY}" vbutil_kernel \
--pack "${USB_KERN}" \
--keyblock "${USB_KEYBLOCK}" \
--signprivate "${USB_SIGNPRIVATE}" \
--version 1 \
--config "${CONFIG}" \
--bootloader "${BIG}" \
--vmlinuz "${BIG}" \
--arch arm
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
# And verify it.
echo -n "verify USB kernel ... "
: $(( tests++ ))
if ! "${FUTILITY}" vbutil_kernel \
--verify "${USB_KERN}" \
--signpubkey "${USB_SIGNPUBKEY}" >/dev/null
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
# Now we re-sign the same image using the normal keys. This is the kernel
# image that is put on the hard disk by the installer. Note: To save space on
# the USB image, we're only emitting the new verfication block, and the
# installer just replaces that part of the hard disk's kernel partition.
SSD_KERN="${TMPDIR}/ssd_kern.bin"
SSD_KEYBLOCK="${DEVKEYS}/kernel.keyblock"
SSD_SIGNPRIVATE="${DEVKEYS}/kernel_data_key.vbprivk"
SSD_SIGNPUBKEY="${DEVKEYS}/kernel_subkey.vbpubk"
echo -n "repack to SSD kernel ... "
: $(( tests++ ))
if ! "${FUTILITY}" vbutil_kernel \
--repack "${SSD_KERN}" \
--vblockonly \
--keyblock "${SSD_KEYBLOCK}" \
--signprivate "${SSD_SIGNPRIVATE}" \
--oldblob "${TMPDIR}/usb_kern.bin" >/dev/null
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
# To verify it, we have to replace the vblock from the original image.
tempfile="${TMPDIR}/foo.bin"
cat "${SSD_KERN}" > "$tempfile"
dd if="${USB_KERN}" bs=65536 skip=1 >> "$tempfile" 2>/dev/null
echo -n "verify SSD kernel ... "
: $(( tests++ ))
if ! "${FUTILITY}" vbutil_kernel \
--verify "$tempfile" \
--signpubkey "${SSD_SIGNPUBKEY}" >/dev/null
then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
# Finally make sure that the kernel command line stays good.
orig=$(tr '\012' ' ' < "${CONFIG}")
packed=$("${FUTILITY}" dump_kernel_config "${USB_KERN}")
echo -n "check USB kernel config ..."
: $(( tests++ ))
if [ "$orig" != "$packed" ]; then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
repacked=$("${FUTILITY}" dump_kernel_config "${tempfile}")
echo -n "check SSD kernel config ..."
: $(( tests++ ))
if [ "$orig" != "$repacked" ]; then
echo -e "${COL_RED}FAILED${COL_STOP}"
: $(( errs++ ))
else
echo -e "${COL_GREEN}PASSED${COL_STOP}"
fi
# Summary
ME=$(basename "$0")
if [ "$errs" -ne 0 ]; then
echo -e "${COL_RED}${ME}: ${errs}/${tests} tests failed${COL_STOP}"
exit 1
fi
happy "${ME}: All ${tests} tests passed"
exit 0
|