2017-07-06 16:56:12 -04:00
|
|
|
|
using System;
|
2017-06-22 09:09:51 -04:00
|
|
|
|
using System.Collections.Generic;
|
2022-01-24 18:13:43 +01:00
|
|
|
|
using System.Text.Json;
|
2017-07-06 16:56:12 -04:00
|
|
|
|
using Bit.Core.Enums;
|
2021-03-22 23:21:43 +01:00
|
|
|
|
using Fido2NetLib.Objects;
|
2017-06-06 17:15:19 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Models
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TwoFactorProvider
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Enabled { get; set; }
|
2017-06-21 21:46:52 -04:00
|
|
|
|
public Dictionary<string, object> MetaData { get; set; } = new Dictionary<string, object>();
|
|
|
|
|
|
|
2021-03-22 23:21:43 +01:00
|
|
|
|
public class WebAuthnData
|
|
|
|
|
|
{
|
|
|
|
|
|
public WebAuthnData() { }
|
|
|
|
|
|
|
|
|
|
|
|
public WebAuthnData(dynamic o)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = o.Name;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Descriptor = o.Descriptor;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2022-01-24 18:13:43 +01:00
|
|
|
|
// Fallback for older newtonsoft serialized tokens.
|
|
|
|
|
|
if (o.Descriptor.Type == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
o.Descriptor.Type = "public-key";
|
|
|
|
|
|
}
|
|
|
|
|
|
Descriptor = JsonSerializer.Deserialize<PublicKeyCredentialDescriptor>(o.Descriptor.ToString(),
|
|
|
|
|
|
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
2021-03-22 23:21:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
PublicKey = o.PublicKey;
|
|
|
|
|
|
UserHandle = o.UserHandle;
|
|
|
|
|
|
SignatureCounter = o.SignatureCounter;
|
|
|
|
|
|
CredType = o.CredType;
|
|
|
|
|
|
RegDate = o.RegDate;
|
|
|
|
|
|
AaGuid = o.AaGuid;
|
|
|
|
|
|
Migrated = o.Migrated;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
public PublicKeyCredentialDescriptor Descriptor { get; internal set; }
|
|
|
|
|
|
public byte[] PublicKey { get; internal set; }
|
|
|
|
|
|
public byte[] UserHandle { get; internal set; }
|
|
|
|
|
|
public uint SignatureCounter { get; set; }
|
|
|
|
|
|
public string CredType { get; internal set; }
|
|
|
|
|
|
public DateTime RegDate { get; internal set; }
|
|
|
|
|
|
public Guid AaGuid { get; internal set; }
|
|
|
|
|
|
public bool Migrated { get; internal set; }
|
2017-06-21 21:46:52 -04:00
|
|
|
|
}
|
2017-07-06 16:56:12 -04:00
|
|
|
|
|
|
|
|
|
|
public static bool RequiresPremium(TwoFactorProviderType type)
|
|
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
switch (type)
|
2017-07-06 16:56:12 -04:00
|
|
|
|
{
|
|
|
|
|
|
case TwoFactorProviderType.Duo:
|
|
|
|
|
|
case TwoFactorProviderType.YubiKey:
|
2021-05-17 09:39:40 +02:00
|
|
|
|
case TwoFactorProviderType.WebAuthn:
|
2017-07-06 16:56:12 -04:00
|
|
|
|
return true;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-06 17:15:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|