|
5 | 5 | //! on the same HSM slot (via `C_GenerateKey`), assigns a generation-suffixed UID, and |
6 | 6 | //! updates `CKA_LABEL` / `CKA_START_DATE` / `CKA_END_DATE` on both old and new keys. |
7 | 7 |
|
8 | | -use cosmian_kms_server_database::reexport::cosmian_kmip::kmip_2_1::{ |
9 | | - kmip_objects::ObjectType, kmip_operations::ReKeyResponse, kmip_types::UniqueIdentifier, |
| 8 | +use cosmian_kms_server_database::reexport::{ |
| 9 | + cosmian_kmip::kmip_2_1::{ |
| 10 | + kmip_objects::ObjectType, kmip_operations::ReKeyResponse, kmip_types::UniqueIdentifier, |
| 11 | + }, |
| 12 | + cosmian_kms_interfaces::AtomicOperation, |
10 | 13 | }; |
11 | 14 | use cosmian_logger::trace; |
12 | 15 | use time::OffsetDateTime; |
@@ -263,6 +266,18 @@ impl KMS { |
263 | 266 |
|
264 | 267 | trace!("HSM ReKey: old={uid} → new={new_uid} (slot={slot_id}, gen={new_gen}), user={user}"); |
265 | 268 |
|
| 269 | + // Re-wrap any DB keys that were wrapped by the old HSM key, so that |
| 270 | + // they remain accessible under the new generation without requiring |
| 271 | + // the caller to keep the old HSM key alive. |
| 272 | + let mut operations: Vec<AtomicOperation> = Vec::new(); |
| 273 | + Box::pin(self.rewrap_dependants(user, uid, &new_uid, &mut operations)).await?; |
| 274 | + if !operations.is_empty() { |
| 275 | + self.database |
| 276 | + .atomic(user, &operations) |
| 277 | + .await |
| 278 | + .map_err(KmsError::Database)?; |
| 279 | + } |
| 280 | + |
266 | 281 | Ok(ReKeyResponse { |
267 | 282 | unique_identifier: UniqueIdentifier::TextString(new_uid), |
268 | 283 | }) |
|
0 commit comments