Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add MLSMessage framework #262

Merged
merged 44 commits into from
Jul 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f4c6425
Add MLSMessage framework
bifurcation Apr 20, 2022
fe8ff94
Fix build errors
bifurcation Apr 28, 2022
0d1e1ac
Revert refactor of confirmation tag computation
bifurcation Apr 28, 2022
b3f6876
clang-tidy
bifurcation Apr 28, 2022
f993b7c
CI errors
bifurcation Apr 28, 2022
13b177c
CI errors
bifurcation Apr 28, 2022
0b7f211
Apply suggestions from code review
bifurcation Apr 29, 2022
4d87cca
Respond to @bifurcation review comments
bifurcation Apr 29, 2022
7f34c67
Update the interop harness
bifurcation Apr 29, 2022
e1c5080
CI errors
bifurcation Apr 29, 2022
e57636c
clang-format
bifurcation Apr 29, 2022
641b75a
Respond to comments from @suhasHere
bifurcation Apr 29, 2022
d07e024
CI errors
bifurcation Jun 10, 2022
3f63909
Noop commit to trigger CI
bifurcation Jul 22, 2022
9cbc05a
Fix some clang-tidy errors
bifurcation Jul 22, 2022
2d2c438
More clang-tidy errors
bifurcation Jul 22, 2022
c08ba67
clang-format
bifurcation Jul 22, 2022
19521e8
Ignore cast formatting errors, too many false positives
bifurcation Jul 22, 2022
db14849
Revert "More clang-tidy errors"
bifurcation Jul 22, 2022
d6c928b
Revert "Fix some clang-tidy errors"
bifurcation Jul 22, 2022
8575c7a
Cleanup from reverts
bifurcation Jul 22, 2022
a3d4978
Add missing comma in .clang-tidy
bifurcation Jul 22, 2022
5ab3954
Adjust NOLINT
bifurcation Jul 22, 2022
843fc65
Update clang-format-action to latest
bifurcation Jul 22, 2022
2a03c56
Format the interop harness
bifurcation Jul 22, 2022
f32dc00
Apply clang-format-14
bifurcation Jul 22, 2022
9318f64
Suppress some clang-tidy warnings
bifurcation Jul 22, 2022
db1394a
More clang-tidy
bifurcation Jul 22, 2022
b9a88cb
More clang-tidy
bifurcation Jul 22, 2022
241b250
clang-format
bifurcation Jul 22, 2022
da161e5
Merge branch 'update-format' into mlsmessage
bifurcation Jul 22, 2022
fb0c1fd
Enable ASan on Windows
bifurcation Jul 22, 2022
807894f
Enable stricter compilation on Windows
bifurcation Jul 22, 2022
164bc6e
Dial back MSVC errors when they stop making sense
bifurcation Jul 22, 2022
44fa481
Revert some stuff
bifurcation Jul 22, 2022
3e378a1
Don't have global objects that use the heap
bifurcation Jul 23, 2022
89927ce
Attempt a different bytes import constructor
bifurcation Jul 24, 2022
dbf1f19
Actually use the new ctor
bifurcation Jul 24, 2022
463d98e
Properly declare sanitization with MSVC
bifurcation Jul 24, 2022
272d188
Don't use static const closures with std::visit
bifurcation Jul 24, 2022
f11255a
Fix compile errors
bifurcation Jul 24, 2022
df45c30
More static const closures
bifurcation Jul 24, 2022
12ded1c
clang-format
bifurcation Jul 24, 2022
4548316
Merge branch 'msvc' into mlsmessage
bifurcation Jul 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clang-format
bifurcation committed Apr 29, 2022
commit e57636c0a069a99a10052c53d2884031ddcf320d
7 changes: 5 additions & 2 deletions include/mls/state.h
Original file line number Diff line number Diff line change
@@ -116,7 +116,8 @@ class State
/// Generic handshake message handler
///
std::optional<State> handle(const MLSMessage& msg);
std::optional<State> handle(const MLSMessage& msg, std::optional<State> cached);
std::optional<State> handle(const MLSMessage& msg,
std::optional<State> cached);

///
/// Accessors
@@ -141,7 +142,9 @@ class State
///
/// Application encryption and decryption
///
MLSMessage protect(const bytes& authenticated_data, const bytes& pt, size_t padding_size);
MLSMessage protect(const bytes& authenticated_data,
const bytes& pt,
size_t padding_size);
std::tuple<bytes, bytes> unprotect(const MLSMessage& ct);

// Assemble a group context for this state
24 changes: 10 additions & 14 deletions src/messages.cpp
Original file line number Diff line number Diff line change
@@ -274,7 +274,7 @@ operator<<(tls::ostream& str, const MLSMessageAuth& obj)
return str << obj.signature;

case ContentType::commit:
return str << obj.signature << opt::get(obj.confirmation_tag);
return str << obj.signature << opt::get(obj.confirmation_tag);

default:
throw InvalidParameterError("Invalid content type");
@@ -307,10 +307,10 @@ operator==(const MLSMessageAuth& lhs, const MLSMessageAuth& rhs)
}

MLSMessageContent::MLSMessageContent(bytes group_id_in,
epoch_t epoch_in,
Sender sender_in,
bytes authenticated_data_in,
RawContent content_in)
epoch_t epoch_in,
Sender sender_in,
bytes authenticated_data_in,
RawContent content_in)
: group_id(std::move(group_id_in))
, epoch(epoch_in)
, sender(std::move(sender_in))
@@ -319,10 +319,10 @@ MLSMessageContent::MLSMessageContent(bytes group_id_in,
{}

MLSMessageContent::MLSMessageContent(bytes group_id_in,
epoch_t epoch_in,
Sender sender_in,
bytes authenticated_data_in,
ContentType content_type)
epoch_t epoch_in,
Sender sender_in,
bytes authenticated_data_in,
ContentType content_type)
: group_id(std::move(group_id_in))
, epoch(epoch_in)
, sender(std::move(sender_in))
@@ -626,16 +626,13 @@ marshal_ciphertext_content(const MLSMessageContent& content,
return w.bytes();
}



static void
unmarshal_ciphertext_content(const bytes& content_pt,
MLSMessageContent& content,
MLSMessageAuth& auth)
{
auto r = tls::istream(content_pt);


auto padding = bytes{};
var::visit([&r](auto& val) { r >> val; }, content.content);
r >> auth >> padding;
@@ -776,8 +773,7 @@ MLSCiphertext::unprotect(CipherSuite suite,

// Parse the content
auto content = MLSMessageContent{
group_id, epoch, { sender_data.sender }, authenticated_data,
content_type
group_id, epoch, { sender_data.sender }, authenticated_data, content_type
};
auto auth = MLSMessageAuth{ content_type, {}, {} };

5 changes: 3 additions & 2 deletions src/session.cpp
Original file line number Diff line number Diff line change
@@ -325,7 +325,8 @@ Session::handle(const bytes& handshake_data)
maybe_cached_state = node.mapped();
}

auto maybe_next_state = inner->history.front().handle(msg, maybe_cached_state);
auto maybe_next_state =
inner->history.front().handle(msg, maybe_cached_state);
if (!maybe_next_state) {
return false;
}
@@ -393,7 +394,7 @@ Session::authentication_secret() const
bytes
Session::protect(const bytes& plaintext)
{
auto msg = inner->history.front().protect({}, plaintext, 0 );
auto msg = inner->history.front().protect({}, plaintext, 0);
return tls::marshal(msg);
}

9 changes: 5 additions & 4 deletions src/state.cpp
Original file line number Diff line number Diff line change
@@ -591,7 +591,6 @@ State::handle(const MLSMessage& msg, std::optional<State> cached_state)
throw InvalidParameterError("Message signature failed to verify");
}


// Validate the MLSMessageContent
const auto& content = content_auth.content;
if (content.group_id != _group_id) {
@@ -636,14 +635,14 @@ State::handle(const MLSMessage& msg, std::optional<State> cached_state)
// This optional is guaranteed to be present because we just did this same
// lookup for signature verification.
sender = opt::get(_tree.find(sender_ref));

}

if (sender == _index) {
if (cached_state) {
// Verify that the cached state is a plausible successor to this state
const auto& next = opt::get(cached_state);
if (next._group_id != _group_id || next._epoch != _epoch + 1 || next._index != _index) {
if (next._group_id != _group_id || next._epoch != _epoch + 1 ||
next._index != _index) {
throw InvalidParameterError("Invalid successor state");
}

@@ -997,7 +996,9 @@ State::apply(const std::vector<CachedProposal>& proposals)
///

MLSMessage
State::protect(const bytes& authenticated_data, const bytes& pt, size_t padding_size)
State::protect(const bytes& authenticated_data,
const bytes& pt,
size_t padding_size)
{
auto msg_opts = MessageOpts{ true, authenticated_data, padding_size };
return protect_full(ApplicationData{ pt }, msg_opts);