Skip to content

Commit

Permalink
Expose more group info
Browse files Browse the repository at this point in the history
  • Loading branch information
Marta Mularczyk committed Dec 18, 2023
1 parent dcc0df3 commit b2f5312
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 59 deletions.
37 changes: 7 additions & 30 deletions mls-rs/src/external_client/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
snapshot::RawGroupState,
state::GroupState,
transcript_hash::InterimTranscriptHash,
validate_group_info, Roster,
validate_group_info, GroupContext, Roster,
},
identity::SigningIdentity,
protocol_version::ProtocolVersion,
Expand Down Expand Up @@ -316,7 +316,7 @@ impl<C: ExternalClientConfig + Clone> ExternalGroup<C> {
let key_id = ResumptionPsk {
psk_epoch,
usage: ResumptionPSKUsage::Application,
psk_group_id: PskGroupId(self.group_id().to_vec()),
psk_group_id: PskGroupId(self.group_context().group_id().to_vec()),
};

let proposal = self.psk_proposal(JustPreSharedKeyID::Resumption(key_id))?;
Expand Down Expand Up @@ -456,7 +456,7 @@ impl<C: ExternalClientConfig + Clone> ExternalGroup<C> {
};

Ok(MlsMessage::new(
self.protocol_version(),
self.group_context().version(),
MlsMessagePayload::Plain(plaintext),
))
}
Expand All @@ -466,28 +466,10 @@ impl<C: ExternalClientConfig + Clone> ExternalGroup<C> {
&self.state
}

/// Get the unique identifier of this group.
/// Get the current group context summarizing various information about the group.
#[inline(always)]
pub fn group_id(&self) -> &[u8] {
&self.group_state().context.group_id
}

/// Get the current epoch number of the group's state.
#[inline(always)]
pub fn current_epoch(&self) -> u64 {
self.group_state().context.epoch
}

/// Get the current protocol version in use by the group.
#[inline(always)]
pub fn protocol_version(&self) -> ProtocolVersion {
self.group_state().context.protocol_version
}

/// Get the current ciphersuite in use by the group.
#[inline(always)]
pub fn cipher_suite(&self) -> CipherSuite {
self.group_state().context.cipher_suite
pub fn group_context(&self) -> &GroupContext {
&self.group_state().context
}

/// Export the current ratchet tree used within the group.
Expand All @@ -505,11 +487,6 @@ impl<C: ExternalClientConfig + Clone> ExternalGroup<C> {
self.group_state().public_tree.roster()
}

#[inline(always)]
pub fn context_extensions(&self) -> &ExtensionList {
&self.group_state().context.extensions
}

/// Get the
/// [transcript hash](https://messaginglayersecurity.rocks/mls-protocol/draft-ietf-mls-protocol.html#name-transcript-hashes)
/// for the current epoch that the group is in.
Expand Down Expand Up @@ -538,7 +515,7 @@ impl<C: ExternalClientConfig + Clone> ExternalGroup<C> {
) -> Result<Member, MlsError> {
let identity = self
.identity_provider()
.identity(identity_id, self.context_extensions())
.identity(identity_id, self.group_context().extensions())
.await
.map_err(|error| MlsError::IdentityProviderError(error.into_any_error()))?;

Expand Down
45 changes: 37 additions & 8 deletions mls-rs/src/group/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ use super::ConfirmedTranscriptHash;

#[derive(Clone, Debug, PartialEq, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
pub struct GroupContext {
pub protocol_version: ProtocolVersion,
pub cipher_suite: CipherSuite,
pub(crate) protocol_version: ProtocolVersion,
pub(crate) cipher_suite: CipherSuite,
#[mls_codec(with = "mls_rs_codec::byte_vec")]
pub group_id: Vec<u8>,
pub epoch: u64,
pub(crate) group_id: Vec<u8>,
pub(crate) epoch: u64,
#[mls_codec(with = "mls_rs_codec::byte_vec")]
pub tree_hash: Vec<u8>,
pub confirmed_transcript_hash: ConfirmedTranscriptHash,
pub extensions: ExtensionList,
pub(crate) tree_hash: Vec<u8>,
pub(crate) confirmed_transcript_hash: ConfirmedTranscriptHash,
pub(crate) extensions: ExtensionList,
}

#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::safer_ffi_gen)]
impl GroupContext {
pub fn new_group(
pub(crate) fn new_group(
protocol_version: ProtocolVersion,
cipher_suite: CipherSuite,
group_id: Vec<u8>,
Expand All @@ -42,4 +47,28 @@ impl GroupContext {
extensions,
}
}

/// Get the current protocol version in use by the group.
pub fn version(&self) -> ProtocolVersion {
self.protocol_version
}

/// Get the current cipher suite in use by the group.
pub fn cipher_suite(&self) -> CipherSuite {
self.cipher_suite
}

/// Get the unique identifier of this group.
pub fn group_id(&self) -> &[u8] {
&self.group_id
}

/// Get the current epoch number of the group's state.
pub fn epoch(&self) -> u64 {
self.epoch
}

pub fn extensions(&self) -> &ExtensionList {
&self.extensions
}
}
2 changes: 1 addition & 1 deletion mls-rs/src/group/framing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl MlsMessage {
}

#[inline(always)]
pub(crate) fn into_group_info(self) -> Option<GroupInfo> {
pub fn into_group_info(self) -> Option<GroupInfo> {
match self.payload {
MlsMessagePayload::GroupInfo(info) => Some(info),
_ => None,
Expand Down
27 changes: 21 additions & 6 deletions mls-rs/src/group/group_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@ use super::*;

#[derive(Clone, Debug, PartialEq, MlsSize, MlsEncode, MlsDecode)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub(crate) struct GroupInfo {
pub group_context: GroupContext,
pub extensions: ExtensionList,
pub confirmation_tag: ConfirmationTag,
pub signer: LeafIndex,
#[cfg_attr(
all(feature = "ffi", not(test)),
safer_ffi_gen::ffi_type(clone, opaque)
)]
pub struct GroupInfo {
pub(crate) group_context: GroupContext,
pub(crate) extensions: ExtensionList,
pub(crate) confirmation_tag: ConfirmationTag,
pub(crate) signer: LeafIndex,
#[mls_codec(with = "mls_rs_codec::byte_vec")]
pub signature: Vec<u8>,
pub(crate) signature: Vec<u8>,
}

#[cfg_attr(all(feature = "ffi", not(test)), ::safer_ffi_gen::safer_ffi_gen)]
impl GroupInfo {
pub fn group_context(&self) -> &GroupContext {
&self.group_context
}

pub fn extensions(&self) -> &ExtensionList {
&self.extensions
}
}

#[derive(MlsEncode, MlsSize)]
Expand Down
15 changes: 5 additions & 10 deletions mls-rs/src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ pub(crate) use group_info::GroupInfo;
use self::framing::MlsMessage;
pub use self::framing::Sender;
pub use commit::*;

pub use context::GroupContext;
pub use roster::*;

pub(crate) use transcript_hash::ConfirmedTranscriptHash;
pub(crate) use util::*;

pub(crate) use context::*;

#[cfg(all(feature = "by_ref_proposal", feature = "external_client"))]
pub use self::message_processor::CachedProposal;

Expand Down Expand Up @@ -1406,13 +1404,10 @@ where
))
}

/// Get the current group context summarizing various information about the group.
#[inline(always)]
pub(crate) fn context(&self) -> &GroupContext {
&self.state.context
}

pub fn context_extensions(&self) -> &ExtensionList {
&self.state.context.extensions
pub fn context(&self) -> &GroupContext {
&self.group_state().context
}

/// Get the
Expand Down Expand Up @@ -1503,7 +1498,7 @@ where
pub(crate) fn encryption_options(&self) -> Result<EncryptionOptions, MlsError> {
self.config
.mls_rules()
.encryption_options(&self.roster(), self.context_extensions())
.encryption_options(&self.roster(), self.group_context().extensions())
.map_err(|e| MlsError::MlsRulesError(e.into_any_error()))
}

Expand Down
6 changes: 3 additions & 3 deletions mls-rs/src/group/resumption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
group_id: &sub_group_id,
cipher_suite: self.cipher_suite(),
version: self.protocol_version(),
extensions: self.context_extensions(),
extensions: &self.group_state().context.extensions,
};

resumption_create_group(
Expand All @@ -81,7 +81,7 @@ where
group_id: &[],
cipher_suite: self.cipher_suite(),
version: self.protocol_version(),
extensions: self.context_extensions(),
extensions: &self.group_state().context.extensions,
};

resumption_join_group(
Expand Down Expand Up @@ -291,7 +291,7 @@ async fn resumption_join_group<C: ClientConfig + Clone>(
Err(MlsError::CipherSuiteMismatch)
} else if verify_group_id && group.group_id() != expected_new_group_params.group_id {
Err(MlsError::GroupIdMismatch)
} else if group.context_extensions() != expected_new_group_params.extensions {
} else if &group.group_state().context.extensions != expected_new_group_params.extensions {
Err(MlsError::ReInitExtensionsMismatch)
} else {
Ok((group, new_member_info))
Expand Down
2 changes: 1 addition & 1 deletion mls-rs/test_harness_integration/src/by_ref_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub(crate) mod inner {
let request = request.into_inner();

self.send_proposal(request.state_id, move |group| {
let mut extensions = group.context_extensions().clone();
let mut extensions = group.context().extensions().clone();

let ext_sender =
SigningIdentity::mls_decode(&mut &*request.external_sender).map_err(abort)?;
Expand Down

0 comments on commit b2f5312

Please sign in to comment.