Files
OpenCellular/tests/gen_test_keys.sh
Gaurav Shah 551037b10e Make dumpRSAPublicKey also accept a public key in PEM format
This change makes dumpRSAPublicKey directly accept a public key in PEM format. This makes it possible to avoid the unnecessary step of generating a self-signed certificate to dump the public key in .keyb format.

The old style certificate input is still accepted.

Using certs (as done previously):
dumpRSAPublicKey -cert <certfile>

Directly using public keys:
dumpRSAPublicKey -pub <pubfile>

Change-Id: Ic35b59aff6613d145d7947212650da281f734b74

BUG=7576
TEST=manual

$ openssl genrsa -F4 -out test.pem 4096
$ openssl rsa -in test.pem -out test.pub
$ dumpRSAPublicKey -pub test.pub >test.pub.keyb

Verify that this matches the output we get using the old style <cert> input.

$ openssl req -batch -new -x509 -key test.pem -out test.cert
$ dumpRSAPublicKey -cert test.cert >test.cert.keyb
$ diff test.pub.keyb test.cert.keyb
$

Review URL: http://codereview.chromium.org/4215006
2010-11-01 13:33:32 -07:00

62 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Generate test keys for use by the tests.
# Load common constants and variables.
. "$(dirname "$0")/common.sh"
set -e
PATH="$(dirname "$0")/../build/utility:${PATH}"
sha_types=( 1 256 512 )
# Generate RSA test keys of various lengths.
function generate_keys {
key_index=0
key_name_base="${TESTKEY_DIR}/key_rsa"
for i in ${key_lengths[@]}
do
key_base="${key_name_base}${i}"
if [ -f "${key_base}.keyb" ]; then
continue
fi
openssl genrsa -F4 -out ${key_base}.pem $i
# Generate self-signed certificate from key.
openssl req -batch -new -x509 -key ${key_base}.pem \
-out ${key_base}.crt
# Generate pre-processed key for use by RSA signature verification code.
${UTIL_DIR}/dumpRSAPublicKey -cert ${key_base}.crt \
> ${key_base}.keyb
alg_index=0
for sha_type in ${sha_types[@]}
do
alg=$((${key_index} * 3 + ${alg_index}))
# wrap the public key
vbutil_key \
--pack "${key_base}.sha${sha_type}.vbpubk" \
--key "${key_base}.keyb" \
--version 1 \
--algorithm ${alg}
# wrap the private key
vbutil_key \
--pack "${key_base}.sha${sha_type}.vbprivk" \
--key "${key_base}.pem" \
--algorithm ${alg}
alg_index=$((${alg_index} + 1))
done
key_index=$((${key_index} + 1))
done
}
mkdir -p ${TESTKEY_DIR}
generate_keys