Yubico / yubikit-ios

Yubico Mobile iOS SDK - YubiKit
Apache License 2.0
194 stars 43 forks source link

`makeCredential(withClientDataHash:` how to read the returned data in JSON format #134

Closed ospfranco closed 9 months ago

ospfranco commented 10 months ago

Hi!

I'm working in integrating the library into an app. I'm having trouble decoding the returned data objects into JSON which I require. On the FIDO demo the webauthnAttestationObject is returned on the response but I need to convert this data into JSON so it can be read from a JavaScript context. However, no matter how I try, I'm not able to read this data.

What format is it in? From what I read in the specification it is supposed to be in CBOR binary data format. When I try to parse it with a CBOR library I get an error. Any help is greatly appreciatted.

To be more specific I'm looking after the credentialID specified here, any idea on how to retrieve that?

ospfranco commented 9 months ago

Found out how to achieve this:

guard let keyResponse = keyResponse else { fatalError() }

YubiKitManager.shared.stopNFCConnection()

guard let authenticatorData = keyResponse.authenticatorData else {
    completion(.failure(FidoError.credentialCreationError))
    return
}

guard let credentialId = authenticatorData.credentialId else {
    completion(.failure(FidoError.credentialCreationError))
    return
}

completion(.success(credentialId.base64EncodedString()))

You don't need to manipulate CBOR structure, you can just access the authenticatorData property on the reponse.