summaryrefslogtreecommitdiff
path: root/scripts/keygeneration
diff options
context:
space:
mode:
authorGaurav Shah <gauravsh@chromium.org>2011-03-02 14:50:46 -0800
committerGaurav Shah <gauravsh@chromium.org>2011-03-02 14:50:46 -0800
commit574684550064ab5ea4adcfd1b8d2c9ce92a0176b (patch)
treef929ef1f1949d30c5fd3a850ccdf1398806c9b70 /scripts/keygeneration
parent340335447f83532228bf388dba50e43595cc2e55 (diff)
downloadvboot-574684550064ab5ea4adcfd1b8d2c9ce92a0176b.tar.gz
Add support for using separate developer firmware keyblock while signing.
Also re-factor the key generation script to its own directory, including wrappers for generating key pairs and keyblocks without needing to start keyset generation process from scratch. (Useful for generating new kernel keyblocks, and for retroactively adding new keys to an existing keyset - as in this case). Finally, change hard coded algorithm ids and keyblock modes to bash variables, for each changes and telling keyset configuration from a glance. BUG=chrome-os-partner:2218 TEST=manually tried the following: 1) Generating an entire new keyset. 2) Generating a new key pair and creating a keyblock from an existing key (for generating dev firmware keyblock for existing PVT keysets) 3) Firmware signing via sign_official_build.sh of an image with a firmware payload/ Change-Id: I4e9bb96ac7e5fe4cc0d95af6162ad6d37bbd4bda Review URL: http://codereview.chromium.org/6594131
Diffstat (limited to 'scripts/keygeneration')
-rwxr-xr-xscripts/keygeneration/common.sh92
-rwxr-xr-xscripts/keygeneration/create_new_keys.sh65
-rwxr-xr-xscripts/keygeneration/make_keyblock.sh27
-rwxr-xr-xscripts/keygeneration/make_pair.sh23
4 files changed, 207 insertions, 0 deletions
diff --git a/scripts/keygeneration/common.sh b/scripts/keygeneration/common.sh
new file mode 100755
index 00000000..0e1a6dfd
--- /dev/null
+++ b/scripts/keygeneration/common.sh
@@ -0,0 +1,92 @@
+#!/bin/bash
+# Copyright (c) 2011 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.
+
+# Common key generation functions.
+
+SCRIPT_DIR="$(dirname "$0")"
+
+# 0 = (RSA1024 SHA1)
+# 1 = (RSA1024 SHA256)
+# 2 = (RSA1024 SHA512)
+# 3 = (RSA2048 SHA1)
+# 4 = (RSA2048 SHA256)
+# 5 = (RSA2048 SHA512)
+# 6 = (RSA4096 SHA1)
+# 7 = (RSA4096 SHA256)
+# 8 = (RSA4096 SHA512)
+# 9 = (RSA8192 SHA1)
+# 10 = (RSA8192 SHA256)
+# 11 = (RSA8192 SHA512)
+function alg_to_keylen {
+ echo $(( 1 << (10 + ($1 / 3)) ))
+}
+
+# Emit .vbpubk and .vbprivk using given basename and algorithm
+# NOTE: This function also appears in ../../utility/dev_make_keypair. Making
+# the two implementations the same would require some common.sh, which is more
+# likely to cause problems than just keeping an eye out for any differences. If
+# you feel the need to change this file, check the history of that other file
+# to see what may need updating here too.
+function make_pair {
+ local base=$1
+ local alg=$2
+ local len=$(alg_to_keylen $alg)
+
+ echo "creating $base keypair..."
+
+ # make the RSA keypair
+ openssl genrsa -F4 -out "${base}_${len}.pem" $len
+ # create a self-signed certificate
+ openssl req -batch -new -x509 -key "${base}_${len}.pem" \
+ -out "${base}_${len}.crt"
+ # generate pre-processed RSA public key
+ dumpRSAPublicKey -cert "${base}_${len}.crt" > "${base}_${len}.keyb"
+
+ # wrap the public key
+ vbutil_key \
+ --pack "${base}.vbpubk" \
+ --key "${base}_${len}.keyb" \
+ --version 1 \
+ --algorithm $alg
+
+ # wrap the private key
+ vbutil_key \
+ --pack "${base}.vbprivk" \
+ --key "${base}_${len}.pem" \
+ --algorithm $alg
+
+ # remove intermediate files
+ rm -f "${base}_${len}.pem" "${base}_${len}.crt" "${base}_${len}.keyb"
+}
+
+
+# Emit a .keyblock containing flags and a public key, signed by a private key
+# flags are the bitwise OR of these (passed in decimal, though)
+# 0x01 Developer switch off
+# 0x02 Developer switch on
+# 0x04 Not recovery mode
+# 0x08 Recovery mode
+function make_keyblock {
+ local base=$1
+ local flags=$2
+ local pubkey=$3
+ local signkey=$4
+
+ echo "creating $base keyblock..."
+
+ # create it
+ vbutil_keyblock \
+ --pack "${base}.keyblock" \
+ --flags $flags \
+ --datapubkey "${pubkey}.vbpubk" \
+ --signprivate "${signkey}.vbprivk"
+
+ # verify it
+ vbutil_keyblock \
+ --unpack "${base}.keyblock" \
+ --signpubkey "${signkey}.vbpubk"
+}
+
+
diff --git a/scripts/keygeneration/create_new_keys.sh b/scripts/keygeneration/create_new_keys.sh
new file mode 100755
index 00000000..d39dd6ee
--- /dev/null
+++ b/scripts/keygeneration/create_new_keys.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# Copyright (c) 2011 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 .vbpubk and .vbprivk pairs for use by developer builds. These should
+# be exactly like the real keys except that the private keys aren't secret.
+
+# Load common constants and functions.
+. "$(dirname "$0")/common.sh"
+
+# Mapping are in common.sh.
+ROOT_KEY_ALGOID=11
+RECOVERY_KEY_ALGOID=11
+
+FIRMWARE_DATAKEY_ALGOID=7
+DEV_FIRMWARE_DATAKEY_ALGOID=7
+
+RECOVERY_KERNEL_ALGOID=11
+INSTALLER_KERNEL_ALGOID=11
+KERNEL_SUBKEY_ALGOID=7
+KERNEL_DATAKEY_ALGOID=4
+
+# Keyblock modes determine which boot modes a signing key is valid for use
+# in verification.
+FIRMWARE_KEYBLOCK_MODE=7
+DEV_FIRMWARE_KEYBLOCK_MODE=6 # Only allow in dev mode.
+RECOVERY_KERNEL_KEYBLOCK_MODE=11
+KERNEL_KEYBLOCK_MODE=7 # Only allow in non-recovery.
+INSTALLER_KERNEL_KEYBLOCK_MODE=10 # Only allow in Dev + Recovery.
+
+# Create the normal keypairs
+make_pair root_key $ROOT_KEY_ALGOID
+make_pair firmware_data_key $FIRMWARE_DATAKEY_ALGOID
+make_pair dev_firmware_data_key $DEV_FIRMWARE_DATAKEY_ALGOID
+make_pair kernel_subkey $KERNEL_SUBKEY_ALGOID
+make_pair kernel_data_key $KERNEL_DATAKEY_ALGOID
+
+# Create the recovery and factory installer keypairs
+make_pair recovery_key $RECOVERY_KEY_ALGOID
+make_pair recovery_kernel_data_key $RECOVERY_KERNEL_ALGOID
+make_pair installer_kernel_data_key $INSTALLER_KERNEL_ALGOID
+
+# Create the firmware keyblock for use only in Normal mode. This is redundant,
+# since it's never even checked during Recovery mode.
+make_keyblock firmware $FIRMWARE_KEYBLOCK_MODE firmware_data_key root_key
+
+# Create the dev firmware keyblock for use only in Developer mode.
+make_keyblock dev_firmware $DEV_FIRMWARE_KEYBLOCK_MODE dev_firmware_data_key root_key
+
+# Create the recovery kernel keyblock for use only in Recovery mode.
+make_keyblock recovery_kernel $RECOVERY_KERNEL_KEYBLOCK_MODE recovery_kernel_data_key recovery_key
+
+# Create the normal kernel keyblock for use only in Normal mode.
+make_keyblock kernel $KERNEL_KEYBLOCK_MODE kernel_data_key kernel_subkey
+
+# Create the installer keyblock for use in Developer + Recovery mode
+# For use in Factory Install and Developer Mode install shims.
+make_keyblock installer_kernel $INSTALLER_KERNEL_KEYBLOCK_MODE installer_kernel_data_key recovery_key
+
+# CAUTION: The public parts of most of these blobs must be compiled into the
+# firmware, which is built separately (and some of which can't be changed after
+# manufacturing). If you update these keys, you must coordinate the changes
+# with the BIOS people or you'll be unable to boot the resulting images.
+
diff --git a/scripts/keygeneration/make_keyblock.sh b/scripts/keygeneration/make_keyblock.sh
new file mode 100755
index 00000000..565a566c
--- /dev/null
+++ b/scripts/keygeneration/make_keyblock.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+# Copyright (c) 2011 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.
+#
+# Generates a keyblock containing a public key and signed using the given
+# signing key.
+
+# Load common constants and functions.
+. "$(dirname "$0")/common.sh"
+
+if [ $# -ne 4 ]; then
+ cat <<EOF
+Usage: $0 <in_public_key> <in_signing_key> <flags> <out_keyblock>
+
+Emits <out_keyblock>.keyblock containing <in_public_key>.vbpubk signed with
+<in_signing_key>.vbprivk with the given keyblock <flags>.
+EOF
+ exit 1
+fi
+
+in_pubkey=$1
+in_signkey=$2
+keyblock_flags=$3
+out_keyblock=$4
+
+make_keyblock $out_keyblock $keyblock_flags $in_pubkey $in_signkey
diff --git a/scripts/keygeneration/make_pair.sh b/scripts/keygeneration/make_pair.sh
new file mode 100755
index 00000000..cd5d0c10
--- /dev/null
+++ b/scripts/keygeneration/make_pair.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Copyright (c) 2011 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 .vbpubk and .vbprivk pairs with the given algorithm id.
+
+# Load common constants and functions.
+. "$(dirname "$0")/common.sh"
+
+if [ $# -ne 2 ]; then
+ cat <<EOF
+Usage: $0 <algoid> <out_keypair>
+
+Output: <out_keypair>.vbprivk and <out_keypair>.vbpubk
+EOF
+ exit 1
+fi
+
+algoid=$1
+out_keypair=$2
+
+make_pair $out_keypair $algoid