Update fido2-manage.sh

This commit is contained in:
Token2
2026-01-08 19:59:15 +01:00
committed by GitHub
parent fdbf170801
commit b2504f97f5

View File

@@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
FIDO2_TOKEN_CMD="/usr/local/bin/fido2-token2" FIDO2_TOKEN_CMD="/usr/local/bin/fido2-token2"
list=false list=false
@@ -51,8 +50,6 @@ while [[ "$#" -gt 0 ]]; do
shift shift
done done
show_help() { show_help() {
cat << EOF cat << EOF
FIDO2 Token Management Tool FIDO2 Token Management Tool
@@ -102,13 +99,11 @@ Examples:
EOF EOF
} }
# Display help if -help parameter is provided
if $help; then if $help; then
show_help show_help
exit 0 exit 0
fi fi
# Check if no arguments are specified, then show help
if ! $list && ! $info && [[ -z $device ]] && ! $fingerprint && ! $storage && ! $residentKeys && [[ -z $domain ]] && ! $delete && [[ -z $credential ]] && ! $changePIN && ! $setMinimumPIN && ! $setPIN && ! $reset && ! $uvs && ! $uvd && ! $help; then if ! $list && ! $info && [[ -z $device ]] && ! $fingerprint && ! $storage && ! $residentKeys && [[ -z $domain ]] && ! $delete && [[ -z $credential ]] && ! $changePIN && ! $setMinimumPIN && ! $setPIN && ! $reset && ! $uvs && ! $uvd && ! $help; then
show_help show_help
exit 1 exit 1
@@ -124,9 +119,7 @@ if $list; then
device_count=1 device_count=1
echo "$command_output" | while read -r line; do echo "$command_output" | while read -r line; do
if [[ $line =~ ^([^:]+) ]]; then if [[ $line =~ ^([^:]+) ]]; then
echo "Device [$device_count] : $(echo "${line}" | grep -oP '(?<=\()(.+)(?=\))')" echo "Device [$device_count] : $(echo "${line}" | grep -oP '(?<=\()(.+)(?=\))')"
device_count=$((device_count + 1)) device_count=$((device_count + 1))
fi fi
done done
@@ -191,6 +184,10 @@ if [[ -n $device ]]; then
if [[ -n $setMinimumPIN ]]; then if [[ -n $setMinimumPIN ]]; then
show_message "Setting minimum PIN length to $setMinimumPIN on device $device" show_message "Setting minimum PIN length to $setMinimumPIN on device $device"
"$FIDO2_TOKEN_CMD" -S -l "$setMinimumPIN" "$device_string" "$FIDO2_TOKEN_CMD" -S -l "$setMinimumPIN" "$device_string"
if [ $? -ne 0 ]; then
show_message "Error: Failed to set minimum PIN length." "Error"
exit 1
fi
exit 0 exit 0
fi fi
@@ -206,13 +203,12 @@ if [[ -n $device ]]; then
exit 0 exit 0
fi fi
# Fingerprint enrollment
if $fingerprint; then if $fingerprint; then
echo "Enrolling fingerprints (for bio models only)" echo "Enrolling fingerprints (for bio models only)"
$FIDO2_TOKEN_CMD -S -e "$device_string" $([[ -n $pin ]] && echo "-w $pin") $FIDO2_TOKEN_CMD -S -e "$device_string" $([[ -n $pin ]] && echo "-w $pin")
exit 0 exit 0
fi fi
# Main logic
if $storage; then if $storage; then
$FIDO2_TOKEN_CMD -I -c "$device_string" $([[ -n $pin ]] && echo "-w $pin") $FIDO2_TOKEN_CMD -I -c "$device_string" $([[ -n $pin ]] && echo "-w $pin")
exit 0 exit 0
@@ -221,9 +217,6 @@ elif $residentKeys; then
domain_command="$FIDO2_TOKEN_CMD -L -k \"$domain\" \"$device_string\" $([[ -n $pin ]] && echo "-w $pin")" domain_command="$FIDO2_TOKEN_CMD -L -k \"$domain\" \"$device_string\" $([[ -n $pin ]] && echo "-w $pin")"
domain_output=$(eval $domain_command) domain_output=$(eval $domain_command)
# Process the output line by line
echo "$domain_output" | while read -r line; do echo "$domain_output" | while read -r line; do
key_id=$(echo "$line" | awk '{print $1}') key_id=$(echo "$line" | awk '{print $1}')
credential_id=$(echo "$line" | awk '{print $2}') credential_id=$(echo "$line" | awk '{print $2}')
@@ -234,7 +227,6 @@ elif $residentKeys; then
user_field="" user_field=""
fi fi
# Determine if user_field is an email
if [[ "$user_field" == *"@"* ]]; then if [[ "$user_field" == *"@"* ]]; then
email=$user_field email=$user_field
user="" user=""
@@ -251,7 +243,6 @@ elif $residentKeys; then
exit 0 exit 0
fi fi
if $info; then if $info; then
command_output=$($FIDO2_TOKEN_CMD -I "$device_string") command_output=$($FIDO2_TOKEN_CMD -I "$device_string")
show_message "Device $device Information:" show_message "Device $device Information:"