mirror of
https://github.com/moparisthebest/cryptsetup-multidisk-ssh
synced 2024-12-21 23:18:48 -05:00
Cache password and attempt to re-use it on later cryptdevices
This commit is contained in:
parent
fbab5a5348
commit
74747ee9da
20
encrypt_hook
Normal file → Executable file
20
encrypt_hook
Normal file → Executable file
@ -4,6 +4,7 @@ run_hook() {
|
|||||||
modprobe -a -q dm-crypt >/dev/null 2>&1
|
modprobe -a -q dm-crypt >/dev/null 2>&1
|
||||||
[ "${quiet}" = "y" ] && CSQUIET=">/dev/null"
|
[ "${quiet}" = "y" ] && CSQUIET=">/dev/null"
|
||||||
|
|
||||||
|
cpassfile="/crypto_passfile.bin"
|
||||||
count=0
|
count=0
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
@ -68,6 +69,14 @@ EOF
|
|||||||
echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
|
echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
query_password() {
|
||||||
|
echo ""
|
||||||
|
echo "A password is required to access the ${cryptname} volume:"
|
||||||
|
read -rsp "Enter passphrase for ${resolved}: " password
|
||||||
|
echo -n "${password}" > ${cpassfile}
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
for cryptopt in ${cryptoptions//,/ }; do
|
for cryptopt in ${cryptoptions//,/ }; do
|
||||||
case ${cryptopt} in
|
case ${cryptopt} in
|
||||||
allow-discards)
|
allow-discards)
|
||||||
@ -93,12 +102,14 @@ EOF
|
|||||||
fi
|
fi
|
||||||
# Ask for a passphrase
|
# Ask for a passphrase
|
||||||
if [ ${dopassphrase} -gt 0 ]; then
|
if [ ${dopassphrase} -gt 0 ]; then
|
||||||
echo ""
|
|
||||||
echo "A password is required to access the ${cryptname} volume:"
|
if [ ! -f ${cpassfile} ]; then
|
||||||
|
query_password
|
||||||
|
fi
|
||||||
|
|
||||||
#loop until we get a real password
|
#loop until we get a real password
|
||||||
while ! eval cryptsetup open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do
|
while ! eval cryptsetup --key-file ${cpassfile} open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do
|
||||||
sleep 2;
|
query_password
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if [ -e "/dev/mapper/${cryptname}" ]; then
|
if [ -e "/dev/mapper/${cryptname}" ]; then
|
||||||
@ -155,6 +166,7 @@ EOF
|
|||||||
rm -f ${ckeyfile}
|
rm -f ${ckeyfile}
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
done
|
done
|
||||||
|
rm -f ${cpassfile}
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim: set ft=sh ts=4 sw=4 et:
|
# vim: set ft=sh ts=4 sw=4 et:
|
||||||
|
Loading…
Reference in New Issue
Block a user