gen_test_keys.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # Copyright (c) 2010 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. #
  6. # Generate test keys for use by the tests.
  7. # Load common constants and variables.
  8. . "$(dirname "$0")/common.sh"
  9. set -e
  10. sha_types=( 1 256 512 )
  11. # Generate RSA test keys of various lengths.
  12. function generate_keys {
  13. key_index=0
  14. key_name_base="${TESTKEY_DIR}/key_rsa"
  15. for i in ${key_lengths[@]}
  16. do
  17. key_base="${key_name_base}${i}"
  18. if [ -f "${key_base}.keyb" ]; then
  19. continue
  20. fi
  21. openssl genrsa -F4 -out ${key_base}.pem $i
  22. # Generate self-signed certificate from key.
  23. openssl req -batch -new -x509 -key ${key_base}.pem \
  24. -out ${key_base}.crt
  25. # Generate pre-processed key for use by RSA signature verification code.
  26. ${BIN_DIR}/dumpRSAPublicKey -cert ${key_base}.crt \
  27. > ${key_base}.keyb
  28. alg_index=0
  29. for sha_type in ${sha_types[@]}
  30. do
  31. alg=$((${key_index} * 3 + ${alg_index}))
  32. # wrap the public key
  33. ${FUTILITY} vbutil_key \
  34. --pack "${key_base}.sha${sha_type}.vbpubk" \
  35. --key "${key_base}.keyb" \
  36. --version 1 \
  37. --algorithm ${alg}
  38. # wrap the private key
  39. ${FUTILITY} vbutil_key \
  40. --pack "${key_base}.sha${sha_type}.vbprivk" \
  41. --key "${key_base}.pem" \
  42. --algorithm ${alg}
  43. alg_index=$((${alg_index} + 1))
  44. done
  45. key_index=$((${key_index} + 1))
  46. done
  47. }
  48. mkdir -p ${TESTKEY_DIR}
  49. generate_keys