Use this file to discover all available pages before exploring further.
Key packages are pre-published bundles of cryptographic key material that enable asynchronous addition of clients to MLS groups. They are a fundamental building block for MLS’s asynchronous design.
The bundle ensures private keys are kept together with the public key package:
// Get the public key package for publishinglet public_kp = key_package.key_package();// Private keys remain in the bundle for later uselet init_private = key_package.init_private_key();
Keep the KeyPackageBundle secure. It contains private key material needed to process Welcome messages when the key package is used to add you to a group.
let key_package = KeyPackage::builder() .mark_as_last_resort() .build( ciphersuite, &provider, &signer, credential_with_key, )?;// Check if a key package is marked as last resortif key_package.key_package().last_resort() { println!("This is a last resort key package");}
Last resort key packages can be reused when no other key packages are available.
Clients publish key packages to a server (Delivery Service) so others can use them:
// Create and store key packagelet key_package_bundle = KeyPackage::builder() .build( ciphersuite, &provider, &signer, credential_with_key, )?;// Serialize the public key package for publishinglet serialized = key_package_bundle .key_package() .tls_serialize_detached()?;// Upload to serverdelivery_service.publish_key_package(&serialized).await?;
When your key package is used to add you to a group, you receive a Welcome message:
use openmls::prelude::*;// Receive Welcome messagelet welcome = MlsMessageIn::tls_deserialize(&mut welcome_bytes.as_slice())?;// Join the group using the Welcomelet group = StagedWelcome::new_from_welcome( &provider, &MlsGroupJoinConfig::default(), welcome, None,)?.into_group(&provider)?;// The key package bundle's private keys are automatically retrieved from storage
OpenMLS automatically retrieves the KeyPackageBundle from storage using the key package reference.
use openmls::prelude::*;// Compute the key package referencelet kp_ref = key_package.key_package().hash_ref(provider.crypto())?;// The reference is used as a storage keylet bytes = kp_ref.as_slice();
Key package references:
Uniquely identify key packages
Are used to store and retrieve KeyPackageBundles
Appear in Welcome messages to indicate which key package was used
Key packages are meant to be used only once. Generate and publish multiple key packages to support multiple group joins. Only reuse key packages marked as “last resort” when no fresh ones are available.
// Generate multiple key packageslet mut key_packages = Vec::new();for _ in 0..10 { let kp = KeyPackage::builder() .build( ciphersuite, &provider, &signer, credential_with_key.clone(), )?; key_packages.push(kp);}// Publish all of themfor kp in &key_packages { let serialized = kp.key_package().tls_serialize_detached()?; delivery_service.publish_key_package(&serialized).await?;}