test_sign_usbpd1.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # The signed input images are signed with dev keys. We resign the unsigned
  10. # images with the same keypair, to make sure that we're producing identical
  11. # binaries.
  12. DATADIR="${SCRIPTDIR}/data"
  13. TESTS="dingdong hoho minimuffin zinger"
  14. set -o pipefail
  15. count=0
  16. for test in $TESTS; do
  17. : $(( count++ ))
  18. echo -n "$count " 1>&3
  19. pemfile=${DATADIR}/${test}.pem
  20. infile=${DATADIR}/${test}.unsigned
  21. goodfile=${DATADIR}/${test}.signed
  22. outfile=${TMP}.${test}.new
  23. # Signing the whole thing with futility should produce identical results
  24. ${FUTILITY} sign --type usbpd1 --pem ${pemfile} ${infile} ${outfile}
  25. cmp ${goodfile} ${outfile}
  26. # Now try signing just the RW part
  27. size=$(stat -c '%s' ${infile})
  28. half=$(( size / 2 ))
  29. newin=${TMP}.${test}.rw_in
  30. dd if=${infile} bs=${half} count=1 skip=1 of=${newin}
  31. newgood=${TMP}.${test}.rw_ok
  32. dd if=${goodfile} bs=${half} count=1 skip=1 of=${newgood}
  33. newout=${TMP}.${test}.rw_out
  34. # Sign the RW part alone
  35. ${FUTILITY} sign --type usbpd1 --pem ${pemfile} \
  36. --ro_size 0 \
  37. ${newin} ${newout}
  38. cmp ${newgood} ${newout}
  39. done
  40. # cleanup
  41. rm -rf ${TMP}*
  42. exit 0