-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a510e4
commit 539bcbb
Showing
5 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/KristofferStrube.Blazor.WebAuthentication/Converters/AttestationFormatConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace KristofferStrube.Blazor.WebAuthentication.Converters; | ||
|
||
public class AttestationFormatConverter : JsonConverter<AttestationFormat> | ||
{ | ||
public override AttestationFormat Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return reader.GetString() switch | ||
{ | ||
"packed" => AttestationFormat.Packed, | ||
"tpm" => AttestationFormat.TPM, | ||
"android-key" => AttestationFormat.AndroidKey, | ||
"android-safetynet" => AttestationFormat.AndroidSafetyNet, | ||
"fido-u2f" => AttestationFormat.FidoU2F, | ||
"apple" => AttestationFormat.Apple, | ||
"none" => AttestationFormat.None, | ||
var value => throw new ArgumentException($"Value '{value}' was not a valid {nameof(AttestationFormat)}.") | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, AttestationFormat value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStringValue(value switch | ||
{ | ||
AttestationFormat.Packed => "packed", | ||
AttestationFormat.TPM => "tpm", | ||
AttestationFormat.AndroidKey => "android-key", | ||
AttestationFormat.AndroidSafetyNet => "android-safetynet", | ||
AttestationFormat.FidoU2F => "fido-u2f", | ||
AttestationFormat.Apple => "apple", | ||
AttestationFormat.None => "none", | ||
_ => throw new ArgumentException($"Value '{value}' was not a valid {nameof(AttestationFormat)}.") | ||
}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/KristofferStrube.Blazor.WebAuthentication/Options/AttestationFormat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using KristofferStrube.Blazor.WebAuthentication.Converters; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace KristofferStrube.Blazor.WebAuthentication; | ||
|
||
/// <summary> | ||
/// Authenticators may implement various transports for communicating with clients. | ||
/// This enum defines hints as to how clients might communicate with a particular authenticator in order to obtain an assertion for a specific credential. | ||
/// </summary> | ||
/// <remarks><see href="https://www.iana.org/assignments/webauthn/webauthn.xhtml">See the API definition here</see>.</remarks> | ||
[JsonConverter(typeof(AttestationFormatConverter))] | ||
public enum AttestationFormat | ||
{ | ||
/// <summary> | ||
/// The "packed" attestation statement format is a WebAuthn-optimized format for attestation. It uses a very compact but still extensible encoding method. | ||
/// This format is implementable by authenticators with limited resources (e.g., secure elements). | ||
/// </summary> | ||
Packed, | ||
/// <summary> | ||
/// The TPM attestation statement format returns an attestation statement in the same format as the packed attestation statement format, | ||
/// although the rawData and signature fields are computed differently. | ||
/// </summary> | ||
TPM, | ||
/// <summary> | ||
/// Platform authenticators on versions "N", and later, may provide this proprietary "hardware attestation" statement. | ||
/// </summary> | ||
AndroidKey, | ||
/// <summary> | ||
/// Android-based platform authenticators MAY produce an attestation statement based on the Android SafetyNet API. | ||
/// </summary> | ||
AndroidSafetyNet, | ||
/// <summary> | ||
/// Used with FIDO U2F authenticators | ||
/// </summary> | ||
FidoU2F, | ||
/// <summary> | ||
/// Used with Apple devices' platform authenticators | ||
/// </summary> | ||
Apple, | ||
/// <summary> | ||
/// Used to replace any authenticator-provided attestation statement when a WebAuthn Relying Party indicates it does not wish to receive attestation information. | ||
/// </summary> | ||
None, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters