Skip to content

Commit b91c8db

Browse files
committed
clean up files and add rsa
1 parent c3de0c8 commit b91c8db

34 files changed

+220
-345
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let package = Package(
3434
dependencies: [
3535
"SwiftCBOR",
3636
.product(name: "Crypto", package: "swift-crypto"),
37+
.product(name: "_CryptoExtras", package: "swift-crypto"),
3738
.product(name: "Logging", package: "swift-log")
3839
]
3940
),

Sources/WebAuthn/Authenticator.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

Sources/WebAuthn/Authenticator/AttestationObject/AttestationStatementVerification.swift

Lines changed: 0 additions & 53 deletions
This file was deleted.

Sources/WebAuthn/Authenticator/AuthenticatorResponse/AuthenticatorResponse.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/WebAuthn/Authenticator/AuthenticatorTransport.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/WebAuthn/Authenticator/AuthenticatorResponse/AuthenticatorAssertionResponse.swift renamed to Sources/WebAuthn/Ceremonies/Authentication/AuthenticatorAssertionResponse.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,20 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
/// From §5.2.2
16-
/// The AuthenticatorAssertionResponse interface represents an authenticator's response to a client’s request for
17-
/// generation of a new authentication assertion given the WebAuthn Relying Party's challenge and OPTIONAL list of
18-
/// credentials it is aware of. This response contains a cryptographic signature proving possession of the credential
19-
/// private key, and optionally evidence of user consent to a specific transaction.
20-
public struct AuthenticatorAssertionResponse: AuthenticatorResponse, Codable {
15+
/// This is what the authenticator device returned after we requested it to authenticate a user.
16+
public struct AuthenticatorAssertionResponse: Codable {
17+
/// Representation of what we passed to `navigator.credentials.get()`
2118
public let clientDataJSON: URLEncodedBase64
2219
/// Contains the authenticator data returned by the authenticator.
2320
public let authenticatorData: URLEncodedBase64
2421
/// Contains the raw signature returned from the authenticator
25-
public let signature: String
22+
public let signature: URLEncodedBase64
2623
/// Contains the user handle returned from the authenticator, or null if the authenticator did not return
27-
/// a user handle.
24+
/// a user handle. Used by to give scope to credentials.
2825
public let userHandle: String?
2926
/// Contains an attestation object, if the authenticator supports attestation in assertions.
3027
/// The attestation object, if present, includes an attestation statement. Unlike the attestationObject
3128
/// in an AuthenticatorAttestationResponse, it does not contain an authData key because the authenticator
3229
/// data is provided directly in an AuthenticatorAssertionResponse structure.
3330
public let attestationObject: String?
3431
}
35-
36-
public struct ParsedAuthenticatorAssertionResponse {
37-
38-
}

Sources/WebAuthn/Ceremonies/Authentication/PublicKeyCredentialRequestOptions.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import Foundation
1616

17+
/// The `PublicKeyCredentialRequestOptions` gets passed to the WebAuthn API (`navigator.credentials.get()`)
1718
public struct PublicKeyCredentialRequestOptions: Codable {
1819
public let challenge: String
1920
public let timeout: TimeInterval?
@@ -26,6 +27,18 @@ public struct PublicKeyCredentialRequestOptions: Codable {
2627
}
2728

2829
public struct PublicKeyCredentialDescriptor: Codable {
30+
public enum AuthenticatorTransport: String, Codable {
31+
case usb
32+
case nfc
33+
case ble
34+
case hybrid
35+
case `internal`
36+
}
37+
38+
enum CodingKeys: String, CodingKey {
39+
case type, id, transports
40+
}
41+
2942
public let type: String
3043
public let id: [UInt8]
3144
public let transports: [AuthenticatorTransport]
@@ -36,10 +49,6 @@ public struct PublicKeyCredentialDescriptor: Codable {
3649
self.transports = transports
3750
}
3851

39-
enum CodingKeys: String, CodingKey {
40-
case type, id, transports
41-
}
42-
4352
public func encode(to encoder: Encoder) throws {
4453
var container = encoder.container(keyedBy: CodingKeys.self)
4554

@@ -48,3 +57,9 @@ public struct PublicKeyCredentialDescriptor: Codable {
4857
try container.encode(transports, forKey: .transports)
4958
}
5059
}
60+
61+
public enum UserVerificationRequirement: String, Codable {
62+
case required
63+
case preferred
64+
case discouraged
65+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
3+
/// On successful authentication, this structure contains a summary of the authentication flow
4+
public struct VerifiedAuthentication {
5+
public enum CredentialDeviceType: String, Codable {
6+
case singleDevice = "single_device"
7+
case multiDevice = "multi_device"
8+
}
9+
10+
let credentialID: URLEncodedBase64
11+
let newSignCount: UInt32
12+
let credentialDeviceType: CredentialDeviceType
13+
let credentialBackedUp: Bool
14+
}

Sources/WebAuthn/Authenticator/AttestationObject/AttestationObject.swift renamed to Sources/WebAuthn/Ceremonies/Registration/AttestationObject.swift

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import Crypto
1616
import SwiftCBOR
1717

18+
/// Contains the cryptographic attestation that a new key pair was created by that authenticator.
1819
public struct AttestationObject {
1920
let authenticatorData: AuthenticatorData
2021
let rawAuthenticatorData: [UInt8]
@@ -24,46 +25,28 @@ public struct AttestationObject {
2425
func verify(relyingPartyID: String, verificationRequired: Bool, clientDataHash: SHA256.Digest) throws {
2526
let relyingPartyIDHash = SHA256.hash(data: relyingPartyID.data(using: .utf8)!)
2627

27-
// Step 12.
2828
guard relyingPartyIDHash == authenticatorData.relyingPartyIDHash else {
2929
throw WebAuthnError.relyingPartyIDHashDoesNotMatch
3030
}
3131

32-
// Step 13.
3332
guard authenticatorData.flags.userPresent else {
3433
throw WebAuthnError.userPresentFlagNotSet
3534
}
3635

37-
// Step 14.
3836
if verificationRequired {
3937
guard authenticatorData.flags.userVerified else {
4038
throw WebAuthnError.userVerificationRequiredButFlagNotSet
4139
}
4240
}
4341

44-
// Step 17. happening somewhere else (maybe we can move it here?)
45-
46-
// Attestation format already determined. Skipping step 19.
47-
48-
// Step 20.
4942
switch format {
50-
case .androidKey:
51-
fatalError("Not implemented")
52-
case .androidSafetynet:
53-
fatalError("Not implemented")
54-
case .apple:
55-
fatalError("Not implemented")
56-
case .fidoU2F:
57-
fatalError("Not implemented")
58-
case .packed:
59-
try AttestationStatementVerification.verifyPacked(attestationObject: self, clientDataHash: clientDataHash)
60-
case .tpm:
61-
fatalError("Not implemented")
6243
case .none:
6344
// if format is `none` statement must be empty
6445
guard attestationStatement == .map([:]) else {
6546
throw WebAuthnError.attestationStatementMissing
6647
}
48+
default:
49+
throw WebAuthnError.attestationVerificationNotSupported
6750
}
6851
}
6952
}

0 commit comments

Comments
 (0)