-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add UpdateAccountCryptographicState repository function #6669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+374
โ3
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e4a8a41
Add user repository update function for account cryptographic state
quexten b170651
Remove comment
quexten 139549d
Remove transaction logic
quexten d59c25c
Fix security version
quexten e78765f
Apply feedback
quexten 9726f49
Update tests
quexten b4681cc
Add support for external actions
quexten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,34 @@ | ||
| ๏ปฟnamespace Bit.Core.KeyManagement.Models.Data; | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Represents an expanded account cryptographic state for a user. Expanded here means | ||
| /// that it does not only contain the (wrapped) private / signing key, but also the public | ||
| /// key / verifying key. The client side only needs a subset of this data to unlock | ||
| /// their vault and the public parts can be derived. | ||
| /// </summary> | ||
| public class UserAccountKeysData | ||
| { | ||
| public required PublicKeyEncryptionKeyPairData PublicKeyEncryptionKeyPairData { get; set; } | ||
| public SignatureKeyPairData? SignatureKeyPairData { get; set; } | ||
| public SecurityStateData? SecurityStateData { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Checks whether the account cryptographic state is for a V1 encryption user or a V2 encryption user. | ||
| /// Throws if the state is invalid | ||
| /// </summary> | ||
| public bool IsV2Encryption() | ||
| { | ||
| if (PublicKeyEncryptionKeyPairData.SignedPublicKey != null && SignatureKeyPairData != null && SecurityStateData != null) | ||
| { | ||
| return true; | ||
| } | ||
| else if (PublicKeyEncryptionKeyPairData.SignedPublicKey == null && SignatureKeyPairData == null && SecurityStateData == null) | ||
| { | ||
| return false; | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidOperationException("Invalid account cryptographic state: V2 encryption fields must be either all present or all absent."); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Sql/dbo/Stored Procedures/User_UpdateAccountCryptographicState.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| CREATE PROCEDURE [dbo].[User_UpdateAccountCryptographicState] | ||
| @Id UNIQUEIDENTIFIER, | ||
| @PublicKey NVARCHAR(MAX), | ||
| @PrivateKey NVARCHAR(MAX), | ||
| @SignedPublicKey NVARCHAR(MAX) = NULL, | ||
| @SecurityState NVARCHAR(MAX) = NULL, | ||
| @SecurityVersion INT = 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 | ||
|
|
||
| -- Update or insert signature key pair if provided | ||
| IF @SignatureAlgorithm IS NOT NULL AND @SigningKey IS NOT NULL AND @VerifyingKey IS NOT NULL | ||
| BEGIN | ||
| 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 | ||
| ( | ||
| NEWID(), | ||
quexten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Id, | ||
| @SignatureAlgorithm, | ||
| @SigningKey, | ||
| @VerifyingKey, | ||
| @RevisionDate, | ||
| @RevisionDate | ||
| ) | ||
| END | ||
| END | ||
| END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.