I wrote a keyscript (and initramfs hook) that allows a key to be retrieved by UUID over HTTPS.
1. Install dependencies:
sudo apt -y install curl initramfs-tools dropbear-initramfs
2. Add a initramfs hook:
sudo nano /usr/share/initramfs-tools/hooks/curl
Paste the following content:
#!/bin/sh -e
PREREQS=""
case $1 in
prereqs) echo "${PREREQS}"; exit 0;;
esac
. /usr/share/initramfs-tools/hook-functions
# copy curl binary
copy_exec /usr/bin/curl /bin
# fix DNS lib (needed for Debian 11)
cp -a /usr/lib/x86_64-linux-gnu/libnss_dns* $DESTDIR/usr/lib/x86_64-linux-gnu/
# fix DNS resolver (needed for Debian 11 + 12)
echo "nameserver 1.1.1.1\n" > ${DESTDIR}/etc/resolv.conf
# copy ca-certs for curl
mkdir -p $DESTDIR/usr/share
cp -ar /usr/share/ca-certificates $DESTDIR/usr/share/
cp -ar /etc/ssl $DESTDIR/etc/
And ensure that the script is executable:
sudo chmod 755 /usr/share/initramfs-tools/hooks/curl
3. Now create the keyscript:
sudo nano /bin/luksunlockhttps
Paste the following content:
#!/bin/sh -e
# Wait 10 seconds for DHCP (needed for Debian 11+12)
if [ $CRYPTTAB_TRIED -eq "0" ]; then
sleep 10
fi
if curl -f --retry-connrefused --retry 5 -F "uuid=$CRYPTTAB_KEY" \
https://www.usbencryptionkey.com/request; then
exit
fi
/lib/cryptsetup/askpass "Enter password and press ENTER: "
Ensure that the keyscript is executable:
sudo chmod 755 /bin/luksunlockhttps
4. Modify the "crypttab"
Replace "none luks" by "cdbafbaa-21d8-11ee-9186-df2d5ef43f21 luks,keyscript=/bin/luksunlockhttps" using:
sed -i 's/none luks/cdbafbaa-21d8-11ee-9186-df2d5ef43f21 luks,keyscript=\/bin\/luksunlockhttps/g' /etc/crypttab
5. Now regenerate the "initramfs" using:
sudo update-initramfs -u
6. Implementing web endpoint
Writing code that responds with the key on POST requests to https://www.usbencryptionkey.com/request
(with 'uuid' as a parameter) is left as an exercise to the reader :-)
source: https://tqdev.com/2023-luks-with-https-unlock