mirror of
https://github.com/bitwarden/server.git
synced 2026-02-05 00:23:24 +08: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:
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user