LibXMTP implements automatic key rotation to maintain forward secrecy and limit the impact of key compromise.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/xmtp/libxmtp/llms.txt
Use this file to discover all available pages before exploring further.
Key Types and Rotation Policies
Installation Signature Keys
NOT rotated Installation signature keys (Ed25519) form the persistent identity for an installation and are never rotated.- MLS leaf nodes as the installation identifier
- Key package signatures
- Credential binding to the inbox
Path Encryption Secrets
Rotated periodically Path encryption secrets provide forward secrecy and are updated automatically. Rotation triggers:- Before first message - Before sending the first message to any group
- After 3 months - Before sending a message if 3 months (90 days) have elapsed since the last path update
HPKE Key Pairs
Rotated with key packages HPKE keys are used to encrypt Welcome messages and are rotated as part of key package rotation. Key package rotation occurs:- After receiving a Welcome message that used the published key package
- When explicitly queued by the application
- Periodically if a rotation is queued
Clients may batch rotations - if N Welcome messages arrive simultaneously, only one rotation is performed.
- Current key package HPKE key
- Previous key package HPKE key
Key Package Lifecycle
Generation and Upload
Key packages are generated during:- Initial registration - First time client is created
- Rotation - After Welcome messages or when queued
crates/xmtp_mls/src/identity.rs:681-690
Post-Quantum Key Package Extensions
LibXMTP includes post-quantum encryption in key packages using XWing-06. Extension structure:crates/xmtp_mls/src/groups/mls_ext.rs
Key Package Validation
When fetching a key package for another user: MLS validation (OpenMLS):- Extract and decode MLS credential
- Fetch identity updates for the inbox
- Verify installation key is in the current association state
crates/xmtp_mls/src/verified_key_package_v2.rs:74-86
Automatic Rotation
Rotation Worker
TheKeyPackagesCleanerWorker runs periodically to:
- Delete expired key packages
- Rotate the key package if needed
crates/xmtp_mls/src/worker/key_package_cleaner.rs
Rotation Trigger Logic
1. After Welcome Message When processing a Welcome:crates/xmtp_mls/src/worker/key_package_cleaner.rs:189-205
Deletion of Old Key Packages
After successful rotation:- OpenMLS key package from key store
- Post-quantum private key (if present)
- Database history entry (after confirmed deleted)
crates/xmtp_mls/src/worker/key_package_cleaner.rs:145-170
Key Package Reuse
LibXMTP uses last resort key packages only, meaning the same key package may be used multiple times.Why does XMTP reuse key packages?
Why does XMTP reuse key packages?
Due to XMTP’s decentralized nature, it is nearly impossible to use truly ephemeral (one-time) key packages.While RFC 9420 Section 10 states key packages SHOULD NOT be reused, XMTP implements aggressive rotation to minimize the window of reuse.
Mitigation Strategy
Immediate rotation protocol:- Client publishes key package KP1 to network
- Alice downloads KP1 and creates a group
- Alice sends Welcome message encrypted with KP1’s HPKE key
- Client receives Welcome, joins group
- Client immediately rotates to KP2
- Any subsequent invites use KP2
- Process all Welcome messages
- Rotate once after processing all
- Reduces rotation overhead while maintaining security
Security Considerations
See Section 16.8 of RFC 9420 for detailed security implications.Key Package Lifetime
Key packages include a lifetime extension specifying validity period:- Current time ≥
not_before - Current time ≤
not_after
Manual Rotation
Applications can trigger key package rotation explicitly:Manual rotation is rarely needed. The automatic rotation system handles most scenarios.
Troubleshooting
Key Package Upload Failures
If upload fails, the locally generated key package is not marked for deletion:Rotation Timing
The rotation interval is tracked in nanoseconds:key_package_rotation_metadata table
Related Documentation
- Security Overview - Forward secrecy properties
- Credential Validation - Key package validation
- Revocation - Revoking installations
