Skip to content

Commit e6bd5b4

Browse files
Added AttestationRegistrationRequest to assist with registration attestations
1 parent 8d7b74f commit e6bd5b4

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the WebAuthn Swift open source project
4+
//
5+
// Copyright (c) 2024 the WebAuthn Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
@preconcurrency import Crypto
16+
import SwiftCBOR
17+
18+
public struct AttestationRegistrationRequest: Sendable {
19+
var options: PublicKeyCredentialCreationOptions
20+
var publicKeyCredentialParameters: [PublicKeyCredentialParameters]
21+
var clientDataHash: SHA256Digest
22+
var attemptRegistration: Callback
23+
24+
init(
25+
options: PublicKeyCredentialCreationOptions,
26+
publicKeyCredentialParameters: [PublicKeyCredentialParameters],
27+
clientDataHash: SHA256Digest,
28+
attemptRegistration: @Sendable @escaping (_ attestationObject: AttestationObject) async throws -> ()
29+
) {
30+
self.options = options
31+
self.publicKeyCredentialParameters = publicKeyCredentialParameters
32+
self.clientDataHash = clientDataHash
33+
self.attemptRegistration = Callback(callback: attemptRegistration)
34+
}
35+
}
36+
37+
extension AttestationRegistrationRequest {
38+
public struct Callback: Sendable {
39+
/// The internal callback the attestation should call.
40+
var callback: @Sendable (_ attestationObject: AttestationObject) async throws -> ()
41+
42+
/// Generate an attestation object for registration and submit it.
43+
///
44+
/// Authenticators should call this to submit a successful registration and cancel any other pending authenticators.
45+
///
46+
/// - SeeAlso: https://w3c.github.io/webauthn/#sctn-generating-an-attestation-object
47+
public func submitAttestationObject(
48+
attestationFormat: AttestationFormat,
49+
authenticatorData: AuthenticatorData,
50+
attestationStatement: CBOR
51+
) async throws {
52+
try await callback(AttestationObject(
53+
authenticatorData: authenticatorData,
54+
format: attestationFormat,
55+
attestationStatement: attestationStatement
56+
))
57+
}
58+
}
59+
}

Sources/WebAuthn/Authenticators/Protocol/AuthenticatorProtocol.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public protocol AuthenticatorProtocol<CredentialSource> {
5858
clientDataHash: SHA256.Digest
5959
) async throws -> CBOR
6060

61+
/// Make credentials for the specified registration request, returning the credential source that the caller should store for subsequent authentication.
62+
///
63+
/// - Important: Depending on the authenticator being used, the credential source may contain private keys, and must be stored sequirely, such as in the user's Keychain, or in a Hardware Security Module appropriate with the level of security you wish to secure your user's account with.
64+
func makeCredentials(with registration: AttestationRegistrationRequest) async throws -> CredentialSource
65+
6166
/// Filter the provided credential descriptors to determine which, if any, should be handled by this authenticator.
6267
///
6368
/// This method should execute a client platform-specific procedure to determine which, if any, public key credentials described by `pkOptions.allowCredentials` are bound to this authenticator, by matching with `rpId`, `pkOptions.allowCredentials.id`, and `pkOptions.allowCredentials.type`
@@ -112,3 +117,13 @@ extension AuthenticatorProtocol {
112117
return credentialDescriptors
113118
}
114119
}
120+
121+
// MARK: Registration
122+
123+
extension AuthenticatorProtocol {
124+
public func makeCredentials(
125+
with registration: AttestationRegistrationRequest
126+
) async throws -> CredentialSource {
127+
throw WebAuthnError.unsupported
128+
}
129+
}

Sources/WebAuthn/Ceremonies/Registration/AttestedCredentialData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
// Contains the new public key created by the authenticator.
16-
struct AttestedCredentialData: Equatable {
16+
public struct AttestedCredentialData: Equatable, Sendable {
1717
let authenticatorAttestationGUID: AAGUID
1818
let credentialID: [UInt8]
1919
let publicKey: [UInt8]

Sources/WebAuthn/Ceremonies/Shared/AuthenticatorData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftCBOR
1818

1919
/// Data created and/ or used by the authenticator during authentication/ registration.
2020
/// The data contains, for example, whether a user was present or verified.
21-
struct AuthenticatorData: Equatable, Sendable {
21+
public struct AuthenticatorData: Equatable, Sendable {
2222
let relyingPartyIDHash: [UInt8]
2323
let flags: AuthenticatorFlags
2424
let counter: UInt32

0 commit comments

Comments
 (0)