Brandon Kim | 0547cc4 | 2021-07-20 15:59:47 -0700 | [diff] [blame] | 1 | #!/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 | |
| 25 | KEYRING=/etc/googlekeys/gbmc/gbmc.gpg |
| 26 | SIGNATURE_FILE=/tmp/bmc.sig |
| 27 | STATUS_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. |
| 31 | IMAGE_FILE=/run/initramfs/bmc-image |
| 32 | VERIFIED_FILE=/run/initramfs/image-bmc |
| 33 | |
| 34 | # Make sure we run ERR traps when a function returns an error |
| 35 | set -e |
| 36 | |
| 37 | # Write out the result of the script to a status file upon exiting |
| 38 | # normally or due to an error |
| 39 | exit_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 | } |
| 49 | trap exit_handler EXIT ERR |
| 50 | |
| 51 | echo "running" > ${STATUS_FILE} |
| 52 | |
| 53 | # Verify the image. |
| 54 | verify-bmc-image.sh @ALLOW_DEV@ "$IMAGE_FILE" "$SIGNATURE_FILE" || exit |
| 55 | |
| 56 | # Rename the staged file for initramfs updates. |
| 57 | mv ${IMAGE_FILE} ${VERIFIED_FILE}#!/bin/bash |