mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
initiating u2f registration
This commit is contained in:
@ -199,33 +199,6 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
[Required]
|
||||
public string DeviceResponse { get; set; }
|
||||
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.U2f))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.U2f);
|
||||
}
|
||||
|
||||
providers.Add(TwoFactorProviderType.U2f, new TwoFactorProvider
|
||||
{
|
||||
MetaData = new Dictionary<string, object>
|
||||
{
|
||||
["Key1"] = new TwoFactorProvider.U2fMetaData
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
},
|
||||
Enabled = true
|
||||
});
|
||||
extistingUser.SetTwoFactorProviders(providers);
|
||||
return extistingUser;
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateTwoFactorEmailRequestModel : TwoFactorEmailRequestModel
|
||||
|
@ -1,11 +1,27 @@
|
||||
using System;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Models.Business;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public TwoFactorU2fResponseModel(User user)
|
||||
: base("twoFactorU2f")
|
||||
{
|
||||
@ -15,18 +31,7 @@ namespace Bit.Core.Models.Api
|
||||
}
|
||||
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.U2f);
|
||||
if(provider?.MetaData != null && provider.MetaData.Count > 0)
|
||||
{
|
||||
Challenge = new ChallengeModel
|
||||
{
|
||||
// TODO
|
||||
};
|
||||
Enabled = provider.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
Enabled = provider != null && provider.Enabled;
|
||||
}
|
||||
|
||||
public ChallengeModel Challenge { get; set; }
|
||||
@ -34,6 +39,14 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public class ChallengeModel
|
||||
{
|
||||
public ChallengeModel(User user, U2fRegistration registration)
|
||||
{
|
||||
UserId = user.Id.ToString();
|
||||
AppId = registration.AppId;
|
||||
Challenge = registration.Challenge;
|
||||
Version = registration.Version;
|
||||
}
|
||||
|
||||
public string UserId { get; set; }
|
||||
public string AppId { get; set; }
|
||||
public string Challenge { get; set; }
|
||||
|
9
src/Core/Models/Business/U2fRegistration.cs
Normal file
9
src/Core/Models/Business/U2fRegistration.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Bit.Core.Models.Business
|
||||
{
|
||||
public class U2fRegistration
|
||||
{
|
||||
public string AppId { get; set; }
|
||||
public string Challenge { get; set; }
|
||||
public string Version { get; set; }
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace Bit.Core.Models
|
||||
public string KeyHandle { get; set; }
|
||||
public string PublicKey { get; set; }
|
||||
public string Certificate { get; set; }
|
||||
public int Counter { get; set; }
|
||||
public uint Counter { get; set; }
|
||||
public bool Compromised { get; set; }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user