2017-07-06 16:56:12 -04:00
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2017-06-22 09:09:51 -04:00
|
|
|
|
using System.Collections.Generic;
|
2017-06-24 09:20:12 -04:00
|
|
|
|
using U2F.Core.Utils;
|
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>();
|
|
|
|
|
|
|
|
|
|
|
|
public class U2fMetaData
|
|
|
|
|
|
{
|
2017-06-22 22:14:51 -04:00
|
|
|
|
public U2fMetaData() { }
|
|
|
|
|
|
|
|
|
|
|
|
public U2fMetaData(dynamic o)
|
|
|
|
|
|
{
|
2018-10-08 14:38:11 -04:00
|
|
|
|
Name = o.Name;
|
2017-06-22 22:14:51 -04:00
|
|
|
|
KeyHandle = o.KeyHandle;
|
|
|
|
|
|
PublicKey = o.PublicKey;
|
|
|
|
|
|
Certificate = o.Certificate;
|
|
|
|
|
|
Counter = o.Counter;
|
|
|
|
|
|
Compromised = o.Compromised;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-08 14:38:11 -04:00
|
|
|
|
public string Name { get; set; }
|
2017-06-21 21:46:52 -04:00
|
|
|
|
public string KeyHandle { get; set; }
|
2017-06-22 22:14:51 -04:00
|
|
|
|
[JsonIgnore]
|
2017-06-22 09:09:51 -04:00
|
|
|
|
public byte[] KeyHandleBytes =>
|
|
|
|
|
|
string.IsNullOrWhiteSpace(KeyHandle) ? null : Utils.Base64StringToByteArray(KeyHandle);
|
2017-06-21 21:46:52 -04:00
|
|
|
|
public string PublicKey { get; set; }
|
2017-06-22 22:14:51 -04:00
|
|
|
|
[JsonIgnore]
|
2017-06-22 09:09:51 -04:00
|
|
|
|
public byte[] PublicKeyBytes =>
|
|
|
|
|
|
string.IsNullOrWhiteSpace(PublicKey) ? null : Utils.Base64StringToByteArray(PublicKey);
|
2017-06-21 21:46:52 -04:00
|
|
|
|
public string Certificate { get; set; }
|
2017-06-22 22:14:51 -04:00
|
|
|
|
[JsonIgnore]
|
2017-06-22 09:09:51 -04:00
|
|
|
|
public byte[] CertificateBytes =>
|
|
|
|
|
|
string.IsNullOrWhiteSpace(Certificate) ? null : Utils.Base64StringToByteArray(Certificate);
|
2017-06-21 22:33:45 -04:00
|
|
|
|
public uint Counter { get; set; }
|
2017-06-21 21:46:52 -04:00
|
|
|
|
public bool Compromised { get; set; }
|
|
|
|
|
|
}
|
2017-07-06 16:56:12 -04:00
|
|
|
|
|
|
|
|
|
|
public static bool RequiresPremium(TwoFactorProviderType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch(type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case TwoFactorProviderType.Duo:
|
|
|
|
|
|
case TwoFactorProviderType.YubiKey:
|
|
|
|
|
|
case TwoFactorProviderType.U2f:
|
|
|
|
|
|
return true;
|
|
|
|
|
|
default:
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-06 17:15:19 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|