Skip to content

Implementation of server_remove proposal #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mls-rs-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serde = ["dep:serde", "zeroize/serde", "hex/serde", "dep:serde_bytes"]
last_resort_key_package_ext = []
post-quantum = []
self_remove_proposal = []
gsma_rcs_e2ee_feature = []

[dependencies]
mls-rs-codec = { version = "0.6", path = "../mls-rs-codec", default-features = false}
Expand Down
2 changes: 2 additions & 0 deletions mls-rs-core/src/group/proposal_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl ProposalType {
pub const GROUP_CONTEXT_EXTENSIONS: ProposalType = ProposalType(7);
#[cfg(feature = "self_remove_proposal")]
pub const SELF_REMOVE: ProposalType = ProposalType(0xF003);
#[cfg(feature = "gsma_rcs_e2ee_feature")]
pub const SERVER_REMOVE: ProposalType = ProposalType(0xF004);

/// Default proposal types defined
/// in [RFC 9420](https://www.rfc-editor.org/rfc/rfc9420.html#name-leaf-node-contents)
Expand Down
1 change: 1 addition & 0 deletions mls-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ x509 = ["mls-rs-core/x509", "dep:mls-rs-identity-x509"]
rfc_compliant = ["private_message", "custom_proposal", "out_of_order", "psk", "x509", "prior_epoch", "by_ref_proposal", "mls-rs-core/rfc_compliant"]
last_resort_key_package_ext = ["mls-rs-core/last_resort_key_package_ext"]
self_remove_proposal = ["mls-rs-core/self_remove_proposal"]
gsma_rcs_e2ee_feature = ["mls-rs-core/gsma_rcs_e2ee_feature"]

std = ["mls-rs-core/std", "mls-rs-codec/std", "mls-rs-identity-x509?/std", "hex/std", "futures/std", "itertools/use_std", "safer-ffi-gen?/std", "zeroize/std", "dep:debug_tree", "dep:thiserror", "serde?/std"]

Expand Down
11 changes: 11 additions & 0 deletions mls-rs/src/external_client/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use crate::{
feature = "self_remove_proposal"
))]
use crate::group::proposal::SelfRemoveProposal;
#[cfg(feature = "gsma_rcs_e2ee_feature")]
use crate::group::proposal::ServerRemoveProposal;

#[cfg(feature = "by_ref_proposal")]
use crate::{
Expand Down Expand Up @@ -699,6 +701,15 @@ where
None
}

#[cfg(feature = "gsma_rcs_e2ee_feature")]
#[cfg_attr(feature = "ffi", safer_ffi_gen::safer_ffi_gen_ignore)]
fn server_removal_proposal(
&self,
_provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<ServerRemoveProposal>> {
None
}

#[cfg(feature = "private_message")]
fn min_epoch_available(&self) -> Option<u64> {
self.config
Expand Down
9 changes: 9 additions & 0 deletions mls-rs/src/group/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ where
Ok(self)
}

/// Insert a [`ServerRemoveProposal`](crate::group::proposal::RemoveProposal) into
/// the current commit that is being built.
#[cfg(feature = "gsma_rcs_e2ee_feature")]
pub fn server_remove_member(mut self, index: u32) -> Result<Self, MlsError> {
let proposal = self.group.server_remove_proposal(index)?;
self.proposals.push(proposal);
Ok(self)
}

/// Insert a
/// [`GroupContextExtensions`](crate::group::proposal::Proposal::GroupContextExtensions)
/// into the current commit that is being built.
Expand Down
29 changes: 29 additions & 0 deletions mls-rs/src/group/external_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ use crate::{
Group, MlsMessage,
};

#[cfg(feature = "gsma_rcs_e2ee_feature")]
use crate::group::proposal::ServerRemoveProposal;

#[cfg(any(feature = "secret_tree_access", feature = "private_message"))]
use crate::group::secret_tree::SecretTree;

Expand Down Expand Up @@ -52,6 +55,8 @@ pub struct ExternalCommitBuilder<C: ClientConfig> {
config: C,
tree_data: Option<ExportedTree<'static>>,
to_remove: Option<u32>,
#[cfg(feature = "gsma_rcs_e2ee_feature")]
to_server_remove: Vec<u32>,
#[cfg(feature = "psk")]
external_psks: Vec<ExternalPskId>,
authenticated_data: Vec<u8>,
Expand All @@ -70,6 +75,8 @@ impl<C: ClientConfig> ExternalCommitBuilder<C> {
Self {
tree_data: None,
to_remove: None,
#[cfg(feature = "gsma_rcs_e2ee_feature")]
to_server_remove: Vec::new(),
authenticated_data: Vec::new(),
signer,
signing_identity,
Expand Down Expand Up @@ -104,6 +111,21 @@ impl<C: ClientConfig> ExternalCommitBuilder<C> {
}
}

#[cfg(feature = "gsma_rcs_e2ee_feature")]
#[must_use]
/// Propose the server-removal of a client as part of the external commit.
pub fn with_server_removal(self, to_remove: u32) -> Self {
Self {
to_server_remove: self
.to_server_remove
.iter()
.chain([&to_remove])
.cloned()
.collect(),
..self
}
}

#[must_use]
/// Add plaintext authenticated data to the resulting commit message.
pub fn with_authenticated_data(self, data: Vec<u8>) -> Self {
Expand Down Expand Up @@ -265,6 +287,13 @@ impl<C: ClientConfig> ExternalCommitBuilder<C> {
}));
}

#[cfg(feature = "gsma_rcs_e2ee_feature")]
for index_to_remove in self.to_server_remove {
proposals.push(Proposal::ServerRemove(ServerRemoveProposal {
to_remove: LeafIndex(index_to_remove),
}));
}

let (commit_output, pending_commit) = group
.commit_internal(
proposals,
Expand Down
29 changes: 29 additions & 0 deletions mls-rs/src/group/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
feature = "self_remove_proposal"
))]
use super::SelfRemoveProposal;
#[cfg(feature = "gsma_rcs_e2ee_feature")]
use super::ServerRemoveProposal;
use super::{
commit_sender,
confirmation_tag::ConfirmationTag,
Expand Down Expand Up @@ -91,6 +93,9 @@ pub(crate) fn path_update_required(proposals: &ProposalBundle) -> bool {
))]
let res = res || !proposals.self_removes.is_empty();

#[cfg(feature = "gsma_rcs_e2ee_feature")]
let res = res || !proposals.server_removes.is_empty();

res || proposals.length() == 0
|| proposals.group_context_extensions_proposal().is_some()
|| !proposals.remove_proposals().is_empty()
Expand Down Expand Up @@ -727,6 +732,9 @@ pub(crate) trait MessageProcessor: Send + Sync {
))]
let self_removed_by_self = self.self_removal_proposal(&provisional_state);

#[cfg(feature = "gsma_rcs_e2ee_feature")]
let self_removed_by_server = self.server_removal_proposal(&provisional_state);

let is_self_removed = self_removed.is_some();
#[cfg(all(
feature = "by_ref_proposal",
Expand All @@ -735,6 +743,9 @@ pub(crate) trait MessageProcessor: Send + Sync {
))]
let is_self_removed = is_self_removed || self_removed_by_self.is_some();

#[cfg(feature = "gsma_rcs_e2ee_feature")]
let is_self_removed = is_self_removed || self_removed_by_server.is_some();

let update_path = match commit.path {
Some(update_path) => Some(
validate_update_path(
Expand Down Expand Up @@ -783,6 +794,17 @@ pub(crate) trait MessageProcessor: Send + Sync {
commit_effect
};

#[cfg(feature = "gsma_rcs_e2ee_feature")]
let commit_effect = if let Some(server_remove_proposal) = self_removed_by_server {
let new_epoch = NewEpoch::new(self.group_state().clone(), &provisional_state);
CommitEffect::Removed {
remover: server_remove_proposal.sender,
new_epoch: Box::new(new_epoch),
}
} else {
commit_effect
};

let new_secrets = match update_path {
Some(update_path) if !is_self_removed => {
self.apply_update_path(sender, &update_path, &mut provisional_state)
Expand Down Expand Up @@ -851,6 +873,13 @@ pub(crate) trait MessageProcessor: Send + Sync {
provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<SelfRemoveProposal>>;

#[cfg(feature = "gsma_rcs_e2ee_feature")]
#[cfg_attr(feature = "ffi", safer_ffi_gen::safer_ffi_gen_ignore)]
fn server_removal_proposal(
&self,
provisional_state: &ProvisionalState,
) -> Option<ProposalInfo<ServerRemoveProposal>>;

#[cfg(feature = "private_message")]
fn min_epoch_available(&self) -> Option<u64>;

Expand Down
Loading