Files
OpenCellular/scripts/keygeneration/accessory/common_leverage_hammer.sh
Marco Chen e0a9a13c82 Add a script to generate a keypair for signing Staff RW firmware.
Staff decided to leverage the key format of Hammer therefore this
script calls Hammer's one to generate a key pair and renames them to
key_staff*.

BUG=b:66889892
TEST=Run this script in the chroot and verify the generated key pair.
BRANCH=None

Change-Id: I73162efaba47a8c08336805130ced0be25ab262a
Reviewed-on: https://chromium-review.googlesource.com/688522
Commit-Ready: Marco Chen <marcochen@chromium.org>
Tested-by: Marco Chen <marcochen@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2017-10-03 08:16:14 -07:00

70 lines
1.5 KiB
Bash

#!/bin/bash
# Copyright 2017 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.
# Load common constants and functions.
. "$(dirname "$0")/../common.sh"
usage() {
cat <<EOF
Usage: ${PROG} [options]
Options:
-o, --output_dir <dir>: Where to write the keys (default is cwd)
EOF
if [[ $# -ne 0 ]]; then
die "$*"
else
exit 0
fi
}
generate_rsa3072_exp3_key() {
local output_dir="$1"
local key_name="$2"
# Generate RSA key.
openssl genrsa -3 -out "${output_dir}/temp.pem" 3072
# Create a keypair from an RSA .pem file generated above.
futility create "${output_dir}/temp.pem" "${output_dir}/key_${key_name}"
# Best attempt to securely delete the temp.pem file.
shred --remove "${output_dir}/temp.pem"
}
# To generate a keypair with the same algorithm of Hammer and rename the kepair
# to specific accessory's name.
leverage_hammer_to_create_key() {
local output_dir="${PWD}"
local key_name="$1"
shift
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
;;
-o|--output_dir)
output_dir="$2"
if [[ ! -d "${output_dir}" ]]; then
die "output dir ("${output_dir}") doesn't exist."
fi
shift
;;
-*)
usage "Unknown option: "$1""
;;
*)
usage "Unknown argument "$1""
;;
esac
shift
done
generate_rsa3072_exp3_key "${output_dir}" "${key_name}"
}