mirror of
https://github.com/bitwarden/server
synced 2026-02-20 11:23:37 +00:00
[PM-29556] Fix: changing organization plan nulls out public and private keys (#6738)
Main fix: only assign new key value where old keys are not set and new keys have been provided. Refactors: - use consistent DTO model for keypairs - delete duplicate property assignment for new orgs
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.KeyManagement.Models.Data;
|
||||
|
||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
|
||||
|
||||
public static class OrganizationExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the organization public and private keys if provided and not already set.
|
||||
/// This is legacy code for old organizations that were not created with a public/private keypair.
|
||||
/// It is a soft migration that will silently migrate organizations when they perform certain actions,
|
||||
/// e.g. change their details or upgrade their plan.
|
||||
/// </summary>
|
||||
public static void BackfillPublicPrivateKeys(this Organization organization, PublicKeyEncryptionKeyPairData? keyPair)
|
||||
{
|
||||
// Only backfill if both new keys are provided and both old keys are missing.
|
||||
if (string.IsNullOrWhiteSpace(keyPair?.PublicKey) ||
|
||||
string.IsNullOrWhiteSpace(keyPair.WrappedPrivateKey) ||
|
||||
!string.IsNullOrWhiteSpace(organization.PublicKey) ||
|
||||
!string.IsNullOrWhiteSpace(organization.PrivateKey))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
organization.PublicKey = keyPair.PublicKey;
|
||||
organization.PrivateKey = keyPair.WrappedPrivateKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user