https://bugzilla.mindrot.org/show_bug.cgi?id=3864
--- Comment #3 from epik <[email protected]> --- Created attachment 4033 --> https://bugzilla.mindrot.org/attachment.cgi?id=4033&action=edit 1/2 ask the middleware whether a PIN is needed before notifying (ssh) I can reproduce this on current master (fa4b2a82b) with a Token2 PIN+ (PIN and touch, no on-token user verification) and a key created with -O verify-required. I think the common case can be fixed without guessing; two patches attached. What happens The token is not replying with an error here; the first attempt never gets as far as the token. The log in comment #2 shows it (mine is the same): debug1: sshsk_sign: provider "internal", key ED25519-SK, flags 0x25 debug1: sk_probe: 1 device(s) detected debug1: sk_probe: selecting sk by touch debug1: check_sk_options: option uv is unknown debug1: ssh_sk_sign: check_sk_options uv debug1: sshsk_sign: sk_sign failed with code -3 For a key with SSH_SK_USER_VERIFICATION_REQD and no PIN, sk_sign() in sk-usbhid.c (lines 1206-1212) looks at the "uv" option in the token's info and returns SSH_SK_ERR_PIN_REQUIRED before fido_dev_get_assert() is called. identity_sign() in sshconnect2.c has already started the notifier by then (line 1260), so it closes it, asks for the PIN (lines 1268-1277) and starts it again. ssh-agent does the same (ssh-agent.c lines 983-989, then 996-1007), where it shows as a notice dialog that flashes before the PIN dialog. So for verify-required keys on tokens without on-token UV, the middleware knows the answer without blocking. It just has no way to tell the caller before the notifier is started. This has been the behaviour since f96480906 (9.1), when ssh began trying without a PIN first. What the patches do 1/2 adds an optional middleware function, sk_sign_check(), that reports without user interaction whether sk_sign() would refuse a request for lack of a PIN, and a new ssh-sk-helper request (SSH_SK_HELPER_SIGN_CHECK) to reach it. The built-in middleware implements it with the same check sk_sign() already makes (moved into a small shared function). It answers "PIN required" only when the key asks for UV and exactly one token is attached (or one is named by the device option), so it never waits for a touch to select a token. ssh calls it before the notifier for verify-required keys; if a PIN is required it prompts for the PIN first and then makes one notified attempt. When the check has said a PIN is required and the PIN prompt comes back empty or cancelled, ssh now stops instead of retrying without a PIN, which today shows the notice once more for an attempt that cannot succeed. The existing fallback path is left alone, so a token with on-token UV still gets its second PIN-less attempt after a cancelled prompt. 2/2 makes ssh-agent use the same check, so it goes straight to its PIN prompt. Before, in a terminal: Confirm user presence for key ED25519-SK SHA256:<hash> Enter PIN for ED25519-SK key /home/user/.ssh/id_ed25519_sk: Confirm user presence for key ED25519-SK SHA256:<hash> User presence confirmed After: Enter PIN for ED25519-SK key /home/user/.ssh/id_ed25519_sk: Confirm user presence for key ED25519-SK SHA256:<hash> User presence confirmed Order of askpass calls with the same token: before after ssh notice, PIN, notice PIN, notice ssh, PIN cancelled notice, PIN, notice, fail PIN, fail ssh-agent notice, PIN PIN What does not change - Keys without verify-required: no extra helper call, same behaviour. - Tokens with on-token UV (uv option true): the check answers "no", ssh notifies and tries without a PIN as it does now. - More than one token attached, no token attached, any error from the check, or a middleware that does not have sk_sign_check(): treated as "cannot tell", same behaviour as now, including the existing fallback to the PIN prompt. - A token that wants a PIN for a key that is not marked verify-required still shows the notice twice. In that case the token really is the one refusing, and I don't see a way to know beforehand. - ssh-keygen -Y sign and CA signing ask for the PIN up front and are not touched. Testing - regress/sk-notify.sh (new) records the notices and PIN prompts shown through askpass, using new off-by-default behaviour in sk-dummy (refuse verify-required keys without a PIN; answer sk_sign_check()). It covers ssh and ssh-agent, with and without the check offered, a touch-only key, and a cancelled PIN. It fails on master for the cases the patches change. - The other FIDO and agent regress tests pass. - Real token: Token2 PIN+ on Linux, libfido2 1.17.0, ssh and ssh-agent, terminal and askpass (ksshaskpass). - Builds with --with-security-key-builtin, --without-security-key-builtin, --disable-security-key and --without-openssl. - Not tested: a token with on-token UV (I don't have one), more than one token attached, Windows Hello, and a third-party middleware that lacks the new symbol (the regress test stands in for it with sk-dummy answering "cannot tell"). The logic in sk-usbhid.c has no regress coverage, only the real-token runs above. - For verify-required keys the check costs one ssh-sk-helper run. On a PIN token it replaces the failed first attempt, so the count is unchanged; on a token with on-token UV it is one extra. Things you may want done differently - sk_sign_check() is an optional symbol looked up with dlsym(), so SSH_SK_VERSION_MAJOR is not changed and existing middlewares keep working. It takes the same arguments as sk_sign() minus the message, the PIN and the response. - SSH_SK_HELPER_VERSION is not bumped. A new ssh with an old ssh-sk-helper gets a fatal from the helper for the unknown request, treats that as "cannot tell" and carries on as before. - Names are only suggestions. Disclosure: the analysis and the patches were written with an AI assistant (Claude). I ran the tests above myself on my own token and have read the patches. -- You are receiving this mail because: You are watching the assignee of the bug. You are watching someone on the CC list of the bug. _______________________________________________ openssh-bugs mailing list [email protected] https://lists.mindrot.org/mailman/listinfo/openssh-bugs
