Created
October 24, 2020 10:28
-
-
Save mschmitt/59770fc582b9b47c517c2a6a2573b4eb to your computer and use it in GitHub Desktop.
Programmatically changing a cryptsetup LUKS key
This file contains hidden or 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
#!/bin/bash | |
luksobject='crypto.dat' | |
read -r -s -p 'Old passphrase: ' old | |
printf "\n" | |
read -r -s -p 'New passphrase: ' new | |
printf "\n" | |
read -r -s -p 'New passphrase again: ' new2 | |
printf "\n" | |
if [[ "${new}" != "${new2}" ]] | |
then | |
printf "New passphrase mismatch. Aborting.\n" | |
exit 1 | |
fi | |
if command -v pwscore >/dev/null && ! pwscore >/dev/null <<< "${new}" | |
then | |
printf "Weak passphrase. Aborting.\n" | |
exit 2 | |
fi | |
printf "Passing control to cryptsetup:\n" | |
exec cryptsetup luksChangeKey --verbose \ | |
--key-file <(tr -d '\n' <<< "${old}") "${luksobject}" <<< "${new}" | |
# Further Reading: | |
# | |
# pwscore(1) | |
# cryptsetup(8) "Notes on passphrase processing" (regarding the \n substition) | |
# bash(1) "Process Substitution" (regarding the <()) | |
# bash(1) "Here Strings" (regarding the <<<) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment