test_show_contents.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash -eux
  2. # Copyright 2015 The Chromium OS Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. me=${0##*/}
  6. TMP="$me.tmp"
  7. # Work in scratch directory
  8. cd "$OUTDIR"
  9. # Test 'futility show' against expected output
  10. SHOW_FILES="
  11. tests/devkeys/root_key.vbpubk
  12. tests/devkeys/root_key.vbprivk
  13. tests/devkeys/kernel.keyblock
  14. tests/futility/data/fw_vblock.bin
  15. tests/futility/data/fw_gbb.bin
  16. tests/futility/data/bios_zgb_mp.bin
  17. tests/futility/data/bios_mario_mp.bin
  18. tests/futility/data/kern_preamble.bin
  19. tests/futility/data/sample.vbpubk2
  20. tests/futility/data/sample.vbprik2
  21. tests/testkeys/key_rsa2048.pem
  22. tests/testkeys/key_rsa8192.pub.pem
  23. "
  24. for file in $SHOW_FILES; do
  25. outfile="show.${file//\//_}"
  26. gotfile="${OUTDIR}/${outfile}"
  27. wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
  28. ${FUTILITY} show "${SRCDIR}/${file}" | tee "${gotfile}"
  29. # Uncomment this to update the expected output
  30. #cp ${gotfile} ${wantfile}
  31. diff ${wantfile} ${gotfile}
  32. done
  33. # Test 'futility vbutil_key' against expected output
  34. VBUTIL_KEY_FILES="
  35. tests/devkeys/root_key.vbpubk
  36. tests/devkeys/root_key.vbprivk
  37. "
  38. for file in $VBUTIL_KEY_FILES; do
  39. outfile="vbutil_key.${file//\//_}"
  40. gotfile="${OUTDIR}/${outfile}"
  41. wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
  42. ${FUTILITY} vbutil_key --unpack "${SRCDIR}/${file}" | tee "${gotfile}"
  43. # Uncomment this to update the expected output
  44. #cp ${gotfile} ${wantfile}
  45. diff ${wantfile} ${gotfile}
  46. done
  47. # Test 'futility vbutil_keyblock' against expected output
  48. file="tests/devkeys/kernel.keyblock"
  49. outfile="vbutil_keyblock.${file//\//_}"
  50. gotfile="${OUTDIR}/${outfile}"
  51. wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
  52. ${FUTILITY} vbutil_keyblock --unpack "${SRCDIR}/${file}" \
  53. --signpubkey "${SRCDIR}/tests/devkeys/kernel_subkey.vbpubk" \
  54. | tee "${gotfile}"
  55. # Uncomment this to update the expected output
  56. #cp ${gotfile} ${wantfile}
  57. diff ${wantfile} ${gotfile}
  58. # Test 'futility vbutil_firmware' against expected output
  59. KEYDIR=${SRCDIR}/tests/devkeys
  60. outfile="vbutil_firmware.verify"
  61. gotfile="${OUTDIR}/${outfile}"
  62. wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
  63. # Create a firmware blob and vblock. Version and flags are just
  64. # arbitrary non-zero numbers so we can verify they're printed
  65. # properly.
  66. dd bs=1024 count=16 if=/dev/urandom of=${TMP}.fw_main
  67. ${FUTILITY} vbutil_firmware --vblock ${TMP}.vblock.old \
  68. --keyblock ${KEYDIR}/firmware.keyblock \
  69. --signprivate ${KEYDIR}/firmware_data_key.vbprivk \
  70. --version 12 \
  71. --fv ${TMP}.fw_main \
  72. --kernelkey ${KEYDIR}/kernel_subkey.vbpubk \
  73. --flags 42
  74. # Verify
  75. ${FUTILITY} vbutil_firmware --verify ${TMP}.vblock.old \
  76. --signpubkey ${KEYDIR}/root_key.vbpubk \
  77. --fv ${TMP}.fw_main | tee "${gotfile}"
  78. # Uncomment this to update the expected output
  79. #cp ${gotfile} ${wantfile}
  80. diff ${wantfile} ${gotfile}
  81. # cleanup
  82. rm -rf ${TMP}*
  83. exit 0