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