Skip to content

Commit

Permalink
WebAuthn with extra logging for the flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Cabanero committed Apr 8, 2024
1 parent fb6a4bb commit d14566f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions BlinkConfig/WebAuthnKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,22 @@ extension WebAuthnKey: Signer {
self.log?.message("WebAuthn Controller called to perform request.", .debug)
return self.signaturePub!
}
.handleEvents(receiveCancel: {
self.log?.message("WebAuthn signature publisher cancelled", .debug)
})
.sink(receiveCompletion: { completion in
self.log?.message("WebAuthn received signature publisher completed with \(completion)", .debug)
switch completion {
case .failure(let err):
error = err
case .finished:
break
}
semaphore.signal()
}, receiveValue: { signature = $0 })
}, receiveValue: { sig in
self.log?.message("WebAuthn signature received.", .debug)
signature = sig
})

self.log?.message("WebAuthn Controller awaiting response.", .debug)
semaphore.wait()
Expand Down Expand Up @@ -151,7 +158,9 @@ extension WebAuthnKey: ASAuthorizationControllerDelegate, ASAuthorizationControl
let credentialAssertion = authorization.credential as? ASAuthorizationPublicKeyCredentialAssertion,
let rawSignature = credentialAssertion.signature
else {
return signaturePub.send(completion: .failure(WebAuthnError.signatureError("Unexpected operation")))
self.log?.message("WebAuthn Controller unexpected operation received.", .warn)
signaturePub.send(completion: .failure(WebAuthnError.signatureError("Unexpected operation")))
return
}

let rawClientData = credentialAssertion.rawClientDataJSON
Expand All @@ -164,6 +173,7 @@ extension WebAuthnKey: ASAuthorizationControllerDelegate, ASAuthorizationControl

// TODO We should validate the CredentialID, to be sure we signed with the proper key,
// before we fail or ask the user to retry.
self.log?.message("WebAuthn Controller sending signature", .debug)
signaturePub.send(webAuthnSig)
signaturePub.send(completion: .finished)
}
Expand Down

0 comments on commit d14566f

Please sign in to comment.