File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed
Ceremonies/Authentication Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -16,15 +16,13 @@ import Foundation
16
16
17
17
/// The unprocessed response received from `navigator.credentials.get()`.
18
18
public struct AuthenticationCredential : Codable {
19
- public let id : String
20
- public let rawID : URLEncodedBase64
19
+ public let id : URLEncodedBase64
21
20
public let response : AuthenticatorAssertionResponse
22
21
public let authenticatorAttachment : String ?
23
22
public let type : String
24
23
25
24
enum CodingKeys : String , CodingKey {
26
25
case id
27
- case rawID = " rawId "
28
26
case response
29
27
case authenticatorAttachment
30
28
case type
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ extension Array where Element == UInt8 {
33
33
}
34
34
}
35
35
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
+
36
44
extension String {
37
45
/// Decode a base64url-encoded `String` to a base64 `String`
38
46
/// - Returns: A base64-encoded `String`
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -129,10 +129,9 @@ public struct WebAuthnManager {
129
129
credentialPublicKey: [ UInt8 ] ,
130
130
credentialCurrentSignCount: Int ,
131
131
requireUserVerification: Bool = false
132
- ) throws {
132
+ ) throws -> VerifiedAuthentication {
133
133
let expectedRpID = config. relyingPartyID
134
134
let expectedOrigin = config. relyingPartyOrigin
135
- guard credential. rawID == credential. id else { throw WebAuthnError . badRequestData }
136
135
guard credential. type == " public-key " else { throw WebAuthnError . badRequestData }
137
136
138
137
let response = credential. response
@@ -170,6 +169,13 @@ public struct WebAuthnManager {
170
169
let credentialPublicKey = try CredentialPublicKey ( publicKeyBytes: credentialPublicKey)
171
170
guard let signatureData = response. signature. base64URLDecodedData else { throw WebAuthnError . badRequestData }
172
171
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
+ )
173
179
}
174
180
}
175
181
You can’t perform that action at this time.
0 commit comments