blob: 79fabf1bfc2ae3b6afbcddd7b6351e7961e59ead [file] [log] [blame]
Gaurav Shahe3ef9c92010-02-10 23:07:02 -08001#!/bin/bash
2
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
5# found in the LICENSE file.
Gaurav Shah445925f2010-03-19 16:19:09 -07006#
Gaurav Shahe3ef9c92010-02-10 23:07:02 -08007# Generate test keys for use by the tests.
8
Gaurav Shah445925f2010-03-19 16:19:09 -07009# Load common constants and variables.
10. "$(dirname "$0")/common.sh"
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080011
vbendeba222fbc2010-09-29 20:25:29 -070012set -e
13
vbendeba222fbc2010-09-29 20:25:29 -070014sha_types=( 1 256 512 )
15
16# Generate RSA test keys of various lengths.
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080017function generate_keys {
vbendeba222fbc2010-09-29 20:25:29 -070018 key_index=0
19 key_name_base="${TESTKEY_DIR}/key_rsa"
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080020 for i in ${key_lengths[@]}
21 do
vbendeba222fbc2010-09-29 20:25:29 -070022 key_base="${key_name_base}${i}"
23 if [ -f "${key_base}.keyb" ]; then
vbendeb70e95092010-06-14 15:41:27 -070024 continue
25 fi
vbendeba222fbc2010-09-29 20:25:29 -070026
27 openssl genrsa -F4 -out ${key_base}.pem $i
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080028 # Generate self-signed certificate from key.
vbendeba222fbc2010-09-29 20:25:29 -070029 openssl req -batch -new -x509 -key ${key_base}.pem \
30 -out ${key_base}.crt
31
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080032 # Generate pre-processed key for use by RSA signature verification code.
Bill Richardson3e3790d2014-07-14 15:05:54 -070033 ${BIN_DIR}/dumpRSAPublicKey -cert ${key_base}.crt \
vbendeba222fbc2010-09-29 20:25:29 -070034 > ${key_base}.keyb
35
36 alg_index=0
37 for sha_type in ${sha_types[@]}
38 do
39 alg=$((${key_index} * 3 + ${alg_index}))
40 # wrap the public key
Bill Richardsona1d9fe62014-09-05 12:52:27 -070041 ${FUTILITY} vbutil_key \
vbendeba222fbc2010-09-29 20:25:29 -070042 --pack "${key_base}.sha${sha_type}.vbpubk" \
43 --key "${key_base}.keyb" \
44 --version 1 \
45 --algorithm ${alg}
46
47 # wrap the private key
Bill Richardsona1d9fe62014-09-05 12:52:27 -070048 ${FUTILITY} vbutil_key \
vbendeba222fbc2010-09-29 20:25:29 -070049 --pack "${key_base}.sha${sha_type}.vbprivk" \
50 --key "${key_base}.pem" \
51 --algorithm ${alg}
52 alg_index=$((${alg_index} + 1))
53 done
54 key_index=$((${key_index} + 1))
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080055 done
56}
57
Gaurav Shah445925f2010-03-19 16:19:09 -070058mkdir -p ${TESTKEY_DIR}
Gaurav Shahe3ef9c92010-02-10 23:07:02 -080059generate_keys