@@ -241,7 +241,8 @@ impl PasskeyApplication {
241241 Ok ( ( ) )
242242 }
243243
244- /// Starts handle-based authentication or lets the authenticator identify the account.
244+ /// Starts sign-in to the account a handle names, or lets the authenticator
245+ /// identify the account. Either way the challenge lists no credentials.
245246 ///
246247 /// Handles are public (`docs/dev/security/handles.md`), so a handle without an active
247248 /// account or passkey is refused at once, before any ceremony. Text that is not a
@@ -251,40 +252,36 @@ impl PasskeyApplication {
251252 headers : HeaderMap ,
252253 Json ( input) : Json < LoginStart > ,
253254 ) -> Result < Response , ApiError > {
254- let ( ceremony, challenge) =
255- if let Some ( input) = input. handle . filter ( |handle| !handle. is_empty ( ) ) {
256- let keys = match Handle :: parse ( & input) {
257- Ok ( handle) => {
258- app. database
259- . passkeys ( )
260- . list_active_by_handle ( & handle)
261- . await ?
262- }
263- Err ( _) => Vec :: new ( ) ,
264- } ;
265- let user_id = keys
266- . first ( )
267- . map ( |key| key. user_id )
268- . ok_or ( PasskeyError :: UnknownHandle ) ?;
269- let ( challenge, state) = app
270- . webauthn
271- . start_passkey_authentication ( & Self :: decode ( keys) ?)
272- . map_err ( PasskeyError :: from) ?;
273- ( Ceremony :: Login ( LoginCeremony { user_id, state } ) , challenge)
274- } else {
275- let ( challenge, state) = app. discoverable ( ) ?;
276- ( Ceremony :: Discover ( state) , challenge)
255+ let ( challenge, state) = app. discoverable ( ) ?;
256+ let ceremony = if let Some ( input) = input. handle . filter ( |handle| !handle. is_empty ( ) ) {
257+ let keys = match Handle :: parse ( & input) {
258+ Ok ( handle) => {
259+ app. database
260+ . passkeys ( )
261+ . list_active_by_handle ( & handle)
262+ . await ?
263+ }
264+ Err ( _) => Vec :: new ( ) ,
277265 } ;
266+ let user_id = keys
267+ . first ( )
268+ . map ( |key| key. user_id )
269+ . ok_or ( PasskeyError :: UnknownHandle ) ?;
270+ Ceremony :: Login ( LoginCeremony { user_id, state } )
271+ } else {
272+ Ceremony :: Discover ( DiscoverCeremony { state } )
273+ } ;
278274 Ok ( app. start ( & headers, ceremony, challenge) . await ?)
279275 }
280276
281- /// Starts an account-picker sign-in, whose account the authenticator names.
277+ /// Starts a sign-in whose account the authenticator names, listing no
278+ /// credentials.
282279 pub ( super ) fn discoverable (
283280 & self ,
284- ) -> Result < ( RequestChallengeResponse , DiscoverCeremony ) , PasskeyError > {
281+ ) -> Result < ( RequestChallengeResponse , DiscoverableAuthentication ) , PasskeyError > {
285282 let ( mut challenge, state) = self . webauthn . start_discoverable_authentication ( ) ?;
286283 challenge. mediation = None ;
287- Ok ( ( challenge, DiscoverCeremony { state } ) )
284+ Ok ( ( challenge, state) )
288285 }
289286
290287 /// Verifies the assertion and latest credential state before signing the browser in.
@@ -320,41 +317,44 @@ impl PasskeyApplication {
320317
321318 /// Checks `credential` against a sign-in `ceremony` with `webauthn`, and
322319 /// returns the account it signs in to with `WebAuthn`'s verdict, which
323- /// [`Self::accept_credential`] takes. A discoverable credential that names no
324- /// account is rejected, and recorded, here.
320+ /// [`Self::accept_credential`] takes. A credential that names no account, or
321+ /// another account than the ceremony named, is rejected, and recorded, here.
325322 pub ( super ) async fn verify (
326323 & self ,
327324 webauthn : & Webauthn ,
328325 context : RequestContext ,
329326 ceremony : AuthenticationCeremony ,
330327 credential : & PublicKeyCredential ,
331328 ) -> Result < ( UserId , Result < AuthenticationResult , WebauthnError > ) , PasskeyError > {
332- match ceremony {
333- AuthenticationCeremony :: Login ( LoginCeremony { user_id, state } ) => Ok ( (
329+ let ( named, state) = match ceremony {
330+ AuthenticationCeremony :: Login ( LoginCeremony { user_id, state } ) => {
331+ ( Some ( user_id) , state)
332+ }
333+ AuthenticationCeremony :: Discover ( DiscoverCeremony { state } ) => ( None , state) ,
334+ } ;
335+ match self . discover ( credential, named) . await {
336+ Ok ( ( user_id, keys) ) => Ok ( (
334337 user_id,
335- webauthn. finish_passkey_authentication ( credential, & state) ,
338+ webauthn. finish_discoverable_authentication ( credential, state, & keys ) ,
336339 ) ) ,
337- AuthenticationCeremony :: Discover ( DiscoverCeremony { state } ) => {
338- match self . discover ( credential) . await {
339- Ok ( ( user_id, keys) ) => Ok ( (
340- user_id,
341- webauthn. finish_discoverable_authentication ( credential, state, & keys) ,
342- ) ) ,
343- Err ( error) => Err ( self . reject ( context, Actor :: Anonymous , None , error) . await ) ,
344- }
345- }
340+ Err ( error) => Err ( self . reject ( context, Actor :: Anonymous , named, error) . await ) ,
346341 }
347342 }
348343
349- /// Reads the account a discoverable credential names, and that account's keys.
344+ /// Reads the account a discoverable credential names, which must be `named`
345+ /// when the ceremony named one, and that account's keys.
350346 async fn discover (
351347 & self ,
352348 credential : & PublicKeyCredential ,
349+ named : Option < UserId > ,
353350 ) -> Result < ( UserId , Vec < DiscoverableKey > ) , PasskeyError > {
354351 let ( uuid, _) = self
355352 . webauthn
356353 . identify_discoverable_authentication ( credential) ?;
357354 let user_id = UserId :: from_uuid ( uuid) . map_err ( PasskeyError :: InvalidUserHandle ) ?;
355+ if named. is_some_and ( |named| named != user_id) {
356+ return Err ( PasskeyError :: OtherAccount ) ;
357+ }
358358 let keys = self
359359 . keys ( user_id)
360360 . await ?
0 commit comments