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

State properties #185

Merged
merged 4 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions cmd/interop/src/mls_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ MLSClientImpl::ExternalJoin(ServerContext* /* context */,
}

// Access information from a group state
Status
MLSClientImpl::PublicGroupState(ServerContext* /* context */,
const PublicGroupStateRequest* request,
PublicGroupStateResponse* response)
{
return state_wrap(request, [=](auto& state) {
return public_group_state(state, request, response);
});
}

Status
MLSClientImpl::StateAuth(ServerContext* /* context */,
const StateAuthRequest* request,
Expand All @@ -142,6 +152,33 @@ MLSClientImpl::PublicGroupState(ServerContext* /* context */,
});
}

Status
MLSClientImpl::Export(ServerContext* /* context */,
const ExportRequest* request,
ExportResponse* response)
{
return state_wrap(
request, [=](auto& state) { return do_export(state, request, response); });
}

Status
MLSClientImpl::Protect(ServerContext* /* context */,
const ProtectRequest* request,
ProtectResponse* response)
{
return state_wrap(
request, [=](auto& state) { return protect(state, request, response); });
}

Status
MLSClientImpl::Unprotect(ServerContext* /* context */,
const UnprotectRequest* request,
UnprotectResponse* response)
{
return state_wrap(
request, [=](auto& state) { return unprotect(state, request, response); });
}

// Operations using a group state
Status
MLSClientImpl::AddProposal(ServerContext* /* context */,
Expand Down Expand Up @@ -446,6 +483,16 @@ MLSClientImpl::external_join(const ExternalJoinRequest* request,
}

// Access information from a group state
Status
MLSClientImpl::public_group_state(CachedState& entry,
const PublicGroupStateRequest* /* request */,
PublicGroupStateResponse* response)
{
auto pgs = tls::marshal(entry.state.public_group_state());
response->set_public_group_state(bytes_to_string(pgs));
return Status::OK;
}

Status
MLSClientImpl::state_auth(CachedState& entry,
const StateAuthRequest* /* request */,
Expand All @@ -456,6 +503,43 @@ MLSClientImpl::state_auth(CachedState& entry,
return Status::OK;
}

Status
MLSClientImpl::do_export(CachedState& entry,
const ExportRequest* request,
ExportResponse* response)
{
auto label = request->label();
auto context = string_to_bytes(request->context());
auto size = request->key_length();
auto secret = entry.state.do_export(label, context, size);
response->set_exported_secret(bytes_to_string(secret));
return Status::OK;
}

Status
MLSClientImpl::protect(CachedState& entry,
const ProtectRequest* request,
ProtectResponse* response)
{
auto pt = string_to_bytes(request->application_data());
auto ct = entry.state.protect(pt);
auto ct_data = tls::marshal(ct);
response->set_ciphertext(bytes_to_string(ct_data));
return Status::OK;
}

Status
MLSClientImpl::unprotect(CachedState& entry,
const UnprotectRequest* request,
UnprotectResponse* response)
{
auto ct_data = string_to_bytes(request->ciphertext());
auto ct = tls::get<mls::MLSCiphertext>(ct_data);
auto pt = entry.state.unprotect(ct);
response->set_application_data(bytes_to_string(pt));
return Status::OK;
}

Status
MLSClientImpl::public_group_state(CachedState& entry,
const PublicGroupStateRequest* /* request */,
Expand Down
24 changes: 24 additions & 0 deletions cmd/interop/src/mls_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,21 @@ class MLSClientImpl final : public MLSClient::Service
ExternalJoinResponse* response) override;

// Access information from a group state
Status PublicGroupState(ServerContext* context,
const PublicGroupStateRequest* request,
PublicGroupStateResponse* response) override;
Status StateAuth(ServerContext* context,
const StateAuthRequest* request,
StateAuthResponse* response) override;
Status Export(ServerContext* context,
const ExportRequest* request,
ExportResponse* response) override;
Status Protect(ServerContext* context,
const ProtectRequest* request,
ProtectResponse* response) override;
Status Unprotect(ServerContext* context,
const UnprotectRequest* request,
UnprotectResponse* response) override;
Status PublicGroupState(ServerContext* context,
const PublicGroupStateRequest* request,
PublicGroupStateResponse* response) override;
Expand Down Expand Up @@ -121,9 +133,21 @@ class MLSClientImpl final : public MLSClient::Service
ExternalJoinResponse* response);

// Access information from a group state
Status public_group_state(CachedState& entry,
const PublicGroupStateRequest* request,
PublicGroupStateResponse* response);
Status state_auth(CachedState& entry,
const StateAuthRequest* request,
StateAuthResponse* response);
Status do_export(CachedState& entry,
const ExportRequest* request,
ExportResponse* response);
Status protect(CachedState& entry,
const ProtectRequest* request,
ProtectResponse* response);
Status unprotect(CachedState& entry,
const UnprotectRequest* request,
UnprotectResponse* response);
Status public_group_state(CachedState& entry,
const PublicGroupStateRequest* request,
PublicGroupStateResponse* response);
Expand Down