Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

security-context -> enclave #407

Merged
merged 2 commits into from
Apr 13, 2020
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
14 changes: 7 additions & 7 deletions rmw_connext_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ rmw_init_options_init(rmw_init_options_t * init_options, rcutils_allocator_t all
init_options->security_options = rmw_get_zero_initialized_security_options();
init_options->domain_id = RMW_DEFAULT_DOMAIN_ID;
init_options->localhost_only = RMW_LOCALHOST_ONLY_DEFAULT;
init_options->security_context = NULL;
init_options->enclave = NULL;
return RMW_RET_OK;
}

Expand All @@ -60,19 +60,19 @@ rmw_init_options_copy(const rmw_init_options_t * src, rmw_init_options_t * dst)
const rcutils_allocator_t * allocator = &src->allocator;
rmw_ret_t ret = RMW_RET_OK;

allocator->deallocate(dst->security_context, allocator->state);
allocator->deallocate(dst->enclave, allocator->state);
*dst = *src;
dst->security_context = NULL;
dst->enclave = NULL;
dst->security_options = rmw_get_zero_initialized_security_options();

dst->security_context = rcutils_strdup(src->security_context, *allocator);
if (src->security_context && !dst->security_context) {
dst->enclave = rcutils_strdup(src->enclave, *allocator);
if (src->enclave && !dst->enclave) {
ret = RMW_RET_BAD_ALLOC;
goto fail;
}
return rmw_security_options_copy(&src->security_options, allocator, &dst->security_options);
fail:
allocator->deallocate(dst->security_context, allocator->state);
allocator->deallocate(dst->enclave, allocator->state);
return ret;
}

Expand All @@ -87,7 +87,7 @@ rmw_init_options_fini(rmw_init_options_t * init_options)
init_options->implementation_identifier,
rti_connext_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
allocator.deallocate(init_options->security_context, allocator.state);
allocator.deallocate(init_options->enclave, allocator.state);
rmw_security_options_fini(&init_options->security_options, &allocator);
*init_options = rmw_get_zero_initialized_init_options();
return RMW_RET_OK;
Expand Down
8 changes: 4 additions & 4 deletions rmw_connext_cpp/src/rmw_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ rmw_get_node_names(
}

rmw_ret_t
rmw_get_node_names_with_security_contexts(
rmw_get_node_names_with_enclaves(
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * security_contexts)
rcutils_string_array_t * enclaves)
{
return get_node_names_with_security_contexts(
rti_connext_identifier, node, node_names, node_namespaces, security_contexts);
return get_node_names_with_enclaves(
rti_connext_identifier, node, node_names, node_namespaces, enclaves);
}
} // extern "C"
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ get_node_names(

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
get_node_names_with_security_contexts(
get_node_names_with_enclaves(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * security_contexts);
rcutils_string_array_t * enclaves);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
Expand Down
8 changes: 4 additions & 4 deletions rmw_connext_shared_cpp/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ create_node(
size_t length = std::snprintf(
nullptr,
0,
"name=%s;namespace=%s;securitycontext=%s;",
name, namespace_, context->options.security_context) + 1;
"name=%s;namespace=%s;enclave=%s;",
mikaelarguedas marked this conversation as resolved.
Show resolved Hide resolved
name, namespace_, context->options.enclave) + 1;
bool success = participant_qos.user_data.value.length(static_cast<DDS::Long>(length));
if (!success) {
RMW_SET_ERROR_MSG("failed to resize participant user_data");
Expand All @@ -87,8 +87,8 @@ create_node(
int written = std::snprintf(
reinterpret_cast<char *>(participant_qos.user_data.value.get_contiguous_buffer()),
length,
"name=%s;namespace=%s;securitycontext=%s;",
name, namespace_, context->options.security_context);
"name=%s;namespace=%s;enclave=%s;",
name, namespace_, context->options.enclave);
if (written < 0 || written > static_cast<int>(length) - 1) {
RMW_SET_ERROR_MSG("failed to populate user_data buffer");
return NULL;
Expand Down
56 changes: 28 additions & 28 deletions rmw_connext_shared_cpp/src/node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ get_node_names_impl(
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * security_contexts)
rcutils_string_array_t * enclaves)
{
if (!node) {
RMW_SET_ERROR_MSG("node handle is null");
Expand Down Expand Up @@ -77,7 +77,7 @@ get_node_names_impl(
// Such names should not be returned
rcutils_string_array_t tmp_names_list = rcutils_get_zero_initialized_string_array();
rcutils_string_array_t tmp_namespaces_list = rcutils_get_zero_initialized_string_array();
rcutils_string_array_t tmp_security_contexts_list = rcutils_get_zero_initialized_string_array();
rcutils_string_array_t tmp_enclaves_list = rcutils_get_zero_initialized_string_array();

int named_nodes_num = 1;

Expand All @@ -97,8 +97,8 @@ get_node_names_impl(
goto cleanup;
}

if (security_contexts) {
rcutils_ret = rcutils_string_array_init(&tmp_security_contexts_list, length, &allocator);
if (enclaves) {
rcutils_ret = rcutils_string_array_init(&tmp_enclaves_list, length, &allocator);

if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG(rcutils_get_error_string().str);
Expand All @@ -120,11 +120,11 @@ get_node_names_impl(
final_ret = rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
goto cleanup;
}
if (security_contexts) {
tmp_security_contexts_list.data[0] = rcutils_strdup(
node->context->options.security_context, allocator);
if (enclaves) {
tmp_enclaves_list.data[0] = rcutils_strdup(
node->context->options.enclave, allocator);
if (!tmp_namespaces_list.data[0]) {
RMW_SET_ERROR_MSG("could not allocate memory for a security context name");
RMW_SET_ERROR_MSG("could not allocate memory for a enclave name");
final_ret = rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
goto cleanup;
}
Expand All @@ -135,7 +135,7 @@ get_node_names_impl(
auto dds_ret = participant->get_discovered_participant_data(pbtd, handles[i - 1]);
std::string name;
std::string namespace_;
std::string security_context;
std::string enclave;
if (DDS::RETCODE_OK == dds_ret) {
auto data = static_cast<unsigned char *>(pbtd.user_data.value.get_contiguous_buffer());
std::vector<uint8_t> kv(data, data + pbtd.user_data.value.length());
Expand All @@ -144,7 +144,7 @@ get_node_names_impl(

auto name_found = map.find("name");
auto ns_found = map.find("namespace");
auto security_context_found = map.find("securitycontext");
auto enclave_found = map.find("enclave");

if (name_found != map.end()) {
name = std::string(name_found->second.begin(), name_found->second.end());
Expand All @@ -154,9 +154,9 @@ get_node_names_impl(
namespace_ = std::string(ns_found->second.begin(), ns_found->second.end());
}

if (security_context_found != map.end()) {
security_context = std::string(
security_context_found->second.begin(), security_context_found->second.end());
if (enclave_found != map.end()) {
enclave = std::string(
enclave_found->second.begin(), enclave_found->second.end());
}
}

Expand All @@ -181,10 +181,10 @@ get_node_names_impl(
goto cleanup;
}

if (security_contexts) {
tmp_security_contexts_list.data[named_nodes_num] = rcutils_strdup(
security_context.c_str(), allocator);
if (!tmp_security_contexts_list.data[named_nodes_num]) {
if (enclaves) {
tmp_enclaves_list.data[named_nodes_num] = rcutils_strdup(
enclave.c_str(), allocator);
if (!tmp_enclaves_list.data[named_nodes_num]) {
RMW_SET_ERROR_MSG("could not allocate memory for a node's namespace");
final_ret = rmw_convert_rcutils_ret_to_rmw_ret(rcutils_ret);
goto cleanup;
Expand All @@ -210,8 +210,8 @@ get_node_names_impl(
goto cleanup;
}

if (security_contexts) {
rcutils_ret = rcutils_string_array_init(security_contexts, named_nodes_num, &allocator);
if (enclaves) {
rcutils_ret = rcutils_string_array_init(enclaves, named_nodes_num, &allocator);

if (rcutils_ret != RCUTILS_RET_OK) {
RMW_SET_ERROR_MSG("could not allocate memory for node_namespaces output");
Expand All @@ -223,8 +223,8 @@ get_node_names_impl(
for (auto i = 0; i < named_nodes_num; ++i) {
node_names->data[i] = rcutils_strdup(tmp_names_list.data[i], allocator);
node_namespaces->data[i] = rcutils_strdup(tmp_namespaces_list.data[i], allocator);
if (security_contexts) {
security_contexts->data[i] = rcutils_strdup(tmp_security_contexts_list.data[i], allocator);
if (enclaves) {
enclaves->data[i] = rcutils_strdup(tmp_enclaves_list.data[i], allocator);
}
}

Expand Down Expand Up @@ -266,8 +266,8 @@ get_node_names_impl(
}
}

if (security_contexts) {
rcutils_ret = rcutils_string_array_fini(security_contexts);
if (enclaves) {
rcutils_ret = rcutils_string_array_fini(enclaves);
if (rcutils_ret != RCUTILS_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_connext_cpp",
Expand Down Expand Up @@ -295,7 +295,7 @@ get_node_names_impl(
rcutils_reset_error();
}

rcutils_ret = rcutils_string_array_fini(&tmp_security_contexts_list);
rcutils_ret = rcutils_string_array_fini(&tmp_enclaves_list);
if (rcutils_ret != RCUTILS_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rmw_connext_cpp",
Expand All @@ -318,16 +318,16 @@ get_node_names(
}

rmw_ret_t
get_node_names_with_security_contexts(
get_node_names_with_enclaves(
const char * implementation_identifier,
const rmw_node_t * node,
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * security_contexts)
rcutils_string_array_t * enclaves)
{
if (rmw_check_zero_rmw_string_array(security_contexts) != RMW_RET_OK) {
if (rmw_check_zero_rmw_string_array(enclaves) != RMW_RET_OK) {
return RMW_RET_ERROR;
}
return get_node_names_impl(
implementation_identifier, node, node_names, node_namespaces, security_contexts);
implementation_identifier, node, node_names, node_namespaces, enclaves);
}