mirror of
https://github.com/bitwarden/server
synced 2025-12-19 09:43:25 +00:00
Add UpdateAccountCryptographicState repository function (#6669)
* Add user repository update function for account cryptographic state * Remove comment * Remove transaction logic * Fix security version * Apply feedback * Update tests * Add support for external actions
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
IF OBJECT_ID('[dbo].[User_UpdateAccountCryptographicState]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[User_UpdateAccountCryptographicState]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[User_UpdateAccountCryptographicState]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@PublicKey NVARCHAR(MAX),
|
||||
@PrivateKey NVARCHAR(MAX),
|
||||
@SignedPublicKey NVARCHAR(MAX) = NULL,
|
||||
@SecurityState NVARCHAR(MAX) = NULL,
|
||||
@SecurityVersion INT = NULL,
|
||||
@SignatureKeyPairId UNIQUEIDENTIFIER = NULL,
|
||||
@SignatureAlgorithm TINYINT = NULL,
|
||||
@SigningKey VARCHAR(MAX) = NULL,
|
||||
@VerifyingKey VARCHAR(MAX) = NULL,
|
||||
@RevisionDate DATETIME2(7),
|
||||
@AccountRevisionDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[User]
|
||||
SET
|
||||
[PublicKey] = @PublicKey,
|
||||
[PrivateKey] = @PrivateKey,
|
||||
[SignedPublicKey] = @SignedPublicKey,
|
||||
[SecurityState] = @SecurityState,
|
||||
[SecurityVersion] = @SecurityVersion,
|
||||
[RevisionDate] = @RevisionDate,
|
||||
[AccountRevisionDate] = @AccountRevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF EXISTS (SELECT 1 FROM [dbo].[UserSignatureKeyPair] WHERE [UserId] = @Id)
|
||||
BEGIN
|
||||
UPDATE [dbo].[UserSignatureKeyPair]
|
||||
SET
|
||||
[SignatureAlgorithm] = @SignatureAlgorithm,
|
||||
[SigningKey] = @SigningKey,
|
||||
[VerifyingKey] = @VerifyingKey,
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[UserId] = @Id
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
INSERT INTO [dbo].[UserSignatureKeyPair]
|
||||
(
|
||||
[Id],
|
||||
[UserId],
|
||||
[SignatureAlgorithm],
|
||||
[SigningKey],
|
||||
[VerifyingKey],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@SignatureKeyPairId,
|
||||
@Id,
|
||||
@SignatureAlgorithm,
|
||||
@SigningKey,
|
||||
@VerifyingKey,
|
||||
@RevisionDate,
|
||||
@RevisionDate
|
||||
)
|
||||
END
|
||||
END
|
||||
GO
|
||||
Reference in New Issue
Block a user