1#!/bin/bash -eu
2#
3# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# This generates the pre-change test data used to ensure that modifications to
8# VbFirmwarePreambleHeader and VbKernelPreambleHeader will not break the
9# signing tools for older releases. This was run *before* any modifications, so
10# be sure to revert the repo back to the correct point if you need to run it
11# again.
12
13
14# Load common constants and variables for tests.
15. "$(dirname "$0")/common.sh"
16
17# Load routines to generate keypairs
18. "${ROOT_DIR}/scripts/keygeneration/common.sh"
19
20# all algs
21algs="0 1 2 3 4 5 6 7 8 9 10 11"
22
23# output directories
24PREAMBLE_DIR="${SCRIPT_DIR}/preamble_tests"
25DATADIR="${PREAMBLE_DIR}/data"
26V2DIR="${PREAMBLE_DIR}/preamble_v2x"
27
28for d in "${PREAMBLE_DIR}" "${DATADIR}" "${V2DIR}"; do
29  [ -d "$d" ] || mkdir -p "$d"
30done
31
32
33# generate a bunch of data keys
34for d in $algs; do
35  make_pair "${DATADIR}/data_$d" "$d"
36done
37
38# generate a bunch of root keys
39for r in $algs; do
40  make_pair "${DATADIR}/root_$r" "$r"
41done
42
43# generate keyblocks using all possible combinations
44for d in $algs; do
45  for r in $algs; do
46     make_keyblock "${DATADIR}/kb_${d}_${r}" 15 \
47       "${DATADIR}/data_$d" "${DATADIR}/root_$r"
48  done
49done
50
51# make a dummy kernel key because we have to have one (crosbug.com/27142)
52make_pair "${DATADIR}/dummy_0" 0
53
54# and a few more dummy files just because (crosbug.com/23548)
55echo "hi there" > "${DATADIR}/dummy_config.txt"
56dd if=/dev/urandom bs=32768 count=1 of="${DATADIR}/dummy_bootloader.bin"
57
58# make some fake data
59dd if=/dev/urandom of="${DATADIR}/FWDATA" bs=32768 count=1
60dd if=/dev/urandom of="${DATADIR}/KERNDATA" bs=32768 count=1
61
62
63# Now sign the firmware and kernel data in all the possible ways using the
64# pre-change tools.
65for d in $algs; do
66  for r in $algs; do
67      vbutil_firmware --vblock "${V2DIR}/fw_${d}_${r}.vblock" \
68        --keyblock "${DATADIR}/kb_${d}_${r}.keyblock" \
69        --signprivate "${DATADIR}/data_${d}.vbprivk" \
70        --version 1 \
71        --kernelkey "${DATADIR}/dummy_0.vbpubk" \
72        --fv "${DATADIR}/FWDATA"
73     vbutil_kernel --pack "${V2DIR}/kern_${d}_${r}.vblock" \
74       --keyblock "${DATADIR}/kb_${d}_${r}.keyblock" \
75       --signprivate "${DATADIR}/data_${d}.vbprivk" \
76       --version 1 \
77       --arch arm \
78       --vmlinuz "${DATADIR}/KERNDATA" \
79       --bootloader "${DATADIR}/dummy_bootloader.bin" \
80       --config "${DATADIR}/dummy_config.txt"
81  done
82done
83
84
85