Skip to content

Comments

[KeyManager] Add key destruction FFI and background reaper#647

Merged
NilanjanDaw merged 6 commits intogoogle:mainfrom
NilanjanDaw:add-destroy-key-ffi
Feb 18, 2026
Merged

[KeyManager] Add key destruction FFI and background reaper#647
NilanjanDaw merged 6 commits intogoogle:mainfrom
NilanjanDaw:add-destroy-key-ffi

Conversation

@NilanjanDaw
Copy link
Collaborator

@NilanjanDaw NilanjanDaw commented Feb 6, 2026

Enhances key lifecycle management by introducing FFI functions for manual key destruction and a background reaper for automatic expiration.

Key Changes:

  • Key destroy FFI: Added key_manager_destroy_kem_key (KPS) and key_manager_destroy_binding_key (WS) to allow external callers to explicitly remove keys from the registry.
  • Background Reaper: Implemented a background thread in KeyRegistry that periodically scans for and purges expired KEM keys.
  • Registry initialization: Updated KPS KEY_REGISTRY initialization to automatically start the reaper thread.
  • Testing: Added unit tests for manual destruction (success, not found, null ptr) and verified reaper functionality.

This PR is built on top of #645 [KeyManager] Implement FFI for KEM and binding key generation
Please review commit #025520d onwards

@bluegate010
Copy link
Collaborator

This PR has lots of files that are already being reviewed in separate PRs. Will hold off on reviewing until this PR just has new files that are relevant to the reaper functionality.

background reaper

Enhances key lifecycle management by introducing FFI functions for
manual key destruction and a background reaper for automatic expiration.

Key Changes:
- FFI Destruction: Added `key_manager_destroy_kem_key` (KPS) and
  `key_manager_destroy_binding_key` (WS) to allow external callers
  to explicitly remove keys from the registry.
- Background Reaper: Implemented a background thread in `KeyRegistry`
  that periodically scans for and purges expired KEM keys.
- Registry initialization: Updated KPS `KEY_REGISTRY` initialization to
  automatically start the reaper thread.
- Testing: Added unit tests for manual destruction (success, not found,
  null ptr) and verified reaper functionality.
Copy link
Collaborator

@atulpatildbz atulpatildbz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. Thanks

let handle = registry.start_reaper(stop_signal.clone());

// Wait for < expiry (1s) - key should still be there
std::thread::sleep(Duration::from_secs(1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to figure out a way use a channel to notify the test when the reaper completes a cycle?

Or expose a trigger_reaper_scan() private method just for tests? WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be that straight forward since these are separate threads. But I have increased the buffer time between the events to tackle any timing issues. Let me know if you think we should introduce a channel.

@NilanjanDaw
Copy link
Collaborator Author

/gcbrun

@NilanjanDaw NilanjanDaw self-assigned this Feb 18, 2026
@NilanjanDaw NilanjanDaw merged commit c7a8f80 into google:main Feb 18, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants