Skip to content

Commit 835978e

Browse files
committed
Add static AttestationVerifier.Create method
1 parent 5752c1d commit 835978e

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

Src/Fido2/AttestationFormat/AttestationVerifier.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Security.Cryptography.X509Certificates;
77

88
using Fido2NetLib.Cbor;
9+
using Fido2NetLib.Exceptions;
910
using Fido2NetLib.Objects;
1011

1112
namespace Fido2NetLib;
@@ -135,4 +136,20 @@ public virtual (AttestationType, X509Certificate2[]) Verify(CborMap attStmt, byt
135136
}
136137

137138
public abstract (AttestationType, X509Certificate2[]) Verify();
139+
140+
public static AttestationVerifier Create(string formatIdentifier)
141+
{
142+
return formatIdentifier switch
143+
{
144+
"none" => new None(), // https://www.w3.org/TR/webauthn-2/#sctn-none-attestation
145+
"tpm" => new Tpm(), // https://www.w3.org/TR/webauthn-2/#sctn-tpm-attestation
146+
"android-key" => new AndroidKey(), // https://www.w3.org/TR/webauthn-2/#sctn-android-key-attestation
147+
"android-safetynet" => new AndroidSafetyNet(), // https://www.w3.org/TR/webauthn-2/#sctn-android-safetynet-attestation
148+
"fido-u2f" => new FidoU2f(), // https://www.w3.org/TR/webauthn-2/#sctn-fido-u2f-attestation
149+
"packed" => new Packed(), // https://www.w3.org/TR/webauthn-2/#sctn-packed-attestation
150+
"apple" => new Apple(), // https://www.w3.org/TR/webauthn-2/#sctn-apple-anonymous-attestation
151+
"apple-appattest" => new AppleAppAttest(), // https://developer.apple.com/documentation/devicecheck/validating_apps_that_connect_to_your_server
152+
_ => throw new Fido2VerificationException(Fido2ErrorCode.UnknownAttestationType, $"Unknown attestation type. Was '{formatIdentifier}'")
153+
};
154+
}
138155
}

Src/Fido2/AuthenticatorAttestationResponse.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,13 @@ public async Task<AttestationVerificationSuccess> VerifyAsync(
136136
throw new Fido2VerificationException(Fido2ErrorCode.MissingAttestationType, Fido2ErrorMessages.MissingAttestationType);
137137
}
138138

139-
// 13. Determine the attestation statement format by performing a USASCII case-sensitive match on fmt against the set of supported WebAuthn Attestation Statement Format Identifier values.
140-
// An up-to-date list of registered WebAuthn Attestation Statement Format Identifier values is maintained in the IANA registry of the same name
141-
// https://www.w3.org/TR/webauthn/#defined-attestation-formats
142-
AttestationVerifier verifier = AttestationObject.Fmt switch
143-
{
144-
// TODO: Better way to build these mappings?
145-
"none" => new None(), // https://www.w3.org/TR/webauthn/#none-attestation
146-
"tpm" => new Tpm(), // https://www.w3.org/TR/webauthn/#tpm-attestation
147-
"android-key" => new AndroidKey(), // https://www.w3.org/TR/webauthn/#android-key-attestation
148-
"android-safetynet" => new AndroidSafetyNet(), // https://www.w3.org/TR/webauthn/#android-safetynet-attestation
149-
"fido-u2f" => new FidoU2f(), // https://www.w3.org/TR/webauthn/#fido-u2f-attestation
150-
"packed" => new Packed(), // https://www.w3.org/TR/webauthn/#packed-attestation
151-
"apple" => new Apple(), // https://www.w3.org/TR/webauthn/#apple-anonymous-attestation
152-
"apple-appattest" => new AppleAppAttest(), // https://developer.apple.com/documentation/devicecheck/validating_apps_that_connect_to_your_server
153-
_ => throw new Fido2VerificationException(Fido2ErrorCode.UnknownAttestationType, $"Unknown attestation type. Was '{AttestationObject.Fmt}'")
154-
};
139+
// 13. Determine the attestation statement format by performing a USASCII case-sensitive match on fmt
140+
// against the set of supported WebAuthn Attestation Statement Format Identifier values.
141+
var verifier = AttestationVerifier.Create(AttestationObject.Fmt);
155142

156143
// 14. Verify that attStmt is a correct attestation statement, conveying a valid attestation signature,
157-
// by using the attestation statement format fmt’s verification procedure given attStmt, authData and the hash of the serialized client data computed in step 7
144+
// by using the attestation statement format fmt’s verification procedure given attStmt, authData
145+
// and the hash of the serialized client data computed in step 7
158146
(var attType, var trustPath) = verifier.Verify(AttestationObject.AttStmt, AttestationObject.AuthData, clientDataHash);
159147

160148
// 15. If validation is successful, obtain a list of acceptable trust anchors (attestation root certificates or ECDAA-Issuer public keys)

0 commit comments

Comments
 (0)