-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Secure Boot Support #12692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Secure Boot Support #12692
Changes from all commits
e5a495a
2eb66bc
ddde4c7
73cda24
78bb260
29e619e
9f184b9
8758f69
2b40911
4108860
455ea5d
d54f1e8
7509fc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,7 +167,8 @@ if [[ $CONFIGURED_ARCH == amd64 ]]; then | |
| fi | ||
|
|
||
| ## Sign the Linux kernel | ||
| if [ "$SONIC_ENABLE_SECUREBOOT_SIGNATURE" = "y" ]; then | ||
| # note: when flag SONIC_ENABLE_SECUREBOOT_SIGNATURE is enabled the Secure Upgrade flags should be disabled (no_sign) to avoid conflict between the features. | ||
| if [ "$SONIC_ENABLE_SECUREBOOT_SIGNATURE" = "y" ] && [ "$SECURE_UPGRADE_MODE" != 'dev' ] && [ "$SECURE_UPGRADE_MODE" != "prod" ]; then | ||
| if [ ! -f $SIGNING_KEY ]; then | ||
| echo "Error: SONiC linux kernel signing key missing" | ||
| exit 1 | ||
|
|
@@ -631,6 +632,62 @@ then | |
|
|
||
| fi | ||
|
|
||
| # ################# | ||
| # secure boot | ||
| # ################# | ||
| if [[ $SECURE_UPGRADE_MODE == 'dev' || $SECURE_UPGRADE_MODE == "prod" && $SONIC_ENABLE_SECUREBOOT_SIGNATURE != 'y' ]]; then | ||
| # note: SONIC_ENABLE_SECUREBOOT_SIGNATURE is a feature that signing just kernel, | ||
| # SECURE_UPGRADE_MODE is signing all the boot component including kernel. | ||
| # its required to do not enable both features together to avoid conflicts. | ||
| echo "Secure Boot support build stage: Starting .." | ||
|
|
||
| # debian secure boot dependecies | ||
| sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install \ | ||
davidpil2002 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shim-unsigned \ | ||
| grub-efi | ||
|
|
||
| if [ ! -f $SECURE_UPGRADE_DEV_SIGNING_CERT ]; then | ||
| echo "Error: SONiC SECURE_UPGRADE_DEV_SIGNING_CERT=$SECURE_UPGRADE_DEV_SIGNING_CERT key missing" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ $SECURE_UPGRADE_MODE == 'dev' ]]; then | ||
| # development signing & verification | ||
|
|
||
| if [ ! -f $SECURE_UPGRADE_DEV_SIGNING_KEY ]; then | ||
| echo "Error: SONiC SECURE_UPGRADE_DEV_SIGNING_KEY=$SECURE_UPGRADE_DEV_SIGNING_KEY key missing" | ||
| exit 1 | ||
| fi | ||
|
|
||
| sudo ./scripts/signing_secure_boot_dev.sh -a $CONFIGURED_ARCH \ | ||
| -r $FILESYSTEM_ROOT \ | ||
| -l $LINUX_KERNEL_VERSION \ | ||
| -c $SECURE_UPGRADE_DEV_SIGNING_CERT \ | ||
| -p $SECURE_UPGRADE_DEV_SIGNING_KEY | ||
| elif [[ $SECURE_UPGRADE_MODE == "prod" ]]; then | ||
davidpil2002 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Here Vendor signing should be implemented | ||
| OUTPUT_SEC_BOOT_DIR=$FILESYSTEM_ROOT/boot | ||
|
|
||
| if [ ! -f $SECURE_UPGRADE_PROD_SIGNING_TOOL ]; then | ||
| echo "Error: SONiC SECURE_UPGRADE_PROD_SIGNING_TOOL=$SECURE_UPGRADE_PROD_SIGNING_TOOL script missing" | ||
| exit 1 | ||
| fi | ||
|
|
||
| sudo $SECURE_UPGRADE_PROD_SIGNING_TOOL $CONFIGURED_ARCH $FILESYSTEM_ROOT $LINUX_KERNEL_VERSION $OUTPUT_SEC_BOOT_DIR | ||
davidpil2002 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # verifying all EFI files and kernel modules in $OUTPUT_SEC_BOOT_DIR | ||
| sudo ./scripts/secure_boot_signature_verification.sh -e $OUTPUT_SEC_BOOT_DIR \ | ||
| -c $SECURE_UPGRADE_DEV_SIGNING_CERT \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In few words, when using DEV the flow is use an script inside the repo for the SECURE BOOT,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for responding! Yes I understand the difference between the two flows. To my understanding this is still in the PROD flow but we are still using |
||
| -k $FILESYSTEM_ROOT | ||
|
|
||
| # verifying vmlinuz file. | ||
| sudo ./scripts/secure_boot_signature_verification.sh -e $FILESYSTEM_ROOT/boot/vmlinuz-${LINUX_KERNEL_VERSION}-${CONFIGURED_ARCH} \ | ||
| -c $SECURE_UPGRADE_DEV_SIGNING_CERT \ | ||
| -k $FILESYSTEM_ROOT | ||
| fi | ||
| echo "Secure Boot support build stage: END." | ||
| fi | ||
|
|
||
| ## Update initramfs | ||
| sudo chroot $FILESYSTEM_ROOT update-initramfs -u | ||
| ## Convert initrd image to u-boot format | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -e | ||
|
|
||
| # | ||
| # Sign efi file with secret key and certificate | ||
| # - shim | ||
| # - grub | ||
| # - vmlinuz | ||
| # | ||
| print_usage() { | ||
| cat <<EOF | ||
|
|
||
| $0: Usage | ||
| $0 -p <PRIVATE_KEY_PEM> -c <CERT_PEM> -e <EFI_FILE> -s <EFI_FILE_SIGNED> | ||
| Usage example: efi-sign.sh -p priv-key.pem -c pub-key.pem -e shimx64.efi -s shimx64-signed.efi | ||
|
|
||
| EOF | ||
| } | ||
|
|
||
| while getopts 'p:c:e:s:hv' flag; do | ||
| case "${flag}" in | ||
| p) PRIVATE_KEY_PEM="${OPTARG}" ;; | ||
| c) CERT_PEM="${OPTARG}" ;; | ||
| e) EFI_FILE="${OPTARG}" ;; | ||
| s) EFI_FILE_SIGNED="${OPTARG}" ;; | ||
| v) VERBOSE='true' ;; | ||
| h) print_usage | ||
| exit 1 ;; | ||
| esac | ||
| done | ||
| if [ $OPTIND -eq 1 ]; then echo "no options were pass"; print_usage; exit 1 ;fi | ||
|
|
||
| [ -f "$PRIVATE_KEY_PEM" ] || { | ||
| echo "Error: PRIVATE_KEY_PEM file does not exist: $PRIVATE_KEY_PEM" | ||
| print_usage | ||
| exit 1 | ||
| } | ||
|
|
||
| [ -f "$CERT_PEM" ] || { | ||
| echo "Error: CERT_PEM file does not exist: $CERT_PEM" | ||
| print_usage | ||
| exit 1 | ||
| } | ||
|
|
||
| [ -f "$EFI_FILE" ] || { | ||
| echo "Error: File for signing does not exist: $EFI_FILE" | ||
| print_usage | ||
| exit 1 | ||
| } | ||
|
|
||
| if [ -z ${EFI_FILE_SIGNED} ]; then | ||
| echo "ERROR: no arg named <EFI_FILE_SIGNED> supplied" | ||
| print_usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "$0 signing $EFI_FILE with ${PRIVATE_KEY_PEM}, ${CERT_PEM} to create $EFI_FILE_SIGNED" | ||
| sbsign --key ${PRIVATE_KEY_PEM} --cert ${CERT_PEM} \ | ||
| --output ${EFI_FILE_SIGNED} ${EFI_FILE} || { | ||
| echo "EFI sign error" | ||
| exit 1 | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.