Skip to content

Commit

Permalink
Fallback password input if fail from yubikey
Browse files Browse the repository at this point in the history
If we tried 3 times, and our yubikey has no response, let's
fallback to password input.

If yubikey repsoned, while we cannot decrypt our disk with
this response, let's ask for new password directly.

Background: I have 2 yubikey, and one is set to 1FA and another
is set to 2FA. I wish that when the 1FA one can just work if I
plug it in, and password is asked if I plug the 2FA one in instead.
  • Loading branch information
wzssyqa committed Dec 3, 2023
1 parent 7cedca9 commit 9c7af15
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion key-script
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ message()

check_yubikey_present="$(ykinfo -q -"$YUBIKEY_LUKS_SLOT")"

if [ -z "$YUBIKEY_CHALLENGE" ] || [ "$check_yubikey_present" != "1" ] ; then
touch /tmp/ykluks-fail
TRIED="$(grep ${CRYPTTAB_SOURCE} /tmp/ykluks-fail | wc -l)"
if [ -z "$YUBIKEY_CHALLENGE" ] || [ "$check_yubikey_present" != "1" ] || [ "$TRIED" -ge 3 ] ; then
if [ -z "$cryptkeyscript" ]; then
if [ -x /bin/plymouth ] && plymouth --ping; then
cryptkeyscript="plymouth ask-for-password --prompt"
Expand All @@ -35,6 +37,7 @@ else
PW="$YUBIKEY_CHALLENGE"
fi


if [ "$check_yubikey_present" = "1" ]; then
message "Accessing yubikey..."
if [ "$HASH" = "1" ]; then
Expand All @@ -48,8 +51,12 @@ if [ "$check_yubikey_present" = "1" ]; then
else
printf '%s' "$R"
fi
echo "$CRYPTTAB_SOURCE tried" >> /tmp/ykluks-fail
echo "$CRYPTTAB_SOURCE tried" >> /tmp/ykluks-fail
echo "$CRYPTTAB_SOURCE tried" >> /tmp/ykluks-fail
else
message "Failed to retrieve the response from the Yubikey"
echo "$CRYPTTAB_SOURCE tried" >> /tmp/ykluks-fail
fi
else
printf '%s' "$PW"
Expand Down

0 comments on commit 9c7af15

Please sign in to comment.