Files
OpenCellular/tests/gen_fuzz_test_cases.sh
vbendeb a222fbc00e Fix test suite deficiencies.
While trying to debug/test some vbutil_kernel changes
(coming in a different CL) it was noticed that this utility
is not covered by tests, and the script which runs it to set
up further testing (tests/gen_fuzz_test_cases.sh) fails
because of the key format mismatch.

Some investigation has shown that this was left behind when
vboot_reference key storage format was changed.

To make gen_fuzz_test_cases.sh work again a new set of test
keys is required, the keys are generated by
tests/gen_test_keys.sh. This utility had to be changed to
generate the proper set of wrapped public and private keys.

Actually code in tests/gen_test_keys.shgenerate_keys() is
copied in pasted in many scripts in this tree, this has to
be refactored, but under a different CL.

Once the changes were made, two scripts were run:
 ./tests/gen_test_keys.sh
 ./gen_test_cases.sh

resulting in the new and updated keys generated.

firmware/stub/tpm_lite_stub.c was edited to fix compilation
warning issued when compiling with debugging enabled.

Change-Id: I26a45cbad00d21a29195f2a89b4df7d3559133fe

BUG=chromium-os:7178
TEST=described below

The following commands succeed:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
make
make runtests
./tests/gen_fuzz_test_cases.sh
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

note that  ./tests/gen_fuzz_test_cases.sh was failing
before this change.

The upcoming CL modifying vbutil_kernel will make sure
gen_fuzz_test_cases.sh is executed when tests are run and
will enhance it to cover vbutil_kernel testing.

Review URL: http://codereview.chromium.org/3423022
2010-09-29 20:25:29 -07:00

85 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2010 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.
# Generate test cases for use for the RSA verify benchmark.
set -e
# Load common constants and variables.
. "$(dirname "$0")/common.sh"
# Use a different directory for fuzzing test cases.
TESTKEY_DIR=${TESTKEY_DIR:-$(realpath ${SCRIPT_DIR}/../tests/testkeys)}
TESTCASE_DIR="$(realpath ${SCRIPT_DIR}/../build)"/fuzz_testcases
TEST_IMAGE_FILE=${TESTCASE_DIR}/testimage
TEST_IMAGE_SIZE=500000
TEST_BOOTLOADER_FILE=${TESTCASE_DIR}/testbootloader
TEST_BOOTLOADER_SIZE=50000
TEST_CONFIG_FILE=${TESTCASE_DIR}/testconfig
# Config size must < 4096
TEST_CONFIG_SIZE=3000
function generate_fuzzing_images {
echo "Generating key blocks..."
# Firmware key block - RSA8192/SHA512 root key, RSA4096/SHA512 firmware
# signing key.
${UTIL_DIR}/vbutil_keyblock --pack ${TESTCASE_DIR}/firmware.keyblock \
--datapubkey ${TESTKEY_DIR}/key_rsa4096.sha512.vbpubk \
--signprivate ${TESTKEY_DIR}/key_rsa8192.sha1.vbprivk
# Kernel key block - RSA4096/SHA512 kernel signing subkey, RSA4096/SHA512
# kernel signing key.
${UTIL_DIR}/vbutil_keyblock --pack ${TESTCASE_DIR}/kernel.keyblock \
--datapubkey ${TESTKEY_DIR}/key_rsa4096.sha512.vbpubk \
--signprivate ${TESTKEY_DIR}/key_rsa4096.sha1.vbprivk \
--flags 15
echo "Generating signed firmware test image..."
${UTIL_DIR}/vbutil_firmware \
--vblock ${TESTCASE_DIR}/firmware.vblock \
--keyblock ${TESTCASE_DIR}/firmware.keyblock\
--signprivate ${TESTKEY_DIR}/key_rsa4096.sha256.vbprivk \
--version 1 \
--fv $1 \
--kernelkey ${TESTKEY_DIR}/key_rsa4096.sha512.vbpubk
# TODO(gauravsh): ALso test with (optional) flags.
cp ${TESTKEY_DIR}/key_rsa8192.sha512.vbpubk ${TESTCASE_DIR}/root_key.vbpubk
echo "Generating signed kernel test image..."
${UTIL_DIR}/vbutil_kernel \
--pack ${TESTCASE_DIR}/kernel.vblock.image \
--keyblock ${TESTCASE_DIR}/kernel.keyblock \
--signprivate ${TESTKEY_DIR}/key_rsa4096.sha256.vbprivk \
--version 1 \
--vmlinuz ${TEST_IMAGE_FILE} \
--bootloader ${TEST_BOOTLOADER_FILE} \
--config ${TEST_CONFIG_FILE}
# TODO(gauravsh): Also test with (optional) padding.
cp ${TESTKEY_DIR}/key_rsa4096.sha512.vbpubk \
${TESTCASE_DIR}/firmware_key.vbpubk
}
function pre_work {
# Generate a file to serve as random bytes for firmware/kernel contents.
# NOTE: The kernel and config file can't really be random, but the bootloader
# can. That's probably close enough.
echo "Generating test image file..."
dd if=/dev/urandom of=${TEST_IMAGE_FILE} bs=${TEST_IMAGE_SIZE} count=1
echo "Generating test bootloader file..."
# TODO(gauravsh): Use a valid bootloader here?
dd if=/dev/urandom of=${TEST_BOOTLOADER_FILE} bs=${TEST_BOOTLOADER_SIZE} \
count=1
echo "Generating test config file..."
# TODO(gauravsh): Use a valid config file here?
dd if=/dev/urandom of=${TEST_CONFIG_FILE} bs=${TEST_CONFIG_SIZE} count=1
}
mkdir -p ${TESTCASE_DIR}
pre_work
check_test_keys
generate_fuzzing_images ${TEST_IMAGE_FILE}