run_preamble_tests.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash -u
  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 tests that vblocks using pre-3.0 versions of vb2_fw_preamble
  8. # and vb2_kernel_preamble will still verify (or not) correctly. We
  9. # need to keep the old versions around to make sure that we can still
  10. # sign images in the ways that existing devices can validate.
  11. # Load common constants and variables for tests.
  12. . "$(dirname "$0")/common.sh"
  13. if [ "${1:---some}" == "--all" ] ; then
  14. # all algs
  15. algs="0 1 2 3 4 5 6 7 8 9 10 11"
  16. else
  17. # just the algs we use
  18. algs="4 7 11"
  19. fi
  20. # output directories
  21. PREAMBLE_DIR="${SCRIPT_DIR}/preamble_tests"
  22. DATADIR="${PREAMBLE_DIR}/data"
  23. V2DIR="${PREAMBLE_DIR}/preamble_v2x"
  24. tests=0
  25. errs=0
  26. # Check the firmware results
  27. for d in $algs; do
  28. for r in $algs; do
  29. for rr in $algs; do
  30. if [ "$r" = "$rr" ]; then
  31. what="verify"
  32. cmp="-ne"
  33. else
  34. what="reject"
  35. cmp="-eq"
  36. fi
  37. : $(( tests++ ))
  38. echo -n "${what} fw_${d}_${r}.vblock with root_${rr}.vbpubk ... "
  39. "${FUTILITY}" vbutil_firmware \
  40. --verify "${V2DIR}/fw_${d}_${r}.vblock" \
  41. --signpubkey "${DATADIR}/root_${rr}.vbpubk" \
  42. --fv "${DATADIR}/FWDATA" >/dev/null 2>&1
  43. if [ "$?" "$cmp" 0 ]; then
  44. echo -e "${COL_RED}FAILED${COL_STOP}"
  45. : $(( errs++ ))
  46. else
  47. echo -e "${COL_GREEN}PASSED${COL_STOP}"
  48. fi
  49. done
  50. done
  51. done
  52. # Check the kernel results
  53. for d in $algs; do
  54. for r in $algs; do
  55. for rr in $algs; do
  56. if [ "$r" = "$rr" ]; then
  57. what="verify"
  58. cmp="-ne"
  59. else
  60. what="reject"
  61. cmp="-eq"
  62. fi
  63. : $(( tests++ ))
  64. echo -n "${what} kern_${d}_${r}.vblock with root_${rr}.vbpubk ... "
  65. "${FUTILITY}" vbutil_kernel \
  66. --verify "${V2DIR}/kern_${d}_${r}.vblock" \
  67. --signpubkey "${DATADIR}/root_${rr}.vbpubk" >/dev/null 2>&1
  68. if [ "$?" "$cmp" 0 ]; then
  69. echo -e "${COL_RED}FAILED${COL_STOP}"
  70. : $(( errs++ ))
  71. else
  72. echo -e "${COL_GREEN}PASSED${COL_STOP}"
  73. fi
  74. done
  75. done
  76. done
  77. # Check the kernel results
  78. for d in $algs; do
  79. for r in $algs; do
  80. : $(( tests++ ))
  81. echo -n "verify kern_${d}_${r}.vblock with hash only ... "
  82. "${FUTILITY}" vbutil_kernel \
  83. --verify "${V2DIR}/kern_${d}_${r}.vblock" >/dev/null 2>&1
  84. if [ "$?" -ne 0 ]; then
  85. echo -e "${COL_RED}FAILED${COL_STOP}"
  86. : $(( errs++ ))
  87. else
  88. echo -e "${COL_GREEN}PASSED${COL_STOP}"
  89. fi
  90. done
  91. done
  92. # Summary
  93. ME=$(basename "$0")
  94. if [ "$errs" -ne 0 ]; then
  95. echo -e "${COL_RED}${ME}: ${errs}/${tests} tests failed${COL_STOP}"
  96. exit 1
  97. fi
  98. happy "${ME}: All ${tests} tests passed"
  99. exit 0