This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / age-detect / age-detect
2.6 kB 82 lines
1#!/usr/bin/env bash 2set -euo pipefail 3 4# age-detect: Detects connected age-compatible security keys 5# Returns identity file path and detected key information 6 7# Function to detect connected security keys and their age identities 8detect_age_keys() { 9 local temp_identities 10 temp_identities=$(mktemp) 11 12 # Check for Secure Enclave on macOS (highest priority) 13 if [[ "$(uname)" == "Darwin" ]] && command -v age-plugin-se >/dev/null 2>&1; then 14 rm -f "$temp_identities" 15 echo "DETECTED_KEY=se" 16 echo "KEY_TYPE=se" 17 return 18 fi 19 20 # Check for YubiKeys (second priority) 21 if command -v ykman >/dev/null 2>&1; then 22 local yubikey_serial 23 yubikey_serial=$(ykman info 2>/dev/null | grep "Serial number:" | cut -d: -f2 | tr -d ' ' || true) 24 if [[ -n "$yubikey_serial" ]]; then 25 echo "AGE-PLUGIN-YUBIKEY-1M2PLUQYZ242EPUSSHDFWJ" > "$temp_identities" 26 echo "IDENTITY_FILE=$temp_identities" 27 case "$yubikey_serial" in 28 "16679898") 29 echo "DETECTED_KEY=yubi1" 30 ;; 31 "11342136") 32 echo "DETECTED_KEY=yubi2" 33 ;; 34 *) 35 echo "DETECTED_KEY=yubikey-${yubikey_serial}" 36 ;; 37 esac 38 echo "KEY_TYPE=yubikey" 39 return 40 fi 41 fi 42 43 # Check for Solo2 (lowest priority) 44 if command -v fido2-token >/dev/null 2>&1; then 45 if fido2-token -L 2>/dev/null | grep -q "Solo 2"; then 46 # FIDO2-HMAC doesn't use identity file 47 rm -f "$temp_identities" 48 echo "IDENTITY_FILE=" 49 echo "DETECTED_KEY=solo2" 50 echo "KEY_TYPE=solo2" 51 return 52 fi 53 fi 54 55 # No keys detected 56 rm -f "$temp_identities" 57 echo "IDENTITY_FILE=" 58 echo "DETECTED_KEY=" 59 echo "KEY_TYPE=" 60} 61 62# Parse command line arguments 63case "${1:-detect}" in 64 detect) 65 detect_age_keys 66 ;; 67 --help|-h) 68 echo "Usage: age-detect [detect]" 69 echo "" 70 echo "Detects the first available age-compatible security key and outputs:" 71 echo " IDENTITY_FILE=<path> - Path to temporary identity file for age (empty for Solo2)" 72 echo " DETECTED_KEY=<name> - Name of the detected key (e.g., yubi1, solo2, se)" 73 echo " KEY_TYPE=<type> - Type of key (yubikey, solo2, se)" 74 echo "" 75 echo "Priority order: se > yubikey > solo2" 76 ;; 77 *) 78 echo "Unknown command: $1" >&2 79 echo "Use --help for usage information" >&2 80 exit 1 81 ;; 82esac