OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 # Generate test keys for use by the tests. | 7 # Generate test keys for use by the tests. |
8 | 8 |
9 # Load common constants and variables. | 9 # Load common constants and variables. |
10 . "$(dirname "$0")/common.sh" | 10 . "$(dirname "$0")/common.sh" |
11 | 11 |
12 # Generate RSA test keys of various lengths. | 12 set -e |
| 13 |
| 14 PATH="$(dirname "$0")/../build/utility:${PATH}" |
| 15 |
| 16 sha_types=( 1 256 512 ) |
| 17 |
| 18 # Generate RSA test keys of various lengths. |
13 function generate_keys { | 19 function generate_keys { |
| 20 key_index=0 |
| 21 key_name_base="${TESTKEY_DIR}/key_rsa" |
14 for i in ${key_lengths[@]} | 22 for i in ${key_lengths[@]} |
15 do | 23 do |
16 if [ -f ${TESTKEY_DIR}/key_rsa$i.keyb ]; then | 24 key_base="${key_name_base}${i}" |
| 25 if [ -f "${key_base}.keyb" ]; then |
17 continue | 26 continue |
18 fi | 27 fi |
19 openssl genrsa -F4 -out ${TESTKEY_DIR}/key_rsa$i.pem $i | 28 |
| 29 openssl genrsa -F4 -out ${key_base}.pem $i |
20 # Generate self-signed certificate from key. | 30 # Generate self-signed certificate from key. |
21 openssl req -batch -new -x509 -key ${TESTKEY_DIR}/key_rsa$i.pem \ | 31 openssl req -batch -new -x509 -key ${key_base}.pem \ |
22 -out ${TESTKEY_DIR}/key_rsa$i.crt | 32 -out ${key_base}.crt |
| 33 |
23 # Generate pre-processed key for use by RSA signature verification code. | 34 # Generate pre-processed key for use by RSA signature verification code. |
24 ${UTIL_DIR}/dumpRSAPublicKey ${TESTKEY_DIR}/key_rsa$i.crt \ | 35 ${UTIL_DIR}/dumpRSAPublicKey ${key_base}.crt \ |
25 > ${TESTKEY_DIR}/key_rsa$i.keyb | 36 > ${key_base}.keyb |
| 37 |
| 38 alg_index=0 |
| 39 for sha_type in ${sha_types[@]} |
| 40 do |
| 41 alg=$((${key_index} * 3 + ${alg_index})) |
| 42 # wrap the public key |
| 43 vbutil_key \ |
| 44 --pack "${key_base}.sha${sha_type}.vbpubk" \ |
| 45 --key "${key_base}.keyb" \ |
| 46 --version 1 \ |
| 47 --algorithm ${alg} |
| 48 |
| 49 # wrap the private key |
| 50 vbutil_key \ |
| 51 --pack "${key_base}.sha${sha_type}.vbprivk" \ |
| 52 --key "${key_base}.pem" \ |
| 53 --algorithm ${alg} |
| 54 alg_index=$((${alg_index} + 1)) |
| 55 done |
| 56 key_index=$((${key_index} + 1)) |
26 done | 57 done |
27 } | 58 } |
28 | 59 |
29 mkdir -p ${TESTKEY_DIR} | 60 mkdir -p ${TESTKEY_DIR} |
30 generate_keys | 61 generate_keys |
OLD | NEW |