Skip to content

Commit

Permalink
Add GroupInfo branch; remove redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bifurcation committed Nov 27, 2023
1 parent caf88b0 commit 70d6c2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,8 @@ MLSMessage::group_id() const
return var::visit(
overloaded{
[](const PublicMessage& pt) -> bytes { return pt.get_group_id(); },
[](const PrivateMessage& pt) -> bytes { return pt.get_group_id(); },
[](const PrivateMessage& ct) -> bytes { return ct.get_group_id(); },
[](const GroupInfo& gi) -> bytes { return gi.group_context.group_id; },
[](const auto& /* unused */) -> bytes {
throw InvalidParameterError("MLSMessage has no group_id");
},
Expand Down
24 changes: 10 additions & 14 deletions src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,12 @@ State::unwrap(const MLSMessage& msg)
},
};

return var::visit(unprotect, msg.message);
const auto content_auth = var::visit(unprotect, msg.message);
if (!verify(content_auth)) {
throw InvalidParameterError("Message signature failed to verify");
}

return content_auth;
}

Proposal
Expand Down Expand Up @@ -833,21 +838,12 @@ 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) {
throw InvalidParameterError("GroupID mismatch");
}

if (content.epoch != _epoch) {
throw InvalidParameterError("Epoch mismatch");
}

if (!verify(content_auth)) {
throw InvalidParameterError("Message signature failed to verify");
}
// XXX(RLB): We assume that the AuthenticatedContent has come to us by way of
// `unwrap()`, so that its authenticity has already been checked. This avoids
// duplicate signature verification.

// Dispatch on content type
const auto& content = content_auth.content;
switch (content.content_type()) {
// Proposals get queued, do not result in a state transition
case ContentType::proposal:
Expand Down

0 comments on commit 70d6c2f

Please sign in to comment.