Files
server/src/Core/Models/TwoFactorProvider.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.3 KiB
C#
Raw Normal View History

2017-07-06 16:56:12 -04:00
using System;
2017-06-22 09:09:51 -04:00
using System.Collections.Generic;
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;
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
{
// 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)
{
switch (type)
2017-07-06 16:56:12 -04:00
{
case TwoFactorProviderType.Duo:
case TwoFactorProviderType.YubiKey:
case TwoFactorProviderType.WebAuthn:
2017-07-06 16:56:12 -04:00
return true;
default:
return false;
}
}
}
}