Skip to content

Commit df6ac35

Browse files
committed
remove AuthenticationCredential rawID
1 parent b2e6e97 commit df6ac35

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

Sources/WebAuthn/Ceremonies/Authentication/AuthenticationCredential.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ import Foundation
1616

1717
/// The unprocessed response received from `navigator.credentials.get()`.
1818
public struct AuthenticationCredential: Codable {
19-
public let id: String
20-
public let rawID: URLEncodedBase64
19+
public let id: URLEncodedBase64
2120
public let response: AuthenticatorAssertionResponse
2221
public let authenticatorAttachment: String?
2322
public let type: String
2423

2524
enum CodingKeys: String, CodingKey {
2625
case id
27-
case rawID = "rawId"
2826
case response
2927
case authenticatorAttachment
3028
case type

Sources/WebAuthn/Helpers/Base64Utilities.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ extension Array where Element == UInt8 {
3333
}
3434
}
3535

36+
extension Data {
37+
/// Encodes data into a base64url-encoded string
38+
/// - Returns: A base64url-encoded string
39+
public func base64URLEncodedString() -> String {
40+
return [UInt8](self).base64URLEncodedString()
41+
}
42+
}
43+
3644
extension String {
3745
/// Decode a base64url-encoded `String` to a base64 `String`
3846
/// - Returns: A base64-encoded `String`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foundation
2+
3+
public struct VerifiedAuthentication {
4+
let credentialID: URLEncodedBase64
5+
let newSignCount: UInt32
6+
let credentialDeviceType: CredentialDeviceType
7+
let credentialBackedUp: Bool
8+
}
9+
10+
public enum CredentialDeviceType: String, Codable {
11+
case singleDevice = "single_device"
12+
case multiDevice = "multi_device"
13+
}

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ public struct WebAuthnManager {
129129
credentialPublicKey: [UInt8],
130130
credentialCurrentSignCount: Int,
131131
requireUserVerification: Bool = false
132-
) throws {
132+
) throws -> VerifiedAuthentication {
133133
let expectedRpID = config.relyingPartyID
134134
let expectedOrigin = config.relyingPartyOrigin
135-
guard credential.rawID == credential.id else { throw WebAuthnError.badRequestData }
136135
guard credential.type == "public-key" else { throw WebAuthnError.badRequestData }
137136

138137
let response = credential.response
@@ -170,6 +169,13 @@ public struct WebAuthnManager {
170169
let credentialPublicKey = try CredentialPublicKey(publicKeyBytes: credentialPublicKey)
171170
guard let signatureData = response.signature.base64URLDecodedData else { throw WebAuthnError.badRequestData }
172171
try credentialPublicKey.verify(signature: signatureData, data: signatureBase)
172+
173+
return VerifiedAuthentication(
174+
credentialID: credential.id,
175+
newSignCount: authenticatorData.counter,
176+
credentialDeviceType: authenticatorData.flags.isBackupEligible ? .multiDevice : .singleDevice,
177+
credentialBackedUp: authenticatorData.flags.isCurrentlyBackedUp
178+
)
173179
}
174180
}
175181

0 commit comments

Comments
 (0)