if[[ ! "$usage"=~ ^(luks/keystore-@{config.networking.hostName!hashString.sha256:0:8}/.*)$ ]];thenprintf'»trivial« key mode is only available for the keystore itself.\n';exit1;fi
## Generates a reproducible secret for a certain »$use«case by prompting for a pin/password and then challenging slot »$slot« of YubiKey »$serial«, and saves it to the »$keystore«.
function add-key-yubikey-pin {(set -eu # 1: usage, 2: serialAndSlot(as »serial:slot«)
usage=$1;serialAndSlot=$2
password=$(prompt-new-password "/ pin as challenge to YubiKey »$serialAndSlot« as key for @{config.networking.hostName}/$usage")
add-key-yubikey-challenge "$usage""$serialAndSlot:$password"true"pin for ${usage}"
)}
## Generates a reproducible secret for a certain »$use«case on a »$host« by challenging slot »$slot« of YubiKey »$serial«, and saves it to the »$keystore«.
function add-key-yubikey {(set -eu # 1: usage, 2: serialAndSlotAndSalt(as »serial:slot:salt«)
## Generates a reproducible secret for a certain »$use«case by challenging slot »$slot« of YubiKey »$serial« with the fixed »$challenge«, and saves it to the »$keystore«.
# If »$sshArgs« is set as (env) var, generate the secret locally, then use »ssh $sshArgs« to write the secret on the other end.
if[["$serial" !="$(@{native.yubikey-personalization}/bin/ykinfo -sq)"]];thenprintf'Please insert / change to YubiKey with serial %s!\n'"$serial";fi
if[[ ! "${3:-}"]];then
read -p 'Challenging YubiKey '"$serial"' slot '"$slot"' twice with '"${message:-challenge »"$challenge":1/2«}"'. Enter to continue, or Ctrl+C to abort:'
else
read -p 'Challenging YubiKey '"$serial"' slot '"$slot"' once with '"${message:-challenge »"$challenge"«}"'. Enter to continue, or Ctrl+C to abort:'
fi
if[["$serial" !="$(@{native.yubikey-personalization}/bin/ykinfo -sq)"]];thenprintf'YubiKey with serial %s not present, aborting.\n'"$serial";exit1;fi