blob: e7727cd72945c8e71d0a467b643049f4efd4a620 [file] [log] [blame]
Brandon Kim0547cc42021-07-20 15:59:47 -07001#!/bin/bash
2# Copyright 2021 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17# This script will check the signature for the BMC image against
18# the baked in keyring available. If any aspect of this fails,
19# the scripts returns non-zero and this can be reported to the
20# host.
21#
22# 1. Verify the image
23# 2. Rename the image
24
25KEYRING=/etc/googlekeys/gbmc/gbmc.gpg
26SIGNATURE_FILE=/tmp/bmc.sig
27STATUS_FILE=/tmp/bmc.verify
28
29# Store in /run/initramfs because the behaviour of mv changes
30# depending on whether the file is moving within a tree or not.
31IMAGE_FILE=/run/initramfs/bmc-image
32VERIFIED_FILE=/run/initramfs/image-bmc
33
34# Make sure we run ERR traps when a function returns an error
35set -e
36
37# Write out the result of the script to a status file upon exiting
38# normally or due to an error
39exit_handler() {
40 local status="$?"
41 if (( status == 0 )); then
42 echo "success" >"${STATUS_FILE}"
43 else
44 echo "failed" >"${STATUS_FILE}"
45 fi
46 trap - EXIT ERR
47 exit "$status"
48}
49trap exit_handler EXIT ERR
50
51echo "running" > ${STATUS_FILE}
52
53# Verify the image.
54verify-bmc-image.sh @ALLOW_DEV@ "$IMAGE_FILE" "$SIGNATURE_FILE" || exit
55
56# Rename the staged file for initramfs updates.
Vivekanand Veeracholanef9ee092021-08-18 17:38:32 -070057mv ${IMAGE_FILE} ${VERIFIED_FILE}