using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Fido2NetLib.Objects;
using Newtonsoft.Json;
namespace gehGassi.Domain.Users
{
///
/// Repräsentiert ein FIDO-Credential für einen Benutzer.
/// Wird für Passwordless Login verwendet
///
public class FidoStoredCredential
{
///
/// Eindeutige Id
///
[Key]
[Required]
public long Id { get; set; }
///
/// Benutzername
///
[Required]
[MaxLength(256)]
[EmailAddress]
public string Username { get; set; }
///
/// Name des Fido-Devices. Es können mehrere verwendet werden
///
[Required]
[MaxLength(100)]
public string Name { get; set; }
///
/// Typ des FIDO-Credentials
///
[Required]
public FidoCredentialType CredentialType { get; set; }
///
/// Userid als byte Array
///
[Required]
public byte[] UserId { get; set; }
///
/// Public-Key des Credentials als byte Array
///
[Required]
public byte[] PublicKey { get; set; }
///
/// Fido2 User-Id als byte Array
///
[Required]
public byte[] UserHandle { get; set; }
///
/// Counter für Signature
///
[Required]
public uint SignatureCounter { get; set; }
///
/// Typ des Credentials
///
[Required]
[MaxLength(50)]
public string CredType { get; set; }
///
/// REgistrierungsdatum
///
[Required]
public DateTimeOffset RegDate { get; set; }
///
/// Authenticator Attestation GUID
///
[Required]
public Guid AaGuid { get; set; }
///
/// 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.
///
[Required]
public string DescriptorJson { get; set; }
///
/// 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.
///
[NotMapped]
public PublicKeyCredentialDescriptor Descriptor
{
get => string.IsNullOrWhiteSpace(DescriptorJson) ? null : JsonConvert.DeserializeObject(DescriptorJson);
set => DescriptorJson = JsonConvert.SerializeObject(value);
}
}
///
/// Typ des FIDO-Credentials
///
public enum FidoCredentialType
{
///
/// Authentifizierung durch ein Gerät / OS
///
Platform = 1,
///
/// Authentifizierung durch ein Token. z.b. YubiKey
///
Crossplatform = 2
}
}