gehgassi_backend/gehGassi.Domain/Users/FidoStoredCredential.cs

118 lines
3.5 KiB
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Fido2NetLib.Objects;
using Newtonsoft.Json;
namespace gehGassi.Domain.Users
{
/// <summary>
/// Repräsentiert ein FIDO-Credential für einen Benutzer.
/// Wird für Passwordless Login verwendet
/// </summary>
public class FidoStoredCredential
{
/// <summary>
/// Eindeutige Id
/// </summary>
[Key]
[Required]
public long Id { get; set; }
/// <summary>
/// Benutzername
/// </summary>
[Required]
[MaxLength(256)]
[EmailAddress]
public string Username { get; set; }
/// <summary>
/// Name des Fido-Devices. Es können mehrere verwendet werden
/// </summary>
[Required]
[MaxLength(100)]
public string Name { get; set; }
/// <summary>
/// Typ des FIDO-Credentials
/// </summary>
[Required]
public FidoCredentialType CredentialType { get; set; }
/// <summary>
/// Userid als byte Array
/// </summary>
[Required]
public byte[] UserId { get; set; }
/// <summary>
/// Public-Key des Credentials als byte Array
/// </summary>
[Required]
public byte[] PublicKey { get; set; }
/// <summary>
/// Fido2 User-Id als byte Array
/// </summary>
[Required]
public byte[] UserHandle { get; set; }
/// <summary>
/// Counter für Signature
/// </summary>
[Required]
public uint SignatureCounter { get; set; }
/// <summary>
/// Typ des Credentials
/// </summary>
[Required]
[MaxLength(50)]
public string CredType { get; set; }
/// <summary>
/// REgistrierungsdatum
/// </summary>
[Required]
public DateTimeOffset RegDate { get; set; }
/// <summary>
/// Authenticator Attestation GUID
/// </summary>
[Required]
public Guid AaGuid { get; set; }
/// <summary>
/// This object contains the attributes that are specified by a caller when referring to a public key credential as an input parameter to the create() or get() methods. It mirrors the fields of the PublicKeyCredential object returned by the latter methods.
/// </summary>
[Required]
public string DescriptorJson { get; set; }
/// <summary>
/// This object contains the attributes that are specified by a caller when referring to a public key credential as an input parameter to the create() or get() methods. It mirrors the fields of the PublicKeyCredential object returned by the latter methods.
/// </summary>
[NotMapped]
public PublicKeyCredentialDescriptor Descriptor
{
get => string.IsNullOrWhiteSpace(DescriptorJson) ? null : JsonConvert.DeserializeObject<PublicKeyCredentialDescriptor>(DescriptorJson);
set => DescriptorJson = JsonConvert.SerializeObject(value);
}
}
/// <summary>
/// Typ des FIDO-Credentials
/// </summary>
public enum FidoCredentialType
{
/// <summary>
/// Authentifizierung durch ein Gerät / OS
/// </summary>
Platform = 1,
/// <summary>
/// Authentifizierung durch ein Token. z.b. YubiKey
/// </summary>
Crossplatform = 2
}
}