File tree Expand file tree Collapse file tree 5 files changed +23
-49
lines changed Expand file tree Collapse file tree 5 files changed +23
-49
lines changed Original file line number Diff line number Diff line change 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 {
42
2
case packed
43
3
case tpm
44
4
case androidKey = " android-key "
Original file line number Diff line number Diff line change @@ -36,10 +36,21 @@ struct AttestationObject {
36
36
fatalError ( " Not implemented yet " )
37
37
}
38
38
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
+ // }
44
55
}
45
56
}
Original file line number Diff line number Diff line change @@ -37,10 +37,14 @@ struct ParsedAuthenticatorAttestationResponse {
37
37
}
38
38
let attestationStatement = decodedAttestationObject [ " attStmt " ]
39
39
40
+ guard let attestationFormat = AttestationFormat ( rawValue: format) else {
41
+ throw WebAuthnError . unsupportedAttestationFormat
42
+ }
43
+
40
44
attestationObject = AttestationObject (
41
45
authenticatorData: try ParsedAuthenticatorAttestationResponse . parseAuthenticatorData ( authDataBytes) ,
42
46
rawAuthenticatorData: authDataBytes,
43
- format: AttestationFormat ( rawValue : format ) ,
47
+ format: attestationFormat ,
44
48
attestationStatement: [ : ]
45
49
)
46
50
}
Original file line number Diff line number Diff line change @@ -38,4 +38,5 @@ public enum WebAuthnError: Error {
38
38
39
39
case unsupportedCOSEAlgorithm
40
40
case unsupportedCredentialPublicKeyAlgorithm
41
+ case unsupportedAttestationFormat
41
42
}
Original file line number Diff line number Diff line change @@ -84,8 +84,6 @@ public struct WebAuthnManager {
84
84
let credentialPublicKey = try CredentialPublicKey ( fromPublicKeyBytes: attestedData. publicKey)
85
85
try credentialPublicKey. verify ( supportedPublicKeyAlgorithms: supportedPublicKeyAlgorithms)
86
86
87
- // TODO: Verify attStmt
88
-
89
87
return Credential (
90
88
id: attestedData. credentialID. base64URLEncodedString ( ) ,
91
89
publicKey: attestedData. publicKey,
You can’t perform that action at this time.
0 commit comments