xref: /aosp_15_r20/external/vboot_reference/tests/gen_preamble_testdata.sh (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1#!/bin/bash -eu
2#
3# Copyright 2012 The ChromiumOS Authors
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
8# modifications to vb2_fw_preamble and vb2_kernel_preamble will not
9# break the signing tools for older releases. This was run *before*
10# any modifications, so be sure to revert the repo back to the correct
11# point if you need to run it 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"
56
57# make some fake data
58dd if=/dev/urandom of="${DATADIR}/FWDATA" bs=32768 count=1
59dd if=/dev/urandom of="${DATADIR}/KERNDATA" bs=32768 count=1
60
61
62# Now sign the firmware and kernel data in all the possible ways using the
63# pre-change tools.
64for d in $algs; do
65  for r in $algs; do
66    "${FUTILITY}" sign \
67      --signprivate "${DATADIR}/data_${d}.vbprivk" \
68      --keyblock "${DATADIR}/kb_${d}_${r}.keyblock" \
69      --kernelkey "${DATADIR}/dummy_0.vbpubk" \
70      --version 1 \
71      --fv "${DATADIR}/FWDATA" \
72      --outfile "${V2DIR}/fw_${d}_${r}.vblock"
73    "${FUTILITY}" sign \
74      --signprivate "${DATADIR}/data_${d}.vbprivk" \
75      --keyblock "${DATADIR}/kb_${d}_${r}.keyblock" \
76      --config "${DATADIR}/dummy_config.txt" \
77      --arch arm \
78      --version 1 \
79      --vmlinuz "${DATADIR}/KERNDATA" \
80      --outfile "${V2DIR}/kern_${d}_${r}.vblock"
81  done
82done
83