Skip to content

Commit

Permalink
Don't double-handle ReInit Commits (#341)
Browse files Browse the repository at this point in the history
* Don't double-handle ReInit Commits

* CI errors
  • Loading branch information
bifurcation authored Apr 4, 2023
1 parent 154beca commit 14d0b7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions include/mls/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ class State
const MLSMessage& msg,
std::optional<State> cached_state,
const std::optional<CommitParams>& expected_params);
std::optional<State> handle(
const AuthenticatedContent& content_auth,
std::optional<State> cached_state,
const std::optional<CommitParams>& expected_params);

// Create an MLSMessage encapsulating some content
template<typename Inner>
Expand Down
26 changes: 16 additions & 10 deletions src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,19 @@ State::handle(const MLSMessage& msg,
std::optional<State> cached_state,
const std::optional<CommitParams>& expected_params)
{
// Verify the signature on the message
auto content_auth = unprotect_to_content_auth(msg);
if (!verify(content_auth)) {
throw InvalidParameterError("Message signature failed to verify");
}

return handle(content_auth, std::move(cached_state), expected_params);
}

std::optional<State>
State::handle(const AuthenticatedContent& content_auth,
std::optional<State> cached_state,
const std::optional<CommitParams>& expected_params)
{
// Validate the GroupContent
const auto& content = content_auth.content;
if (content.group_id != _group_id) {
Expand Down Expand Up @@ -1051,17 +1058,16 @@ State::reinit_commit(const bytes& leaf_secret,
State::Tombstone
State::handle_reinit_commit(const MLSMessage& commit_msg)
{
// Verify the signature and process the commit
auto content_auth = unprotect_to_content_auth(commit_msg);
if (!verify(content_auth)) {
throw InvalidParameterError("Message signature failed to verify");
}

auto new_state =
opt::get(handle(commit_msg, std::nullopt, ReInitCommitParams{}));
opt::get(handle(content_auth, std::nullopt, ReInitCommitParams{}));

// XXX(RLB): This is pretty brute force, replicating a bunch of logic in
// State::handle() so that we can find the ReInit commit. There is probably a
// more elegant way to extract the reinit parameters.
//
// XXX(RLB): We also skip a bunch of checks that are done in State::handle(),
// on the theory that they will have already been done in the State::handle()
// call above.
auto content_auth = unprotect_to_content_auth(commit_msg);
// Extract the ReInit and create the Tombstone
const auto& commit = var::get<Commit>(content_auth.content.content);
const auto proposals = must_resolve(commit.proposals, std::nullopt);
if (!valid_reinit(proposals)) {
Expand Down

0 comments on commit 14d0b7e

Please sign in to comment.