| 1 |
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 |
// Copyright by contributors to this project. |
| 3 |
// SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 4 |
|
| 5 |
use alloc::vec::Vec; |
| 6 |
|
| 7 |
use super::{ |
| 8 |
message_processor::ProvisionalState, |
| 9 |
mls_rules::{CommitDirection, CommitSource, MlsRules}, |
| 10 |
proposal_filter::prepare_proposals_for_mls_rules, |
| 11 |
GroupState, ProposalOrRef, |
| 12 |
}; |
| 13 |
use crate::{ |
| 14 |
client::MlsError, |
| 15 |
group::{ |
| 16 |
proposal_filter::{ProposalApplier, ProposalBundle, ProposalSource}, |
| 17 |
Proposal, Sender, |
| 18 |
}, |
| 19 |
time::MlsTime, |
| 20 |
}; |
| 21 |
|
| 22 |
#[cfg(feature = "by_ref_proposal")] |
| 23 |
use crate::{ |
| 24 |
group::{message_hash::MessageHash, ProposalMessageDescription, ProposalRef, ProtocolVersion}, |
| 25 |
MlsMessage, |
| 26 |
}; |
| 27 |
|
| 28 |
use crate::tree_kem::leaf_node::LeafNode; |
| 29 |
|
| 30 |
#[cfg(feature = "by_ref_proposal")] |
| 31 |
use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize}; |
| 32 |
|
| 33 |
use mls_rs_core::{ |
| 34 |
crypto::CipherSuiteProvider, error::IntoAnyError, identity::IdentityProvider, |
| 35 |
psk::PreSharedKeyStorage, |
| 36 |
}; |
| 37 |
|
| 38 |
#[cfg(feature = "by_ref_proposal")] |
| 39 |
use core::fmt::{self, Debug}; |
| 40 |
|
| 41 |
#[cfg(feature = "by_ref_proposal")] |
| 42 |
#[derive(Debug, Clone, MlsSize, MlsEncode, MlsDecode, PartialEq)] |
| 43 |
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
| 44 |
pub struct CachedProposal { |
| 45 |
pub(crate) proposal: Proposal, |
| 46 |
pub(crate) sender: Sender, |
| 47 |
} |
| 48 |
|
| 49 |
#[cfg(feature = "by_ref_proposal")] |
| 50 |
#[derive(Clone, MlsSize, MlsEncode, MlsDecode)] |
| 51 |
pub(crate) struct ProposalCache { |
| 52 |
protocol_version: ProtocolVersion, |
| 53 |
group_id: Vec<u8>, |
| 54 |
pub(crate) proposals: crate::map::SmallMap<ProposalRef, CachedProposal>, |
| 55 |
pub(crate) own_proposals: crate::map::SmallMap<MessageHash, ProposalMessageDescription>, |
| 56 |
} |
| 57 |
|
| 58 |
#[cfg(feature = "by_ref_proposal")] |
| 59 |
impl PartialEq for ProposalCache { |
| 60 |
fn eq(&self, other: &Self) -> bool { |
| 61 |
self.protocol_version == other.protocol_version |
| 62 |
&& self.group_id == other.group_id |
| 63 |
&& self.proposals == other.proposals |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
#[cfg(feature = "by_ref_proposal")] |
| 68 |
impl Debug for ProposalCache { |
| 69 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 70 |
f.debug_struct("ProposalCache") |
| 71 |
.field("protocol_version", &self.protocol_version) |
| 72 |
.field( |
| 73 |
"group_id", |
| 74 |
&mls_rs_core::debug::pretty_group_id(&self.group_id), |
| 75 |
) |
| 76 |
.field("proposals", &self.proposals) |
| 77 |
.finish() |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
#[cfg(feature = "by_ref_proposal")] |
| 82 |
impl ProposalCache { |
| 83 |
pub fn new(protocol_version: ProtocolVersion, group_id: Vec<u8>) -> Self { |
| 84 |
Self { |
| 85 |
protocol_version, |
| 86 |
group_id, |
| 87 |
proposals: Default::default(), |
| 88 |
own_proposals: Default::default(), |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
pub fn import( |
| 93 |
protocol_version: ProtocolVersion, |
| 94 |
group_id: Vec<u8>, |
| 95 |
proposals: crate::map::SmallMap<ProposalRef, CachedProposal>, |
| 96 |
own_proposals: crate::map::SmallMap<MessageHash, ProposalMessageDescription>, |
| 97 |
) -> Self { |
| 98 |
Self { |
| 99 |
protocol_version, |
| 100 |
group_id, |
| 101 |
proposals, |
| 102 |
own_proposals, |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
pub fn clear(&mut self) { |
| 107 |
self.proposals.clear(); |
| 108 |
self.own_proposals.clear(); |
| 109 |
} |
| 110 |
|
| 111 |
#[cfg(feature = "by_ref_proposal")] |
| 112 |
#[inline] |
| 113 |
pub fn is_empty(&self) -> bool { |
| 114 |
self.proposals.is_empty() |
| 115 |
} |
| 116 |
|
| 117 |
pub fn insert(&mut self, proposal_ref: ProposalRef, proposal: Proposal, sender: Sender) { |
| 118 |
let cached_proposal = CachedProposal { proposal, sender }; |
| 119 |
|
| 120 |
#[cfg(feature = "std")] |
| 121 |
self.proposals.insert(proposal_ref, cached_proposal); |
| 122 |
|
| 123 |
#[cfg(not(feature = "std"))] |
| 124 |
// This may result in dups but it does not matter |
| 125 |
self.proposals.push((proposal_ref, cached_proposal)); |
| 126 |
} |
| 127 |
|
| 128 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 129 |
pub async fn insert_own<CS: CipherSuiteProvider>( |
| 130 |
&mut self, |
| 131 |
proposal: ProposalMessageDescription, |
| 132 |
message: &MlsMessage, |
| 133 |
sender: Sender, |
| 134 |
cs: &CS, |
| 135 |
) -> Result<(), MlsError> { |
| 136 |
self.insert( |
| 137 |
proposal.proposal_ref.clone(), |
| 138 |
proposal.proposal.clone(), |
| 139 |
sender, |
| 140 |
); |
| 141 |
|
| 142 |
let message_hash = MessageHash::compute(cs, message).await?; |
| 143 |
self.own_proposals.insert(message_hash, proposal); |
| 144 |
|
| 145 |
Ok(()) |
| 146 |
} |
| 147 |
|
| 148 |
pub fn prepare_commit( |
| 149 |
&self, |
| 150 |
sender: Sender, |
| 151 |
additional_proposals: Vec<Proposal>, |
| 152 |
) -> ProposalBundle { |
| 153 |
self.proposals |
| 154 |
.iter() |
| 155 |
.map(|(r, p)| { |
| 156 |
( |
| 157 |
p.proposal.clone(), |
| 158 |
p.sender, |
| 159 |
ProposalSource::ByReference(r.clone()), |
| 160 |
) |
| 161 |
}) |
| 162 |
.chain( |
| 163 |
additional_proposals |
| 164 |
.into_iter() |
| 165 |
.map(|p| (p, sender, ProposalSource::ByValue)), |
| 166 |
) |
| 167 |
.collect() |
| 168 |
} |
| 169 |
|
| 170 |
pub fn resolve_for_commit( |
| 171 |
&self, |
| 172 |
sender: Sender, |
| 173 |
proposal_list: Vec<ProposalOrRef>, |
| 174 |
) -> Result<ProposalBundle, MlsError> { |
| 175 |
let mut proposals = ProposalBundle::default(); |
| 176 |
|
| 177 |
for p in proposal_list { |
| 178 |
match p { |
| 179 |
ProposalOrRef::Proposal(p) => proposals.add(*p, sender, ProposalSource::ByValue), |
| 180 |
ProposalOrRef::Reference(r) => { |
| 181 |
#[cfg(feature = "std")] |
| 182 |
let p = self |
| 183 |
.proposals |
| 184 |
.get(&r) |
| 185 |
.ok_or(MlsError::ProposalNotFound)? |
| 186 |
.clone(); |
| 187 |
#[cfg(not(feature = "std"))] |
| 188 |
let p = self |
| 189 |
.proposals |
| 190 |
.iter() |
| 191 |
.find_map(|(rr, p)| (rr == &r).then_some(p)) |
| 192 |
.ok_or(MlsError::ProposalNotFound)? |
| 193 |
.clone(); |
| 194 |
|
| 195 |
proposals.add(p.proposal, p.sender, ProposalSource::ByReference(r)); |
| 196 |
} |
| 197 |
}; |
| 198 |
} |
| 199 |
|
| 200 |
Ok(proposals) |
| 201 |
} |
| 202 |
|
| 203 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 204 |
pub async fn get_own<CS: CipherSuiteProvider>( |
| 205 |
&self, |
| 206 |
cs: &CS, |
| 207 |
message: &MlsMessage, |
| 208 |
) -> Result<Option<ProposalMessageDescription>, MlsError> { |
| 209 |
let message_hash = MessageHash::compute(cs, message).await?; |
| 210 |
|
| 211 |
Ok(self.own_proposals.get(&message_hash).cloned()) |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
#[cfg(not(feature = "by_ref_proposal"))] |
| 216 |
pub(crate) fn prepare_commit( |
| 217 |
sender: Sender, |
| 218 |
additional_proposals: Vec<Proposal>, |
| 219 |
) -> ProposalBundle { |
| 220 |
let mut proposals = ProposalBundle::default(); |
| 221 |
|
| 222 |
for p in additional_proposals.into_iter() { |
| 223 |
proposals.add(p, sender, ProposalSource::ByValue); |
| 224 |
} |
| 225 |
|
| 226 |
proposals |
| 227 |
} |
| 228 |
|
| 229 |
#[cfg(not(feature = "by_ref_proposal"))] |
| 230 |
pub(crate) fn resolve_for_commit( |
| 231 |
sender: Sender, |
| 232 |
proposal_list: Vec<ProposalOrRef>, |
| 233 |
) -> Result<ProposalBundle, MlsError> { |
| 234 |
let mut proposals = ProposalBundle::default(); |
| 235 |
|
| 236 |
for p in proposal_list { |
| 237 |
let ProposalOrRef::Proposal(p) = p; |
| 238 |
proposals.add(*p, sender, ProposalSource::ByValue); |
| 239 |
} |
| 240 |
|
| 241 |
Ok(proposals) |
| 242 |
} |
| 243 |
|
| 244 |
impl GroupState { |
| 245 |
#[inline(never)] |
| 246 |
#[allow(clippy::too_many_arguments)] |
| 247 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 248 |
pub(crate) async fn apply_resolved<C, F, P, CSP>( |
| 249 |
&self, |
| 250 |
sender: Sender, |
| 251 |
mut proposals: ProposalBundle, |
| 252 |
external_leaf: Option<&LeafNode>, |
| 253 |
identity_provider: &C, |
| 254 |
cipher_suite_provider: &CSP, |
| 255 |
psk_storage: &P, |
| 256 |
user_rules: &F, |
| 257 |
commit_time: Option<MlsTime>, |
| 258 |
direction: CommitDirection, |
| 259 |
) -> Result<ProvisionalState, MlsError> |
| 260 |
where |
| 261 |
C: IdentityProvider, |
| 262 |
F: MlsRules, |
| 263 |
P: PreSharedKeyStorage, |
| 264 |
CSP: CipherSuiteProvider, |
| 265 |
{ |
| 266 |
let roster = self.public_tree.roster(); |
| 267 |
|
| 268 |
#[cfg(feature = "by_ref_proposal")] |
| 269 |
let all_proposals = proposals.clone(); |
| 270 |
|
| 271 |
let origin = match sender { |
| 272 |
Sender::Member(index) => Ok::<_, MlsError>(CommitSource::ExistingMember( |
| 273 |
roster.member_with_index(index)?, |
| 274 |
)), |
| 275 |
#[cfg(feature = "by_ref_proposal")] |
| 276 |
Sender::NewMemberProposal => Err(MlsError::InvalidSender), |
| 277 |
#[cfg(feature = "by_ref_proposal")] |
| 278 |
Sender::External(_) => Err(MlsError::InvalidSender), |
| 279 |
Sender::NewMemberCommit => Ok(CommitSource::NewMember( |
| 280 |
external_leaf |
| 281 |
.map(|l| l.signing_identity.clone()) |
| 282 |
.ok_or(MlsError::ExternalCommitMustHaveNewLeaf)?, |
| 283 |
)), |
| 284 |
}?; |
| 285 |
|
| 286 |
prepare_proposals_for_mls_rules(&mut proposals, direction, &self.public_tree)?; |
| 287 |
|
| 288 |
proposals = user_rules |
| 289 |
.filter_proposals(direction, origin, &roster, &self.context, proposals) |
| 290 |
.await |
| 291 |
.map_err(|e| MlsError::MlsRulesError(e.into_any_error()))?; |
| 292 |
|
| 293 |
let applier = ProposalApplier::new( |
| 294 |
&self.public_tree, |
| 295 |
cipher_suite_provider, |
| 296 |
&self.context, |
| 297 |
external_leaf, |
| 298 |
identity_provider, |
| 299 |
psk_storage, |
| 300 |
); |
| 301 |
|
| 302 |
#[cfg(feature = "by_ref_proposal")] |
| 303 |
let applier_output = applier |
| 304 |
.apply_proposals(direction.into(), &sender, proposals, commit_time) |
| 305 |
.await?; |
| 306 |
|
| 307 |
#[cfg(not(feature = "by_ref_proposal"))] |
| 308 |
let applier_output = applier |
| 309 |
.apply_proposals(&sender, &proposals, commit_time) |
| 310 |
.await?; |
| 311 |
|
| 312 |
#[cfg(feature = "by_ref_proposal")] |
| 313 |
let unused_proposals = unused_proposals( |
| 314 |
match direction { |
| 315 |
CommitDirection::Send => all_proposals, |
| 316 |
CommitDirection::Receive => self.proposals.proposals.iter().collect(), |
| 317 |
}, |
| 318 |
&applier_output.applied_proposals, |
| 319 |
); |
| 320 |
|
| 321 |
#[cfg(not(feature = "by_ref_proposal"))] |
| 322 |
let unused_proposals = alloc::vec::Vec::default(); |
| 323 |
|
| 324 |
let mut group_context = self.context.clone(); |
| 325 |
group_context.epoch += 1; |
| 326 |
|
| 327 |
if let Some(ext) = applier_output.new_context_extensions { |
| 328 |
group_context.extensions = ext; |
| 329 |
} |
| 330 |
|
| 331 |
#[cfg(feature = "by_ref_proposal")] |
| 332 |
let proposals = applier_output.applied_proposals; |
| 333 |
|
| 334 |
Ok(ProvisionalState { |
| 335 |
public_tree: applier_output.new_tree, |
| 336 |
group_context, |
| 337 |
applied_proposals: proposals, |
| 338 |
external_init_index: applier_output.external_init_index, |
| 339 |
indexes_of_added_kpkgs: applier_output.indexes_of_added_kpkgs, |
| 340 |
unused_proposals, |
| 341 |
}) |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
#[cfg(feature = "by_ref_proposal")] |
| 346 |
impl Extend<(ProposalRef, CachedProposal)> for ProposalCache { |
| 347 |
fn extend<T>(&mut self, iter: T) |
| 348 |
where |
| 349 |
T: IntoIterator<Item = (ProposalRef, CachedProposal)>, |
| 350 |
{ |
| 351 |
self.proposals.extend(iter); |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
#[cfg(feature = "by_ref_proposal")] |
| 356 |
fn has_ref(proposals: &ProposalBundle, reference: &ProposalRef) -> bool { |
| 357 |
proposals |
| 358 |
.iter_proposals() |
| 359 |
.any(|p| matches!(&p.source, ProposalSource::ByReference(r) if r == reference)) |
| 360 |
} |
| 361 |
|
| 362 |
#[cfg(feature = "by_ref_proposal")] |
| 363 |
fn unused_proposals( |
| 364 |
all_proposals: ProposalBundle, |
| 365 |
accepted_proposals: &ProposalBundle, |
| 366 |
) -> Vec<crate::mls_rules::ProposalInfo<Proposal>> { |
| 367 |
all_proposals |
| 368 |
.into_proposals() |
| 369 |
.filter(|p| { |
| 370 |
matches!(p.source, ProposalSource::ByReference(ref r) if !has_ref(accepted_proposals, r) |
| 371 |
) |
| 372 |
}) |
| 373 |
.collect() |
| 374 |
} |
| 375 |
|
| 376 |
// TODO add tests for lite version of filtering |
| 377 |
#[cfg(all(feature = "by_ref_proposal", test))] |
| 378 |
pub(crate) mod test_utils { |
| 379 |
use mls_rs_core::{ |
| 380 |
crypto::CipherSuiteProvider, extension::ExtensionList, identity::IdentityProvider, |
| 381 |
psk::PreSharedKeyStorage, |
| 382 |
}; |
| 383 |
|
| 384 |
use crate::{ |
| 385 |
client::test_utils::TEST_PROTOCOL_VERSION, |
| 386 |
group::{ |
| 387 |
confirmation_tag::ConfirmationTag, |
| 388 |
mls_rules::{CommitDirection, DefaultMlsRules, MlsRules}, |
| 389 |
proposal::{Proposal, ProposalOrRef}, |
| 390 |
proposal_ref::ProposalRef, |
| 391 |
state::GroupState, |
| 392 |
test_utils::{get_test_group_context, TEST_GROUP}, |
| 393 |
GroupContext, LeafIndex, LeafNode, ProvisionalState, Sender, TreeKemPublic, |
| 394 |
}, |
| 395 |
identity::{basic::BasicIdentityProvider, test_utils::BasicWithCustomProvider}, |
| 396 |
psk::AlwaysFoundPskStorage, |
| 397 |
}; |
| 398 |
|
| 399 |
use super::{CachedProposal, MlsError, ProposalCache}; |
| 400 |
|
| 401 |
use alloc::vec::Vec; |
| 402 |
|
| 403 |
impl CachedProposal { |
| 404 |
pub fn new(proposal: Proposal, sender: Sender) -> Self { |
| 405 |
Self { proposal, sender } |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
#[derive(Debug)] |
| 410 |
pub(crate) struct CommitReceiver<'a, C, F, P, CSP> { |
| 411 |
tree: &'a TreeKemPublic, |
| 412 |
sender: Sender, |
| 413 |
receiver: LeafIndex, |
| 414 |
cache: ProposalCache, |
| 415 |
identity_provider: C, |
| 416 |
cipher_suite_provider: CSP, |
| 417 |
group_context_extensions: ExtensionList, |
| 418 |
user_rules: F, |
| 419 |
with_psk_storage: P, |
| 420 |
} |
| 421 |
|
| 422 |
impl<'a, CSP> |
| 423 |
CommitReceiver<'a, BasicWithCustomProvider, DefaultMlsRules, AlwaysFoundPskStorage, CSP> |
| 424 |
{ |
| 425 |
pub fn new<S>( |
| 426 |
tree: &'a TreeKemPublic, |
| 427 |
sender: S, |
| 428 |
receiver: LeafIndex, |
| 429 |
cipher_suite_provider: CSP, |
| 430 |
) -> Self |
| 431 |
where |
| 432 |
S: Into<Sender>, |
| 433 |
{ |
| 434 |
Self { |
| 435 |
tree, |
| 436 |
sender: sender.into(), |
| 437 |
receiver, |
| 438 |
cache: make_proposal_cache(), |
| 439 |
identity_provider: BasicWithCustomProvider::new(BasicIdentityProvider), |
| 440 |
group_context_extensions: Default::default(), |
| 441 |
user_rules: pass_through_rules(), |
| 442 |
with_psk_storage: AlwaysFoundPskStorage, |
| 443 |
cipher_suite_provider, |
| 444 |
} |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
impl<'a, C, F, P, CSP> CommitReceiver<'a, C, F, P, CSP> |
| 449 |
where |
| 450 |
C: IdentityProvider, |
| 451 |
F: MlsRules, |
| 452 |
P: PreSharedKeyStorage, |
| 453 |
CSP: CipherSuiteProvider, |
| 454 |
{ |
| 455 |
#[cfg(feature = "by_ref_proposal")] |
| 456 |
pub fn with_identity_provider<V>(self, validator: V) -> CommitReceiver<'a, V, F, P, CSP> |
| 457 |
where |
| 458 |
V: IdentityProvider, |
| 459 |
{ |
| 460 |
CommitReceiver { |
| 461 |
tree: self.tree, |
| 462 |
sender: self.sender, |
| 463 |
receiver: self.receiver, |
| 464 |
cache: self.cache, |
| 465 |
identity_provider: validator, |
| 466 |
group_context_extensions: self.group_context_extensions, |
| 467 |
user_rules: self.user_rules, |
| 468 |
with_psk_storage: self.with_psk_storage, |
| 469 |
cipher_suite_provider: self.cipher_suite_provider, |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
pub fn with_user_rules<G>(self, f: G) -> CommitReceiver<'a, C, G, P, CSP> |
| 474 |
where |
| 475 |
G: MlsRules, |
| 476 |
{ |
| 477 |
CommitReceiver { |
| 478 |
tree: self.tree, |
| 479 |
sender: self.sender, |
| 480 |
receiver: self.receiver, |
| 481 |
cache: self.cache, |
| 482 |
identity_provider: self.identity_provider, |
| 483 |
group_context_extensions: self.group_context_extensions, |
| 484 |
user_rules: f, |
| 485 |
with_psk_storage: self.with_psk_storage, |
| 486 |
cipher_suite_provider: self.cipher_suite_provider, |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
pub fn with_psk_storage<V>(self, v: V) -> CommitReceiver<'a, C, F, V, CSP> |
| 491 |
where |
| 492 |
V: PreSharedKeyStorage, |
| 493 |
{ |
| 494 |
CommitReceiver { |
| 495 |
tree: self.tree, |
| 496 |
sender: self.sender, |
| 497 |
receiver: self.receiver, |
| 498 |
cache: self.cache, |
| 499 |
identity_provider: self.identity_provider, |
| 500 |
group_context_extensions: self.group_context_extensions, |
| 501 |
user_rules: self.user_rules, |
| 502 |
with_psk_storage: v, |
| 503 |
cipher_suite_provider: self.cipher_suite_provider, |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
#[cfg(feature = "by_ref_proposal")] |
| 508 |
pub fn with_extensions(self, extensions: ExtensionList) -> Self { |
| 509 |
Self { |
| 510 |
group_context_extensions: extensions, |
| 511 |
..self |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
pub fn cache<S>(mut self, r: ProposalRef, p: Proposal, proposer: S) -> Self |
| 516 |
where |
| 517 |
S: Into<Sender>, |
| 518 |
{ |
| 519 |
self.cache.insert(r, p, proposer.into()); |
| 520 |
self |
| 521 |
} |
| 522 |
|
| 523 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 524 |
pub async fn receive<I>(&self, proposals: I) -> Result<ProvisionalState, MlsError> |
| 525 |
where |
| 526 |
I: IntoIterator, |
| 527 |
I::Item: Into<ProposalOrRef>, |
| 528 |
{ |
| 529 |
self.cache |
| 530 |
.resolve_for_commit_default( |
| 531 |
self.sender, |
| 532 |
proposals.into_iter().map(Into::into).collect(), |
| 533 |
None, |
| 534 |
&self.group_context_extensions, |
| 535 |
&self.identity_provider, |
| 536 |
&self.cipher_suite_provider, |
| 537 |
self.tree, |
| 538 |
&self.with_psk_storage, |
| 539 |
&self.user_rules, |
| 540 |
) |
| 541 |
.await |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
pub(crate) fn make_proposal_cache() -> ProposalCache { |
| 546 |
ProposalCache::new(TEST_PROTOCOL_VERSION, TEST_GROUP.to_vec()) |
| 547 |
} |
| 548 |
|
| 549 |
pub fn pass_through_rules() -> DefaultMlsRules { |
| 550 |
DefaultMlsRules::new() |
| 551 |
} |
| 552 |
|
| 553 |
impl ProposalCache { |
| 554 |
#[allow(clippy::too_many_arguments)] |
| 555 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 556 |
pub async fn resolve_for_commit_default<C, F, P, CSP>( |
| 557 |
&self, |
| 558 |
sender: Sender, |
| 559 |
proposal_list: Vec<ProposalOrRef>, |
| 560 |
external_leaf: Option<&LeafNode>, |
| 561 |
group_extensions: &ExtensionList, |
| 562 |
identity_provider: &C, |
| 563 |
cipher_suite_provider: &CSP, |
| 564 |
public_tree: &TreeKemPublic, |
| 565 |
psk_storage: &P, |
| 566 |
user_rules: F, |
| 567 |
) -> Result<ProvisionalState, MlsError> |
| 568 |
where |
| 569 |
C: IdentityProvider, |
| 570 |
F: MlsRules, |
| 571 |
P: PreSharedKeyStorage, |
| 572 |
CSP: CipherSuiteProvider, |
| 573 |
{ |
| 574 |
let mut context = |
| 575 |
get_test_group_context(123, cipher_suite_provider.cipher_suite()).await; |
| 576 |
|
| 577 |
context.extensions = group_extensions.clone(); |
| 578 |
|
| 579 |
let mut state = GroupState::new( |
| 580 |
context, |
| 581 |
public_tree.clone(), |
| 582 |
Vec::new().into(), |
| 583 |
ConfirmationTag::empty(cipher_suite_provider).await, |
| 584 |
); |
| 585 |
|
| 586 |
state.proposals.proposals.clone_from(&self.proposals); |
| 587 |
let proposals = self.resolve_for_commit(sender, proposal_list)?; |
| 588 |
|
| 589 |
state |
| 590 |
.apply_resolved( |
| 591 |
sender, |
| 592 |
proposals, |
| 593 |
external_leaf, |
| 594 |
identity_provider, |
| 595 |
cipher_suite_provider, |
| 596 |
psk_storage, |
| 597 |
&user_rules, |
| 598 |
None, |
| 599 |
CommitDirection::Receive, |
| 600 |
) |
| 601 |
.await |
| 602 |
} |
| 603 |
|
| 604 |
#[allow(clippy::too_many_arguments)] |
| 605 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 606 |
pub async fn prepare_commit_default<C, F, P, CSP>( |
| 607 |
&self, |
| 608 |
sender: Sender, |
| 609 |
additional_proposals: Vec<Proposal>, |
| 610 |
context: &GroupContext, |
| 611 |
identity_provider: &C, |
| 612 |
cipher_suite_provider: &CSP, |
| 613 |
public_tree: &TreeKemPublic, |
| 614 |
external_leaf: Option<&LeafNode>, |
| 615 |
psk_storage: &P, |
| 616 |
user_rules: F, |
| 617 |
) -> Result<ProvisionalState, MlsError> |
| 618 |
where |
| 619 |
C: IdentityProvider, |
| 620 |
F: MlsRules, |
| 621 |
P: PreSharedKeyStorage, |
| 622 |
CSP: CipherSuiteProvider, |
| 623 |
{ |
| 624 |
let state = GroupState::new( |
| 625 |
context.clone(), |
| 626 |
public_tree.clone(), |
| 627 |
Vec::new().into(), |
| 628 |
ConfirmationTag::empty(cipher_suite_provider).await, |
| 629 |
); |
| 630 |
|
| 631 |
let proposals = self.prepare_commit(sender, additional_proposals); |
| 632 |
|
| 633 |
state |
| 634 |
.apply_resolved( |
| 635 |
sender, |
| 636 |
proposals, |
| 637 |
external_leaf, |
| 638 |
identity_provider, |
| 639 |
cipher_suite_provider, |
| 640 |
psk_storage, |
| 641 |
&user_rules, |
| 642 |
None, |
| 643 |
CommitDirection::Send, |
| 644 |
) |
| 645 |
.await |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
// TODO add tests for lite version of filtering |
| 651 |
#[cfg(all(feature = "by_ref_proposal", test))] |
| 652 |
mod tests { |
| 653 |
use alloc::{boxed::Box, vec, vec::Vec}; |
| 654 |
|
| 655 |
use super::test_utils::{make_proposal_cache, pass_through_rules, CommitReceiver}; |
| 656 |
use super::{CachedProposal, ProposalCache}; |
| 657 |
use crate::client::MlsError; |
| 658 |
use crate::group::message_processor::ProvisionalState; |
| 659 |
use crate::group::mls_rules::{CommitDirection, CommitSource, EncryptionOptions}; |
| 660 |
use crate::group::proposal_filter::{ProposalBundle, ProposalInfo, ProposalSource}; |
| 661 |
use crate::group::proposal_ref::test_utils::auth_content_from_proposal; |
| 662 |
use crate::group::proposal_ref::ProposalRef; |
| 663 |
use crate::group::{ |
| 664 |
AddProposal, AuthenticatedContent, Content, ExternalInit, GroupContext, Proposal, |
| 665 |
ProposalOrRef, ReInitProposal, RemoveProposal, Roster, Sender, UpdateProposal, |
| 666 |
}; |
| 667 |
use crate::key_package::test_utils::test_key_package_with_signer; |
| 668 |
use crate::signer::Signable; |
| 669 |
use crate::tree_kem::leaf_node::LeafNode; |
| 670 |
use crate::tree_kem::node::LeafIndex; |
| 671 |
use crate::tree_kem::TreeKemPublic; |
| 672 |
use crate::{ |
| 673 |
client::test_utils::{TEST_CIPHER_SUITE, TEST_PROTOCOL_VERSION}, |
| 674 |
crypto::{self, test_utils::test_cipher_suite_provider}, |
| 675 |
extension::test_utils::TestExtension, |
| 676 |
group::{ |
| 677 |
message_processor::path_update_required, |
| 678 |
proposal_filter::proposer_can_propose, |
| 679 |
test_utils::{get_test_group_context, random_bytes, test_group, TEST_GROUP}, |
| 680 |
}, |
| 681 |
identity::basic::BasicIdentityProvider, |
| 682 |
identity::test_utils::{get_test_signing_identity, BasicWithCustomProvider}, |
| 683 |
key_package::{test_utils::test_key_package, KeyPackageGenerator}, |
| 684 |
mls_rules::{CommitOptions, DefaultMlsRules}, |
| 685 |
psk::AlwaysFoundPskStorage, |
| 686 |
tree_kem::{ |
| 687 |
leaf_node::{ |
| 688 |
test_utils::{ |
| 689 |
default_properties, get_basic_test_node, get_basic_test_node_capabilities, |
| 690 |
get_basic_test_node_sig_key, get_test_capabilities, |
| 691 |
}, |
| 692 |
ConfigProperties, LeafNodeSigningContext, LeafNodeSource, |
| 693 |
}, |
| 694 |
Lifetime, |
| 695 |
}, |
| 696 |
}; |
| 697 |
use crate::{KeyPackage, MlsRules}; |
| 698 |
|
| 699 |
use crate::extension::RequiredCapabilitiesExt; |
| 700 |
|
| 701 |
#[cfg(feature = "by_ref_proposal")] |
| 702 |
use crate::{ |
| 703 |
extension::ExternalSendersExt, |
| 704 |
tree_kem::leaf_node_validator::test_utils::FailureIdentityProvider, |
| 705 |
}; |
| 706 |
|
| 707 |
#[cfg(feature = "psk")] |
| 708 |
use crate::{ |
| 709 |
group::proposal::PreSharedKeyProposal, |
| 710 |
psk::{ |
| 711 |
ExternalPskId, JustPreSharedKeyID, PreSharedKeyID, PskGroupId, PskNonce, |
| 712 |
ResumptionPSKUsage, ResumptionPsk, |
| 713 |
}, |
| 714 |
}; |
| 715 |
|
| 716 |
#[cfg(feature = "custom_proposal")] |
| 717 |
use crate::group::proposal::CustomProposal; |
| 718 |
|
| 719 |
use assert_matches::assert_matches; |
| 720 |
use core::convert::Infallible; |
| 721 |
use itertools::Itertools; |
| 722 |
use mls_rs_core::crypto::{CipherSuite, CipherSuiteProvider}; |
| 723 |
use mls_rs_core::extension::ExtensionList; |
| 724 |
use mls_rs_core::group::{Capabilities, ProposalType}; |
| 725 |
use mls_rs_core::identity::IdentityProvider; |
| 726 |
use mls_rs_core::protocol_version::ProtocolVersion; |
| 727 |
use mls_rs_core::psk::{PreSharedKey, PreSharedKeyStorage}; |
| 728 |
use mls_rs_core::{ |
| 729 |
extension::MlsExtension, |
| 730 |
identity::{Credential, CredentialType, CustomCredential}, |
| 731 |
}; |
| 732 |
|
| 733 |
fn test_sender() -> u32 { |
| 734 |
1 |
| 735 |
} |
| 736 |
|
| 737 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 738 |
async fn new_tree_custom_proposals( |
| 739 |
name: &str, |
| 740 |
proposal_types: Vec<ProposalType>, |
| 741 |
) -> (LeafIndex, TreeKemPublic) { |
| 742 |
let (leaf, secret, _) = get_basic_test_node_capabilities( |
| 743 |
TEST_CIPHER_SUITE, |
| 744 |
name, |
| 745 |
Capabilities { |
| 746 |
proposals: proposal_types, |
| 747 |
..get_test_capabilities() |
| 748 |
}, |
| 749 |
) |
| 750 |
.await; |
| 751 |
|
| 752 |
let (pub_tree, priv_tree) = |
| 753 |
TreeKemPublic::derive(leaf, secret, &BasicIdentityProvider, &Default::default()) |
| 754 |
.await |
| 755 |
.unwrap(); |
| 756 |
|
| 757 |
(priv_tree.self_index, pub_tree) |
| 758 |
} |
| 759 |
|
| 760 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 761 |
async fn new_tree(name: &str) -> (LeafIndex, TreeKemPublic) { |
| 762 |
new_tree_custom_proposals(name, vec![]).await |
| 763 |
} |
| 764 |
|
| 765 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 766 |
async fn add_member(tree: &mut TreeKemPublic, name: &str) -> LeafIndex { |
| 767 |
let test_node = get_basic_test_node(TEST_CIPHER_SUITE, name).await; |
| 768 |
|
| 769 |
tree.add_leaves( |
| 770 |
vec![test_node], |
| 771 |
&BasicIdentityProvider, |
| 772 |
&test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 773 |
) |
| 774 |
.await |
| 775 |
.unwrap()[0] |
| 776 |
} |
| 777 |
|
| 778 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 779 |
async fn update_leaf_node(name: &str, leaf_index: u32) -> LeafNode { |
| 780 |
let (mut leaf, _, signer) = get_basic_test_node_sig_key(TEST_CIPHER_SUITE, name).await; |
| 781 |
|
| 782 |
leaf.update( |
| 783 |
&test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 784 |
TEST_GROUP, |
| 785 |
leaf_index, |
| 786 |
Some(default_properties()), |
| 787 |
None, |
| 788 |
&signer, |
| 789 |
) |
| 790 |
.await |
| 791 |
.unwrap(); |
| 792 |
|
| 793 |
leaf |
| 794 |
} |
| 795 |
|
| 796 |
struct TestProposals { |
| 797 |
test_sender: u32, |
| 798 |
test_proposals: Vec<AuthenticatedContent>, |
| 799 |
expected_effects: ProvisionalState, |
| 800 |
tree: TreeKemPublic, |
| 801 |
} |
| 802 |
|
| 803 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 804 |
async fn test_proposals( |
| 805 |
protocol_version: ProtocolVersion, |
| 806 |
cipher_suite: CipherSuite, |
| 807 |
) -> TestProposals { |
| 808 |
let cipher_suite_provider = test_cipher_suite_provider(cipher_suite); |
| 809 |
|
| 810 |
let (sender_leaf, sender_leaf_secret, _) = |
| 811 |
get_basic_test_node_sig_key(cipher_suite, "alice").await; |
| 812 |
|
| 813 |
let sender = LeafIndex(0); |
| 814 |
|
| 815 |
let (mut tree, _) = TreeKemPublic::derive( |
| 816 |
sender_leaf, |
| 817 |
sender_leaf_secret, |
| 818 |
&BasicIdentityProvider, |
| 819 |
&Default::default(), |
| 820 |
) |
| 821 |
.await |
| 822 |
.unwrap(); |
| 823 |
|
| 824 |
let add_package = test_key_package(protocol_version, cipher_suite, "dave").await; |
| 825 |
|
| 826 |
let remove_leaf_index = add_member(&mut tree, "carol").await; |
| 827 |
|
| 828 |
let add = Proposal::Add(Box::new(AddProposal { |
| 829 |
key_package: add_package.clone(), |
| 830 |
})); |
| 831 |
|
| 832 |
let remove = Proposal::Remove(RemoveProposal { |
| 833 |
to_remove: remove_leaf_index, |
| 834 |
}); |
| 835 |
|
| 836 |
let extensions = Proposal::GroupContextExtensions(ExtensionList::new()); |
| 837 |
|
| 838 |
let proposals = vec![add, remove, extensions]; |
| 839 |
|
| 840 |
let test_node = get_basic_test_node(cipher_suite, "charlie").await; |
| 841 |
|
| 842 |
let test_sender = *tree |
| 843 |
.add_leaves( |
| 844 |
vec![test_node], |
| 845 |
&BasicIdentityProvider, |
| 846 |
&cipher_suite_provider, |
| 847 |
) |
| 848 |
.await |
| 849 |
.unwrap()[0]; |
| 850 |
|
| 851 |
let mut expected_tree = tree.clone(); |
| 852 |
|
| 853 |
let mut bundle = ProposalBundle::default(); |
| 854 |
|
| 855 |
let plaintext = proposals |
| 856 |
.iter() |
| 857 |
.cloned() |
| 858 |
.map(|p| auth_content_from_proposal(p, sender)) |
| 859 |
.collect_vec(); |
| 860 |
|
| 861 |
for i in 0..proposals.len() { |
| 862 |
let pref = ProposalRef::from_content(&cipher_suite_provider, &plaintext[i]) |
| 863 |
.await |
| 864 |
.unwrap(); |
| 865 |
|
| 866 |
bundle.add( |
| 867 |
proposals[i].clone(), |
| 868 |
Sender::Member(test_sender), |
| 869 |
ProposalSource::ByReference(pref), |
| 870 |
) |
| 871 |
} |
| 872 |
|
| 873 |
expected_tree |
| 874 |
.batch_edit( |
| 875 |
&mut bundle, |
| 876 |
&Default::default(), |
| 877 |
&BasicIdentityProvider, |
| 878 |
&cipher_suite_provider, |
| 879 |
true, |
| 880 |
) |
| 881 |
.await |
| 882 |
.unwrap(); |
| 883 |
|
| 884 |
let expected_effects = ProvisionalState { |
| 885 |
public_tree: expected_tree, |
| 886 |
group_context: get_test_group_context(1, cipher_suite).await, |
| 887 |
external_init_index: None, |
| 888 |
indexes_of_added_kpkgs: vec![LeafIndex(1)], |
| 889 |
unused_proposals: vec![], |
| 890 |
applied_proposals: bundle, |
| 891 |
}; |
| 892 |
|
| 893 |
TestProposals { |
| 894 |
test_sender, |
| 895 |
test_proposals: plaintext, |
| 896 |
expected_effects, |
| 897 |
tree, |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 902 |
async fn filter_proposals( |
| 903 |
cipher_suite: CipherSuite, |
| 904 |
proposals: Vec<AuthenticatedContent>, |
| 905 |
) -> Vec<(ProposalRef, CachedProposal)> { |
| 906 |
let mut contents = Vec::new(); |
| 907 |
|
| 908 |
for p in proposals { |
| 909 |
if let Content::Proposal(proposal) = &p.content.content { |
| 910 |
let proposal_ref = |
| 911 |
ProposalRef::from_content(&test_cipher_suite_provider(cipher_suite), &p) |
| 912 |
.await |
| 913 |
.unwrap(); |
| 914 |
contents.push(( |
| 915 |
proposal_ref, |
| 916 |
CachedProposal::new(proposal.as_ref().clone(), p.content.sender), |
| 917 |
)); |
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
contents |
| 922 |
} |
| 923 |
|
| 924 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 925 |
async fn make_proposal_ref<S>(p: &Proposal, sender: S) -> ProposalRef |
| 926 |
where |
| 927 |
S: Into<Sender>, |
| 928 |
{ |
| 929 |
ProposalRef::from_content( |
| 930 |
&test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 931 |
&auth_content_from_proposal(p.clone(), sender), |
| 932 |
) |
| 933 |
.await |
| 934 |
.unwrap() |
| 935 |
} |
| 936 |
|
| 937 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 938 |
async fn make_proposal_info<S>(p: &Proposal, sender: S) -> ProposalInfo<Proposal> |
| 939 |
where |
| 940 |
S: Into<Sender> + Clone, |
| 941 |
{ |
| 942 |
ProposalInfo { |
| 943 |
proposal: p.clone(), |
| 944 |
sender: sender.clone().into(), |
| 945 |
source: ProposalSource::ByReference(make_proposal_ref(p, sender).await), |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 950 |
async fn test_proposal_cache_setup(proposals: Vec<AuthenticatedContent>) -> ProposalCache { |
| 951 |
let mut cache = make_proposal_cache(); |
| 952 |
cache.extend(filter_proposals(TEST_CIPHER_SUITE, proposals).await); |
| 953 |
cache |
| 954 |
} |
| 955 |
|
| 956 |
fn assert_matches(mut expected_state: ProvisionalState, state: ProvisionalState) { |
| 957 |
let expected_proposals = expected_state.applied_proposals.proposals_or_refs(); |
| 958 |
let proposals = state.applied_proposals.proposals_or_refs(); |
| 959 |
|
| 960 |
assert_eq!(proposals.len(), expected_proposals.len()); |
| 961 |
|
| 962 |
// Determine there are no duplicates in the proposals returned |
| 963 |
assert!(!proposals.iter().enumerate().any(|(i, p1)| proposals |
| 964 |
.iter() |
| 965 |
.enumerate() |
| 966 |
.any(|(j, p2)| p1 == p2 && i != j)),); |
| 967 |
|
| 968 |
// Proposal order may change so we just compare the length and contents are the same |
| 969 |
expected_proposals |
| 970 |
.iter() |
| 971 |
.for_each(|p| assert!(proposals.contains(p))); |
| 972 |
|
| 973 |
assert_eq!( |
| 974 |
expected_state.external_init_index, |
| 975 |
state.external_init_index |
| 976 |
); |
| 977 |
|
| 978 |
// We don't compare the epoch in this test. |
| 979 |
expected_state.group_context.epoch = state.group_context.epoch; |
| 980 |
assert_eq!(expected_state.group_context, state.group_context); |
| 981 |
|
| 982 |
assert_eq!( |
| 983 |
expected_state.indexes_of_added_kpkgs, |
| 984 |
state.indexes_of_added_kpkgs |
| 985 |
); |
| 986 |
|
| 987 |
assert_eq!(expected_state.public_tree, state.public_tree); |
| 988 |
|
| 989 |
assert_eq!(expected_state.unused_proposals, state.unused_proposals); |
| 990 |
} |
| 991 |
|
| 992 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 993 |
async fn test_proposal_cache_commit_all_cached() { |
| 994 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 995 |
|
| 996 |
let TestProposals { |
| 997 |
test_sender, |
| 998 |
test_proposals, |
| 999 |
expected_effects, |
| 1000 |
tree, |
| 1001 |
.. |
| 1002 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1003 |
|
| 1004 |
let cache = test_proposal_cache_setup(test_proposals.clone()).await; |
| 1005 |
|
| 1006 |
let provisional_state = cache |
| 1007 |
.prepare_commit_default( |
| 1008 |
Sender::Member(test_sender), |
| 1009 |
vec![], |
| 1010 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1011 |
&BasicIdentityProvider, |
| 1012 |
&cipher_suite_provider, |
| 1013 |
&tree, |
| 1014 |
None, |
| 1015 |
&AlwaysFoundPskStorage, |
| 1016 |
pass_through_rules(), |
| 1017 |
) |
| 1018 |
.await |
| 1019 |
.unwrap(); |
| 1020 |
|
| 1021 |
assert_matches(expected_effects, provisional_state) |
| 1022 |
} |
| 1023 |
|
| 1024 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1025 |
async fn test_proposal_cache_commit_additional() { |
| 1026 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1027 |
|
| 1028 |
let TestProposals { |
| 1029 |
test_sender, |
| 1030 |
test_proposals, |
| 1031 |
mut expected_effects, |
| 1032 |
tree, |
| 1033 |
.. |
| 1034 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1035 |
|
| 1036 |
let additional_key_package = |
| 1037 |
test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "frank").await; |
| 1038 |
|
| 1039 |
let additional = AddProposal { |
| 1040 |
key_package: additional_key_package.clone(), |
| 1041 |
}; |
| 1042 |
|
| 1043 |
let cache = test_proposal_cache_setup(test_proposals.clone()).await; |
| 1044 |
|
| 1045 |
let provisional_state = cache |
| 1046 |
.prepare_commit_default( |
| 1047 |
Sender::Member(test_sender), |
| 1048 |
vec![Proposal::Add(Box::new(additional.clone()))], |
| 1049 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1050 |
&BasicIdentityProvider, |
| 1051 |
&cipher_suite_provider, |
| 1052 |
&tree, |
| 1053 |
None, |
| 1054 |
&AlwaysFoundPskStorage, |
| 1055 |
pass_through_rules(), |
| 1056 |
) |
| 1057 |
.await |
| 1058 |
.unwrap(); |
| 1059 |
|
| 1060 |
expected_effects.applied_proposals.add( |
| 1061 |
Proposal::Add(Box::new(additional.clone())), |
| 1062 |
Sender::Member(test_sender), |
| 1063 |
ProposalSource::ByValue, |
| 1064 |
); |
| 1065 |
|
| 1066 |
let leaf = vec![additional_key_package.leaf_node.clone()]; |
| 1067 |
|
| 1068 |
expected_effects |
| 1069 |
.public_tree |
| 1070 |
.add_leaves(leaf, &BasicIdentityProvider, &cipher_suite_provider) |
| 1071 |
.await |
| 1072 |
.unwrap(); |
| 1073 |
|
| 1074 |
expected_effects.indexes_of_added_kpkgs.push(LeafIndex(3)); |
| 1075 |
|
| 1076 |
assert_matches(expected_effects, provisional_state); |
| 1077 |
} |
| 1078 |
|
| 1079 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1080 |
async fn test_proposal_cache_update_filter() { |
| 1081 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1082 |
|
| 1083 |
let TestProposals { |
| 1084 |
test_proposals, |
| 1085 |
tree, |
| 1086 |
.. |
| 1087 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1088 |
|
| 1089 |
let update_proposal = make_update_proposal("foo").await; |
| 1090 |
|
| 1091 |
let additional = vec![Proposal::Update(update_proposal)]; |
| 1092 |
|
| 1093 |
let cache = test_proposal_cache_setup(test_proposals).await; |
| 1094 |
|
| 1095 |
let res = cache |
| 1096 |
.prepare_commit_default( |
| 1097 |
Sender::Member(test_sender()), |
| 1098 |
additional, |
| 1099 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1100 |
&BasicIdentityProvider, |
| 1101 |
&cipher_suite_provider, |
| 1102 |
&tree, |
| 1103 |
None, |
| 1104 |
&AlwaysFoundPskStorage, |
| 1105 |
pass_through_rules(), |
| 1106 |
) |
| 1107 |
.await; |
| 1108 |
|
| 1109 |
assert_matches!(res, Err(MlsError::InvalidProposalTypeForSender)); |
| 1110 |
} |
| 1111 |
|
| 1112 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1113 |
async fn test_proposal_cache_removal_override_update() { |
| 1114 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1115 |
|
| 1116 |
let TestProposals { |
| 1117 |
test_sender, |
| 1118 |
test_proposals, |
| 1119 |
tree, |
| 1120 |
.. |
| 1121 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1122 |
|
| 1123 |
let update = Proposal::Update(make_update_proposal("foo").await); |
| 1124 |
let update_proposal_ref = make_proposal_ref(&update, LeafIndex(1)).await; |
| 1125 |
let mut cache = test_proposal_cache_setup(test_proposals).await; |
| 1126 |
|
| 1127 |
cache.insert(update_proposal_ref.clone(), update, Sender::Member(1)); |
| 1128 |
|
| 1129 |
let provisional_state = cache |
| 1130 |
.prepare_commit_default( |
| 1131 |
Sender::Member(test_sender), |
| 1132 |
vec![], |
| 1133 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1134 |
&BasicIdentityProvider, |
| 1135 |
&cipher_suite_provider, |
| 1136 |
&tree, |
| 1137 |
None, |
| 1138 |
&AlwaysFoundPskStorage, |
| 1139 |
pass_through_rules(), |
| 1140 |
) |
| 1141 |
.await |
| 1142 |
.unwrap(); |
| 1143 |
|
| 1144 |
assert!(provisional_state |
| 1145 |
.applied_proposals |
| 1146 |
.removals |
| 1147 |
.iter() |
| 1148 |
.any(|p| *p.proposal.to_remove == 1)); |
| 1149 |
|
| 1150 |
assert!(!provisional_state |
| 1151 |
.applied_proposals |
| 1152 |
.proposals_or_refs() |
| 1153 |
.contains(&ProposalOrRef::Reference(update_proposal_ref))) |
| 1154 |
} |
| 1155 |
|
| 1156 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1157 |
async fn test_proposal_cache_filter_duplicates_insert() { |
| 1158 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1159 |
|
| 1160 |
let TestProposals { |
| 1161 |
test_sender, |
| 1162 |
test_proposals, |
| 1163 |
expected_effects, |
| 1164 |
tree, |
| 1165 |
.. |
| 1166 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1167 |
|
| 1168 |
let mut cache = test_proposal_cache_setup(test_proposals.clone()).await; |
| 1169 |
cache.extend(filter_proposals(TEST_CIPHER_SUITE, test_proposals.clone()).await); |
| 1170 |
|
| 1171 |
let provisional_state = cache |
| 1172 |
.prepare_commit_default( |
| 1173 |
Sender::Member(test_sender), |
| 1174 |
vec![], |
| 1175 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1176 |
&BasicIdentityProvider, |
| 1177 |
&cipher_suite_provider, |
| 1178 |
&tree, |
| 1179 |
None, |
| 1180 |
&AlwaysFoundPskStorage, |
| 1181 |
pass_through_rules(), |
| 1182 |
) |
| 1183 |
.await |
| 1184 |
.unwrap(); |
| 1185 |
|
| 1186 |
assert_matches(expected_effects, provisional_state) |
| 1187 |
} |
| 1188 |
|
| 1189 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1190 |
async fn test_proposal_cache_filter_duplicates_additional() { |
| 1191 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1192 |
|
| 1193 |
let TestProposals { |
| 1194 |
test_proposals, |
| 1195 |
expected_effects, |
| 1196 |
tree, |
| 1197 |
.. |
| 1198 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1199 |
|
| 1200 |
let mut cache = test_proposal_cache_setup(test_proposals.clone()).await; |
| 1201 |
|
| 1202 |
// Updates from different senders will be allowed so we test duplicates for add / remove |
| 1203 |
let additional = test_proposals |
| 1204 |
.clone() |
| 1205 |
.into_iter() |
| 1206 |
.filter_map(|plaintext| match plaintext.content.content { |
| 1207 |
Content::Proposal(p) if p.proposal_type() == ProposalType::UPDATE => None, |
| 1208 |
Content::Proposal(_) => Some(plaintext), |
| 1209 |
_ => None, |
| 1210 |
}) |
| 1211 |
.collect::<Vec<_>>(); |
| 1212 |
|
| 1213 |
cache.extend(filter_proposals(TEST_CIPHER_SUITE, additional).await); |
| 1214 |
|
| 1215 |
let provisional_state = cache |
| 1216 |
.prepare_commit_default( |
| 1217 |
Sender::Member(2), |
| 1218 |
Vec::new(), |
| 1219 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1220 |
&BasicIdentityProvider, |
| 1221 |
&cipher_suite_provider, |
| 1222 |
&tree, |
| 1223 |
None, |
| 1224 |
&AlwaysFoundPskStorage, |
| 1225 |
pass_through_rules(), |
| 1226 |
) |
| 1227 |
.await |
| 1228 |
.unwrap(); |
| 1229 |
|
| 1230 |
assert_matches(expected_effects, provisional_state) |
| 1231 |
} |
| 1232 |
|
| 1233 |
#[cfg(feature = "private_message")] |
| 1234 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1235 |
async fn test_proposal_cache_is_empty() { |
| 1236 |
let mut cache = make_proposal_cache(); |
| 1237 |
assert!(cache.is_empty()); |
| 1238 |
|
| 1239 |
let test_proposal = Proposal::Remove(RemoveProposal { |
| 1240 |
to_remove: LeafIndex(test_sender()), |
| 1241 |
}); |
| 1242 |
|
| 1243 |
let proposer = test_sender(); |
| 1244 |
let test_proposal_ref = make_proposal_ref(&test_proposal, LeafIndex(proposer)).await; |
| 1245 |
cache.insert(test_proposal_ref, test_proposal, Sender::Member(proposer)); |
| 1246 |
|
| 1247 |
assert!(!cache.is_empty()) |
| 1248 |
} |
| 1249 |
|
| 1250 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1251 |
async fn test_proposal_cache_resolve() { |
| 1252 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1253 |
|
| 1254 |
let TestProposals { |
| 1255 |
test_sender, |
| 1256 |
test_proposals, |
| 1257 |
tree, |
| 1258 |
.. |
| 1259 |
} = test_proposals(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1260 |
|
| 1261 |
let cache = test_proposal_cache_setup(test_proposals).await; |
| 1262 |
|
| 1263 |
let proposal = Proposal::Add(Box::new(AddProposal { |
| 1264 |
key_package: test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "frank").await, |
| 1265 |
})); |
| 1266 |
|
| 1267 |
let additional = vec![proposal]; |
| 1268 |
|
| 1269 |
let expected_effects = cache |
| 1270 |
.prepare_commit_default( |
| 1271 |
Sender::Member(test_sender), |
| 1272 |
additional, |
| 1273 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1274 |
&BasicIdentityProvider, |
| 1275 |
&cipher_suite_provider, |
| 1276 |
&tree, |
| 1277 |
None, |
| 1278 |
&AlwaysFoundPskStorage, |
| 1279 |
pass_through_rules(), |
| 1280 |
) |
| 1281 |
.await |
| 1282 |
.unwrap(); |
| 1283 |
|
| 1284 |
let proposals = expected_effects |
| 1285 |
.applied_proposals |
| 1286 |
.clone() |
| 1287 |
.proposals_or_refs(); |
| 1288 |
|
| 1289 |
let resolution = cache |
| 1290 |
.resolve_for_commit_default( |
| 1291 |
Sender::Member(test_sender), |
| 1292 |
proposals, |
| 1293 |
None, |
| 1294 |
&ExtensionList::new(), |
| 1295 |
&BasicIdentityProvider, |
| 1296 |
&cipher_suite_provider, |
| 1297 |
&tree, |
| 1298 |
&AlwaysFoundPskStorage, |
| 1299 |
pass_through_rules(), |
| 1300 |
) |
| 1301 |
.await |
| 1302 |
.unwrap(); |
| 1303 |
|
| 1304 |
assert_matches(expected_effects, resolution); |
| 1305 |
} |
| 1306 |
|
| 1307 |
#[cfg(feature = "psk")] |
| 1308 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1309 |
async fn proposal_cache_filters_duplicate_psk_ids() { |
| 1310 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1311 |
|
| 1312 |
let (alice, tree) = new_tree("alice").await; |
| 1313 |
let cache = make_proposal_cache(); |
| 1314 |
|
| 1315 |
let proposal = Proposal::Psk(make_external_psk( |
| 1316 |
b"ted", |
| 1317 |
crate::psk::PskNonce::random(&test_cipher_suite_provider(TEST_CIPHER_SUITE)).unwrap(), |
| 1318 |
)); |
| 1319 |
|
| 1320 |
let res = cache |
| 1321 |
.prepare_commit_default( |
| 1322 |
Sender::Member(*alice), |
| 1323 |
vec![proposal.clone(), proposal], |
| 1324 |
&get_test_group_context(0, TEST_CIPHER_SUITE).await, |
| 1325 |
&BasicIdentityProvider, |
| 1326 |
&cipher_suite_provider, |
| 1327 |
&tree, |
| 1328 |
None, |
| 1329 |
&AlwaysFoundPskStorage, |
| 1330 |
pass_through_rules(), |
| 1331 |
) |
| 1332 |
.await; |
| 1333 |
|
| 1334 |
assert_matches!(res, Err(MlsError::DuplicatePskIds)); |
| 1335 |
} |
| 1336 |
|
| 1337 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 1338 |
async fn test_node() -> LeafNode { |
| 1339 |
let (mut leaf_node, _, signer) = |
| 1340 |
get_basic_test_node_sig_key(TEST_CIPHER_SUITE, "foo").await; |
| 1341 |
|
| 1342 |
leaf_node |
| 1343 |
.commit( |
| 1344 |
&test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 1345 |
TEST_GROUP, |
| 1346 |
0, |
| 1347 |
Some(default_properties()), |
| 1348 |
None, |
| 1349 |
&signer, |
| 1350 |
) |
| 1351 |
.await |
| 1352 |
.unwrap(); |
| 1353 |
|
| 1354 |
leaf_node |
| 1355 |
} |
| 1356 |
|
| 1357 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1358 |
async fn external_commit_must_have_new_leaf() { |
| 1359 |
let cache = make_proposal_cache(); |
| 1360 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1361 |
|
| 1362 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1363 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1364 |
let public_tree = &group.state.public_tree; |
| 1365 |
|
| 1366 |
let res = cache |
| 1367 |
.resolve_for_commit_default( |
| 1368 |
Sender::NewMemberCommit, |
| 1369 |
vec![ProposalOrRef::Proposal(Box::new(Proposal::ExternalInit( |
| 1370 |
ExternalInit { kem_output }, |
| 1371 |
)))], |
| 1372 |
None, |
| 1373 |
&group.context().extensions, |
| 1374 |
&BasicIdentityProvider, |
| 1375 |
&cipher_suite_provider, |
| 1376 |
public_tree, |
| 1377 |
&AlwaysFoundPskStorage, |
| 1378 |
pass_through_rules(), |
| 1379 |
) |
| 1380 |
.await; |
| 1381 |
|
| 1382 |
assert_matches!(res, Err(MlsError::ExternalCommitMustHaveNewLeaf)); |
| 1383 |
} |
| 1384 |
|
| 1385 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1386 |
async fn proposal_cache_rejects_proposals_by_ref_for_new_member() { |
| 1387 |
let mut cache = make_proposal_cache(); |
| 1388 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1389 |
|
| 1390 |
let proposal = { |
| 1391 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1392 |
Proposal::ExternalInit(ExternalInit { kem_output }) |
| 1393 |
}; |
| 1394 |
|
| 1395 |
let proposal_ref = make_proposal_ref(&proposal, test_sender()).await; |
| 1396 |
|
| 1397 |
cache.insert( |
| 1398 |
proposal_ref.clone(), |
| 1399 |
proposal, |
| 1400 |
Sender::Member(test_sender()), |
| 1401 |
); |
| 1402 |
|
| 1403 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1404 |
let public_tree = &group.state.public_tree; |
| 1405 |
|
| 1406 |
let res = cache |
| 1407 |
.resolve_for_commit_default( |
| 1408 |
Sender::NewMemberCommit, |
| 1409 |
vec![ProposalOrRef::Reference(proposal_ref)], |
| 1410 |
Some(&test_node().await), |
| 1411 |
&group.context().extensions, |
| 1412 |
&BasicIdentityProvider, |
| 1413 |
&cipher_suite_provider, |
| 1414 |
public_tree, |
| 1415 |
&AlwaysFoundPskStorage, |
| 1416 |
pass_through_rules(), |
| 1417 |
) |
| 1418 |
.await; |
| 1419 |
|
| 1420 |
assert_matches!(res, Err(MlsError::OnlyMembersCanCommitProposalsByRef)); |
| 1421 |
} |
| 1422 |
|
| 1423 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1424 |
async fn proposal_cache_rejects_multiple_external_init_proposals_in_commit() { |
| 1425 |
let cache = make_proposal_cache(); |
| 1426 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1427 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1428 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1429 |
let public_tree = &group.state.public_tree; |
| 1430 |
|
| 1431 |
let res = cache |
| 1432 |
.resolve_for_commit_default( |
| 1433 |
Sender::NewMemberCommit, |
| 1434 |
[ |
| 1435 |
Proposal::ExternalInit(ExternalInit { |
| 1436 |
kem_output: kem_output.clone(), |
| 1437 |
}), |
| 1438 |
Proposal::ExternalInit(ExternalInit { kem_output }), |
| 1439 |
] |
| 1440 |
.into_iter() |
| 1441 |
.map(|p| ProposalOrRef::Proposal(Box::new(p))) |
| 1442 |
.collect(), |
| 1443 |
Some(&test_node().await), |
| 1444 |
&group.context().extensions, |
| 1445 |
&BasicIdentityProvider, |
| 1446 |
&cipher_suite_provider, |
| 1447 |
public_tree, |
| 1448 |
&AlwaysFoundPskStorage, |
| 1449 |
pass_through_rules(), |
| 1450 |
) |
| 1451 |
.await; |
| 1452 |
|
| 1453 |
assert_matches!( |
| 1454 |
res, |
| 1455 |
Err(MlsError::ExternalCommitMustHaveExactlyOneExternalInit) |
| 1456 |
); |
| 1457 |
} |
| 1458 |
|
| 1459 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 1460 |
async fn new_member_commits_proposal(proposal: Proposal) -> Result<ProvisionalState, MlsError> { |
| 1461 |
let cache = make_proposal_cache(); |
| 1462 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1463 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1464 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1465 |
let public_tree = &group.state.public_tree; |
| 1466 |
|
| 1467 |
cache |
| 1468 |
.resolve_for_commit_default( |
| 1469 |
Sender::NewMemberCommit, |
| 1470 |
[ |
| 1471 |
Proposal::ExternalInit(ExternalInit { kem_output }), |
| 1472 |
proposal, |
| 1473 |
] |
| 1474 |
.into_iter() |
| 1475 |
.map(|p| ProposalOrRef::Proposal(Box::new(p))) |
| 1476 |
.collect(), |
| 1477 |
Some(&test_node().await), |
| 1478 |
&group.context().extensions, |
| 1479 |
&BasicIdentityProvider, |
| 1480 |
&cipher_suite_provider, |
| 1481 |
public_tree, |
| 1482 |
&AlwaysFoundPskStorage, |
| 1483 |
pass_through_rules(), |
| 1484 |
) |
| 1485 |
.await |
| 1486 |
} |
| 1487 |
|
| 1488 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1489 |
async fn new_member_cannot_commit_add_proposal() { |
| 1490 |
let res = new_member_commits_proposal(Proposal::Add(Box::new(AddProposal { |
| 1491 |
key_package: test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "frank").await, |
| 1492 |
}))) |
| 1493 |
.await; |
| 1494 |
|
| 1495 |
assert_matches!( |
| 1496 |
res, |
| 1497 |
Err(MlsError::InvalidProposalTypeInExternalCommit( |
| 1498 |
ProposalType::ADD |
| 1499 |
)) |
| 1500 |
); |
| 1501 |
} |
| 1502 |
|
| 1503 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1504 |
async fn new_member_cannot_commit_more_than_one_remove_proposal() { |
| 1505 |
let cache = make_proposal_cache(); |
| 1506 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1507 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1508 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1509 |
let group_extensions = group.context().extensions.clone(); |
| 1510 |
let mut public_tree = group.group.state.public_tree; |
| 1511 |
|
| 1512 |
let foo = get_basic_test_node(TEST_CIPHER_SUITE, "foo").await; |
| 1513 |
|
| 1514 |
let bar = get_basic_test_node(TEST_CIPHER_SUITE, "bar").await; |
| 1515 |
|
| 1516 |
let test_leaf_nodes = vec![foo, bar]; |
| 1517 |
|
| 1518 |
let test_leaf_node_indexes = public_tree |
| 1519 |
.add_leaves( |
| 1520 |
test_leaf_nodes, |
| 1521 |
&BasicIdentityProvider, |
| 1522 |
&cipher_suite_provider, |
| 1523 |
) |
| 1524 |
.await |
| 1525 |
.unwrap(); |
| 1526 |
|
| 1527 |
let proposals = vec![ |
| 1528 |
Proposal::ExternalInit(ExternalInit { kem_output }), |
| 1529 |
Proposal::Remove(RemoveProposal { |
| 1530 |
to_remove: test_leaf_node_indexes[0], |
| 1531 |
}), |
| 1532 |
Proposal::Remove(RemoveProposal { |
| 1533 |
to_remove: test_leaf_node_indexes[1], |
| 1534 |
}), |
| 1535 |
]; |
| 1536 |
|
| 1537 |
let res = cache |
| 1538 |
.resolve_for_commit_default( |
| 1539 |
Sender::NewMemberCommit, |
| 1540 |
proposals |
| 1541 |
.into_iter() |
| 1542 |
.map(|p| ProposalOrRef::Proposal(Box::new(p))) |
| 1543 |
.collect(), |
| 1544 |
Some(&test_node().await), |
| 1545 |
&group_extensions, |
| 1546 |
&BasicIdentityProvider, |
| 1547 |
&cipher_suite_provider, |
| 1548 |
&public_tree, |
| 1549 |
&AlwaysFoundPskStorage, |
| 1550 |
pass_through_rules(), |
| 1551 |
) |
| 1552 |
.await; |
| 1553 |
|
| 1554 |
assert_matches!(res, Err(MlsError::ExternalCommitWithMoreThanOneRemove)); |
| 1555 |
} |
| 1556 |
|
| 1557 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1558 |
async fn new_member_remove_proposal_invalid_credential() { |
| 1559 |
let cache = make_proposal_cache(); |
| 1560 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1561 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1562 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1563 |
let group_extensions = group.context().extensions.clone(); |
| 1564 |
let mut public_tree = group.group.state.public_tree; |
| 1565 |
|
| 1566 |
let node = get_basic_test_node(TEST_CIPHER_SUITE, "bar").await; |
| 1567 |
|
| 1568 |
let test_leaf_nodes = vec![node]; |
| 1569 |
|
| 1570 |
let test_leaf_node_indexes = public_tree |
| 1571 |
.add_leaves( |
| 1572 |
test_leaf_nodes, |
| 1573 |
&BasicIdentityProvider, |
| 1574 |
&cipher_suite_provider, |
| 1575 |
) |
| 1576 |
.await |
| 1577 |
.unwrap(); |
| 1578 |
|
| 1579 |
let proposals = vec![ |
| 1580 |
Proposal::ExternalInit(ExternalInit { kem_output }), |
| 1581 |
Proposal::Remove(RemoveProposal { |
| 1582 |
to_remove: test_leaf_node_indexes[0], |
| 1583 |
}), |
| 1584 |
]; |
| 1585 |
|
| 1586 |
let res = cache |
| 1587 |
.resolve_for_commit_default( |
| 1588 |
Sender::NewMemberCommit, |
| 1589 |
proposals |
| 1590 |
.into_iter() |
| 1591 |
.map(|p| ProposalOrRef::Proposal(Box::new(p))) |
| 1592 |
.collect(), |
| 1593 |
Some(&test_node().await), |
| 1594 |
&group_extensions, |
| 1595 |
&BasicIdentityProvider, |
| 1596 |
&cipher_suite_provider, |
| 1597 |
&public_tree, |
| 1598 |
&AlwaysFoundPskStorage, |
| 1599 |
pass_through_rules(), |
| 1600 |
) |
| 1601 |
.await; |
| 1602 |
|
| 1603 |
assert_matches!(res, Err(MlsError::ExternalCommitRemovesOtherIdentity)); |
| 1604 |
} |
| 1605 |
|
| 1606 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1607 |
async fn new_member_remove_proposal_valid_credential() { |
| 1608 |
let cache = make_proposal_cache(); |
| 1609 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1610 |
let kem_output = vec![0; cipher_suite_provider.kdf_extract_size()]; |
| 1611 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1612 |
let group_extensions = group.context().extensions.clone(); |
| 1613 |
let mut public_tree = group.group.state.public_tree; |
| 1614 |
|
| 1615 |
let node = get_basic_test_node(TEST_CIPHER_SUITE, "foo").await; |
| 1616 |
|
| 1617 |
let test_leaf_nodes = vec![node]; |
| 1618 |
|
| 1619 |
let test_leaf_node_indexes = public_tree |
| 1620 |
.add_leaves( |
| 1621 |
test_leaf_nodes, |
| 1622 |
&BasicIdentityProvider, |
| 1623 |
&cipher_suite_provider, |
| 1624 |
) |
| 1625 |
.await |
| 1626 |
.unwrap(); |
| 1627 |
|
| 1628 |
let proposals = vec![ |
| 1629 |
Proposal::ExternalInit(ExternalInit { kem_output }), |
| 1630 |
Proposal::Remove(RemoveProposal { |
| 1631 |
to_remove: test_leaf_node_indexes[0], |
| 1632 |
}), |
| 1633 |
]; |
| 1634 |
|
| 1635 |
let res = cache |
| 1636 |
.resolve_for_commit_default( |
| 1637 |
Sender::NewMemberCommit, |
| 1638 |
proposals |
| 1639 |
.into_iter() |
| 1640 |
.map(|p| ProposalOrRef::Proposal(Box::new(p))) |
| 1641 |
.collect(), |
| 1642 |
Some(&test_node().await), |
| 1643 |
&group_extensions, |
| 1644 |
&BasicIdentityProvider, |
| 1645 |
&cipher_suite_provider, |
| 1646 |
&public_tree, |
| 1647 |
&AlwaysFoundPskStorage, |
| 1648 |
pass_through_rules(), |
| 1649 |
) |
| 1650 |
.await; |
| 1651 |
|
| 1652 |
assert_matches!(res, Ok(_)); |
| 1653 |
} |
| 1654 |
|
| 1655 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1656 |
async fn new_member_cannot_commit_update_proposal() { |
| 1657 |
let res = new_member_commits_proposal(Proposal::Update(UpdateProposal { |
| 1658 |
leaf_node: get_basic_test_node(TEST_CIPHER_SUITE, "foo").await, |
| 1659 |
})) |
| 1660 |
.await; |
| 1661 |
|
| 1662 |
assert_matches!( |
| 1663 |
res, |
| 1664 |
Err(MlsError::InvalidProposalTypeInExternalCommit( |
| 1665 |
ProposalType::UPDATE |
| 1666 |
)) |
| 1667 |
); |
| 1668 |
} |
| 1669 |
|
| 1670 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1671 |
async fn new_member_cannot_commit_group_extensions_proposal() { |
| 1672 |
let res = |
| 1673 |
new_member_commits_proposal(Proposal::GroupContextExtensions(ExtensionList::new())) |
| 1674 |
.await; |
| 1675 |
|
| 1676 |
assert_matches!( |
| 1677 |
res, |
| 1678 |
Err(MlsError::InvalidProposalTypeInExternalCommit( |
| 1679 |
ProposalType::GROUP_CONTEXT_EXTENSIONS, |
| 1680 |
)) |
| 1681 |
); |
| 1682 |
} |
| 1683 |
|
| 1684 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1685 |
async fn new_member_cannot_commit_reinit_proposal() { |
| 1686 |
let res = new_member_commits_proposal(Proposal::ReInit(ReInitProposal { |
| 1687 |
group_id: b"foo".to_vec(), |
| 1688 |
version: TEST_PROTOCOL_VERSION, |
| 1689 |
cipher_suite: TEST_CIPHER_SUITE, |
| 1690 |
extensions: ExtensionList::new(), |
| 1691 |
})) |
| 1692 |
.await; |
| 1693 |
|
| 1694 |
assert_matches!( |
| 1695 |
res, |
| 1696 |
Err(MlsError::InvalidProposalTypeInExternalCommit( |
| 1697 |
ProposalType::RE_INIT |
| 1698 |
)) |
| 1699 |
); |
| 1700 |
} |
| 1701 |
|
| 1702 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1703 |
async fn new_member_commit_must_contain_an_external_init_proposal() { |
| 1704 |
let cache = make_proposal_cache(); |
| 1705 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1706 |
let group = test_group(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE).await; |
| 1707 |
let public_tree = &group.state.public_tree; |
| 1708 |
|
| 1709 |
let res = cache |
| 1710 |
.resolve_for_commit_default( |
| 1711 |
Sender::NewMemberCommit, |
| 1712 |
Vec::new(), |
| 1713 |
Some(&test_node().await), |
| 1714 |
&group.context().extensions, |
| 1715 |
&BasicIdentityProvider, |
| 1716 |
&cipher_suite_provider, |
| 1717 |
public_tree, |
| 1718 |
&AlwaysFoundPskStorage, |
| 1719 |
pass_through_rules(), |
| 1720 |
) |
| 1721 |
.await; |
| 1722 |
|
| 1723 |
assert_matches!( |
| 1724 |
res, |
| 1725 |
Err(MlsError::ExternalCommitMustHaveExactlyOneExternalInit) |
| 1726 |
); |
| 1727 |
} |
| 1728 |
|
| 1729 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1730 |
async fn test_path_update_required_empty() { |
| 1731 |
let cache = make_proposal_cache(); |
| 1732 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1733 |
|
| 1734 |
let mut tree = TreeKemPublic::new(); |
| 1735 |
add_member(&mut tree, "alice").await; |
| 1736 |
add_member(&mut tree, "bob").await; |
| 1737 |
|
| 1738 |
let effects = cache |
| 1739 |
.prepare_commit_default( |
| 1740 |
Sender::Member(test_sender()), |
| 1741 |
vec![], |
| 1742 |
&get_test_group_context(1, TEST_CIPHER_SUITE).await, |
| 1743 |
&BasicIdentityProvider, |
| 1744 |
&cipher_suite_provider, |
| 1745 |
&tree, |
| 1746 |
None, |
| 1747 |
&AlwaysFoundPskStorage, |
| 1748 |
pass_through_rules(), |
| 1749 |
) |
| 1750 |
.await |
| 1751 |
.unwrap(); |
| 1752 |
|
| 1753 |
assert!(path_update_required(&effects.applied_proposals)) |
| 1754 |
} |
| 1755 |
|
| 1756 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1757 |
async fn test_path_update_required_updates() { |
| 1758 |
let mut cache = make_proposal_cache(); |
| 1759 |
let update = Proposal::Update(make_update_proposal("bar").await); |
| 1760 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1761 |
|
| 1762 |
cache.insert( |
| 1763 |
make_proposal_ref(&update, LeafIndex(2)).await, |
| 1764 |
update, |
| 1765 |
Sender::Member(2), |
| 1766 |
); |
| 1767 |
|
| 1768 |
let mut tree = TreeKemPublic::new(); |
| 1769 |
add_member(&mut tree, "alice").await; |
| 1770 |
add_member(&mut tree, "bob").await; |
| 1771 |
add_member(&mut tree, "carol").await; |
| 1772 |
|
| 1773 |
let effects = cache |
| 1774 |
.prepare_commit_default( |
| 1775 |
Sender::Member(test_sender()), |
| 1776 |
Vec::new(), |
| 1777 |
&get_test_group_context(1, TEST_CIPHER_SUITE).await, |
| 1778 |
&BasicIdentityProvider, |
| 1779 |
&cipher_suite_provider, |
| 1780 |
&tree, |
| 1781 |
None, |
| 1782 |
&AlwaysFoundPskStorage, |
| 1783 |
pass_through_rules(), |
| 1784 |
) |
| 1785 |
.await |
| 1786 |
.unwrap(); |
| 1787 |
|
| 1788 |
assert!(path_update_required(&effects.applied_proposals)) |
| 1789 |
} |
| 1790 |
|
| 1791 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1792 |
async fn test_path_update_required_removes() { |
| 1793 |
let cache = make_proposal_cache(); |
| 1794 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1795 |
|
| 1796 |
let (alice_leaf, alice_secret, _) = |
| 1797 |
get_basic_test_node_sig_key(TEST_CIPHER_SUITE, "alice").await; |
| 1798 |
let alice = 0; |
| 1799 |
|
| 1800 |
let (mut tree, _) = TreeKemPublic::derive( |
| 1801 |
alice_leaf, |
| 1802 |
alice_secret, |
| 1803 |
&BasicIdentityProvider, |
| 1804 |
&Default::default(), |
| 1805 |
) |
| 1806 |
.await |
| 1807 |
.unwrap(); |
| 1808 |
|
| 1809 |
let bob_node = get_basic_test_node(TEST_CIPHER_SUITE, "bob").await; |
| 1810 |
|
| 1811 |
let bob = tree |
| 1812 |
.add_leaves( |
| 1813 |
vec![bob_node], |
| 1814 |
&BasicIdentityProvider, |
| 1815 |
&cipher_suite_provider, |
| 1816 |
) |
| 1817 |
.await |
| 1818 |
.unwrap()[0]; |
| 1819 |
|
| 1820 |
let remove = Proposal::Remove(RemoveProposal { to_remove: bob }); |
| 1821 |
|
| 1822 |
let effects = cache |
| 1823 |
.prepare_commit_default( |
| 1824 |
Sender::Member(alice), |
| 1825 |
vec![remove], |
| 1826 |
&get_test_group_context(1, TEST_CIPHER_SUITE).await, |
| 1827 |
&BasicIdentityProvider, |
| 1828 |
&cipher_suite_provider, |
| 1829 |
&tree, |
| 1830 |
None, |
| 1831 |
&AlwaysFoundPskStorage, |
| 1832 |
pass_through_rules(), |
| 1833 |
) |
| 1834 |
.await |
| 1835 |
.unwrap(); |
| 1836 |
|
| 1837 |
assert!(path_update_required(&effects.applied_proposals)) |
| 1838 |
} |
| 1839 |
|
| 1840 |
#[cfg(feature = "psk")] |
| 1841 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1842 |
async fn test_path_update_not_required() { |
| 1843 |
let (alice, tree) = new_tree("alice").await; |
| 1844 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1845 |
let cache = make_proposal_cache(); |
| 1846 |
|
| 1847 |
let psk = Proposal::Psk(PreSharedKeyProposal { |
| 1848 |
psk: PreSharedKeyID::new( |
| 1849 |
JustPreSharedKeyID::External(ExternalPskId::new(vec![])), |
| 1850 |
&test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 1851 |
) |
| 1852 |
.unwrap(), |
| 1853 |
}); |
| 1854 |
|
| 1855 |
let add = Proposal::Add(Box::new(AddProposal { |
| 1856 |
key_package: test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "bob").await, |
| 1857 |
})); |
| 1858 |
|
| 1859 |
let effects = cache |
| 1860 |
.prepare_commit_default( |
| 1861 |
Sender::Member(*alice), |
| 1862 |
vec![psk, add], |
| 1863 |
&get_test_group_context(1, TEST_CIPHER_SUITE).await, |
| 1864 |
&BasicIdentityProvider, |
| 1865 |
&cipher_suite_provider, |
| 1866 |
&tree, |
| 1867 |
None, |
| 1868 |
&AlwaysFoundPskStorage, |
| 1869 |
pass_through_rules(), |
| 1870 |
) |
| 1871 |
.await |
| 1872 |
.unwrap(); |
| 1873 |
|
| 1874 |
assert!(!path_update_required(&effects.applied_proposals)) |
| 1875 |
} |
| 1876 |
|
| 1877 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 1878 |
async fn path_update_is_not_required_for_re_init() { |
| 1879 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 1880 |
let (alice, tree) = new_tree("alice").await; |
| 1881 |
let cache = make_proposal_cache(); |
| 1882 |
|
| 1883 |
let reinit = Proposal::ReInit(ReInitProposal { |
| 1884 |
group_id: vec![], |
| 1885 |
version: TEST_PROTOCOL_VERSION, |
| 1886 |
cipher_suite: TEST_CIPHER_SUITE, |
| 1887 |
extensions: Default::default(), |
| 1888 |
}); |
| 1889 |
|
| 1890 |
let effects = cache |
| 1891 |
.prepare_commit_default( |
| 1892 |
Sender::Member(*alice), |
| 1893 |
vec![reinit], |
| 1894 |
&get_test_group_context(1, TEST_CIPHER_SUITE).await, |
| 1895 |
&BasicIdentityProvider, |
| 1896 |
&cipher_suite_provider, |
| 1897 |
&tree, |
| 1898 |
None, |
| 1899 |
&AlwaysFoundPskStorage, |
| 1900 |
pass_through_rules(), |
| 1901 |
) |
| 1902 |
.await |
| 1903 |
.unwrap(); |
| 1904 |
|
| 1905 |
assert!(!path_update_required(&effects.applied_proposals)) |
| 1906 |
} |
| 1907 |
|
| 1908 |
#[derive(Debug)] |
| 1909 |
struct CommitSender<'a, C, F, P, CSP> { |
| 1910 |
cipher_suite_provider: CSP, |
| 1911 |
tree: &'a TreeKemPublic, |
| 1912 |
sender: LeafIndex, |
| 1913 |
cache: ProposalCache, |
| 1914 |
additional_proposals: Vec<Proposal>, |
| 1915 |
identity_provider: C, |
| 1916 |
user_rules: F, |
| 1917 |
psk_storage: P, |
| 1918 |
} |
| 1919 |
|
| 1920 |
impl<'a, CSP> |
| 1921 |
CommitSender<'a, BasicWithCustomProvider, DefaultMlsRules, AlwaysFoundPskStorage, CSP> |
| 1922 |
{ |
| 1923 |
fn new(tree: &'a TreeKemPublic, sender: LeafIndex, cipher_suite_provider: CSP) -> Self { |
| 1924 |
Self { |
| 1925 |
tree, |
| 1926 |
sender, |
| 1927 |
cache: make_proposal_cache(), |
| 1928 |
additional_proposals: Vec::new(), |
| 1929 |
identity_provider: BasicWithCustomProvider::new(BasicIdentityProvider::new()), |
| 1930 |
user_rules: pass_through_rules(), |
| 1931 |
psk_storage: AlwaysFoundPskStorage, |
| 1932 |
cipher_suite_provider, |
| 1933 |
} |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
impl<'a, C, F, P, CSP> CommitSender<'a, C, F, P, CSP> |
| 1938 |
where |
| 1939 |
C: IdentityProvider, |
| 1940 |
F: MlsRules, |
| 1941 |
P: PreSharedKeyStorage, |
| 1942 |
CSP: CipherSuiteProvider, |
| 1943 |
{ |
| 1944 |
#[cfg(feature = "by_ref_proposal")] |
| 1945 |
fn with_identity_provider<V>(self, identity_provider: V) -> CommitSender<'a, V, F, P, CSP> |
| 1946 |
where |
| 1947 |
V: IdentityProvider, |
| 1948 |
{ |
| 1949 |
CommitSender { |
| 1950 |
identity_provider, |
| 1951 |
cipher_suite_provider: self.cipher_suite_provider, |
| 1952 |
tree: self.tree, |
| 1953 |
sender: self.sender, |
| 1954 |
cache: self.cache, |
| 1955 |
additional_proposals: self.additional_proposals, |
| 1956 |
user_rules: self.user_rules, |
| 1957 |
psk_storage: self.psk_storage, |
| 1958 |
} |
| 1959 |
} |
| 1960 |
|
| 1961 |
fn cache<S>(mut self, r: ProposalRef, p: Proposal, proposer: S) -> Self |
| 1962 |
where |
| 1963 |
S: Into<Sender>, |
| 1964 |
{ |
| 1965 |
self.cache.insert(r, p, proposer.into()); |
| 1966 |
self |
| 1967 |
} |
| 1968 |
|
| 1969 |
fn with_additional<I>(mut self, proposals: I) -> Self |
| 1970 |
where |
| 1971 |
I: IntoIterator<Item = Proposal>, |
| 1972 |
{ |
| 1973 |
self.additional_proposals.extend(proposals); |
| 1974 |
self |
| 1975 |
} |
| 1976 |
|
| 1977 |
fn with_user_rules<G>(self, f: G) -> CommitSender<'a, C, G, P, CSP> |
| 1978 |
where |
| 1979 |
G: MlsRules, |
| 1980 |
{ |
| 1981 |
CommitSender { |
| 1982 |
tree: self.tree, |
| 1983 |
sender: self.sender, |
| 1984 |
cache: self.cache, |
| 1985 |
additional_proposals: self.additional_proposals, |
| 1986 |
identity_provider: self.identity_provider, |
| 1987 |
user_rules: f, |
| 1988 |
psk_storage: self.psk_storage, |
| 1989 |
cipher_suite_provider: self.cipher_suite_provider, |
| 1990 |
} |
| 1991 |
} |
| 1992 |
|
| 1993 |
fn with_psk_storage<V>(self, v: V) -> CommitSender<'a, C, F, V, CSP> |
| 1994 |
where |
| 1995 |
V: PreSharedKeyStorage, |
| 1996 |
{ |
| 1997 |
CommitSender { |
| 1998 |
tree: self.tree, |
| 1999 |
sender: self.sender, |
| 2000 |
cache: self.cache, |
| 2001 |
additional_proposals: self.additional_proposals, |
| 2002 |
identity_provider: self.identity_provider, |
| 2003 |
user_rules: self.user_rules, |
| 2004 |
psk_storage: v, |
| 2005 |
cipher_suite_provider: self.cipher_suite_provider, |
| 2006 |
} |
| 2007 |
} |
| 2008 |
|
| 2009 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2010 |
async fn send(&self) -> Result<(Vec<ProposalOrRef>, ProvisionalState), MlsError> { |
| 2011 |
let state = self |
| 2012 |
.cache |
| 2013 |
.prepare_commit_default( |
| 2014 |
Sender::Member(*self.sender), |
| 2015 |
self.additional_proposals.clone(), |
| 2016 |
&get_test_group_context(1, TEST_CIPHER_SUITE).await, |
| 2017 |
&self.identity_provider, |
| 2018 |
&self.cipher_suite_provider, |
| 2019 |
self.tree, |
| 2020 |
None, |
| 2021 |
&self.psk_storage, |
| 2022 |
&self.user_rules, |
| 2023 |
) |
| 2024 |
.await?; |
| 2025 |
|
| 2026 |
let proposals = state.applied_proposals.clone().proposals_or_refs(); |
| 2027 |
|
| 2028 |
Ok((proposals, state)) |
| 2029 |
} |
| 2030 |
} |
| 2031 |
|
| 2032 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2033 |
async fn key_package_with_invalid_signature() -> KeyPackage { |
| 2034 |
let mut kp = test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "mallory").await; |
| 2035 |
kp.signature = vec![1, 2, 3]; |
| 2036 |
kp |
| 2037 |
} |
| 2038 |
|
| 2039 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2040 |
async fn key_package_with_public_key(key: crypto::HpkePublicKey) -> KeyPackage { |
| 2041 |
let cs = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 2042 |
|
| 2043 |
let (mut key_package, signer) = |
| 2044 |
test_key_package_with_signer(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "test").await; |
| 2045 |
|
| 2046 |
key_package.leaf_node.public_key = key; |
| 2047 |
|
| 2048 |
key_package |
| 2049 |
.leaf_node |
| 2050 |
.sign( |
| 2051 |
&cs, |
| 2052 |
&signer, |
| 2053 |
&LeafNodeSigningContext { |
| 2054 |
group_id: None, |
| 2055 |
leaf_index: None, |
| 2056 |
}, |
| 2057 |
) |
| 2058 |
.await |
| 2059 |
.unwrap(); |
| 2060 |
|
| 2061 |
key_package.sign(&cs, &signer, &()).await.unwrap(); |
| 2062 |
|
| 2063 |
key_package |
| 2064 |
} |
| 2065 |
|
| 2066 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2067 |
async fn receiving_add_with_invalid_key_package_fails() { |
| 2068 |
let (alice, tree) = new_tree("alice").await; |
| 2069 |
let kp = key_package_with_invalid_signature().await; |
| 2070 |
|
| 2071 |
let res = CommitReceiver::new( |
| 2072 |
&tree, |
| 2073 |
alice, |
| 2074 |
alice, |
| 2075 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2076 |
) |
| 2077 |
.receive([Proposal::Add(Box::new(AddProposal { key_package: kp }))]) |
| 2078 |
.await; |
| 2079 |
|
| 2080 |
assert_matches!(res, Err(MlsError::InvalidSignature)); |
| 2081 |
} |
| 2082 |
|
| 2083 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2084 |
async fn sending_additional_add_with_invalid_key_package_fails() { |
| 2085 |
let (alice, tree) = new_tree("alice").await; |
| 2086 |
|
| 2087 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2088 |
.with_additional([Proposal::Add(Box::new(AddProposal { |
| 2089 |
key_package: key_package_with_invalid_signature().await, |
| 2090 |
}))]) |
| 2091 |
.send() |
| 2092 |
.await; |
| 2093 |
|
| 2094 |
assert_matches!(res, Err(MlsError::InvalidSignature)); |
| 2095 |
} |
| 2096 |
|
| 2097 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2098 |
async fn sending_add_with_invalid_key_package_filters_it_out() { |
| 2099 |
let (alice, tree) = new_tree("alice").await; |
| 2100 |
|
| 2101 |
let proposal = Proposal::Add(Box::new(AddProposal { |
| 2102 |
key_package: key_package_with_invalid_signature().await, |
| 2103 |
})); |
| 2104 |
|
| 2105 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2106 |
|
| 2107 |
let processed_proposals = |
| 2108 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2109 |
.cache( |
| 2110 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2111 |
proposal.clone(), |
| 2112 |
alice, |
| 2113 |
) |
| 2114 |
.send() |
| 2115 |
.await |
| 2116 |
.unwrap(); |
| 2117 |
|
| 2118 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2119 |
|
| 2120 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2121 |
} |
| 2122 |
|
| 2123 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2124 |
async fn sending_add_with_hpke_key_of_another_member_fails() { |
| 2125 |
let (alice, tree) = new_tree("alice").await; |
| 2126 |
|
| 2127 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2128 |
.with_additional([Proposal::Add(Box::new(AddProposal { |
| 2129 |
key_package: key_package_with_public_key( |
| 2130 |
tree.get_leaf_node(alice).unwrap().public_key.clone(), |
| 2131 |
) |
| 2132 |
.await, |
| 2133 |
}))]) |
| 2134 |
.send() |
| 2135 |
.await; |
| 2136 |
|
| 2137 |
assert_matches!(res, Err(MlsError::DuplicateLeafData(_))); |
| 2138 |
} |
| 2139 |
|
| 2140 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2141 |
async fn sending_add_with_hpke_key_of_another_member_filters_it_out() { |
| 2142 |
let (alice, tree) = new_tree("alice").await; |
| 2143 |
|
| 2144 |
let proposal = Proposal::Add(Box::new(AddProposal { |
| 2145 |
key_package: key_package_with_public_key( |
| 2146 |
tree.get_leaf_node(alice).unwrap().public_key.clone(), |
| 2147 |
) |
| 2148 |
.await, |
| 2149 |
})); |
| 2150 |
|
| 2151 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2152 |
|
| 2153 |
let processed_proposals = |
| 2154 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2155 |
.cache( |
| 2156 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2157 |
proposal.clone(), |
| 2158 |
alice, |
| 2159 |
) |
| 2160 |
.send() |
| 2161 |
.await |
| 2162 |
.unwrap(); |
| 2163 |
|
| 2164 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2165 |
|
| 2166 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2167 |
} |
| 2168 |
|
| 2169 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2170 |
async fn receiving_update_with_invalid_leaf_node_fails() { |
| 2171 |
let (alice, mut tree) = new_tree("alice").await; |
| 2172 |
let bob = add_member(&mut tree, "bob").await; |
| 2173 |
|
| 2174 |
let proposal = Proposal::Update(UpdateProposal { |
| 2175 |
leaf_node: get_basic_test_node(TEST_CIPHER_SUITE, "alice").await, |
| 2176 |
}); |
| 2177 |
|
| 2178 |
let proposal_ref = make_proposal_ref(&proposal, bob).await; |
| 2179 |
|
| 2180 |
let res = CommitReceiver::new( |
| 2181 |
&tree, |
| 2182 |
alice, |
| 2183 |
bob, |
| 2184 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2185 |
) |
| 2186 |
.cache(proposal_ref.clone(), proposal, bob) |
| 2187 |
.receive([proposal_ref]) |
| 2188 |
.await; |
| 2189 |
|
| 2190 |
assert_matches!(res, Err(MlsError::InvalidLeafNodeSource)); |
| 2191 |
} |
| 2192 |
|
| 2193 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2194 |
async fn sending_update_with_invalid_leaf_node_filters_it_out() { |
| 2195 |
let (alice, mut tree) = new_tree("alice").await; |
| 2196 |
let bob = add_member(&mut tree, "bob").await; |
| 2197 |
|
| 2198 |
let proposal = Proposal::Update(UpdateProposal { |
| 2199 |
leaf_node: get_basic_test_node(TEST_CIPHER_SUITE, "alice").await, |
| 2200 |
}); |
| 2201 |
|
| 2202 |
let proposal_info = make_proposal_info(&proposal, bob).await; |
| 2203 |
|
| 2204 |
let processed_proposals = |
| 2205 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2206 |
.cache(proposal_info.proposal_ref().unwrap().clone(), proposal, bob) |
| 2207 |
.send() |
| 2208 |
.await |
| 2209 |
.unwrap(); |
| 2210 |
|
| 2211 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2212 |
|
| 2213 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2214 |
} |
| 2215 |
|
| 2216 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2217 |
async fn receiving_remove_with_invalid_index_fails() { |
| 2218 |
let (alice, tree) = new_tree("alice").await; |
| 2219 |
|
| 2220 |
let res = CommitReceiver::new( |
| 2221 |
&tree, |
| 2222 |
alice, |
| 2223 |
alice, |
| 2224 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2225 |
) |
| 2226 |
.receive([Proposal::Remove(RemoveProposal { |
| 2227 |
to_remove: LeafIndex(10), |
| 2228 |
})]) |
| 2229 |
.await; |
| 2230 |
|
| 2231 |
assert_matches!(res, Err(MlsError::InvalidNodeIndex(20))); |
| 2232 |
} |
| 2233 |
|
| 2234 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2235 |
async fn sending_additional_remove_with_invalid_index_fails() { |
| 2236 |
let (alice, tree) = new_tree("alice").await; |
| 2237 |
|
| 2238 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2239 |
.with_additional([Proposal::Remove(RemoveProposal { |
| 2240 |
to_remove: LeafIndex(10), |
| 2241 |
})]) |
| 2242 |
.send() |
| 2243 |
.await; |
| 2244 |
|
| 2245 |
assert_matches!(res, Err(MlsError::InvalidNodeIndex(20))); |
| 2246 |
} |
| 2247 |
|
| 2248 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2249 |
async fn sending_remove_with_invalid_index_filters_it_out() { |
| 2250 |
let (alice, tree) = new_tree("alice").await; |
| 2251 |
|
| 2252 |
let proposal = Proposal::Remove(RemoveProposal { |
| 2253 |
to_remove: LeafIndex(10), |
| 2254 |
}); |
| 2255 |
|
| 2256 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2257 |
|
| 2258 |
let processed_proposals = |
| 2259 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2260 |
.cache( |
| 2261 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2262 |
proposal.clone(), |
| 2263 |
alice, |
| 2264 |
) |
| 2265 |
.send() |
| 2266 |
.await |
| 2267 |
.unwrap(); |
| 2268 |
|
| 2269 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2270 |
|
| 2271 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2272 |
} |
| 2273 |
|
| 2274 |
#[cfg(feature = "psk")] |
| 2275 |
fn make_external_psk(id: &[u8], nonce: PskNonce) -> PreSharedKeyProposal { |
| 2276 |
PreSharedKeyProposal { |
| 2277 |
psk: PreSharedKeyID { |
| 2278 |
key_id: JustPreSharedKeyID::External(ExternalPskId::new(id.to_vec())), |
| 2279 |
psk_nonce: nonce, |
| 2280 |
}, |
| 2281 |
} |
| 2282 |
} |
| 2283 |
|
| 2284 |
#[cfg(feature = "psk")] |
| 2285 |
fn new_external_psk(id: &[u8]) -> PreSharedKeyProposal { |
| 2286 |
make_external_psk( |
| 2287 |
id, |
| 2288 |
PskNonce::random(&test_cipher_suite_provider(TEST_CIPHER_SUITE)).unwrap(), |
| 2289 |
) |
| 2290 |
} |
| 2291 |
|
| 2292 |
#[cfg(feature = "psk")] |
| 2293 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2294 |
async fn receiving_psk_with_invalid_nonce_fails() { |
| 2295 |
let invalid_nonce = PskNonce(vec![0, 1, 2]); |
| 2296 |
let (alice, tree) = new_tree("alice").await; |
| 2297 |
|
| 2298 |
let res = CommitReceiver::new( |
| 2299 |
&tree, |
| 2300 |
alice, |
| 2301 |
alice, |
| 2302 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2303 |
) |
| 2304 |
.receive([Proposal::Psk(make_external_psk( |
| 2305 |
b"foo", |
| 2306 |
invalid_nonce.clone(), |
| 2307 |
))]) |
| 2308 |
.await; |
| 2309 |
|
| 2310 |
assert_matches!(res, Err(MlsError::InvalidPskNonceLength,)); |
| 2311 |
} |
| 2312 |
|
| 2313 |
#[cfg(feature = "psk")] |
| 2314 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2315 |
async fn sending_additional_psk_with_invalid_nonce_fails() { |
| 2316 |
let invalid_nonce = PskNonce(vec![0, 1, 2]); |
| 2317 |
let (alice, tree) = new_tree("alice").await; |
| 2318 |
|
| 2319 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2320 |
.with_additional([Proposal::Psk(make_external_psk( |
| 2321 |
b"foo", |
| 2322 |
invalid_nonce.clone(), |
| 2323 |
))]) |
| 2324 |
.send() |
| 2325 |
.await; |
| 2326 |
|
| 2327 |
assert_matches!(res, Err(MlsError::InvalidPskNonceLength)); |
| 2328 |
} |
| 2329 |
|
| 2330 |
#[cfg(feature = "psk")] |
| 2331 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2332 |
async fn sending_psk_with_invalid_nonce_filters_it_out() { |
| 2333 |
let invalid_nonce = PskNonce(vec![0, 1, 2]); |
| 2334 |
let (alice, tree) = new_tree("alice").await; |
| 2335 |
let proposal = Proposal::Psk(make_external_psk(b"foo", invalid_nonce)); |
| 2336 |
|
| 2337 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2338 |
|
| 2339 |
let processed_proposals = |
| 2340 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2341 |
.cache( |
| 2342 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2343 |
proposal.clone(), |
| 2344 |
alice, |
| 2345 |
) |
| 2346 |
.send() |
| 2347 |
.await |
| 2348 |
.unwrap(); |
| 2349 |
|
| 2350 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2351 |
|
| 2352 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2353 |
} |
| 2354 |
|
| 2355 |
#[cfg(feature = "psk")] |
| 2356 |
fn make_resumption_psk(usage: ResumptionPSKUsage) -> PreSharedKeyProposal { |
| 2357 |
PreSharedKeyProposal { |
| 2358 |
psk: PreSharedKeyID { |
| 2359 |
key_id: JustPreSharedKeyID::Resumption(ResumptionPsk { |
| 2360 |
usage, |
| 2361 |
psk_group_id: PskGroupId(TEST_GROUP.to_vec()), |
| 2362 |
psk_epoch: 1, |
| 2363 |
}), |
| 2364 |
psk_nonce: PskNonce::random(&test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2365 |
.unwrap(), |
| 2366 |
}, |
| 2367 |
} |
| 2368 |
} |
| 2369 |
|
| 2370 |
#[cfg(feature = "psk")] |
| 2371 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2372 |
async fn receiving_resumption_psk_with_bad_usage_fails(usage: ResumptionPSKUsage) { |
| 2373 |
let (alice, tree) = new_tree("alice").await; |
| 2374 |
|
| 2375 |
let res = CommitReceiver::new( |
| 2376 |
&tree, |
| 2377 |
alice, |
| 2378 |
alice, |
| 2379 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2380 |
) |
| 2381 |
.receive([Proposal::Psk(make_resumption_psk(usage))]) |
| 2382 |
.await; |
| 2383 |
|
| 2384 |
assert_matches!(res, Err(MlsError::InvalidTypeOrUsageInPreSharedKeyProposal)); |
| 2385 |
} |
| 2386 |
|
| 2387 |
#[cfg(feature = "psk")] |
| 2388 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2389 |
async fn sending_additional_resumption_psk_with_bad_usage_fails(usage: ResumptionPSKUsage) { |
| 2390 |
let (alice, tree) = new_tree("alice").await; |
| 2391 |
|
| 2392 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2393 |
.with_additional([Proposal::Psk(make_resumption_psk(usage))]) |
| 2394 |
.send() |
| 2395 |
.await; |
| 2396 |
|
| 2397 |
assert_matches!(res, Err(MlsError::InvalidTypeOrUsageInPreSharedKeyProposal)); |
| 2398 |
} |
| 2399 |
|
| 2400 |
#[cfg(feature = "psk")] |
| 2401 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2402 |
async fn sending_resumption_psk_with_bad_usage_filters_it_out(usage: ResumptionPSKUsage) { |
| 2403 |
let (alice, tree) = new_tree("alice").await; |
| 2404 |
let proposal = Proposal::Psk(make_resumption_psk(usage)); |
| 2405 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2406 |
|
| 2407 |
let processed_proposals = |
| 2408 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2409 |
.cache( |
| 2410 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2411 |
proposal.clone(), |
| 2412 |
alice, |
| 2413 |
) |
| 2414 |
.send() |
| 2415 |
.await |
| 2416 |
.unwrap(); |
| 2417 |
|
| 2418 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2419 |
|
| 2420 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2421 |
} |
| 2422 |
|
| 2423 |
#[cfg(feature = "psk")] |
| 2424 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2425 |
async fn receiving_resumption_psk_with_reinit_usage_fails() { |
| 2426 |
receiving_resumption_psk_with_bad_usage_fails(ResumptionPSKUsage::Reinit).await; |
| 2427 |
} |
| 2428 |
|
| 2429 |
#[cfg(feature = "psk")] |
| 2430 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2431 |
async fn sending_additional_resumption_psk_with_reinit_usage_fails() { |
| 2432 |
sending_additional_resumption_psk_with_bad_usage_fails(ResumptionPSKUsage::Reinit).await; |
| 2433 |
} |
| 2434 |
|
| 2435 |
#[cfg(feature = "psk")] |
| 2436 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2437 |
async fn sending_resumption_psk_with_reinit_usage_filters_it_out() { |
| 2438 |
sending_resumption_psk_with_bad_usage_filters_it_out(ResumptionPSKUsage::Reinit).await; |
| 2439 |
} |
| 2440 |
|
| 2441 |
#[cfg(feature = "psk")] |
| 2442 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2443 |
async fn receiving_resumption_psk_with_branch_usage_fails() { |
| 2444 |
receiving_resumption_psk_with_bad_usage_fails(ResumptionPSKUsage::Branch).await; |
| 2445 |
} |
| 2446 |
|
| 2447 |
#[cfg(feature = "psk")] |
| 2448 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2449 |
async fn sending_additional_resumption_psk_with_branch_usage_fails() { |
| 2450 |
sending_additional_resumption_psk_with_bad_usage_fails(ResumptionPSKUsage::Branch).await; |
| 2451 |
} |
| 2452 |
|
| 2453 |
#[cfg(feature = "psk")] |
| 2454 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2455 |
async fn sending_resumption_psk_with_branch_usage_filters_it_out() { |
| 2456 |
sending_resumption_psk_with_bad_usage_filters_it_out(ResumptionPSKUsage::Branch).await; |
| 2457 |
} |
| 2458 |
|
| 2459 |
fn make_reinit(version: ProtocolVersion) -> ReInitProposal { |
| 2460 |
ReInitProposal { |
| 2461 |
group_id: TEST_GROUP.to_vec(), |
| 2462 |
version, |
| 2463 |
cipher_suite: TEST_CIPHER_SUITE, |
| 2464 |
extensions: ExtensionList::new(), |
| 2465 |
} |
| 2466 |
} |
| 2467 |
|
| 2468 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2469 |
async fn receiving_reinit_downgrading_version_fails() { |
| 2470 |
let smaller_protocol_version = ProtocolVersion::from(0); |
| 2471 |
let (alice, tree) = new_tree("alice").await; |
| 2472 |
|
| 2473 |
let res = CommitReceiver::new( |
| 2474 |
&tree, |
| 2475 |
alice, |
| 2476 |
alice, |
| 2477 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2478 |
) |
| 2479 |
.receive([Proposal::ReInit(make_reinit(smaller_protocol_version))]) |
| 2480 |
.await; |
| 2481 |
|
| 2482 |
assert_matches!(res, Err(MlsError::InvalidProtocolVersionInReInit)); |
| 2483 |
} |
| 2484 |
|
| 2485 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2486 |
async fn sending_additional_reinit_downgrading_version_fails() { |
| 2487 |
let smaller_protocol_version = ProtocolVersion::from(0); |
| 2488 |
let (alice, tree) = new_tree("alice").await; |
| 2489 |
|
| 2490 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2491 |
.with_additional([Proposal::ReInit(make_reinit(smaller_protocol_version))]) |
| 2492 |
.send() |
| 2493 |
.await; |
| 2494 |
|
| 2495 |
assert_matches!(res, Err(MlsError::InvalidProtocolVersionInReInit)); |
| 2496 |
} |
| 2497 |
|
| 2498 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2499 |
async fn sending_reinit_downgrading_version_filters_it_out() { |
| 2500 |
let smaller_protocol_version = ProtocolVersion::from(0); |
| 2501 |
let (alice, tree) = new_tree("alice").await; |
| 2502 |
let proposal = Proposal::ReInit(make_reinit(smaller_protocol_version)); |
| 2503 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2504 |
|
| 2505 |
let processed_proposals = |
| 2506 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2507 |
.cache( |
| 2508 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2509 |
proposal.clone(), |
| 2510 |
alice, |
| 2511 |
) |
| 2512 |
.send() |
| 2513 |
.await |
| 2514 |
.unwrap(); |
| 2515 |
|
| 2516 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2517 |
|
| 2518 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2519 |
} |
| 2520 |
|
| 2521 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2522 |
async fn receiving_update_for_committer_fails() { |
| 2523 |
let (alice, tree) = new_tree("alice").await; |
| 2524 |
let update = Proposal::Update(make_update_proposal("alice").await); |
| 2525 |
let update_ref = make_proposal_ref(&update, alice).await; |
| 2526 |
|
| 2527 |
let res = CommitReceiver::new( |
| 2528 |
&tree, |
| 2529 |
alice, |
| 2530 |
alice, |
| 2531 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2532 |
) |
| 2533 |
.cache(update_ref.clone(), update, alice) |
| 2534 |
.receive([update_ref]) |
| 2535 |
.await; |
| 2536 |
|
| 2537 |
assert_matches!(res, Err(MlsError::InvalidCommitSelfUpdate)); |
| 2538 |
} |
| 2539 |
|
| 2540 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2541 |
async fn sending_additional_update_for_committer_fails() { |
| 2542 |
let (alice, tree) = new_tree("alice").await; |
| 2543 |
|
| 2544 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2545 |
.with_additional([Proposal::Update(make_update_proposal("alice").await)]) |
| 2546 |
.send() |
| 2547 |
.await; |
| 2548 |
|
| 2549 |
assert_matches!(res, Err(MlsError::InvalidProposalTypeForSender)); |
| 2550 |
} |
| 2551 |
|
| 2552 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2553 |
async fn sending_update_for_committer_filters_it_out() { |
| 2554 |
let (alice, tree) = new_tree("alice").await; |
| 2555 |
let proposal = Proposal::Update(make_update_proposal("alice").await); |
| 2556 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2557 |
|
| 2558 |
let processed_proposals = |
| 2559 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2560 |
.cache( |
| 2561 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2562 |
proposal.clone(), |
| 2563 |
alice, |
| 2564 |
) |
| 2565 |
.send() |
| 2566 |
.await |
| 2567 |
.unwrap(); |
| 2568 |
|
| 2569 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2570 |
|
| 2571 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2572 |
} |
| 2573 |
|
| 2574 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2575 |
async fn receiving_remove_for_committer_fails() { |
| 2576 |
let (alice, tree) = new_tree("alice").await; |
| 2577 |
|
| 2578 |
let res = CommitReceiver::new( |
| 2579 |
&tree, |
| 2580 |
alice, |
| 2581 |
alice, |
| 2582 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2583 |
) |
| 2584 |
.receive([Proposal::Remove(RemoveProposal { to_remove: alice })]) |
| 2585 |
.await; |
| 2586 |
|
| 2587 |
assert_matches!(res, Err(MlsError::CommitterSelfRemoval)); |
| 2588 |
} |
| 2589 |
|
| 2590 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2591 |
async fn sending_additional_remove_for_committer_fails() { |
| 2592 |
let (alice, tree) = new_tree("alice").await; |
| 2593 |
|
| 2594 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2595 |
.with_additional([Proposal::Remove(RemoveProposal { to_remove: alice })]) |
| 2596 |
.send() |
| 2597 |
.await; |
| 2598 |
|
| 2599 |
assert_matches!(res, Err(MlsError::CommitterSelfRemoval)); |
| 2600 |
} |
| 2601 |
|
| 2602 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2603 |
async fn sending_remove_for_committer_filters_it_out() { |
| 2604 |
let (alice, tree) = new_tree("alice").await; |
| 2605 |
let proposal = Proposal::Remove(RemoveProposal { to_remove: alice }); |
| 2606 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 2607 |
|
| 2608 |
let processed_proposals = |
| 2609 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2610 |
.cache( |
| 2611 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2612 |
proposal.clone(), |
| 2613 |
alice, |
| 2614 |
) |
| 2615 |
.send() |
| 2616 |
.await |
| 2617 |
.unwrap(); |
| 2618 |
|
| 2619 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2620 |
|
| 2621 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2622 |
} |
| 2623 |
|
| 2624 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2625 |
async fn receiving_update_and_remove_for_same_leaf_fails() { |
| 2626 |
let (alice, mut tree) = new_tree("alice").await; |
| 2627 |
let bob = add_member(&mut tree, "bob").await; |
| 2628 |
|
| 2629 |
let update = Proposal::Update(make_update_proposal("bob").await); |
| 2630 |
let update_ref = make_proposal_ref(&update, bob).await; |
| 2631 |
|
| 2632 |
let remove = Proposal::Remove(RemoveProposal { to_remove: bob }); |
| 2633 |
let remove_ref = make_proposal_ref(&remove, bob).await; |
| 2634 |
|
| 2635 |
let res = CommitReceiver::new( |
| 2636 |
&tree, |
| 2637 |
alice, |
| 2638 |
alice, |
| 2639 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2640 |
) |
| 2641 |
.cache(update_ref.clone(), update, bob) |
| 2642 |
.cache(remove_ref.clone(), remove, bob) |
| 2643 |
.receive([update_ref, remove_ref]) |
| 2644 |
.await; |
| 2645 |
|
| 2646 |
assert_matches!(res, Err(MlsError::UpdatingNonExistingMember)); |
| 2647 |
} |
| 2648 |
|
| 2649 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2650 |
async fn sending_update_and_remove_for_same_leaf_filters_update_out() { |
| 2651 |
let (alice, mut tree) = new_tree("alice").await; |
| 2652 |
let bob = add_member(&mut tree, "bob").await; |
| 2653 |
|
| 2654 |
let update = Proposal::Update(make_update_proposal("bob").await); |
| 2655 |
let update_info = make_proposal_info(&update, alice).await; |
| 2656 |
|
| 2657 |
let remove = Proposal::Remove(RemoveProposal { to_remove: bob }); |
| 2658 |
let remove_ref = make_proposal_ref(&remove, alice).await; |
| 2659 |
|
| 2660 |
let processed_proposals = |
| 2661 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2662 |
.cache( |
| 2663 |
update_info.proposal_ref().unwrap().clone(), |
| 2664 |
update.clone(), |
| 2665 |
alice, |
| 2666 |
) |
| 2667 |
.cache(remove_ref.clone(), remove, alice) |
| 2668 |
.send() |
| 2669 |
.await |
| 2670 |
.unwrap(); |
| 2671 |
|
| 2672 |
assert_eq!(processed_proposals.0, vec![remove_ref.into()]); |
| 2673 |
|
| 2674 |
assert_eq!(processed_proposals.1.unused_proposals, vec![update_info]); |
| 2675 |
} |
| 2676 |
|
| 2677 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 2678 |
async fn make_add_proposal() -> Box<AddProposal> { |
| 2679 |
Box::new(AddProposal { |
| 2680 |
key_package: test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "frank").await, |
| 2681 |
}) |
| 2682 |
} |
| 2683 |
|
| 2684 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2685 |
async fn receiving_add_proposals_for_same_client_fails() { |
| 2686 |
let (alice, tree) = new_tree("alice").await; |
| 2687 |
|
| 2688 |
let res = CommitReceiver::new( |
| 2689 |
&tree, |
| 2690 |
alice, |
| 2691 |
alice, |
| 2692 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2693 |
) |
| 2694 |
.receive([ |
| 2695 |
Proposal::Add(make_add_proposal().await), |
| 2696 |
Proposal::Add(make_add_proposal().await), |
| 2697 |
]) |
| 2698 |
.await; |
| 2699 |
|
| 2700 |
assert_matches!(res, Err(MlsError::DuplicateLeafData(1))); |
| 2701 |
} |
| 2702 |
|
| 2703 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2704 |
async fn sending_additional_add_proposals_for_same_client_fails() { |
| 2705 |
let (alice, tree) = new_tree("alice").await; |
| 2706 |
|
| 2707 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2708 |
.with_additional([ |
| 2709 |
Proposal::Add(make_add_proposal().await), |
| 2710 |
Proposal::Add(make_add_proposal().await), |
| 2711 |
]) |
| 2712 |
.send() |
| 2713 |
.await; |
| 2714 |
|
| 2715 |
assert_matches!(res, Err(MlsError::DuplicateLeafData(1))); |
| 2716 |
} |
| 2717 |
|
| 2718 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2719 |
async fn sending_add_proposals_for_same_client_keeps_only_one() { |
| 2720 |
let (alice, tree) = new_tree("alice").await; |
| 2721 |
|
| 2722 |
let add_one = Proposal::Add(make_add_proposal().await); |
| 2723 |
let add_two = Proposal::Add(make_add_proposal().await); |
| 2724 |
let add_ref_one = make_proposal_ref(&add_one, alice).await; |
| 2725 |
let add_ref_two = make_proposal_ref(&add_two, alice).await; |
| 2726 |
|
| 2727 |
let processed_proposals = |
| 2728 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2729 |
.cache(add_ref_one.clone(), add_one.clone(), alice) |
| 2730 |
.cache(add_ref_two.clone(), add_two.clone(), alice) |
| 2731 |
.send() |
| 2732 |
.await |
| 2733 |
.unwrap(); |
| 2734 |
|
| 2735 |
let committed_add_ref = match &*processed_proposals.0 { |
| 2736 |
[ProposalOrRef::Reference(add_ref)] => add_ref, |
| 2737 |
_ => panic!("committed proposals list does not contain exactly one reference"), |
| 2738 |
}; |
| 2739 |
|
| 2740 |
let add_refs = [add_ref_one, add_ref_two]; |
| 2741 |
assert!(add_refs.contains(committed_add_ref)); |
| 2742 |
|
| 2743 |
assert_matches!( |
| 2744 |
&*processed_proposals.1.unused_proposals, |
| 2745 |
[rejected_add_info] if committed_add_ref != rejected_add_info.proposal_ref().unwrap() && add_refs.contains(rejected_add_info.proposal_ref().unwrap()) |
| 2746 |
); |
| 2747 |
} |
| 2748 |
|
| 2749 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2750 |
async fn receiving_update_for_different_identity_fails() { |
| 2751 |
let (alice, mut tree) = new_tree("alice").await; |
| 2752 |
let bob = add_member(&mut tree, "bob").await; |
| 2753 |
|
| 2754 |
let update = Proposal::Update(make_update_proposal_custom("carol", 1).await); |
| 2755 |
let update_ref = make_proposal_ref(&update, bob).await; |
| 2756 |
|
| 2757 |
let res = CommitReceiver::new( |
| 2758 |
&tree, |
| 2759 |
alice, |
| 2760 |
alice, |
| 2761 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2762 |
) |
| 2763 |
.cache(update_ref.clone(), update, bob) |
| 2764 |
.receive([update_ref]) |
| 2765 |
.await; |
| 2766 |
|
| 2767 |
assert_matches!(res, Err(MlsError::InvalidSuccessor)); |
| 2768 |
} |
| 2769 |
|
| 2770 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2771 |
async fn sending_update_for_different_identity_filters_it_out() { |
| 2772 |
let (alice, mut tree) = new_tree("alice").await; |
| 2773 |
let bob = add_member(&mut tree, "bob").await; |
| 2774 |
|
| 2775 |
let update = Proposal::Update(make_update_proposal("carol").await); |
| 2776 |
let update_info = make_proposal_info(&update, bob).await; |
| 2777 |
|
| 2778 |
let processed_proposals = |
| 2779 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2780 |
.cache(update_info.proposal_ref().unwrap().clone(), update, bob) |
| 2781 |
.send() |
| 2782 |
.await |
| 2783 |
.unwrap(); |
| 2784 |
|
| 2785 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2786 |
|
| 2787 |
// Bob proposed the update, so it is not listed as rejected when Alice commits it because |
| 2788 |
// she didn't propose it. |
| 2789 |
assert_eq!(processed_proposals.1.unused_proposals, vec![update_info]); |
| 2790 |
} |
| 2791 |
|
| 2792 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2793 |
async fn receiving_add_for_same_client_as_existing_member_fails() { |
| 2794 |
let (alice, public_tree) = new_tree("alice").await; |
| 2795 |
let add = Proposal::Add(make_add_proposal().await); |
| 2796 |
|
| 2797 |
let ProvisionalState { public_tree, .. } = CommitReceiver::new( |
| 2798 |
&public_tree, |
| 2799 |
alice, |
| 2800 |
alice, |
| 2801 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2802 |
) |
| 2803 |
.receive([add.clone()]) |
| 2804 |
.await |
| 2805 |
.unwrap(); |
| 2806 |
|
| 2807 |
let res = CommitReceiver::new( |
| 2808 |
&public_tree, |
| 2809 |
alice, |
| 2810 |
alice, |
| 2811 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2812 |
) |
| 2813 |
.receive([add]) |
| 2814 |
.await; |
| 2815 |
|
| 2816 |
assert_matches!(res, Err(MlsError::DuplicateLeafData(1))); |
| 2817 |
} |
| 2818 |
|
| 2819 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2820 |
async fn sending_additional_add_for_same_client_as_existing_member_fails() { |
| 2821 |
let (alice, public_tree) = new_tree("alice").await; |
| 2822 |
let add = Proposal::Add(make_add_proposal().await); |
| 2823 |
|
| 2824 |
let ProvisionalState { public_tree, .. } = CommitReceiver::new( |
| 2825 |
&public_tree, |
| 2826 |
alice, |
| 2827 |
alice, |
| 2828 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2829 |
) |
| 2830 |
.receive([add.clone()]) |
| 2831 |
.await |
| 2832 |
.unwrap(); |
| 2833 |
|
| 2834 |
let res = CommitSender::new( |
| 2835 |
&public_tree, |
| 2836 |
alice, |
| 2837 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2838 |
) |
| 2839 |
.with_additional([add]) |
| 2840 |
.send() |
| 2841 |
.await; |
| 2842 |
|
| 2843 |
assert_matches!(res, Err(MlsError::DuplicateLeafData(1))); |
| 2844 |
} |
| 2845 |
|
| 2846 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2847 |
async fn sending_add_for_same_client_as_existing_member_filters_it_out() { |
| 2848 |
let (alice, public_tree) = new_tree("alice").await; |
| 2849 |
let add = Proposal::Add(make_add_proposal().await); |
| 2850 |
|
| 2851 |
let ProvisionalState { public_tree, .. } = CommitReceiver::new( |
| 2852 |
&public_tree, |
| 2853 |
alice, |
| 2854 |
alice, |
| 2855 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2856 |
) |
| 2857 |
.receive([add.clone()]) |
| 2858 |
.await |
| 2859 |
.unwrap(); |
| 2860 |
|
| 2861 |
let proposal_info = make_proposal_info(&add, alice).await; |
| 2862 |
|
| 2863 |
let processed_proposals = CommitSender::new( |
| 2864 |
&public_tree, |
| 2865 |
alice, |
| 2866 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2867 |
) |
| 2868 |
.cache( |
| 2869 |
proposal_info.proposal_ref().unwrap().clone(), |
| 2870 |
add.clone(), |
| 2871 |
alice, |
| 2872 |
) |
| 2873 |
.send() |
| 2874 |
.await |
| 2875 |
.unwrap(); |
| 2876 |
|
| 2877 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 2878 |
|
| 2879 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 2880 |
} |
| 2881 |
|
| 2882 |
#[cfg(feature = "psk")] |
| 2883 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2884 |
async fn receiving_psk_proposals_with_same_psk_id_fails() { |
| 2885 |
let (alice, tree) = new_tree("alice").await; |
| 2886 |
let psk_proposal = Proposal::Psk(new_external_psk(b"foo")); |
| 2887 |
|
| 2888 |
let res = CommitReceiver::new( |
| 2889 |
&tree, |
| 2890 |
alice, |
| 2891 |
alice, |
| 2892 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2893 |
) |
| 2894 |
.receive([psk_proposal.clone(), psk_proposal]) |
| 2895 |
.await; |
| 2896 |
|
| 2897 |
assert_matches!(res, Err(MlsError::DuplicatePskIds)); |
| 2898 |
} |
| 2899 |
|
| 2900 |
#[cfg(feature = "psk")] |
| 2901 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2902 |
async fn sending_additional_psk_proposals_with_same_psk_id_fails() { |
| 2903 |
let (alice, tree) = new_tree("alice").await; |
| 2904 |
let psk_proposal = Proposal::Psk(new_external_psk(b"foo")); |
| 2905 |
|
| 2906 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2907 |
.with_additional([psk_proposal.clone(), psk_proposal]) |
| 2908 |
.send() |
| 2909 |
.await; |
| 2910 |
|
| 2911 |
assert_matches!(res, Err(MlsError::DuplicatePskIds)); |
| 2912 |
} |
| 2913 |
|
| 2914 |
#[cfg(feature = "psk")] |
| 2915 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2916 |
async fn sending_psk_proposals_with_same_psk_id_keeps_only_one() { |
| 2917 |
let (alice, mut tree) = new_tree("alice").await; |
| 2918 |
let bob = add_member(&mut tree, "bob").await; |
| 2919 |
|
| 2920 |
let proposal = Proposal::Psk(new_external_psk(b"foo")); |
| 2921 |
|
| 2922 |
let proposal_info = [ |
| 2923 |
make_proposal_info(&proposal, alice).await, |
| 2924 |
make_proposal_info(&proposal, bob).await, |
| 2925 |
]; |
| 2926 |
|
| 2927 |
let processed_proposals = |
| 2928 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2929 |
.cache( |
| 2930 |
proposal_info[0].proposal_ref().unwrap().clone(), |
| 2931 |
proposal.clone(), |
| 2932 |
alice, |
| 2933 |
) |
| 2934 |
.cache( |
| 2935 |
proposal_info[1].proposal_ref().unwrap().clone(), |
| 2936 |
proposal, |
| 2937 |
bob, |
| 2938 |
) |
| 2939 |
.send() |
| 2940 |
.await |
| 2941 |
.unwrap(); |
| 2942 |
|
| 2943 |
let committed_info = match processed_proposals |
| 2944 |
.1 |
| 2945 |
.applied_proposals |
| 2946 |
.clone() |
| 2947 |
.into_proposals() |
| 2948 |
.collect_vec() |
| 2949 |
.as_slice() |
| 2950 |
{ |
| 2951 |
[r] => r.clone(), |
| 2952 |
_ => panic!("Expected single proposal reference in {processed_proposals:?}"), |
| 2953 |
}; |
| 2954 |
|
| 2955 |
assert!(proposal_info.contains(&committed_info)); |
| 2956 |
|
| 2957 |
match &*processed_proposals.1.unused_proposals { |
| 2958 |
[r] => { |
| 2959 |
assert_ne!(*r, committed_info); |
| 2960 |
assert!(proposal_info.contains(r)); |
| 2961 |
} |
| 2962 |
_ => panic!( |
| 2963 |
"Expected one proposal reference in {:?}", |
| 2964 |
processed_proposals.1.unused_proposals |
| 2965 |
), |
| 2966 |
} |
| 2967 |
} |
| 2968 |
|
| 2969 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2970 |
async fn receiving_multiple_group_context_extensions_fails() { |
| 2971 |
let (alice, tree) = new_tree("alice").await; |
| 2972 |
|
| 2973 |
let res = CommitReceiver::new( |
| 2974 |
&tree, |
| 2975 |
alice, |
| 2976 |
alice, |
| 2977 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 2978 |
) |
| 2979 |
.receive([ |
| 2980 |
Proposal::GroupContextExtensions(ExtensionList::new()), |
| 2981 |
Proposal::GroupContextExtensions(ExtensionList::new()), |
| 2982 |
]) |
| 2983 |
.await; |
| 2984 |
|
| 2985 |
assert_matches!( |
| 2986 |
res, |
| 2987 |
Err(MlsError::MoreThanOneGroupContextExtensionsProposal) |
| 2988 |
); |
| 2989 |
} |
| 2990 |
|
| 2991 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 2992 |
async fn sending_multiple_additional_group_context_extensions_fails() { |
| 2993 |
let (alice, tree) = new_tree("alice").await; |
| 2994 |
|
| 2995 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 2996 |
.with_additional([ |
| 2997 |
Proposal::GroupContextExtensions(ExtensionList::new()), |
| 2998 |
Proposal::GroupContextExtensions(ExtensionList::new()), |
| 2999 |
]) |
| 3000 |
.send() |
| 3001 |
.await; |
| 3002 |
|
| 3003 |
assert_matches!( |
| 3004 |
res, |
| 3005 |
Err(MlsError::MoreThanOneGroupContextExtensionsProposal) |
| 3006 |
); |
| 3007 |
} |
| 3008 |
|
| 3009 |
fn make_extension_list(something: u8) -> ExtensionList { |
| 3010 |
vec![TestExtension { foo: something }.into_extension().unwrap()].into() |
| 3011 |
} |
| 3012 |
|
| 3013 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3014 |
async fn sending_multiple_group_context_extensions_keeps_only_one() { |
| 3015 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 3016 |
|
| 3017 |
let (alice, tree) = { |
| 3018 |
let (signing_identity, signature_key) = |
| 3019 |
get_test_signing_identity(TEST_CIPHER_SUITE, b"alice").await; |
| 3020 |
|
| 3021 |
let properties = ConfigProperties { |
| 3022 |
capabilities: Capabilities { |
| 3023 |
extensions: vec![42.into()], |
| 3024 |
..Capabilities::default() |
| 3025 |
}, |
| 3026 |
extensions: Default::default(), |
| 3027 |
}; |
| 3028 |
|
| 3029 |
let (leaf, secret) = LeafNode::generate( |
| 3030 |
&cipher_suite_provider, |
| 3031 |
properties, |
| 3032 |
signing_identity, |
| 3033 |
&signature_key, |
| 3034 |
Lifetime::years(1).unwrap(), |
| 3035 |
) |
| 3036 |
.await |
| 3037 |
.unwrap(); |
| 3038 |
|
| 3039 |
let (pub_tree, priv_tree) = |
| 3040 |
TreeKemPublic::derive(leaf, secret, &BasicIdentityProvider, &Default::default()) |
| 3041 |
.await |
| 3042 |
.unwrap(); |
| 3043 |
|
| 3044 |
(priv_tree.self_index, pub_tree) |
| 3045 |
}; |
| 3046 |
|
| 3047 |
let proposals = [ |
| 3048 |
Proposal::GroupContextExtensions(make_extension_list(0)), |
| 3049 |
Proposal::GroupContextExtensions(make_extension_list(1)), |
| 3050 |
]; |
| 3051 |
|
| 3052 |
let gce_info = [ |
| 3053 |
make_proposal_info(&proposals[0], alice).await, |
| 3054 |
make_proposal_info(&proposals[1], alice).await, |
| 3055 |
]; |
| 3056 |
|
| 3057 |
let processed_proposals = |
| 3058 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3059 |
.cache( |
| 3060 |
gce_info[0].proposal_ref().unwrap().clone(), |
| 3061 |
proposals[0].clone(), |
| 3062 |
alice, |
| 3063 |
) |
| 3064 |
.cache( |
| 3065 |
gce_info[1].proposal_ref().unwrap().clone(), |
| 3066 |
proposals[1].clone(), |
| 3067 |
alice, |
| 3068 |
) |
| 3069 |
.send() |
| 3070 |
.await |
| 3071 |
.unwrap(); |
| 3072 |
|
| 3073 |
let committed_gce_info = match processed_proposals |
| 3074 |
.1 |
| 3075 |
.applied_proposals |
| 3076 |
.clone() |
| 3077 |
.into_proposals() |
| 3078 |
.collect_vec() |
| 3079 |
.as_slice() |
| 3080 |
{ |
| 3081 |
[gce_info] => gce_info.clone(), |
| 3082 |
_ => panic!("committed proposals list does not contain exactly one reference"), |
| 3083 |
}; |
| 3084 |
|
| 3085 |
assert!(gce_info.contains(&committed_gce_info)); |
| 3086 |
|
| 3087 |
assert_matches!( |
| 3088 |
&*processed_proposals.1.unused_proposals, |
| 3089 |
[rejected_gce_info] if committed_gce_info != *rejected_gce_info && gce_info.contains(rejected_gce_info) |
| 3090 |
); |
| 3091 |
} |
| 3092 |
|
| 3093 |
#[cfg(feature = "by_ref_proposal")] |
| 3094 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 3095 |
async fn make_external_senders_extension() -> ExtensionList { |
| 3096 |
let identity = get_test_signing_identity(TEST_CIPHER_SUITE, b"alice") |
| 3097 |
.await |
| 3098 |
.0; |
| 3099 |
|
| 3100 |
vec![ExternalSendersExt::new(vec![identity]) |
| 3101 |
.into_extension() |
| 3102 |
.unwrap()] |
| 3103 |
.into() |
| 3104 |
} |
| 3105 |
|
| 3106 |
#[cfg(feature = "by_ref_proposal")] |
| 3107 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3108 |
async fn receiving_invalid_external_senders_extension_fails() { |
| 3109 |
let (alice, tree) = new_tree("alice").await; |
| 3110 |
|
| 3111 |
let res = CommitReceiver::new( |
| 3112 |
&tree, |
| 3113 |
alice, |
| 3114 |
alice, |
| 3115 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3116 |
) |
| 3117 |
.with_identity_provider(FailureIdentityProvider::new()) |
| 3118 |
.receive([Proposal::GroupContextExtensions( |
| 3119 |
make_external_senders_extension().await, |
| 3120 |
)]) |
| 3121 |
.await; |
| 3122 |
|
| 3123 |
assert_matches!(res, Err(MlsError::IdentityProviderError(_))); |
| 3124 |
} |
| 3125 |
|
| 3126 |
#[cfg(feature = "by_ref_proposal")] |
| 3127 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3128 |
async fn sending_additional_invalid_external_senders_extension_fails() { |
| 3129 |
let (alice, tree) = new_tree("alice").await; |
| 3130 |
|
| 3131 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3132 |
.with_identity_provider(FailureIdentityProvider::new()) |
| 3133 |
.with_additional([Proposal::GroupContextExtensions( |
| 3134 |
make_external_senders_extension().await, |
| 3135 |
)]) |
| 3136 |
.send() |
| 3137 |
.await; |
| 3138 |
|
| 3139 |
assert_matches!(res, Err(MlsError::IdentityProviderError(_))); |
| 3140 |
} |
| 3141 |
|
| 3142 |
#[cfg(feature = "by_ref_proposal")] |
| 3143 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3144 |
async fn sending_invalid_external_senders_extension_filters_it_out() { |
| 3145 |
let (alice, tree) = new_tree("alice").await; |
| 3146 |
|
| 3147 |
let proposal = Proposal::GroupContextExtensions(make_external_senders_extension().await); |
| 3148 |
|
| 3149 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 3150 |
|
| 3151 |
let processed_proposals = |
| 3152 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3153 |
.with_identity_provider(FailureIdentityProvider::new()) |
| 3154 |
.cache( |
| 3155 |
proposal_info.proposal_ref().unwrap().clone(), |
| 3156 |
proposal.clone(), |
| 3157 |
alice, |
| 3158 |
) |
| 3159 |
.send() |
| 3160 |
.await |
| 3161 |
.unwrap(); |
| 3162 |
|
| 3163 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3164 |
|
| 3165 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 3166 |
} |
| 3167 |
|
| 3168 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3169 |
async fn receiving_reinit_with_other_proposals_fails() { |
| 3170 |
let (alice, tree) = new_tree("alice").await; |
| 3171 |
|
| 3172 |
let res = CommitReceiver::new( |
| 3173 |
&tree, |
| 3174 |
alice, |
| 3175 |
alice, |
| 3176 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3177 |
) |
| 3178 |
.receive([ |
| 3179 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 3180 |
Proposal::Add(make_add_proposal().await), |
| 3181 |
]) |
| 3182 |
.await; |
| 3183 |
|
| 3184 |
assert_matches!(res, Err(MlsError::OtherProposalWithReInit)); |
| 3185 |
} |
| 3186 |
|
| 3187 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3188 |
async fn sending_additional_reinit_with_other_proposals_fails() { |
| 3189 |
let (alice, tree) = new_tree("alice").await; |
| 3190 |
|
| 3191 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3192 |
.with_additional([ |
| 3193 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 3194 |
Proposal::Add(make_add_proposal().await), |
| 3195 |
]) |
| 3196 |
.send() |
| 3197 |
.await; |
| 3198 |
|
| 3199 |
assert_matches!(res, Err(MlsError::OtherProposalWithReInit)); |
| 3200 |
} |
| 3201 |
|
| 3202 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3203 |
async fn sending_reinit_with_other_proposals_filters_it_out() { |
| 3204 |
let (alice, tree) = new_tree("alice").await; |
| 3205 |
let reinit = Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)); |
| 3206 |
let reinit_info = make_proposal_info(&reinit, alice).await; |
| 3207 |
let add = Proposal::Add(make_add_proposal().await); |
| 3208 |
let add_ref = make_proposal_ref(&add, alice).await; |
| 3209 |
|
| 3210 |
let processed_proposals = |
| 3211 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3212 |
.cache( |
| 3213 |
reinit_info.proposal_ref().unwrap().clone(), |
| 3214 |
reinit.clone(), |
| 3215 |
alice, |
| 3216 |
) |
| 3217 |
.cache(add_ref.clone(), add, alice) |
| 3218 |
.send() |
| 3219 |
.await |
| 3220 |
.unwrap(); |
| 3221 |
|
| 3222 |
assert_eq!(processed_proposals.0, vec![add_ref.into()]); |
| 3223 |
|
| 3224 |
assert_eq!(processed_proposals.1.unused_proposals, vec![reinit_info]); |
| 3225 |
} |
| 3226 |
|
| 3227 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3228 |
async fn receiving_multiple_reinits_fails() { |
| 3229 |
let (alice, tree) = new_tree("alice").await; |
| 3230 |
|
| 3231 |
let res = CommitReceiver::new( |
| 3232 |
&tree, |
| 3233 |
alice, |
| 3234 |
alice, |
| 3235 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3236 |
) |
| 3237 |
.receive([ |
| 3238 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 3239 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 3240 |
]) |
| 3241 |
.await; |
| 3242 |
|
| 3243 |
assert_matches!(res, Err(MlsError::OtherProposalWithReInit)); |
| 3244 |
} |
| 3245 |
|
| 3246 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3247 |
async fn sending_additional_multiple_reinits_fails() { |
| 3248 |
let (alice, tree) = new_tree("alice").await; |
| 3249 |
|
| 3250 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3251 |
.with_additional([ |
| 3252 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 3253 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 3254 |
]) |
| 3255 |
.send() |
| 3256 |
.await; |
| 3257 |
|
| 3258 |
assert_matches!(res, Err(MlsError::OtherProposalWithReInit)); |
| 3259 |
} |
| 3260 |
|
| 3261 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3262 |
async fn sending_multiple_reinits_keeps_only_one() { |
| 3263 |
let (alice, tree) = new_tree("alice").await; |
| 3264 |
let reinit = Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)); |
| 3265 |
let reinit_ref = make_proposal_ref(&reinit, alice).await; |
| 3266 |
let other_reinit = Proposal::ReInit(ReInitProposal { |
| 3267 |
group_id: b"other_group".to_vec(), |
| 3268 |
..make_reinit(TEST_PROTOCOL_VERSION) |
| 3269 |
}); |
| 3270 |
let other_reinit_ref = make_proposal_ref(&other_reinit, alice).await; |
| 3271 |
|
| 3272 |
let processed_proposals = |
| 3273 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3274 |
.cache(reinit_ref.clone(), reinit.clone(), alice) |
| 3275 |
.cache(other_reinit_ref.clone(), other_reinit.clone(), alice) |
| 3276 |
.send() |
| 3277 |
.await |
| 3278 |
.unwrap(); |
| 3279 |
|
| 3280 |
let processed_ref = match &*processed_proposals.0 { |
| 3281 |
[ProposalOrRef::Reference(r)] => r, |
| 3282 |
p => panic!("Expected single proposal reference but found {p:?}"), |
| 3283 |
}; |
| 3284 |
|
| 3285 |
assert!(*processed_ref == reinit_ref || *processed_ref == other_reinit_ref); |
| 3286 |
|
| 3287 |
{ |
| 3288 |
let (rejected_ref, unused_proposal) = match &*processed_proposals.1.unused_proposals { |
| 3289 |
[r] => (r.proposal_ref().unwrap().clone(), r.proposal.clone()), |
| 3290 |
p => panic!("Expected single proposal but found {p:?}"), |
| 3291 |
}; |
| 3292 |
|
| 3293 |
assert_ne!(rejected_ref, *processed_ref); |
| 3294 |
assert!(rejected_ref == reinit_ref || rejected_ref == other_reinit_ref); |
| 3295 |
assert!(unused_proposal == reinit || unused_proposal == other_reinit); |
| 3296 |
} |
| 3297 |
} |
| 3298 |
|
| 3299 |
fn make_external_init() -> ExternalInit { |
| 3300 |
ExternalInit { |
| 3301 |
kem_output: vec![33; test_cipher_suite_provider(TEST_CIPHER_SUITE).kdf_extract_size()], |
| 3302 |
} |
| 3303 |
} |
| 3304 |
|
| 3305 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3306 |
async fn receiving_external_init_from_member_fails() { |
| 3307 |
let (alice, tree) = new_tree("alice").await; |
| 3308 |
|
| 3309 |
let res = CommitReceiver::new( |
| 3310 |
&tree, |
| 3311 |
alice, |
| 3312 |
alice, |
| 3313 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3314 |
) |
| 3315 |
.receive([Proposal::ExternalInit(make_external_init())]) |
| 3316 |
.await; |
| 3317 |
|
| 3318 |
assert_matches!(res, Err(MlsError::InvalidProposalTypeForSender)); |
| 3319 |
} |
| 3320 |
|
| 3321 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3322 |
async fn sending_additional_external_init_from_member_fails() { |
| 3323 |
let (alice, tree) = new_tree("alice").await; |
| 3324 |
|
| 3325 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3326 |
.with_additional([Proposal::ExternalInit(make_external_init())]) |
| 3327 |
.send() |
| 3328 |
.await; |
| 3329 |
|
| 3330 |
assert_matches!(res, Err(MlsError::InvalidProposalTypeForSender)); |
| 3331 |
} |
| 3332 |
|
| 3333 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3334 |
async fn sending_external_init_from_member_filters_it_out() { |
| 3335 |
let (alice, tree) = new_tree("alice").await; |
| 3336 |
let external_init = Proposal::ExternalInit(make_external_init()); |
| 3337 |
let external_init_info = make_proposal_info(&external_init, alice).await; |
| 3338 |
|
| 3339 |
let processed_proposals = |
| 3340 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3341 |
.cache( |
| 3342 |
external_init_info.proposal_ref().unwrap().clone(), |
| 3343 |
external_init.clone(), |
| 3344 |
alice, |
| 3345 |
) |
| 3346 |
.send() |
| 3347 |
.await |
| 3348 |
.unwrap(); |
| 3349 |
|
| 3350 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3351 |
|
| 3352 |
assert_eq!( |
| 3353 |
processed_proposals.1.unused_proposals, |
| 3354 |
vec![external_init_info] |
| 3355 |
); |
| 3356 |
} |
| 3357 |
|
| 3358 |
fn required_capabilities_proposal(extension: u16) -> Proposal { |
| 3359 |
let required_capabilities = RequiredCapabilitiesExt { |
| 3360 |
extensions: vec![extension.into()], |
| 3361 |
..Default::default() |
| 3362 |
}; |
| 3363 |
|
| 3364 |
let ext = vec![required_capabilities.into_extension().unwrap()]; |
| 3365 |
|
| 3366 |
Proposal::GroupContextExtensions(ext.into()) |
| 3367 |
} |
| 3368 |
|
| 3369 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3370 |
async fn receiving_required_capabilities_not_supported_by_member_fails() { |
| 3371 |
let (alice, tree) = new_tree("alice").await; |
| 3372 |
|
| 3373 |
let res = CommitReceiver::new( |
| 3374 |
&tree, |
| 3375 |
alice, |
| 3376 |
alice, |
| 3377 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3378 |
) |
| 3379 |
.receive([required_capabilities_proposal(33)]) |
| 3380 |
.await; |
| 3381 |
|
| 3382 |
assert_matches!( |
| 3383 |
res, |
| 3384 |
Err(MlsError::RequiredExtensionNotFound(v)) if v == 33.into() |
| 3385 |
); |
| 3386 |
} |
| 3387 |
|
| 3388 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3389 |
async fn sending_required_capabilities_not_supported_by_member_fails() { |
| 3390 |
let (alice, tree) = new_tree("alice").await; |
| 3391 |
|
| 3392 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3393 |
.with_additional([required_capabilities_proposal(33)]) |
| 3394 |
.send() |
| 3395 |
.await; |
| 3396 |
|
| 3397 |
assert_matches!( |
| 3398 |
res, |
| 3399 |
Err(MlsError::RequiredExtensionNotFound(v)) if v == 33.into() |
| 3400 |
); |
| 3401 |
} |
| 3402 |
|
| 3403 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3404 |
async fn sending_additional_required_capabilities_not_supported_by_member_filters_it_out() { |
| 3405 |
let (alice, tree) = new_tree("alice").await; |
| 3406 |
|
| 3407 |
let proposal = required_capabilities_proposal(33); |
| 3408 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 3409 |
|
| 3410 |
let processed_proposals = |
| 3411 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3412 |
.cache( |
| 3413 |
proposal_info.proposal_ref().unwrap().clone(), |
| 3414 |
proposal.clone(), |
| 3415 |
alice, |
| 3416 |
) |
| 3417 |
.send() |
| 3418 |
.await |
| 3419 |
.unwrap(); |
| 3420 |
|
| 3421 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3422 |
|
| 3423 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 3424 |
} |
| 3425 |
|
| 3426 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3427 |
async fn committing_update_from_pk1_to_pk2_and_update_from_pk2_to_pk3_works() { |
| 3428 |
let (alice_leaf, alice_secret, alice_signer) = |
| 3429 |
get_basic_test_node_sig_key(TEST_CIPHER_SUITE, "alice").await; |
| 3430 |
|
| 3431 |
let (mut tree, priv_tree) = TreeKemPublic::derive( |
| 3432 |
alice_leaf.clone(), |
| 3433 |
alice_secret, |
| 3434 |
&BasicIdentityProvider, |
| 3435 |
&Default::default(), |
| 3436 |
) |
| 3437 |
.await |
| 3438 |
.unwrap(); |
| 3439 |
|
| 3440 |
let alice = priv_tree.self_index; |
| 3441 |
|
| 3442 |
let bob = add_member(&mut tree, "bob").await; |
| 3443 |
let carol = add_member(&mut tree, "carol").await; |
| 3444 |
|
| 3445 |
let bob_current_leaf = tree.get_leaf_node(bob).unwrap(); |
| 3446 |
|
| 3447 |
let mut alice_new_leaf = LeafNode { |
| 3448 |
public_key: bob_current_leaf.public_key.clone(), |
| 3449 |
leaf_node_source: LeafNodeSource::Update, |
| 3450 |
..alice_leaf |
| 3451 |
}; |
| 3452 |
|
| 3453 |
alice_new_leaf |
| 3454 |
.sign( |
| 3455 |
&test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3456 |
&alice_signer, |
| 3457 |
&(TEST_GROUP, 0).into(), |
| 3458 |
) |
| 3459 |
.await |
| 3460 |
.unwrap(); |
| 3461 |
|
| 3462 |
let bob_new_leaf = update_leaf_node("bob", 1).await; |
| 3463 |
|
| 3464 |
let pk1_to_pk2 = Proposal::Update(UpdateProposal { |
| 3465 |
leaf_node: alice_new_leaf.clone(), |
| 3466 |
}); |
| 3467 |
|
| 3468 |
let pk1_to_pk2_ref = make_proposal_ref(&pk1_to_pk2, alice).await; |
| 3469 |
|
| 3470 |
let pk2_to_pk3 = Proposal::Update(UpdateProposal { |
| 3471 |
leaf_node: bob_new_leaf.clone(), |
| 3472 |
}); |
| 3473 |
|
| 3474 |
let pk2_to_pk3_ref = make_proposal_ref(&pk2_to_pk3, bob).await; |
| 3475 |
|
| 3476 |
let effects = CommitReceiver::new( |
| 3477 |
&tree, |
| 3478 |
carol, |
| 3479 |
carol, |
| 3480 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3481 |
) |
| 3482 |
.cache(pk1_to_pk2_ref.clone(), pk1_to_pk2, alice) |
| 3483 |
.cache(pk2_to_pk3_ref.clone(), pk2_to_pk3, bob) |
| 3484 |
.receive([pk1_to_pk2_ref, pk2_to_pk3_ref]) |
| 3485 |
.await |
| 3486 |
.unwrap(); |
| 3487 |
|
| 3488 |
assert_eq!(effects.applied_proposals.update_senders, vec![alice, bob]); |
| 3489 |
|
| 3490 |
assert_eq!( |
| 3491 |
effects |
| 3492 |
.applied_proposals |
| 3493 |
.updates |
| 3494 |
.into_iter() |
| 3495 |
.map(|p| p.proposal.leaf_node) |
| 3496 |
.collect_vec(), |
| 3497 |
vec![alice_new_leaf, bob_new_leaf] |
| 3498 |
); |
| 3499 |
} |
| 3500 |
|
| 3501 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3502 |
async fn committing_update_from_pk1_to_pk2_and_removal_of_pk2_works() { |
| 3503 |
let cipher_suite_provider = test_cipher_suite_provider(TEST_CIPHER_SUITE); |
| 3504 |
|
| 3505 |
let (alice_leaf, alice_secret, alice_signer) = |
| 3506 |
get_basic_test_node_sig_key(TEST_CIPHER_SUITE, "alice").await; |
| 3507 |
|
| 3508 |
let (mut tree, priv_tree) = TreeKemPublic::derive( |
| 3509 |
alice_leaf.clone(), |
| 3510 |
alice_secret, |
| 3511 |
&BasicIdentityProvider, |
| 3512 |
&Default::default(), |
| 3513 |
) |
| 3514 |
.await |
| 3515 |
.unwrap(); |
| 3516 |
|
| 3517 |
let alice = priv_tree.self_index; |
| 3518 |
|
| 3519 |
let bob = add_member(&mut tree, "bob").await; |
| 3520 |
let carol = add_member(&mut tree, "carol").await; |
| 3521 |
|
| 3522 |
let bob_current_leaf = tree.get_leaf_node(bob).unwrap(); |
| 3523 |
|
| 3524 |
let mut alice_new_leaf = LeafNode { |
| 3525 |
public_key: bob_current_leaf.public_key.clone(), |
| 3526 |
leaf_node_source: LeafNodeSource::Update, |
| 3527 |
..alice_leaf |
| 3528 |
}; |
| 3529 |
|
| 3530 |
alice_new_leaf |
| 3531 |
.sign( |
| 3532 |
&cipher_suite_provider, |
| 3533 |
&alice_signer, |
| 3534 |
&(TEST_GROUP, 0).into(), |
| 3535 |
) |
| 3536 |
.await |
| 3537 |
.unwrap(); |
| 3538 |
|
| 3539 |
let pk1_to_pk2 = Proposal::Update(UpdateProposal { |
| 3540 |
leaf_node: alice_new_leaf.clone(), |
| 3541 |
}); |
| 3542 |
|
| 3543 |
let pk1_to_pk2_ref = make_proposal_ref(&pk1_to_pk2, alice).await; |
| 3544 |
|
| 3545 |
let remove_pk2 = Proposal::Remove(RemoveProposal { to_remove: bob }); |
| 3546 |
|
| 3547 |
let remove_pk2_ref = make_proposal_ref(&remove_pk2, bob).await; |
| 3548 |
|
| 3549 |
let effects = CommitReceiver::new( |
| 3550 |
&tree, |
| 3551 |
carol, |
| 3552 |
carol, |
| 3553 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3554 |
) |
| 3555 |
.cache(pk1_to_pk2_ref.clone(), pk1_to_pk2, alice) |
| 3556 |
.cache(remove_pk2_ref.clone(), remove_pk2, bob) |
| 3557 |
.receive([pk1_to_pk2_ref, remove_pk2_ref]) |
| 3558 |
.await |
| 3559 |
.unwrap(); |
| 3560 |
|
| 3561 |
assert_eq!(effects.applied_proposals.update_senders, vec![alice]); |
| 3562 |
|
| 3563 |
assert_eq!( |
| 3564 |
effects |
| 3565 |
.applied_proposals |
| 3566 |
.updates |
| 3567 |
.into_iter() |
| 3568 |
.map(|p| p.proposal.leaf_node) |
| 3569 |
.collect_vec(), |
| 3570 |
vec![alice_new_leaf] |
| 3571 |
); |
| 3572 |
|
| 3573 |
assert_eq!( |
| 3574 |
effects |
| 3575 |
.applied_proposals |
| 3576 |
.removals |
| 3577 |
.into_iter() |
| 3578 |
.map(|p| p.proposal.to_remove) |
| 3579 |
.collect_vec(), |
| 3580 |
vec![bob] |
| 3581 |
); |
| 3582 |
} |
| 3583 |
|
| 3584 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 3585 |
async fn unsupported_credential_key_package(name: &str) -> KeyPackage { |
| 3586 |
let (mut signing_identity, secret_key) = |
| 3587 |
get_test_signing_identity(TEST_CIPHER_SUITE, name.as_bytes()).await; |
| 3588 |
|
| 3589 |
signing_identity.credential = Credential::Custom(CustomCredential::new( |
| 3590 |
CredentialType::new(BasicWithCustomProvider::CUSTOM_CREDENTIAL_TYPE), |
| 3591 |
random_bytes(32), |
| 3592 |
)); |
| 3593 |
|
| 3594 |
let generator = KeyPackageGenerator { |
| 3595 |
protocol_version: TEST_PROTOCOL_VERSION, |
| 3596 |
cipher_suite_provider: &test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3597 |
signing_identity: &signing_identity, |
| 3598 |
signing_key: &secret_key, |
| 3599 |
}; |
| 3600 |
|
| 3601 |
generator |
| 3602 |
.generate( |
| 3603 |
Lifetime::years(1).unwrap(), |
| 3604 |
Capabilities { |
| 3605 |
credentials: vec![42.into()], |
| 3606 |
..Default::default() |
| 3607 |
}, |
| 3608 |
Default::default(), |
| 3609 |
Default::default(), |
| 3610 |
) |
| 3611 |
.await |
| 3612 |
.unwrap() |
| 3613 |
.key_package |
| 3614 |
} |
| 3615 |
|
| 3616 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3617 |
async fn receiving_add_with_leaf_not_supporting_credential_type_of_other_leaf_fails() { |
| 3618 |
let (alice, tree) = new_tree("alice").await; |
| 3619 |
|
| 3620 |
let res = CommitReceiver::new( |
| 3621 |
&tree, |
| 3622 |
alice, |
| 3623 |
alice, |
| 3624 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3625 |
) |
| 3626 |
.receive([Proposal::Add(Box::new(AddProposal { |
| 3627 |
key_package: unsupported_credential_key_package("bob").await, |
| 3628 |
}))]) |
| 3629 |
.await; |
| 3630 |
|
| 3631 |
assert_matches!(res, Err(MlsError::InUseCredentialTypeUnsupportedByNewLeaf)); |
| 3632 |
} |
| 3633 |
|
| 3634 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3635 |
async fn sending_additional_add_with_leaf_not_supporting_credential_type_of_other_leaf_fails() { |
| 3636 |
let (alice, tree) = new_tree("alice").await; |
| 3637 |
|
| 3638 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3639 |
.with_additional([Proposal::Add(Box::new(AddProposal { |
| 3640 |
key_package: unsupported_credential_key_package("bob").await, |
| 3641 |
}))]) |
| 3642 |
.send() |
| 3643 |
.await; |
| 3644 |
|
| 3645 |
assert_matches!(res, Err(MlsError::InUseCredentialTypeUnsupportedByNewLeaf)); |
| 3646 |
} |
| 3647 |
|
| 3648 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3649 |
async fn sending_add_with_leaf_not_supporting_credential_type_of_other_leaf_filters_it_out() { |
| 3650 |
let (alice, tree) = new_tree("alice").await; |
| 3651 |
|
| 3652 |
let add = Proposal::Add(Box::new(AddProposal { |
| 3653 |
key_package: unsupported_credential_key_package("bob").await, |
| 3654 |
})); |
| 3655 |
|
| 3656 |
let add_info = make_proposal_info(&add, alice).await; |
| 3657 |
|
| 3658 |
let processed_proposals = |
| 3659 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3660 |
.cache(add_info.proposal_ref().unwrap().clone(), add.clone(), alice) |
| 3661 |
.send() |
| 3662 |
.await |
| 3663 |
.unwrap(); |
| 3664 |
|
| 3665 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3666 |
|
| 3667 |
assert_eq!(processed_proposals.1.unused_proposals, vec![add_info]); |
| 3668 |
} |
| 3669 |
|
| 3670 |
#[cfg(feature = "custom_proposal")] |
| 3671 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3672 |
async fn sending_custom_proposal_with_member_not_supporting_proposal_type_fails() { |
| 3673 |
let (alice, tree) = new_tree("alice").await; |
| 3674 |
|
| 3675 |
let custom_proposal = Proposal::Custom(CustomProposal::new(ProposalType::new(42), vec![])); |
| 3676 |
|
| 3677 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3678 |
.with_additional([custom_proposal.clone()]) |
| 3679 |
.send() |
| 3680 |
.await; |
| 3681 |
|
| 3682 |
assert_matches!( |
| 3683 |
res, |
| 3684 |
Err( |
| 3685 |
MlsError::UnsupportedCustomProposal(c) |
| 3686 |
) if c == custom_proposal.proposal_type() |
| 3687 |
); |
| 3688 |
} |
| 3689 |
|
| 3690 |
#[cfg(feature = "custom_proposal")] |
| 3691 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3692 |
async fn sending_custom_proposal_with_member_not_supporting_filters_it_out() { |
| 3693 |
let (alice, tree) = new_tree("alice").await; |
| 3694 |
|
| 3695 |
let custom_proposal = Proposal::Custom(CustomProposal::new(ProposalType::new(42), vec![])); |
| 3696 |
|
| 3697 |
let custom_info = make_proposal_info(&custom_proposal, alice).await; |
| 3698 |
|
| 3699 |
let processed_proposals = |
| 3700 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3701 |
.cache( |
| 3702 |
custom_info.proposal_ref().unwrap().clone(), |
| 3703 |
custom_proposal.clone(), |
| 3704 |
alice, |
| 3705 |
) |
| 3706 |
.send() |
| 3707 |
.await |
| 3708 |
.unwrap(); |
| 3709 |
|
| 3710 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3711 |
|
| 3712 |
assert_eq!(processed_proposals.1.unused_proposals, vec![custom_info]); |
| 3713 |
} |
| 3714 |
|
| 3715 |
#[cfg(feature = "custom_proposal")] |
| 3716 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3717 |
async fn receiving_custom_proposal_with_member_not_supporting_fails() { |
| 3718 |
let (alice, tree) = new_tree("alice").await; |
| 3719 |
|
| 3720 |
let custom_proposal = Proposal::Custom(CustomProposal::new(ProposalType::new(42), vec![])); |
| 3721 |
|
| 3722 |
let res = CommitReceiver::new( |
| 3723 |
&tree, |
| 3724 |
alice, |
| 3725 |
alice, |
| 3726 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3727 |
) |
| 3728 |
.receive([custom_proposal.clone()]) |
| 3729 |
.await; |
| 3730 |
|
| 3731 |
assert_matches!( |
| 3732 |
res, |
| 3733 |
Err(MlsError::UnsupportedCustomProposal(c)) if c == custom_proposal.proposal_type() |
| 3734 |
); |
| 3735 |
} |
| 3736 |
|
| 3737 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3738 |
async fn receiving_group_extension_unsupported_by_leaf_fails() { |
| 3739 |
let (alice, tree) = new_tree("alice").await; |
| 3740 |
|
| 3741 |
let res = CommitReceiver::new( |
| 3742 |
&tree, |
| 3743 |
alice, |
| 3744 |
alice, |
| 3745 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3746 |
) |
| 3747 |
.receive([Proposal::GroupContextExtensions(make_extension_list(0))]) |
| 3748 |
.await; |
| 3749 |
|
| 3750 |
assert_matches!( |
| 3751 |
res, |
| 3752 |
Err( |
| 3753 |
MlsError::UnsupportedGroupExtension(v) |
| 3754 |
) if v == 42.into() |
| 3755 |
); |
| 3756 |
} |
| 3757 |
|
| 3758 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3759 |
async fn sending_additional_group_extension_unsupported_by_leaf_fails() { |
| 3760 |
let (alice, tree) = new_tree("alice").await; |
| 3761 |
|
| 3762 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3763 |
.with_additional([Proposal::GroupContextExtensions(make_extension_list(0))]) |
| 3764 |
.send() |
| 3765 |
.await; |
| 3766 |
|
| 3767 |
assert_matches!( |
| 3768 |
res, |
| 3769 |
Err( |
| 3770 |
MlsError::UnsupportedGroupExtension(v) |
| 3771 |
) if v == 42.into() |
| 3772 |
); |
| 3773 |
} |
| 3774 |
|
| 3775 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3776 |
async fn sending_group_extension_unsupported_by_leaf_filters_it_out() { |
| 3777 |
let (alice, tree) = new_tree("alice").await; |
| 3778 |
|
| 3779 |
let proposal = Proposal::GroupContextExtensions(make_extension_list(0)); |
| 3780 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 3781 |
|
| 3782 |
let processed_proposals = |
| 3783 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3784 |
.cache( |
| 3785 |
proposal_info.proposal_ref().unwrap().clone(), |
| 3786 |
proposal.clone(), |
| 3787 |
alice, |
| 3788 |
) |
| 3789 |
.send() |
| 3790 |
.await |
| 3791 |
.unwrap(); |
| 3792 |
|
| 3793 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3794 |
|
| 3795 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 3796 |
} |
| 3797 |
|
| 3798 |
#[cfg(feature = "psk")] |
| 3799 |
#[derive(Debug)] |
| 3800 |
struct AlwaysNotFoundPskStorage; |
| 3801 |
|
| 3802 |
#[cfg(feature = "psk")] |
| 3803 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 3804 |
#[cfg_attr(mls_build_async, maybe_async::must_be_async)] |
| 3805 |
impl PreSharedKeyStorage for AlwaysNotFoundPskStorage { |
| 3806 |
type Error = Infallible; |
| 3807 |
|
| 3808 |
async fn get(&self, _: &ExternalPskId) -> Result<Option<PreSharedKey>, Self::Error> { |
| 3809 |
Ok(None) |
| 3810 |
} |
| 3811 |
} |
| 3812 |
|
| 3813 |
#[cfg(feature = "psk")] |
| 3814 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3815 |
async fn receiving_external_psk_with_unknown_id_fails() { |
| 3816 |
let (alice, tree) = new_tree("alice").await; |
| 3817 |
|
| 3818 |
let res = CommitReceiver::new( |
| 3819 |
&tree, |
| 3820 |
alice, |
| 3821 |
alice, |
| 3822 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 3823 |
) |
| 3824 |
.with_psk_storage(AlwaysNotFoundPskStorage) |
| 3825 |
.receive([Proposal::Psk(new_external_psk(b"abc"))]) |
| 3826 |
.await; |
| 3827 |
|
| 3828 |
assert_matches!(res, Err(MlsError::MissingRequiredPsk)); |
| 3829 |
} |
| 3830 |
|
| 3831 |
#[cfg(feature = "psk")] |
| 3832 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3833 |
async fn sending_additional_external_psk_with_unknown_id_fails() { |
| 3834 |
let (alice, tree) = new_tree("alice").await; |
| 3835 |
|
| 3836 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3837 |
.with_psk_storage(AlwaysNotFoundPskStorage) |
| 3838 |
.with_additional([Proposal::Psk(new_external_psk(b"abc"))]) |
| 3839 |
.send() |
| 3840 |
.await; |
| 3841 |
|
| 3842 |
assert_matches!(res, Err(MlsError::MissingRequiredPsk)); |
| 3843 |
} |
| 3844 |
|
| 3845 |
#[cfg(feature = "psk")] |
| 3846 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3847 |
async fn sending_external_psk_with_unknown_id_filters_it_out() { |
| 3848 |
let (alice, tree) = new_tree("alice").await; |
| 3849 |
let proposal = Proposal::Psk(new_external_psk(b"abc")); |
| 3850 |
let proposal_info = make_proposal_info(&proposal, alice).await; |
| 3851 |
|
| 3852 |
let processed_proposals = |
| 3853 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3854 |
.with_psk_storage(AlwaysNotFoundPskStorage) |
| 3855 |
.cache( |
| 3856 |
proposal_info.proposal_ref().unwrap().clone(), |
| 3857 |
proposal.clone(), |
| 3858 |
alice, |
| 3859 |
) |
| 3860 |
.send() |
| 3861 |
.await |
| 3862 |
.unwrap(); |
| 3863 |
|
| 3864 |
assert_eq!(processed_proposals.0, Vec::new()); |
| 3865 |
|
| 3866 |
assert_eq!(processed_proposals.1.unused_proposals, vec![proposal_info]); |
| 3867 |
} |
| 3868 |
|
| 3869 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 3870 |
async fn user_defined_filter_can_remove_proposals() { |
| 3871 |
struct RemoveGroupContextExtensions; |
| 3872 |
|
| 3873 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 3874 |
#[cfg_attr(mls_build_async, maybe_async::must_be_async)] |
| 3875 |
impl MlsRules for RemoveGroupContextExtensions { |
| 3876 |
type Error = Infallible; |
| 3877 |
|
| 3878 |
async fn filter_proposals( |
| 3879 |
&self, |
| 3880 |
_: CommitDirection, |
| 3881 |
_: CommitSource, |
| 3882 |
_: &Roster, |
| 3883 |
_: &GroupContext, |
| 3884 |
mut proposals: ProposalBundle, |
| 3885 |
) -> Result<ProposalBundle, Self::Error> { |
| 3886 |
proposals.group_context_extensions.clear(); |
| 3887 |
Ok(proposals) |
| 3888 |
} |
| 3889 |
|
| 3890 |
#[cfg_attr(coverage_nightly, coverage(off))] |
| 3891 |
fn commit_options( |
| 3892 |
&self, |
| 3893 |
_: &Roster, |
| 3894 |
_: &GroupContext, |
| 3895 |
_: &ProposalBundle, |
| 3896 |
) -> Result<CommitOptions, Self::Error> { |
| 3897 |
Ok(Default::default()) |
| 3898 |
} |
| 3899 |
|
| 3900 |
#[cfg_attr(coverage_nightly, coverage(off))] |
| 3901 |
fn encryption_options( |
| 3902 |
&self, |
| 3903 |
_: &Roster, |
| 3904 |
_: &GroupContext, |
| 3905 |
) -> Result<EncryptionOptions, Self::Error> { |
| 3906 |
Ok(Default::default()) |
| 3907 |
} |
| 3908 |
} |
| 3909 |
|
| 3910 |
let (alice, tree) = new_tree("alice").await; |
| 3911 |
|
| 3912 |
let (committed, _) = |
| 3913 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 3914 |
.with_additional([Proposal::GroupContextExtensions(Default::default())]) |
| 3915 |
.with_user_rules(RemoveGroupContextExtensions) |
| 3916 |
.send() |
| 3917 |
.await |
| 3918 |
.unwrap(); |
| 3919 |
|
| 3920 |
assert_eq!(committed, Vec::new()); |
| 3921 |
} |
| 3922 |
|
| 3923 |
struct FailureMlsRules; |
| 3924 |
|
| 3925 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 3926 |
#[cfg_attr(mls_build_async, maybe_async::must_be_async)] |
| 3927 |
impl MlsRules for FailureMlsRules { |
| 3928 |
type Error = MlsError; |
| 3929 |
|
| 3930 |
async fn filter_proposals( |
| 3931 |
&self, |
| 3932 |
_: CommitDirection, |
| 3933 |
_: CommitSource, |
| 3934 |
_: &Roster, |
| 3935 |
_: &GroupContext, |
| 3936 |
_: ProposalBundle, |
| 3937 |
) -> Result<ProposalBundle, Self::Error> { |
| 3938 |
Err(MlsError::InvalidSignature) |
| 3939 |
} |
| 3940 |
|
| 3941 |
#[cfg_attr(coverage_nightly, coverage(off))] |
| 3942 |
fn commit_options( |
| 3943 |
&self, |
| 3944 |
_: &Roster, |
| 3945 |
_: &GroupContext, |
| 3946 |
_: &ProposalBundle, |
| 3947 |
) -> Result<CommitOptions, Self::Error> { |
| 3948 |
Ok(Default::default()) |
| 3949 |
} |
| 3950 |
|
| 3951 |
#[cfg_attr(coverage_nightly, coverage(off))] |
| 3952 |
fn encryption_options( |
| 3953 |
&self, |
| 3954 |
_: &Roster, |
| 3955 |
_: &GroupContext, |
| 3956 |
) -> Result<EncryptionOptions, Self::Error> { |
| 3957 |
Ok(Default::default()) |
| 3958 |
} |
| 3959 |
} |
| 3960 |
|
| 3961 |
struct InjectMlsRules { |
| 3962 |
to_inject: Vec<Proposal>, |
| 3963 |
source: ProposalSource, |
| 3964 |
} |
| 3965 |
|
| 3966 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 3967 |
#[cfg_attr(mls_build_async, maybe_async::must_be_async)] |
| 3968 |
impl MlsRules for InjectMlsRules { |
| 3969 |
type Error = MlsError; |
| 3970 |
|
| 3971 |
async fn filter_proposals( |
| 3972 |
&self, |
| 3973 |
_: CommitDirection, |
| 3974 |
_: CommitSource, |
| 3975 |
_: &Roster, |
| 3976 |
_: &GroupContext, |
| 3977 |
mut proposals: ProposalBundle, |
| 3978 |
) -> Result<ProposalBundle, Self::Error> { |
| 3979 |
for proposal in self.to_inject.iter().cloned() { |
| 3980 |
proposals.add(proposal, Sender::Member(0), self.source.clone()); |
| 3981 |
} |
| 3982 |
|
| 3983 |
Ok(proposals) |
| 3984 |
} |
| 3985 |
|
| 3986 |
#[cfg_attr(coverage_nightly, coverage(off))] |
| 3987 |
fn commit_options( |
| 3988 |
&self, |
| 3989 |
_: &Roster, |
| 3990 |
_: &GroupContext, |
| 3991 |
_: &ProposalBundle, |
| 3992 |
) -> Result<CommitOptions, Self::Error> { |
| 3993 |
Ok(Default::default()) |
| 3994 |
} |
| 3995 |
|
| 3996 |
#[cfg_attr(coverage_nightly, coverage(off))] |
| 3997 |
fn encryption_options( |
| 3998 |
&self, |
| 3999 |
_: &Roster, |
| 4000 |
_: &GroupContext, |
| 4001 |
) -> Result<EncryptionOptions, Self::Error> { |
| 4002 |
Ok(Default::default()) |
| 4003 |
} |
| 4004 |
} |
| 4005 |
|
| 4006 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4007 |
async fn user_defined_filter_can_inject_proposals() { |
| 4008 |
let (alice, tree) = new_tree("alice").await; |
| 4009 |
|
| 4010 |
let test_proposal = Proposal::GroupContextExtensions(Default::default()); |
| 4011 |
|
| 4012 |
let (committed, _) = |
| 4013 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 4014 |
.with_user_rules(InjectMlsRules { |
| 4015 |
to_inject: vec![test_proposal.clone()], |
| 4016 |
source: ProposalSource::ByValue, |
| 4017 |
}) |
| 4018 |
.send() |
| 4019 |
.await |
| 4020 |
.unwrap(); |
| 4021 |
|
| 4022 |
assert_eq!( |
| 4023 |
committed, |
| 4024 |
vec![ProposalOrRef::Proposal(test_proposal.into())] |
| 4025 |
); |
| 4026 |
} |
| 4027 |
|
| 4028 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4029 |
async fn user_defined_filter_can_inject_local_only_proposals() { |
| 4030 |
let (alice, tree) = new_tree("alice").await; |
| 4031 |
|
| 4032 |
let test_proposal = Proposal::GroupContextExtensions(Default::default()); |
| 4033 |
|
| 4034 |
let (committed, _) = |
| 4035 |
CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 4036 |
.with_user_rules(InjectMlsRules { |
| 4037 |
to_inject: vec![test_proposal.clone()], |
| 4038 |
source: ProposalSource::Local, |
| 4039 |
}) |
| 4040 |
.send() |
| 4041 |
.await |
| 4042 |
.unwrap(); |
| 4043 |
|
| 4044 |
assert_eq!(committed, vec![]); |
| 4045 |
} |
| 4046 |
|
| 4047 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4048 |
async fn user_defined_filter_cant_break_base_rules() { |
| 4049 |
let (alice, tree) = new_tree("alice").await; |
| 4050 |
|
| 4051 |
let test_proposal = Proposal::Update(UpdateProposal { |
| 4052 |
leaf_node: get_basic_test_node(TEST_CIPHER_SUITE, "leaf").await, |
| 4053 |
}); |
| 4054 |
|
| 4055 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 4056 |
.with_user_rules(InjectMlsRules { |
| 4057 |
to_inject: vec![test_proposal.clone()], |
| 4058 |
source: ProposalSource::ByValue, |
| 4059 |
}) |
| 4060 |
.send() |
| 4061 |
.await; |
| 4062 |
|
| 4063 |
assert_matches!(res, Err(MlsError::InvalidProposalTypeForSender { .. })) |
| 4064 |
} |
| 4065 |
|
| 4066 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4067 |
async fn sending_invalid_local_proposal_fails() { |
| 4068 |
let (alice, tree) = new_tree("alice").await; |
| 4069 |
let gce_proposal = Proposal::GroupContextExtensions(Default::default()); |
| 4070 |
|
| 4071 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 4072 |
.with_user_rules(InjectMlsRules { |
| 4073 |
to_inject: vec![gce_proposal.clone(), gce_proposal], |
| 4074 |
source: ProposalSource::Local, |
| 4075 |
}) |
| 4076 |
.send() |
| 4077 |
.await; |
| 4078 |
|
| 4079 |
assert_matches!( |
| 4080 |
res, |
| 4081 |
Err(MlsError::MoreThanOneGroupContextExtensionsProposal) |
| 4082 |
); |
| 4083 |
} |
| 4084 |
|
| 4085 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4086 |
async fn user_defined_filter_can_refuse_to_send_commit() { |
| 4087 |
let (alice, tree) = new_tree("alice").await; |
| 4088 |
|
| 4089 |
let res = CommitSender::new(&tree, alice, test_cipher_suite_provider(TEST_CIPHER_SUITE)) |
| 4090 |
.with_additional([Proposal::GroupContextExtensions(Default::default())]) |
| 4091 |
.with_user_rules(FailureMlsRules) |
| 4092 |
.send() |
| 4093 |
.await; |
| 4094 |
|
| 4095 |
assert_matches!(res, Err(MlsError::MlsRulesError(_))); |
| 4096 |
} |
| 4097 |
|
| 4098 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4099 |
async fn user_defined_filter_can_reject_incoming_commit() { |
| 4100 |
let (alice, tree) = new_tree("alice").await; |
| 4101 |
|
| 4102 |
let res = CommitReceiver::new( |
| 4103 |
&tree, |
| 4104 |
alice, |
| 4105 |
alice, |
| 4106 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 4107 |
) |
| 4108 |
.with_user_rules(FailureMlsRules) |
| 4109 |
.receive([Proposal::GroupContextExtensions(Default::default())]) |
| 4110 |
.await; |
| 4111 |
|
| 4112 |
assert_matches!(res, Err(MlsError::MlsRulesError(_))); |
| 4113 |
} |
| 4114 |
|
| 4115 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4116 |
async fn proposers_are_verified() { |
| 4117 |
let (alice, mut tree) = new_tree("alice").await; |
| 4118 |
let bob = add_member(&mut tree, "bob").await; |
| 4119 |
|
| 4120 |
#[cfg(feature = "by_ref_proposal")] |
| 4121 |
let identity = get_test_signing_identity(TEST_CIPHER_SUITE, b"carol") |
| 4122 |
.await |
| 4123 |
.0; |
| 4124 |
|
| 4125 |
#[cfg(feature = "by_ref_proposal")] |
| 4126 |
let external_senders = ExternalSendersExt::new(vec![identity]); |
| 4127 |
|
| 4128 |
let proposals: &[Proposal] = &[ |
| 4129 |
Proposal::Add(make_add_proposal().await), |
| 4130 |
Proposal::Update(make_update_proposal("alice").await), |
| 4131 |
Proposal::Remove(RemoveProposal { to_remove: bob }), |
| 4132 |
#[cfg(feature = "psk")] |
| 4133 |
Proposal::Psk(make_external_psk( |
| 4134 |
b"ted", |
| 4135 |
PskNonce::random(&test_cipher_suite_provider(TEST_CIPHER_SUITE)).unwrap(), |
| 4136 |
)), |
| 4137 |
Proposal::ReInit(make_reinit(TEST_PROTOCOL_VERSION)), |
| 4138 |
Proposal::ExternalInit(make_external_init()), |
| 4139 |
Proposal::GroupContextExtensions(Default::default()), |
| 4140 |
]; |
| 4141 |
|
| 4142 |
let proposers = [ |
| 4143 |
Sender::Member(*alice), |
| 4144 |
#[cfg(feature = "by_ref_proposal")] |
| 4145 |
Sender::External(0), |
| 4146 |
Sender::NewMemberCommit, |
| 4147 |
Sender::NewMemberProposal, |
| 4148 |
]; |
| 4149 |
|
| 4150 |
for ((proposer, proposal), by_ref) in proposers |
| 4151 |
.into_iter() |
| 4152 |
.cartesian_product(proposals) |
| 4153 |
.cartesian_product([true]) |
| 4154 |
{ |
| 4155 |
let committer = Sender::Member(*alice); |
| 4156 |
|
| 4157 |
let receiver = CommitReceiver::new( |
| 4158 |
&tree, |
| 4159 |
committer, |
| 4160 |
alice, |
| 4161 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 4162 |
); |
| 4163 |
|
| 4164 |
#[cfg(feature = "by_ref_proposal")] |
| 4165 |
let extensions: ExtensionList = |
| 4166 |
vec![external_senders.clone().into_extension().unwrap()].into(); |
| 4167 |
|
| 4168 |
#[cfg(feature = "by_ref_proposal")] |
| 4169 |
let receiver = receiver.with_extensions(extensions); |
| 4170 |
|
| 4171 |
let (receiver, proposals, proposer, source) = if by_ref { |
| 4172 |
let proposal_ref = make_proposal_ref(proposal, proposer).await; |
| 4173 |
let receiver = receiver.cache(proposal_ref.clone(), proposal.clone(), proposer); |
| 4174 |
( |
| 4175 |
receiver, |
| 4176 |
vec![ProposalOrRef::from(proposal_ref.clone())], |
| 4177 |
proposer, |
| 4178 |
ProposalSource::ByReference(proposal_ref), |
| 4179 |
) |
| 4180 |
} else { |
| 4181 |
( |
| 4182 |
receiver, |
| 4183 |
vec![proposal.clone().into()], |
| 4184 |
committer, |
| 4185 |
ProposalSource::Local, |
| 4186 |
) |
| 4187 |
}; |
| 4188 |
|
| 4189 |
let res = receiver.receive(proposals).await; |
| 4190 |
|
| 4191 |
if proposer_can_propose(proposer, proposal.proposal_type(), &source).is_err() { |
| 4192 |
assert_matches!(res, Err(MlsError::InvalidProposalTypeForSender)); |
| 4193 |
} else { |
| 4194 |
let is_self_update = proposal.proposal_type() == ProposalType::UPDATE |
| 4195 |
&& by_ref |
| 4196 |
&& matches!(proposer, Sender::Member(_)); |
| 4197 |
|
| 4198 |
if !is_self_update { |
| 4199 |
res.unwrap(); |
| 4200 |
} |
| 4201 |
} |
| 4202 |
} |
| 4203 |
} |
| 4204 |
|
| 4205 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 4206 |
async fn make_update_proposal(name: &str) -> UpdateProposal { |
| 4207 |
UpdateProposal { |
| 4208 |
leaf_node: update_leaf_node(name, 1).await, |
| 4209 |
} |
| 4210 |
} |
| 4211 |
|
| 4212 |
#[cfg_attr(not(mls_build_async), maybe_async::must_be_sync)] |
| 4213 |
async fn make_update_proposal_custom(name: &str, leaf_index: u32) -> UpdateProposal { |
| 4214 |
UpdateProposal { |
| 4215 |
leaf_node: update_leaf_node(name, leaf_index).await, |
| 4216 |
} |
| 4217 |
} |
| 4218 |
|
| 4219 |
#[maybe_async::test(not(mls_build_async), async(mls_build_async, crate::futures_test))] |
| 4220 |
async fn when_receiving_commit_unused_proposals_are_proposals_in_cache_but_not_in_commit() { |
| 4221 |
let (alice, tree) = new_tree("alice").await; |
| 4222 |
|
| 4223 |
let proposal = Proposal::GroupContextExtensions(Default::default()); |
| 4224 |
let proposal_ref = make_proposal_ref(&proposal, alice).await; |
| 4225 |
|
| 4226 |
let state = CommitReceiver::new( |
| 4227 |
&tree, |
| 4228 |
alice, |
| 4229 |
alice, |
| 4230 |
test_cipher_suite_provider(TEST_CIPHER_SUITE), |
| 4231 |
) |
| 4232 |
.cache(proposal_ref.clone(), proposal, alice) |
| 4233 |
.receive([Proposal::Add(Box::new(AddProposal { |
| 4234 |
key_package: test_key_package(TEST_PROTOCOL_VERSION, TEST_CIPHER_SUITE, "bob").await, |
| 4235 |
}))]) |
| 4236 |
.await |
| 4237 |
.unwrap(); |
| 4238 |
|
| 4239 |
let [p] = &state.unused_proposals[..] else { |
| 4240 |
panic!( |
| 4241 |
"Expected single unused proposal but got {:?}", |
| 4242 |
state.unused_proposals |
| 4243 |
); |
| 4244 |
}; |
| 4245 |
|
| 4246 |
assert_eq!(p.proposal_ref(), Some(&proposal_ref)); |
| 4247 |
} |
| 4248 |
} |