summaryrefslogtreecommitdiff
path: root/tests/gen_test_keys.sh
blob: edc3d204af4677da59a7a8b2e052f11e5edea084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/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"

# Generate RSA test keys of various lengths. 
function generate_keys {
  for i in ${key_lengths[@]}
  do
    if [ -f ${TESTKEY_DIR}/key_rsa$i.keyb ]; then
      continue
    fi
    openssl genrsa -F4 -out ${TESTKEY_DIR}/key_rsa$i.pem $i
    # Generate self-signed certificate from key.
    openssl req -batch -new -x509 -key ${TESTKEY_DIR}/key_rsa$i.pem \
      -out ${TESTKEY_DIR}/key_rsa$i.crt
    # Generate pre-processed key for use by RSA signature verification code.
    ${UTIL_DIR}/dumpRSAPublicKey ${TESTKEY_DIR}/key_rsa$i.crt \
      > ${TESTKEY_DIR}/key_rsa$i.keyb
  done
}

mkdir -p ${TESTKEY_DIR}
generate_keys