mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
add support for multiple u2f keys
This commit is contained in:
@ -223,10 +223,25 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
}
|
||||
|
||||
public class TwoFactorU2fRequestModel : TwoFactorRequestModel
|
||||
public class TwoFactorU2fRequestModel : TwoFactorU2fDeleteRequestModel
|
||||
{
|
||||
[Required]
|
||||
public string DeviceResponse { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class TwoFactorU2fDeleteRequestModel : TwoFactorRequestModel, IValidatableObject
|
||||
{
|
||||
[Required]
|
||||
public int? Id { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Id.HasValue || Id < 0 || Id > 5)
|
||||
{
|
||||
yield return new ValidationResult("Invalid Key Id", new string[] { nameof(Id) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateTwoFactorEmailRequestModel : TwoFactorEmailRequestModel
|
||||
|
@ -2,26 +2,13 @@
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Models.Business;
|
||||
using Bit.Core.Enums;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class TwoFactorU2fResponseModel : ResponseModel
|
||||
{
|
||||
public TwoFactorU2fResponseModel(User user, TwoFactorProvider provider, U2fRegistration registration = null)
|
||||
: base("twoFactorU2f")
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
|
||||
if(registration != null)
|
||||
{
|
||||
Challenge = new ChallengeModel(user, registration);
|
||||
}
|
||||
Enabled = provider?.Enabled ?? false;
|
||||
}
|
||||
|
||||
public TwoFactorU2fResponseModel(User user)
|
||||
: base("twoFactorU2f")
|
||||
{
|
||||
@ -31,11 +18,27 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.U2f);
|
||||
Enabled = provider != null && provider.Enabled;
|
||||
Enabled = provider?.Enabled ?? false;
|
||||
Keys = provider?.MetaData?.Select(k => new KeyModel(k.Key,
|
||||
new TwoFactorProvider.U2fMetaData((dynamic)k.Value)));
|
||||
}
|
||||
|
||||
public ChallengeModel Challenge { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public IEnumerable<KeyModel> Keys { get; set; }
|
||||
|
||||
public class KeyModel
|
||||
{
|
||||
public KeyModel(string id, TwoFactorProvider.U2fMetaData data)
|
||||
{
|
||||
Name = data.Name;
|
||||
Id = Convert.ToInt32(id.Replace("Key", string.Empty));
|
||||
Compromised = data.Compromised;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
public bool Compromised { get; set; }
|
||||
}
|
||||
|
||||
public class ChallengeModel
|
||||
{
|
||||
|
@ -17,6 +17,7 @@ namespace Bit.Core.Models
|
||||
|
||||
public U2fMetaData(dynamic o)
|
||||
{
|
||||
Name = o.Name;
|
||||
KeyHandle = o.KeyHandle;
|
||||
PublicKey = o.PublicKey;
|
||||
Certificate = o.Certificate;
|
||||
@ -24,6 +25,7 @@ namespace Bit.Core.Models
|
||||
Compromised = o.Compromised;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string KeyHandle { get; set; }
|
||||
[JsonIgnore]
|
||||
public byte[] KeyHandleBytes =>
|
||||
|
Reference in New Issue
Block a user