mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
add support for storing u2f challenges
This commit is contained in:
parent
50c0b3e752
commit
0c84f9c151
20
src/Core/Models/Table/U2f.cs
Normal file
20
src/Core/Models/Table/U2f.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.Core.Models.Table
|
||||
{
|
||||
public class U2f : IDataObject<int>
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public string KeyHandle { get; set; }
|
||||
public string Challenge { get; set; }
|
||||
public string AppId { get; set; }
|
||||
public string Version { get; set; }
|
||||
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
|
||||
|
||||
public void SetNewId()
|
||||
{
|
||||
// do nothing since it is an identity
|
||||
}
|
||||
}
|
||||
}
|
13
src/Core/Repositories/IU2fRepository.cs
Normal file
13
src/Core/Repositories/IU2fRepository.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IU2fRepository : IRepository<U2f, int>
|
||||
{
|
||||
Task<ICollection<U2f>> GetManyByUserIdAsync(Guid userId);
|
||||
Task DeleteManyByUserIdAsync(Guid userId);
|
||||
}
|
||||
}
|
66
src/Core/Repositories/SqlServer/U2fRepository.cs
Normal file
66
src/Core/Repositories/SqlServer/U2fRepository.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Models.Table;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
public class U2fRepository : Repository<U2f, int>, IU2fRepository
|
||||
{
|
||||
public U2fRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString)
|
||||
{ }
|
||||
|
||||
public U2fRepository(string connectionString)
|
||||
: base(connectionString)
|
||||
{ }
|
||||
|
||||
public async Task<ICollection<U2f>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.QueryAsync<U2f>(
|
||||
$"[{Schema}].[U2f_ReadByUserId]",
|
||||
new { UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
$"[{Schema}].[U2f_DeleteByUserId]",
|
||||
new { UserId = userId },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
}
|
||||
}
|
||||
|
||||
public override Task<U2f> GetByIdAsync(int id)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override Task ReplaceAsync(U2f obj)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override Task UpsertAsync(U2f obj)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override Task DeleteAsync(U2f obj)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -195,5 +195,10 @@
|
||||
<Build Include="dbo\Stored Procedures\Cipher_Delete.sql" />
|
||||
<Build Include="dbo\Functions\UserCipherDetails.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Cipher_Move.sql" />
|
||||
<Build Include="dbo\Tables\U2f.sql" />
|
||||
<Build Include="dbo\Stored Procedures\U2f_Create.sql" />
|
||||
<Build Include="dbo\Stored Procedures\U2f_DeleteByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\U2f_ReadByUserId.sql" />
|
||||
<Build Include="dbo\Views\U2fView.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
33
src/Sql/dbo/Stored Procedures/U2f_Create.sql
Normal file
33
src/Sql/dbo/Stored Procedures/U2f_Create.sql
Normal file
@ -0,0 +1,33 @@
|
||||
CREATE PROCEDURE [dbo].[U2f_Create]
|
||||
@Id INT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@KeyHandle VARCHAR(50),
|
||||
@Challenge VARCHAR(50),
|
||||
@AppId VARCHAR(50),
|
||||
@Version VARCHAR(50),
|
||||
@CreationDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[U2f]
|
||||
(
|
||||
[Id],
|
||||
[UserId],
|
||||
[KeyHandle],
|
||||
[Challenge],
|
||||
[AppId],
|
||||
[Version],
|
||||
[CreationDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@UserId,
|
||||
@KeyHandle,
|
||||
@Challenge,
|
||||
@AppId,
|
||||
@Version,
|
||||
@CreationDate
|
||||
)
|
||||
END
|
12
src/Sql/dbo/Stored Procedures/U2f_DeleteByUserId.sql
Normal file
12
src/Sql/dbo/Stored Procedures/U2f_DeleteByUserId.sql
Normal file
@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [dbo].[U2f_DeleteByUserId]
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[U2f]
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
END
|
13
src/Sql/dbo/Stored Procedures/U2f_ReadByUserId.sql
Normal file
13
src/Sql/dbo/Stored Procedures/U2f_ReadByUserId.sql
Normal file
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[U2f_ReadByUserId]
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[U2fView]
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
END
|
11
src/Sql/dbo/Tables/U2f.sql
Normal file
11
src/Sql/dbo/Tables/U2f.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE [dbo].[U2f] (
|
||||
[Id] INT NOT NULL IDENTITY,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[KeyHandle] VARCHAR (50) NOT NULL,
|
||||
[Challenge] VARCHAR (50) NOT NULL,
|
||||
[AppId] VARCHAR (50) NOT NULL,
|
||||
[Version] VARCHAR (50) NOT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_U2f] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_U2f_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
6
src/Sql/dbo/Views/U2fView.sql
Normal file
6
src/Sql/dbo/Views/U2fView.sql
Normal file
@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[U2fView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[U2f]
|
Loading…
Reference in New Issue
Block a user