AppAttest icon indicating copy to clipboard operation
AppAttest copied to clipboard

No clue for keyId when creating AttestationRequest

Open cpromise opened this issue 1 year ago • 0 comments

Such an easy way to understand how to verify attestation on server side in Swift. Thank you :)

I was a bit confused with what keyID means when initializing AttestationRequest. Because generateKey() method returns String not Data and the initializer requires keyID as a Data type. And the document doesn't ask developers to encode keyId when sending it to the server.

I found that I should encode keyId generated by generateKey() as Data(base64Encoded: keyId)! after seeing a test code.

What if make it possible to initialize AttestationRequest with String type keyID? For example,

public struct AttestationRequest: Codable {
    /// The attestation object generated by the App Attest service.
    public let attestation: Data
    
    /// The public key identifier associated with the client app.
    public let keyID: Data
    
    /// Creates an `AttestationRequest` with the given attestation and key identifier.
    public init(attestation: Data, keyID: String) {
        self.attestation = attestation
        self.keyID = Data(base64Encoded: keyID)!
    }

    /// Make it failable if needed
    public init?(attestation: Data, keyID: String) {
        guard let keyID = Data(base64Encoded: keyID) else { return nil }
        self.attestation = attestation
        self.keyID = keyID
    }
}

Thanks for reading.

cpromise avatar Apr 12 '23 06:04 cpromise