sonic-buildimage/installer/sharch_body.sh
mssonicbld 43585c3326
Add support for secure upgrade (#11862) (#15691)
- What I did
Added support for secure upgrade.

- How I did it
During sonic_installer install, added secure upgrade image verification.
HLD can be found in the following PR: sonic-net/SONiC#1024

- Why I did it
Feature is used to allow image was not modified since built from vendor. During installation, image can be verified with a signature attached to it.

- How I did it
Feature includes image signing during build (in sonic buildimage repo) and verification during image install (in sonic-utilities).

- How to verify it
In order for image verification - image must be signed - need to provide signing key and certificate (paths in SECURE_UPGRADE_DEV_SIGNING_KEY and SECURE_UPGRADE_DEV_SIGNING_CERT in rules/config) during build , and during image install, need to enable secure boot flag in bios, and signing_certificate should be available in bios.

- Feature dependencies
In order for this feature to work smoothly, need to have secure boot feature implemented as well.
The Secure boot feature will be merged in the near future.

Co-authored-by: ycoheNvidia <99744138+ycoheNvidia@users.noreply.github.com>
2023-07-19 16:08:14 +08:00

75 lines
2.0 KiB
Bash

#!/bin/sh
# Copyright (C) 2013 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0
##
## Shell archive template
##
## Strings of the form %%VAR%% are replaced during construction.
##
echo -n "Verifying image checksum ..."
payload_image_size=%%PAYLOAD_IMAGE_SIZE%%
sha1=$(sed -e '1,/^exit_marker$/d' "$0" | head -c $payload_image_size | sha1sum | awk '{ print $1 }')
payload_sha1=%%IMAGE_SHA1%%
if [ "$sha1" != "$payload_sha1" ] ; then
echo
echo "ERROR: Unable to verify archive checksum"
echo "Expected: $payload_sha1"
echo "Found : $sha1"
exit 1
fi
echo " OK."
image_size_in_kb=$((($(sed -e '1,/^exit_marker$/d' "$0" | tar --to-stdout -xf - | wc -c) + 1023 ) / 1024))
# Untar and launch install script in a tmpfs
cur_wd=$(pwd)
export cur_wd
archive_path=$(realpath "$0")
tmp_dir=$(mktemp -d)
if [ "$(id -u)" = "0" ] ; then
mount -t tmpfs tmpfs-installer $tmp_dir || exit 1
mount_size_in_kb=$(df $tmp_dir | tail -1 | tr -s ' ' | cut -d' ' -f4)
#checking extra 100KB space in tmp_dir, after image extraction
padding=102400
if [ "$mount_size_in_kb" -le "$((image_size_in_kb + padding))" ]; then
image_size_in_mb=$(((image_size_in_kb + 1023) / 1024))
#Adding extra 32MB free space for image extraction.
mount_size_in_mb=$((((image_size_in_mb + 31) / 32) * 32))
mount -o remount,size="${mount_size_in_mb}M" -t tmpfs tmpfs-installer $tmp_dir || exit 1
fi
fi
cd $tmp_dir
echo -n "Preparing image archive ..."
sed -e '1,/^exit_marker$/d' $archive_path | head -c $payload_image_size | tar xf - || exit 1
echo " OK."
cd $cur_wd
if [ -n "$extract" ] ; then
# stop here
echo "Image extracted to: $tmp_dir"
if [ "$(id -u)" = "0" ] && [ ! -d "$extract" ] ; then
echo "To un-mount the tmpfs when finished type: umount $tmp_dir"
fi
exit 0
fi
$tmp_dir/installer/install.sh
rc="$?"
# clean up
if [ "$(id -u)" = "0" ] ; then
umount $tmp_dir
fi
rm -rf $tmp_dir
exit $rc
exit_marker