test_show_kernel.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash -eux
  2. # Copyright (c) 2014 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. DEVKEYS=${SRCDIR}/tests/devkeys
  10. TESTKEYS=${SRCDIR}/tests/testkeys
  11. echo 'Creating test kernel'
  12. # Dummy kernel data
  13. echo "hi there" > ${TMP}.config.txt
  14. dd if=/dev/urandom bs=16384 count=1 of=${TMP}.bootloader.bin
  15. dd if=/dev/urandom bs=32768 count=1 of=${TMP}.kernel.bin
  16. # Pack kernel data key using original vboot utilities.
  17. ${FUTILITY} vbutil_key --pack ${TMP}.datakey.test \
  18. --key ${TESTKEYS}/key_rsa2048.keyb --algorithm 4
  19. # Keyblock with kernel data key is signed by kernel subkey
  20. # Flags=5 means dev=0 rec=0
  21. ${FUTILITY} vbutil_keyblock --pack ${TMP}.keyblock.test \
  22. --datapubkey ${TMP}.datakey.test \
  23. --flags 5 \
  24. --signprivate ${DEVKEYS}/kernel_subkey.vbprivk
  25. # Kernel preamble is signed with the kernel data key
  26. ${FUTILITY} vbutil_kernel \
  27. --pack ${TMP}.kernel.test \
  28. --keyblock ${TMP}.keyblock.test \
  29. --signprivate ${TESTKEYS}/key_rsa2048.sha256.vbprivk \
  30. --version 1 \
  31. --arch arm \
  32. --vmlinuz ${TMP}.kernel.bin \
  33. --bootloader ${TMP}.bootloader.bin \
  34. --config ${TMP}.config.txt
  35. echo 'Verifying test kernel'
  36. # Verify the kernel
  37. ${FUTILITY} show ${TMP}.kernel.test \
  38. --publickey ${DEVKEYS}/kernel_subkey.vbpubk \
  39. | egrep 'Signature.*valid'
  40. echo 'Test kernel blob looks good'
  41. # Mess up the padding, make sure it fails.
  42. rc=0
  43. ${FUTILITY} show ${TMP}.kernel.test \
  44. --pad 0x100 \
  45. --publickey ${DEVKEYS}/kernel_subkey.vbpubk \
  46. || rc=$?
  47. [ $rc -ne 0 ]
  48. [ $rc -lt 128 ]
  49. echo 'Invalid args are invalid'
  50. # Look waaaaaay off the end of the file, make sure it fails.
  51. rc=0
  52. ${FUTILITY} show ${TMP}.kernel.test \
  53. --pad 0x100000 \
  54. --publickey ${DEVKEYS}/kernel_subkey.vbpubk \
  55. || rc=$?
  56. [ $rc -ne 0 ]
  57. [ $rc -lt 128 ]
  58. echo 'Really invalid args are still invalid'
  59. # cleanup
  60. rm -rf ${TMP}*
  61. exit 0