Hello everybody, I'm trying to implement passkey provider for iOS device. I'm in the register phase of the passkey. Let's say this is my code to register request, what am I doing wrong?:
import SwiftCBOR
class CredentialProviderViewController: ASCredentialProviderViewController {
.
.
.
func generatePublicKeyCborEncoded() -> Data {
let privateKey = P256.Signing.PrivateKey()
let publicKey = privateKey.publicKey.x963Representation
let decoded: [CBOR: CBOR] = [
CBOR.init(integerLiteral: 1): CBOR.init(integerLiteral: 2),
CBOR.init(integerLiteral: 3): CBOR.init(integerLiteral: -7),
CBOR.init(integerLiteral: -1): CBOR.init(integerLiteral: 1),
CBOR.init(integerLiteral: -2): CBOR.byteString(publicKey[1..<33].map { $0 }),
CBOR.init(integerLiteral: -3): CBOR.byteString(publicKey[33..<65].map { $0 })
]
return Data(CBOR.encode(decoded))
}
@IBAction func onRegister(_ sender: UIButton) {
NSLog("onRegister called 1")
guard let request = newRegistrationRequest as? ASPasskeyCredentialRequest else {return}
let attObj: Data = generatePublicKeyCborEncoded()
let passkey: ASPasskeyRegistrationCredential = ASPasskeyRegistrationCredential(
relyingParty: request.credentialIdentity.serviceIdentifier.identifier,
clientDataHash: request.clientDataHash,
credentialID: Data([67, 92, 125, 254, 60, 232, 238, 248, 14, 107, 245, 21, 85, 130, 40, 54],
attestationObject: attObj
)
extensionContext.completeRegistrationRequest(using: passkey){ endedWell in
NSLog("onRegister called \(endedWell ? "" : "not") ended well")
}
}
}