helm/mount-crypted.sh

22 lines
664 B
Bash
Raw Normal View History

2022-12-06 22:29:07 -08:00
#!/usr/bin/env bash
2024-03-15 23:25:49 -07:00
# nix-shell https://github.com/sgillespie/nixos-yubikey-luks/archive/master.tar.gz
rbtohex() {
( od -An -vtx1 | tr -d ' \n' )
}
hextorb() {
( tr '[:lower:]' '[:upper:]' | sed -e 's/\([0-9A-F]\{2\}\)/\\\\\\x\1/gI'| xargs printf )
}
2022-09-18 15:13:50 -07:00
key_length=512
2024-03-15 23:25:49 -07:00
iterations=1000000
salt="$(head -n 1 /mnt/crypt-storage/default)"
2022-09-18 15:13:50 -07:00
chal="$(echo -n $salt | openssl dgst -binary -sha512 | rbtohex)"
resp="$(ykchalresp -2 -x $chal 2>/dev/null)"
2024-03-15 23:25:49 -07:00
user_key=
read -r user_key
2022-09-18 15:13:50 -07:00
luks_key="$(echo -n $user_key | pbkdf2-sha512 $(($key_length / 8)) $iterations $resp | rbtohex)"
echo -n $luks_key | hextorb | sudo cryptsetup luksOpen /dev/sda2 crypted --key-file=-