-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
ujust setup-luks-tpm-unlock
chore: justfile cleanup
- Loading branch information
Showing
7 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
system_files/desktop/shared/usr/libexec/luks-enable-tpm2-autounlock
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
## setup auto-unlock LUKS2 encrypted root on Fedora/Silverblue/maybe others | ||
## From https://github.com/bsherman/ublue-custom/blob/main/usr/bin/luks-enable-tpm2-autounlock | ||
set -u | ||
|
||
[ "$UID" -eq 0 ] || { echo "This script must be run as root."; exit 1;} | ||
|
||
read -p "This will modify your system and enable TPM2 auto-unlock of your LUKS partition! Are you sure you've read the script and are good with this? " -n 1 -r | ||
echo | ||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | ||
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell | ||
fi | ||
|
||
## Inspect crypttab to find disk info, should look like this | ||
#sudo cat /etc/crypttab | ||
#luks-912462a2-39ce-abcd-1234-89c6c0304cb4 UUID=912462a2-39ce-abcd-1234-89c6c0304cb4 none discard | ||
DISK_UUID=$(sudo awk '{ print $2 }' /etc/crypttab | cut -d= -f2) | ||
CRYPT_DISK="/dev/disk/by-uuid/$DISK_UUID" | ||
|
||
## Backup the crypttab | ||
if [ -f /etc/crypttab.known-good ]; then | ||
echo "Our backup already exists at /etc/crypttab.known-good\nExiting..." | ||
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 | ||
fi | ||
cp -a /etc/crypttab /etc/crypttab.known-good | ||
|
||
## modify the crypttab | ||
grep tpm2-device /etc/crypttab > /dev/null | ||
if [ 0 -eq $? ]; then | ||
echo "TPM2 already present in /etc/crypttab. Exiting..." | ||
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 | ||
fi | ||
sed -i "s/discard/discard,tpm2-device=auto/" /etc/crypttab | ||
|
||
cryptsetup luksDump $CRYPT_DISK | grep systemd-tpm2 > /dev/null | ||
if [ 0 -eq $? ]; then | ||
KEYSLOT=$(cryptsetup luksDump $CRYPT_DISK|grep -A23 systemd-tpm2|grep Keyslot|awk '{print $2}') | ||
echo "TPM2 already present in LUKS Keyslot $KEYSLOT of $CRYPT_DISK. Exiting..." | ||
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 | ||
fi | ||
|
||
## Run crypt enroll | ||
echo "Enrolling TPM2 unlock requires your existing LUKS2 unlock password" | ||
echo | ||
systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 $CRYPT_DISK | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
## Now reboot | ||
echo | ||
echo "TPM2 LUKS auto-unlock configured. Reboot now." | ||
|
||
|
||
# References: | ||
# https://www.reddit.com/r/Fedora/comments/uo4ufq/any_way_to_get_systemdcryptenroll_working_on/ | ||
# https://0pointer.net/blog/unlocking-luks2-volumes-with-tpm2-fido2-pkcs11-security-hardware-on-systemd-248.html |
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
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
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
Is there a reason that PCR 8 was not included in here ?