xref: /aosp_15_r20/external/vboot_reference/scripts/image_signing/insert_au_publickey.sh (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1#!/bin/bash
2
3# Copyright 2011 The ChromiumOS Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Install an update payload verification public key to the image.
8
9# Load common constants and variables.
10. "$(dirname "$0")/common.sh"
11
12main() {
13  set -e
14
15  local image="$1"
16  local pub_key="$2"
17  if [ $# -ne 2 ]; then
18    cat <<EOF
19Usage: $PROG <image.bin> <au_public_key.pem>
20Installs the update verification public key <au_public_key.pem> to <image.bin>.
21EOF
22    exit 1
23  fi
24
25  local loopdev rootfs
26  if [[ -d "${image}" ]]; then
27    rootfs="${image}"
28  else
29    rootfs=$(make_temp_dir)
30    loopdev=$(loopback_partscan "${image}")
31    mount_loop_image_partition "${loopdev}" 3 "${rootfs}"
32  fi
33
34  local key_location="/usr/share/update_engine/"
35  sudo mkdir -p "$rootfs/$key_location"
36  sudo cp "$pub_key" "$rootfs/$key_location/update-payload-key.pub.pem"
37  sudo chown root:root "$rootfs/$key_location/update-payload-key.pub.pem"
38  sudo chmod 644 "$rootfs/$key_location/update-payload-key.pub.pem"
39  echo "AU verification key was installed. Do not forget to resign the image!"
40}
41
42main "$@"
43