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

Use keystore root as security root directory, and not contexts folder #607

Merged
merged 2 commits into from
Apr 9, 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
13 changes: 8 additions & 5 deletions rcl/src/rcl/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,21 @@ char * exact_match_lookup(
const char * ros_secure_root_env,
const rcl_allocator_t * allocator)
{
// Perform an exact match for the node/context's name in directory <root dir>/<namespace>.
// Perform an exact match for the context name in directory <root dir>.
char * secure_root = NULL;
// "/" case when root namespace is explicitly passed in
if (0 == strcmp(name, "/")) {
secure_root = rcutils_strdup(ros_secure_root_env, *allocator);
} else {
char * root_path = NULL;
char * relative_path = NULL;
char * contexts_dir = NULL;
// Get native path, ignore the leading forward slash
// TODO(ros2team): remove the hard-coded length, use the length of the root namespace instead
root_path = rcutils_to_native_path(name + 1, *allocator);
secure_root = rcutils_join_path(ros_secure_root_env, root_path, *allocator);
allocator->deallocate(root_path, allocator->state);
relative_path = rcutils_to_native_path(name + 1, *allocator);
contexts_dir = rcutils_join_path(ros_secure_root_env, "contexts", *allocator);
secure_root = rcutils_join_path(contexts_dir, relative_path, *allocator);
allocator->deallocate(relative_path, allocator->state);
allocator->deallocate(contexts_dir, allocator->state);
}
return secure_root;
}
Expand Down
14 changes: 11 additions & 3 deletions rcl/test/rcl/test_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
# define PATH_SEPARATOR "\\"
#endif

#define TEST_SECURITY_CONTEXT_MULTIPLE_TOKENS \
"/group1" PATH_SEPARATOR TEST_SECURITY_CONTEXT

char g_envstring[512] = {0};

static int putenv_wrapper(const char * env_var)
Expand Down Expand Up @@ -137,17 +140,21 @@ TEST_F(TestGetSecureRoot, successScenarios_local_exactMatch) {
TEST_RESOURCES_DIRECTORY TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME);

secure_root = rcl_get_secure_root(TEST_SECURITY_CONTEXT_ABSOLUTE, &allocator);
ASSERT_NE(nullptr, secure_root);
std::string secure_root_str(secure_root);
ASSERT_STREQ(
TEST_SECURITY_CONTEXT,
secure_root_str.substr(secure_root_str.size() - strlen(TEST_SECURITY_CONTEXT)).c_str());
}

TEST_F(TestGetSecureRoot, successScenarios_local_exactMatch_multipleTokensName) {
putenv_wrapper(ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "=" TEST_RESOURCES_DIRECTORY);
putenv_wrapper(
ROS_SECURITY_ROOT_DIRECTORY_VAR_NAME "="
TEST_RESOURCES_DIRECTORY TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME);

secure_root = rcl_get_secure_root(
TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME PATH_SEPARATOR TEST_SECURITY_CONTEXT, &allocator);
TEST_SECURITY_CONTEXT_MULTIPLE_TOKENS, &allocator);
ASSERT_NE(nullptr, secure_root);
std::string secure_root_str(secure_root);
ASSERT_STREQ(
TEST_SECURITY_CONTEXT,
Expand Down Expand Up @@ -217,5 +224,6 @@ TEST_F(TestGetSecureRoot, test_get_security_options) {
EXPECT_EQ(RMW_SECURITY_ENFORCEMENT_ENFORCE, options.enforce_security);
EXPECT_STREQ(
TEST_RESOURCES_DIRECTORY TEST_SECURITY_DIRECTORY_RESOURCES_DIR_NAME
PATH_SEPARATOR TEST_SECURITY_CONTEXT, options.security_root_path);
PATH_SEPARATOR "contexts" PATH_SEPARATOR TEST_SECURITY_CONTEXT,
options.security_root_path);
}