Skip to content

Commit 027b74e

Browse files
committed
update CredentialKeyData struct
1 parent db58569 commit 027b74e

File tree

8 files changed

+39
-22
lines changed

8 files changed

+39
-22
lines changed

Sources/WebAuthn/Authenticator/AttestationObject/AttestationObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import Crypto
1616
import SwiftCBOR
1717

18-
struct AttestationObject {
18+
public struct AttestationObject {
1919
let authenticatorData: AuthenticatorData
2020
let rawAuthenticatorData: [UInt8]
2121
let format: AttestationFormat

Sources/WebAuthn/Authenticator/AuthenticatorAttestationResponse.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct ParsedAuthenticatorAttestationResponse {
3737
let clientData = try JSONDecoder().decode(CollectedClientData.self, from: clientDataJSONData)
3838
self.clientData = clientData
3939

40-
// assembling attestationObject
40+
// Step 11. (assembling attestationObject)
4141
guard let attestationData = rawResponse.attestationObject.base64URLDecodedData,
4242
let decodedAttestationObject = try CBOR.decode([UInt8](attestationData)) else {
4343
throw WebAuthnError.cborDecodingAttestationDataFailed
@@ -54,8 +54,6 @@ struct ParsedAuthenticatorAttestationResponse {
5454
throw WebAuthnError.missingAttestationFormat
5555
}
5656

57-
// use `format` to decode attestationStatement
58-
5957
guard let attestationFormat = AttestationFormat(rawValue: format) else {
6058
throw WebAuthnError.unsupportedAttestationFormat
6159
}

Sources/WebAuthn/Authenticator/CollectedClientData.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ import Foundation
1616

1717
/// https://www.w3.org/TR/webauthn/#dictionary-client-data
1818
/// The client data represents the contextual bindings of both the WebAuthn Relying Party and the client.
19-
struct CollectedClientData: Codable, Hashable {
19+
public struct CollectedClientData: Codable, Hashable {
2020
enum CollectedClientDataVerifyError: Error {
2121
case ceremonyTypeDoesNotMatch
2222
case challengeDoesNotMatch
2323
case originDoesNotMatch
2424
}
2525

26+
/// Contains the string "webauthn.create" when creating new credentials,
27+
/// and "webauthn.get" when getting an assertion from an existing credential
2628
let type: CeremonyType
29+
/// Contains the base64url encoding of the challenge provided by the Relying Party
2730
let challenge: String
2831
let origin: String
2932
// TODO: Token binding

Sources/WebAuthn/Ceremonies/Registration/CredentialCreationResponse.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,4 @@ public struct CredentialCreationResponse {
4747
}
4848
}
4949

50-
extension CredentialCreationResponse: Codable {
51-
52-
}
50+
extension CredentialCreationResponse: Codable {}

Sources/WebAuthn/Credential.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,31 @@ import Foundation
1616

1717
/// Credential contains all needed information about a WebAuthn credential for storage
1818
public struct Credential {
19+
/// Value will always be "public-key" (for now)
20+
public let type: String
21+
1922
/// base64 encoded String of the credential ID bytes
2023
public let id: String
2124

2225
/// The public key for this certificate
2326
public let publicKey: [UInt8]
2427

25-
/// The attestation format used (if any) by the authenticator when creating the credential.
26-
public let attestationType: AttestationFormat
28+
/// How often the authenticator says the credential was used
29+
/// If this is not implemented by the authenticator this value will always be zero.
30+
public let signCount: UInt32
31+
32+
/// Wether the public key is allowed to be backed up.
33+
/// If a public key is considered backup eligible it is referred to as a multi-device credential (the
34+
/// opposite being single-device credential)
35+
public let backupEligible: Bool
36+
37+
/// If the public key is currently backed up (using another authenticator than the one that generated
38+
/// the credential)
39+
public let isBackedUp: Bool
40+
41+
// MARK: Optional content
42+
43+
public let attestationObject: AttestationObject
2744

28-
/// The Authenticator information for a given certificate
29-
public let authenticator: Authenticator
45+
public let attestationClientDataJSON: CollectedClientData
3046
}

Sources/WebAuthn/CredentialPublicKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protocol PublicKey {
2020
func getString() throws -> String
2121
}
2222

23-
struct CredentialPublicKey {
23+
struct ParsedPublicKeyData {
2424
/// The type of key created. Should be OKP, EC2, or RSA.
2525
let keyType: COSEKeyType
2626
/// A COSEAlgorithmIdentifier for the algorithm used to derive the key signature.

Sources/WebAuthn/Helpers/Base64Utilities.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension String {
4343
}
4444

4545
extension String {
46-
var base64URLDecodedData: Data? {
46+
public var base64URLDecodedData: Data? {
4747
var result = self.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
4848
while result.count % 4 != 0 {
4949
result = result.appending("=")

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,19 @@ public struct WebAuthnManager {
8181
throw WebAuthnError.missingAttestedCredentialData
8282
}
8383

84-
let credentialPublicKey = try CredentialPublicKey(fromPublicKeyBytes: attestedData.publicKey)
85-
try credentialPublicKey.verify(supportedPublicKeyAlgorithms: supportedPublicKeyAlgorithms)
84+
let parsedPublicKeyData = try ParsedPublicKeyData(fromPublicKeyBytes: attestedData.publicKey)
85+
try parsedPublicKeyData.verify(supportedPublicKeyAlgorithms: supportedPublicKeyAlgorithms)
8686

87+
// Return a new credential record (based on step 25.)
8788
return Credential(
88-
id: attestedData.credentialID.base64URLEncodedString(),
89+
type: parsedData.type,
90+
id: parsedData.id,
8991
publicKey: attestedData.publicKey,
90-
attestationType: parsedData.response.attestationObject.format,
91-
authenticator: Authenticator(
92-
aaguid: attestedData.aaguid,
93-
signCount: parsedData.response.attestationObject.authenticatorData.counter
94-
)
92+
signCount: parsedData.response.attestationObject.authenticatorData.counter,
93+
backupEligible: parsedData.response.attestationObject.authenticatorData.flags.isBackupEligible,
94+
isBackedUp: parsedData.response.attestationObject.authenticatorData.flags.isCurrentlyBackedUp,
95+
attestationObject: parsedData.response.attestationObject,
96+
attestationClientDataJSON: parsedData.response.clientData
9597
)
9698
}
9799
}

0 commit comments

Comments
 (0)