Skip to content

Commit

Permalink
Merge pull request #8 from Bren2010/brendan/deleting-lr
Browse files Browse the repository at this point in the history
Don't delete private key for last resort KP.
  • Loading branch information
neekolas authored Jan 5, 2024
2 parents 2f50273 + 57d2a60 commit 9c7d5cb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
3 changes: 1 addition & 2 deletions openmls/src/credentials/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ impl tls_codec::Serialize for Credential {
impl tls_codec::Deserialize for Credential {
fn tls_deserialize<R: Read>(bytes: &mut R) -> Result<Self, tls_codec::Error> {
let val = u16::tls_deserialize(bytes)?;
let credential_type = CredentialType::try_from(val)
.map_err(|e| tls_codec::Error::DecodingError(e.to_string()))?;
let credential_type = CredentialType::from(val);
match credential_type {
CredentialType::Basic => Ok(Credential::from(MlsCredentialType::Basic(
BasicCredential::tls_deserialize(bytes)?,
Expand Down
26 changes: 24 additions & 2 deletions openmls/src/extensions/test_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tls_codec::{Deserialize, Serialize};

use super::*;
use crate::{
ciphersuite::HpkePrivateKey,
credentials::*,
framing::*,
group::{config::CryptoConfig, errors::*, *},
Expand All @@ -16,6 +17,7 @@ use crate::{
prelude::Capabilities,
schedule::psk::store::ResumptionPskStore,
test_utils::*,
treesync::node::encryption_keys::EncryptionKeyPair,
versions::ProtocolVersion,
};

Expand Down Expand Up @@ -324,19 +326,39 @@ fn last_resort_extension(ciphersuite: Ciphersuite, provider: &impl OpenMlsProvid

alice_group.merge_pending_commit(provider).unwrap();

let _bob_group = MlsGroup::new_from_welcome(
let mut bob_group = MlsGroup::new_from_welcome(
provider,
&mls_group_config,
welcome.into_welcome().expect("Unexpected MLS message"),
Some(alice_group.export_ratchet_tree().into()),
)
.expect("An unexpected error occurred.");

// This should not have deleted the KP from the store
// === Bob sends a commit ==

let (_message, _welcome, _group_info) = bob_group
.self_update(provider, &signer)
.expect("An unexpected error occurred.");
bob_group
.merge_pending_commit(provider)
.expect("An unexpected error occurred.");

// This should not have deleted the KP or private keys from the store
let kp: Option<KeyPackage> = provider.key_store().read(
kp.hash_ref(provider.crypto())
.expect("error hashing kp")
.as_slice(),
);
assert!(kp.is_some());

let kp = kp.unwrap();

let leaf_keypair =
EncryptionKeyPair::read_from_key_store(provider, kp.leaf_node().encryption_key());
assert!(leaf_keypair.is_some());

let private_key = provider
.key_store()
.read::<HpkePrivateKey>(kp.hpke_init_key().as_slice());
assert!(private_key.is_some());
}
8 changes: 5 additions & 3 deletions openmls/src/group/core_group/new_from_welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ impl CoreGroup {
key_package_bundle.key_package.leaf_node().encryption_key(),
)
.ok_or(WelcomeError::NoMatchingEncryptionKey)?;
leaf_keypair
.delete_from_key_store(provider.key_store())
.map_err(|_| WelcomeError::NoMatchingEncryptionKey)?;
if !key_package_bundle.key_package.last_resort() {
leaf_keypair
.delete_from_key_store(provider.key_store())
.map_err(|_| WelcomeError::NoMatchingEncryptionKey)?;
}

let ciphersuite = welcome.ciphersuite();

Expand Down
7 changes: 1 addition & 6 deletions openmls/src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ pub(crate) mod errors;
pub use core_group::proposals::*;
pub use core_group::staged_commit::StagedCommit;
pub use errors::*;
pub use group_context::*;
pub use group_context::GroupContext;
pub use mls_group::config::*;
pub use mls_group::membership::*;
pub use mls_group::processing::*;
pub use mls_group::*;
pub use public_group::*;

Expand All @@ -41,11 +40,7 @@ pub use public_group::*;
pub(crate) use core_group::create_commit_params::*;
#[cfg(any(feature = "test-utils", test))]
pub(crate) mod tests;
#[cfg(any(feature = "test-utils", test))]
pub use group_context::GroupContext;
use openmls_traits::random::OpenMlsRand;
#[cfg(any(feature = "test-utils", test))]
pub use proposals::*;

/// A group ID. The group ID is chosen by the creator of the group and should be globally unique.
#[derive(
Expand Down
4 changes: 2 additions & 2 deletions openmls/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// MlsGroup
pub use crate::group::{config::CryptoConfig, core_group::Member, ser::*, *};

pub use crate::group::public_group::{errors::*, process::*, *};
pub use crate::group::public_group::errors::*;

// Ciphersuite
pub use crate::ciphersuite::{hash_ref::KeyPackageRef, signable::*, signature::*, *};
Expand All @@ -22,7 +22,7 @@ pub use crate::versions::*;
pub use crate::extensions::{errors::*, *};

// Framing
pub use crate::framing::{message_in::*, message_out::*, sender::*, validation::*, *};
pub use crate::framing::*;

// Key packages
pub use crate::key_packages::{errors::*, *};
Expand Down

0 comments on commit 9c7d5cb

Please sign in to comment.