gen_preamble_testdata.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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
  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. # Load common constants and variables for tests.
  13. . "$(dirname "$0")/common.sh"
  14. # Load routines to generate keypairs
  15. . "${ROOT_DIR}/scripts/keygeneration/common.sh"
  16. # all algs
  17. algs="0 1 2 3 4 5 6 7 8 9 10 11"
  18. # output directories
  19. PREAMBLE_DIR="${SCRIPT_DIR}/preamble_tests"
  20. DATADIR="${PREAMBLE_DIR}/data"
  21. V2DIR="${PREAMBLE_DIR}/preamble_v2x"
  22. for d in "${PREAMBLE_DIR}" "${DATADIR}" "${V2DIR}"; do
  23. [ -d "$d" ] || mkdir -p "$d"
  24. done
  25. # generate a bunch of data keys
  26. for d in $algs; do
  27. make_pair "${DATADIR}/data_$d" "$d"
  28. done
  29. # generate a bunch of root keys
  30. for r in $algs; do
  31. make_pair "${DATADIR}/root_$r" "$r"
  32. done
  33. # generate keyblocks using all possible combinations
  34. for d in $algs; do
  35. for r in $algs; do
  36. make_keyblock "${DATADIR}/kb_${d}_${r}" 15 \
  37. "${DATADIR}/data_$d" "${DATADIR}/root_$r"
  38. done
  39. done
  40. # make a dummy kernel key because we have to have one (crosbug.com/27142)
  41. make_pair "${DATADIR}/dummy_0" 0
  42. # and a few more dummy files just because (crosbug.com/23548)
  43. echo "hi there" > "${DATADIR}/dummy_config.txt"
  44. dd if=/dev/urandom bs=32768 count=1 of="${DATADIR}/dummy_bootloader.bin"
  45. # make some fake data
  46. dd if=/dev/urandom of="${DATADIR}/FWDATA" bs=32768 count=1
  47. dd if=/dev/urandom of="${DATADIR}/KERNDATA" bs=32768 count=1
  48. # Now sign the firmware and kernel data in all the possible ways using the
  49. # pre-change tools.
  50. for d in $algs; do
  51. for r in $algs; do
  52. vbutil_firmware --vblock "${V2DIR}/fw_${d}_${r}.vblock" \
  53. --keyblock "${DATADIR}/kb_${d}_${r}.keyblock" \
  54. --signprivate "${DATADIR}/data_${d}.vbprivk" \
  55. --version 1 \
  56. --kernelkey "${DATADIR}/dummy_0.vbpubk" \
  57. --fv "${DATADIR}/FWDATA"
  58. vbutil_kernel --pack "${V2DIR}/kern_${d}_${r}.vblock" \
  59. --keyblock "${DATADIR}/kb_${d}_${r}.keyblock" \
  60. --signprivate "${DATADIR}/data_${d}.vbprivk" \
  61. --version 1 \
  62. --arch arm \
  63. --vmlinuz "${DATADIR}/KERNDATA" \
  64. --bootloader "${DATADIR}/dummy_bootloader.bin" \
  65. --config "${DATADIR}/dummy_config.txt"
  66. done
  67. done