test_create.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # Current vb1 keys, including original .pem files.
  10. TESTKEYS=${SRCDIR}/tests/testkeys
  11. # Demonstrate that we can recreate the same vb1 keys without the .keyb files
  12. for sig in rsa1024 rsa2048 rsa4096 rsa8192; do
  13. for hash in sha1 sha256 sha512; do
  14. ${FUTILITY} --vb1 create --hash_alg "${hash}" \
  15. "${TESTKEYS}/key_${sig}.pem" "${TMP}_key_${sig}.${hash}"
  16. cmp "${TESTKEYS}/key_${sig}.${hash}.vbprivk" \
  17. "${TMP}_key_${sig}.${hash}.vbprivk"
  18. cmp "${TESTKEYS}/key_${sig}.${hash}.vbpubk" \
  19. "${TMP}_key_${sig}.${hash}.vbpubk"
  20. done
  21. done
  22. # Demonstrate that we can create some vb21 keypairs. This doesn't prove
  23. # prove anything until we've used them to sign some stuff, though.
  24. for sig in rsa1024 rsa2048 rsa4096 rsa8192; do
  25. for hash in sha1 sha256 sha512; do
  26. ${FUTILITY} --vb21 create --hash_alg "${hash}" \
  27. "${TESTKEYS}/key_${sig}.pem" "${TMP}_key_${sig}.${hash}"
  28. done
  29. done
  30. # Demonstrate that the sha1sums are the same for all the keys created from the
  31. # same .pem files, both public and private, vb1 and vb21.
  32. for sig in rsa1024 rsa2048 rsa4096 rsa8192; do
  33. pem_sum=$(${FUTILITY} show "${TESTKEYS}/key_${sig}.pem" |
  34. awk '/sha1sum/ {print $3}')
  35. # expect only one
  36. [ $(echo "$pem_sum" | wc -w) = 1 ]
  37. num_keys=$(echo ${TMP}_key_${sig}.* | wc -w)
  38. key_sums=$(${FUTILITY} show ${TMP}_key_${sig}.* |
  39. awk '/sha1sum:|ID:/ {print $NF}')
  40. num_sums=$(echo "$key_sums" | wc -w)
  41. # expect one sha1sum (or ID) line per file
  42. [ "$num_keys" = "$num_sums" ]
  43. uniq_sums=$(echo "$key_sums" | uniq)
  44. # note that this also tests that all the key_sums are the same
  45. [ "$pem_sum" = "$uniq_sums" ]
  46. done
  47. # Demonstrate that we can create some vb21 public key from PEM containing
  48. # only the pubkeypairs and verify it's the same as the one generated from
  49. # the private key.
  50. for sig in rsa1024 rsa2048 rsa4096 rsa8192; do
  51. for hash in sha1 sha256 sha512; do
  52. ${FUTILITY} --vb21 create --hash_alg "${hash}" \
  53. "${TESTKEYS}/key_${sig}.pub.pem" "${TMP}_key_${sig}.pubonly.${hash}"
  54. cmp "${TMP}_key_${sig}.pubonly.${hash}.vbpubk2" \
  55. "${TMP}_key_${sig}.${hash}.vbpubk2"
  56. done
  57. done
  58. # cleanup
  59. rm -rf ${TMP}*
  60. exit 0