Skip to content

Commit

Permalink
Use keystore root as security root directory, and not contexts folder (
Browse files Browse the repository at this point in the history
…#607)

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored Apr 9, 2020
1 parent 4a7ba02 commit 6ca6545
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
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);
}
Empty file.

0 comments on commit 6ca6545

Please sign in to comment.