Skip to content

Commit

Permalink
Improve output and let ykman manage the FIDO reset (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
daisukixci committed Sep 21, 2020
1 parent 9cf9efb commit e4202f4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions reset.sh
Expand Up @@ -9,9 +9,10 @@ confirm() {
msg="$1"

echo "$msg"
read -srn 3 answer
read -rn 3 answer
case $answer in
Yes|yes|Y|y|YES)
echo
return 0
;;
*)
Expand All @@ -24,21 +25,23 @@ reset_device() {
local serial
serial="$1"

$YKMAN --device "${serial}" otp delete 1 -f
$YKMAN --device "${serial}" otp delete 2 -f
for i in $(seq 1 2); do
if ! $YKMAN --device "${serial}" otp delete "$i" -f >/dev/null 2>&1; then
echo "Warning the slot $i didn't contain OTP configuration or an error happened"
fi
done
$YKMAN --device "${serial}" oath reset -f
$YKMAN --device "${serial}" openpgp reset -f
$YKMAN --device "${serial}" piv reset -f
$YKMAN --device "${serial}" fido reset -f
$YKMAN --device "${serial}" fido reset
}

yubikeys=$($YKMAN list --serials)
select serial in all $yubikeys cancel; do
echo "You chose $serial"
case $serial in
all)
echo "Are you sure you want to reset $yubikeys ? yes/no"
confirm || exit 0
confirm "Are you sure you want to reset $yubikeys ? yes/no" || exit 0
for yubikey in $yubikeys; do
echo "Reset $yubikey"
reset_device "$yubikey"
Expand All @@ -50,8 +53,7 @@ select serial in all $yubikeys cancel; do
break
;;
+([0-9]))
echo "Are you sure you want to reset $serial ? yes/no"
confirm || exit 0
confirm "Are you sure you want to reset $serial ? yes/no" || exit 0
echo "Reset $serial"
reset_device "$serial"
break
Expand Down

0 comments on commit e4202f4

Please sign in to comment.