Skip to content

Commit 793be78

Browse files
committed
wip
1 parent 588e6dd commit 793be78

File tree

5 files changed

+23
-49
lines changed

5 files changed

+23
-49
lines changed

Sources/WebAuthn/Authenticator/AttestationObject/AttestationFormat.swift

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,4 @@
1-
public enum AttestationFormat: RawRepresentable {
2-
case iana(IANAAttestationFormat)
3-
case custom(String)
4-
5-
public var rawValue: String {
6-
switch self {
7-
case let .iana(format): return format.rawValue
8-
case let .custom(custom): return custom
9-
}
10-
}
11-
12-
public init(rawValue: String) {
13-
if let ianaFormat = IANAAttestationFormat(rawValue: rawValue) {
14-
self = .iana(ianaFormat)
15-
} else {
16-
self = .custom(rawValue)
17-
}
18-
}
19-
20-
// init(from decoder: Decoder) throws {
21-
// let container = try decoder.singleValueContainer()
22-
23-
// let value = try container.decode(String.self)
24-
// if let ianaFormat = IANAAttestationFormat(rawValue: value) {
25-
// self = .iana(ianaFormat)
26-
// } else {
27-
// self = .custom(value)
28-
// }
29-
// }
30-
31-
public func encode(to encoder: Encoder) throws {
32-
var container = encoder.singleValueContainer()
33-
34-
switch self {
35-
case let .iana(format): try container.encode(format)
36-
case let .custom(custom): try container.encode(custom)
37-
}
38-
}
39-
}
40-
41-
public enum IANAAttestationFormat: String, Codable {
1+
public enum AttestationFormat: String, RawRepresentable {
422
case packed
433
case tpm
444
case androidKey = "android-key"

Sources/WebAuthn/Authenticator/AttestationObject/AttestationObject.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ struct AttestationObject {
3636
fatalError("Not implemented yet")
3737
}
3838

39-
if format == .iana(.none) {
40-
guard attestationStatement.isEmpty else {
41-
throw WebAuthnError.attestationStatementMissing
42-
}
43-
}
39+
// Step 17. happening somewhere else (maybe we can move it here?)
40+
41+
// Attestation format already determined. Skipping step 19.
42+
43+
// Step 20.
44+
// TODO: Implement case .packed first! fatalError the rest
45+
// switch format {
46+
// case .androidKey:
47+
// case .androidSafetynet:
48+
// case .apple:
49+
// case .fidoU2F:
50+
// case .packed:
51+
// case .tpm:
52+
// case .none:
53+
// guard attestationStatement.isEmpty else { throw WebAuthnError.attestationStatementMissing }
54+
// }
4455
}
4556
}

Sources/WebAuthn/Authenticator/AuthenticatorAttestationResponse.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ struct ParsedAuthenticatorAttestationResponse {
3737
}
3838
let attestationStatement = decodedAttestationObject["attStmt"]
3939

40+
guard let attestationFormat = AttestationFormat(rawValue: format) else {
41+
throw WebAuthnError.unsupportedAttestationFormat
42+
}
43+
4044
attestationObject = AttestationObject(
4145
authenticatorData: try ParsedAuthenticatorAttestationResponse.parseAuthenticatorData(authDataBytes),
4246
rawAuthenticatorData: authDataBytes,
43-
format: AttestationFormat(rawValue: format),
47+
format: attestationFormat,
4448
attestationStatement: [:]
4549
)
4650
}

Sources/WebAuthn/WebAuthnError.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ public enum WebAuthnError: Error {
3838

3939
case unsupportedCOSEAlgorithm
4040
case unsupportedCredentialPublicKeyAlgorithm
41+
case unsupportedAttestationFormat
4142
}

Sources/WebAuthn/WebAuthnManager.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public struct WebAuthnManager {
8484
let credentialPublicKey = try CredentialPublicKey(fromPublicKeyBytes: attestedData.publicKey)
8585
try credentialPublicKey.verify(supportedPublicKeyAlgorithms: supportedPublicKeyAlgorithms)
8686

87-
// TODO: Verify attStmt
88-
8987
return Credential(
9088
id: attestedData.credentialID.base64URLEncodedString(),
9189
publicKey: attestedData.publicKey,

0 commit comments

Comments
 (0)