Skip to content

Commit

Permalink
feat: Add notification for secure boot key check
Browse files Browse the repository at this point in the history
- Add script to check for sb enabled and key registration
- Add systemd service to run script and notify
  • Loading branch information
jardon committed Sep 10, 2024
1 parent 0b49d5c commit 4f3bbac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions build_files/systemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ systemctl enable brew-upgrade.timer
systemctl enable brew-update.timer
systemctl --global enable ublue-user-setup.service
systemctl --global enable podman-auto-update.timer
systemctl enable sb-key-notify.service
15 changes: 15 additions & 0 deletions system_files/shared/usr/bin/check-sb-key
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

FINGERPRINT="2B:E9:91:E3:B1:B5:40:70:F4:3D:80:BB:13:EB:C6:57:E5:A3:78:0D"
mokutil --list-enrolled | grep -q $FINGERPRINT
ENROLLED=$?
mokutil --sb-state | grep -q enabled
SB_ENABLED=$?

if [[ $ENROLLED -eq 1 ]] && [[ $SB_ENABLED -eq 0 ]]; then
echo "Secure Boot enabled. Key missing..."
exit 1
fi

echo "No key enrollment needed at this time."
exit 0
12 changes: 12 additions & 0 deletions system_files/shared/usr/lib/systemd/system/sb-key-notify.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Service to check for secure boot key enrollment and send notifications

[Service]
ExecStart=/usr/libexec/sb-key-notify.service

[Install]
WantedBy=multi-user.target

[Timer]
OnBootSec=1min
OnUnitActiveSec=3h
15 changes: 15 additions & 0 deletions system_files/shared/usr/libexec/sb-key-notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
/usr/bin/check-sb-key > /dev/null

if [[ $? -eq 1 ]]; then
USER_ID=$(/usr/bin/loginctl list-users --output=json | jq -r '.[] | .user')
XDG_DIR=$(/usr/bin/loginctl show-user $USER_ID | grep RuntimePath | cut -c 13-)
/usr/bin/sudo -u \
$USER_ID DISPLAY=:0 \
DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_DIR/bus \
notify-send "WARNING" \
"This machine has secure boot turned on, but you haven't enrolled Universal Blue's keys. Failing to enroll these before rebooting may cause your system to fail to boot. Follow this link https://docs.projectbluefin.io/introduction#secure-boot for instructions on how to enroll the keys." \
-i dialog-warning \
-u critical \
-a mokutil \
--wait

0 comments on commit 4f3bbac

Please sign in to comment.