1
0
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:
Kyle Spearrin
2017-06-21 22:33:45 -04:00
parent fd5e2c9466
commit 731a1e31b9
12 changed files with 149 additions and 47 deletions

View File

@ -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

View File

@ -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; }

View 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; }
}
}

View File

@ -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; }
}
}