Skip to content

Instantly share code, notes, and snippets.

@frostschutz
Last active January 12, 2019 12:59
Show Gist options
  • Save frostschutz/ca44c333887490ab3dcf2a3cd83c78fe to your computer and use it in GitHub Desktop.
Save frostschutz/ca44c333887490ab3dcf2a3cd83c78fe to your computer and use it in GitHub Desktop.
ArchLinux self-decrypting server keygen hook
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