-
Notifications
You must be signed in to change notification settings - Fork 197
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
New feature: bootloader signing #152
Open
pandom79
wants to merge
2
commits into
void-linux:master
Choose a base branch
from
pandom79:new-mklive
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,6 +32,7 @@ umask 022 | |||||
readonly REQUIRED_PKGS="base-files libgcc dash coreutils sed tar gawk syslinux grub-i386-efi grub-x86_64-efi squashfs-tools xorriso" | ||||||
readonly INITRAMFS_PKGS="binutils xz device-mapper dhclient dracut-network openresolv" | ||||||
readonly PROGNAME=$(basename "$0") | ||||||
toSign=0 | ||||||
|
||||||
info_msg() { | ||||||
printf "\033[1m$@\n\033[m" | ||||||
|
@@ -82,6 +83,8 @@ directory if unset). | |||||
-C "cmdline args" Add additional kernel command line arguments. | ||||||
-T "title" Modify the bootloader title. | ||||||
-v linux<version> Install a custom Linux version on ISO image (linux meta-package if unset). | ||||||
-d <key-file> Set a key file to sign bootloader. | ||||||
-t <cert-file> Set a certificate file to sign bootloader. | ||||||
-K Do not remove builddir. | ||||||
|
||||||
The $PROGNAME script generates a live image of the Void Linux distribution. | ||||||
|
@@ -190,6 +193,17 @@ generate_isolinux_boot() { | |||||
"$ISOLINUX_DIR"/isolinux.cfg | ||||||
} | ||||||
|
||||||
dosign() { | ||||||
print_step "Signing $2..." | ||||||
|
||||||
if ! sbsign --key "$DBKEY" --cert "$DBCRT" --output "$1.signed" "$1"; then | ||||||
die "Failed to sign $2" | ||||||
fi | ||||||
if ! sbverify --cert "$DBCRT" "$1.signed"; then | ||||||
die "failed to verify the signature" | ||||||
fi | ||||||
} | ||||||
|
||||||
generate_grub_efi_boot() { | ||||||
cp -f grub/grub.cfg "$GRUB_DIR" | ||||||
cp -f grub/grub_void.cfg.in "$GRUB_DIR"/grub_void.cfg | ||||||
|
@@ -226,6 +240,12 @@ generate_grub_efi_boot() { | |||||
fi | ||||||
mkdir -p "${GRUB_EFI_TMPDIR}"/EFI/BOOT | ||||||
cp -f "$VOIDHOSTDIR"/tmp/bootia32.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTIA32.EFI | ||||||
|
||||||
#Bootloader signing | ||||||
if [ $toSign -eq 1 ] && [ -f "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX32.EFI ]; then | ||||||
dosign "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX32.EFI BOOTX32.EFI | ||||||
fi | ||||||
|
||||||
xbps-uchroot "$VOIDHOSTDIR" grub-mkstandalone -- \ | ||||||
--directory="/usr/lib/grub/x86_64-efi" \ | ||||||
--format="x86_64-efi" \ | ||||||
|
@@ -237,6 +257,12 @@ generate_grub_efi_boot() { | |||||
die "Failed to generate EFI loader" | ||||||
fi | ||||||
cp -f "$VOIDHOSTDIR"/tmp/bootx64.efi "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI | ||||||
|
||||||
#Bootloader signing | ||||||
if [ $toSign -eq 1 ] && [ -f "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI ]; then | ||||||
dosign "${GRUB_EFI_TMPDIR}"/EFI/BOOT/BOOTX64.EFI BOOTX64.EFI | ||||||
fi | ||||||
|
||||||
umount "$GRUB_EFI_TMPDIR" | ||||||
losetup --detach "${LOOP_DEVICE}" | ||||||
rm -rf "$GRUB_EFI_TMPDIR" | ||||||
|
@@ -282,7 +308,7 @@ generate_iso_image() { | |||||
# | ||||||
# main() | ||||||
# | ||||||
while getopts "a:b:r:c:C:T:Kk:l:i:I:s:o:p:v:h" opt; do | ||||||
while getopts "a:b:r:c:C:T:Kk:l:i:I:s:S:o:p:v:d:t:h" opt; do | ||||||
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.
Suggested change
Sorry! I have removed the |
||||||
case $opt in | ||||||
a) BASE_ARCH="$OPTARG";; | ||||||
b) BASE_SYSTEM_PKG="$OPTARG";; | ||||||
|
@@ -299,6 +325,8 @@ while getopts "a:b:r:c:C:T:Kk:l:i:I:s:o:p:v:h" opt; do | |||||
C) BOOT_CMDLINE="$OPTARG";; | ||||||
T) BOOT_TITLE="$OPTARG";; | ||||||
v) LINUX_VERSION="$OPTARG";; | ||||||
d) DBKEY="$OPTARG";; | ||||||
t) DBCRT="$OPTARG";; | ||||||
h) usage;; | ||||||
*) usage;; | ||||||
esac | ||||||
|
@@ -329,6 +357,22 @@ if [ "$(id -u)" -ne 0 ]; then | |||||
die "Must be run as root, exiting..." | ||||||
fi | ||||||
|
||||||
#The -d and -t options are complementary. If one exists, the other must also exist. | ||||||
#If these options are set, I also check sbsign command. | ||||||
if ([ $DBKEY ] && [ ! $DBCRT ]) || ([ ! $DBKEY ] && [ $DBCRT ]); then | ||||||
die "Must be set a key and certificate via -d and -t option, exiting..." | ||||||
elif [ $DBKEY ] && [ $DBCRT ]; then | ||||||
if [ ! -f $DBKEY ]; then | ||||||
die "$DBKEY does not exist, exiting..." | ||||||
elif [ ! -f $DBCRT ]; then | ||||||
die "$DBCRT does not exist, exiting..." | ||||||
elif ! command -v sbsign > /dev/null; then | ||||||
die "sbsign command does not exist, exiting..." | ||||||
else | ||||||
toSign=1 | ||||||
fi | ||||||
fi | ||||||
|
||||||
if [ -n "$ROOTDIR" ]; then | ||||||
BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d) | ||||||
else | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
d
andt
? Is it because they're random characters that still available?