blob: 8668ba9da31537ce25529321120f9de3bb164183 [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
Brandon Kim0547cc42021-07-20 15:59:47 -070025SIGNATURE_FILE=/tmp/bmc.sig
26STATUS_FILE=/tmp/bmc.verify
27
28# Store in /run/initramfs because the behaviour of mv changes
29# depending on whether the file is moving within a tree or not.
30IMAGE_FILE=/run/initramfs/bmc-image
31VERIFIED_FILE=/run/initramfs/image-bmc
32
33# Make sure we run ERR traps when a function returns an error
34set -e
35
36# Write out the result of the script to a status file upon exiting
37# normally or due to an error
38exit_handler() {
39 local status="$?"
40 if (( status == 0 )); then
41 echo "success" >"${STATUS_FILE}"
42 else
43 echo "failed" >"${STATUS_FILE}"
44 fi
45 trap - EXIT ERR
46 exit "$status"
47}
48trap exit_handler EXIT ERR
49
50echo "running" > ${STATUS_FILE}
51
52# Verify the image.
53verify-bmc-image.sh @ALLOW_DEV@ "$IMAGE_FILE" "$SIGNATURE_FILE" || exit
54
55# Rename the staged file for initramfs updates.
Vivekanand Veeracholanef9ee092021-08-18 17:38:32 -070056mv ${IMAGE_FILE} ${VERIFIED_FILE}