Home | History | Annotate | Download | only in tests
      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
     21 algs="0 1 2 3 4 5 6 7 8 9 10 11"
     22 
     23 # output directories
     24 PREAMBLE_DIR="${SCRIPT_DIR}/preamble_tests"
     25 DATADIR="${PREAMBLE_DIR}/data"
     26 V2DIR="${PREAMBLE_DIR}/preamble_v2x"
     27 
     28 for d in "${PREAMBLE_DIR}" "${DATADIR}" "${V2DIR}"; do
     29   [ -d "$d" ] || mkdir -p "$d"
     30 done
     31 
     32 
     33 # generate a bunch of data keys
     34 for d in $algs; do
     35   make_pair "${DATADIR}/data_$d" "$d"
     36 done
     37 
     38 # generate a bunch of root keys
     39 for r in $algs; do
     40   make_pair "${DATADIR}/root_$r" "$r"
     41 done
     42 
     43 # generate keyblocks using all possible combinations
     44 for 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
     49 done
     50 
     51 # make a dummy kernel key because we have to have one (crosbug.com/27142)
     52 make_pair "${DATADIR}/dummy_0" 0
     53 
     54 # and a few more dummy files just because (crosbug.com/23548)
     55 echo "hi there" > "${DATADIR}/dummy_config.txt"
     56 dd if=/dev/urandom bs=32768 count=1 of="${DATADIR}/dummy_bootloader.bin"
     57 
     58 # make some fake data
     59 dd if=/dev/urandom of="${DATADIR}/FWDATA" bs=32768 count=1
     60 dd 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.
     65 for 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
     82 done
     83 
     84 
     85