Last active
January 12, 2019 12:59
-
-
Save frostschutz/ca44c333887490ab3dcf2a3cd83c78fe to your computer and use it in GitHub Desktop.
ArchLinux self-decrypting server keygen hook
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
HOOKS="... keygen encrypt ..." | |
# /etc/initcpio/hooks/keygen | |
LUKS="/dev/sdxy" | |
run_hook() { | |
# Produce key without newlines. | |
echo -n $( | |
( | |
cat /sys/class/net/*/address | |
tail /proc/iomem | |
grep -vE '(MHz|bogomips)' /proc/cpuinfo | |
grep -v sr0 /proc/partitions | |
cat /root/secret | |
) | sha512sum | |
) > /crypto_keyfile.bin | |
# Reset key. (if applicable) | |
# TODO: Find a stable alternative to /proc/iomem | |
echo -n $(sha512sum /root/secret) | cryptsetup --iter-time=5000 luksChangeKey /dev/"$LUKS" /crypto_keyfile.bin | |
} | |
# /etc/initcpio/install/keygen | |
build() { | |
add_file "/root/secret" | |
add_runscript | |
} | |
help() { | |
cat <<HELPEOF | |
Self-Decrypting Server | |
https://wiki.gentoo.org/wiki/Custom_Initramfs/Examples#Self-Decrypting_Server | |
HELPEOF | |
} | |
# reset-passphrase.sh | |
LUKS="/dev/sdxy" | |
cryptsetup luksAddKey /dev/"$LUKS" <(echo -n $(sha512sum /root/secret)) | |
cryptsetup luksKillSlot /dev/"$LUKS" 0 | |
# generate-secret.sh | |
dd if=/dev/urandom of=/root/secret count=64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment