Skip to content
Closed
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
51 changes: 51 additions & 0 deletions zenoh_security_configuration_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 3.8)
project(zenoh_security_configuration_tools)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(TinyXML2 REQUIRED)
find_package(CLI11 REQUIRED)
find_package(zenoh_cpp_vendor REQUIRED)

add_executable(zenoh_security_configuration_tools
src/zenoh_security_configuration_tools.cpp
src/policy_parser.cpp
)
target_link_libraries(zenoh_security_configuration_tools PRIVATE
CLI11::CLI11
nlohmann_json::nlohmann_json
tinyxml2::tinyxml2
zenohcxx::zenohc
)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
if(WIN32)
target_compile_definitions(${PROJECT_NAME}
PRIVATE "ZENOH_SECURITY_CONFIGURATION_TOOLS_BUILDING_LIBRARY")
endif()

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()


install(
TARGETS zenoh_security_configuration_tools
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) 2025, Open Source Robotics Foundation, Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef ZENOH_SECURITY_CONFIGURATION_TOOLS__POLICY_PARSER_HPP_
#define ZENOH_SECURITY_CONFIGURATION_TOOLS__POLICY_PARSER_HPP_

#include <tinyxml2.h>

#include <cstdint>
#include <set>
#include <string>

#include <zenoh.hxx>

#include "zenoh_security_configuration_tools/visibility_control.hpp"

namespace zenoh
{
/**
* This class parses the ROS 2 secutiry policy files into json5 Zenoh Config files
**/
class PolicyParser
{
public:
/// The library is loaded in the constructor.
/**
* \param[in] filename The policy string path.
* \throws std::runtime_error if there are some invalid arguments or the library
* was not load properly
*/
ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC
PolicyParser(
const std::string & filename,
const std::string & configfile,
uint16_t domain_id);

void parse();

private:
void parse_enclaves(const tinyxml2::XMLElement * root);
void parse_profiles(const tinyxml2::XMLElement * root);
void parse_services(const tinyxml2::XMLElement * root, const std::string & node_name);
void parse_topics(const tinyxml2::XMLElement * root, const std::string & node_name);
void clear();
void fill_data(
zenoh::Config & config,
const std::string & node_name);

std::string check_name(
const std::string & name,
const std::string & node_name);

tinyxml2::XMLDocument doc_;
std::string configfile_path_;

std::set<std::string> services_reply_allow_;
std::set<std::string> services_reply_deny_;
std::set<std::string> services_request_allow_;
std::set<std::string> services_request_deny_;

std::set<std::string> topics_sub_allow_;
std::set<std::string> topics_pub_allow_;
std::set<std::string> topics_sub_deny_;
std::set<std::string> topics_pub_deny_;

uint16_t domain_id_;
};
} // namespace zenoh

#endif // ZENOH_SECURITY_CONFIGURATION_TOOLS__POLICY_PARSER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2025, Open Source Robotics Foundation, Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef ZENOH_SECURITY_CONFIGURATION_TOOLS__VISIBILITY_CONTROL_HPP_
#define ZENOH_SECURITY_CONFIGURATION_TOOLS__VISIBILITY_CONTROL_HPP_

/*! \file visibility_control.hpp
* \brief Macros for controlling visibilty of exported iterfaces.
*
* This logic was borrowed (then namespaced) from the examples on the gcc wiki:
* https://gcc.gnu.org/wiki/Visibility
*/
/**
* \def ZENOH_SECURITY_CONFIGURATION_TOOLS_EXPORT
* \brief Exposes the function with its decorated name in the compiled library object.
*/
/**
* \def ZENOH_SECURITY_CONFIGURATION_TOOLS_IMPORT
* \brief On Windows declares a function will be imported from a dll, otherwise it is empty
*/
/**
* \def ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC
* \brief Declares symbols and functions will be visible for export.
*/
/**
* \def ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC_TYPE
* \brief On Windows, this is a replica of ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC, otherwise it is empty.
*/
/**
* \def ZENOH_SECURITY_CONFIGURATION_TOOLS_LOCAL
* \brief Declares symbols cannot be exported from the dll.
*/

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_EXPORT __attribute__ ((dllexport))
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_IMPORT __attribute__ ((dllimport))
#else
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_EXPORT __declspec(dllexport)
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_IMPORT __declspec(dllimport)
#endif
#ifdef ZENOH_SECURITY_CONFIGURATION_TOOLS_BUILDING_LIBRARY
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC ZENOH_SECURITY_CONFIGURATION_TOOLS_EXPORT
#else
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC ZENOH_SECURITY_CONFIGURATION_TOOLS_IMPORT
#endif
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC_TYPE ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_LOCAL
#else
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_EXPORT __attribute__ ((visibility("default")))
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_IMPORT
#if __GNUC__ >= 4
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC __attribute__ ((visibility("default")))
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_LOCAL __attribute__ ((visibility("hidden")))
#else
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_LOCAL
#endif
#define ZENOH_SECURITY_CONFIGURATION_TOOLS_PUBLIC_TYPE
#endif

#endif // ZENOH_SECURITY_CONFIGURATION_TOOLS__VISIBILITY_CONTROL_HPP_
23 changes: 23 additions & 0 deletions zenoh_security_configuration_tools/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>zenoh_security_configuration_tools</name>
<version>0.3.0</version>
<description>This package generates zenoh secutiry configurations</description>
<maintainer email="alejandro@openrobotics.org">Alejandro Hernanadez</maintainer>
<license>Apache License 2.0</license>


<build_depend>nlohmann-json-dev</build_depend>

<depend>cli11</depend>
<depend>tinyxml2_vendor</depend>
<depend>zenoh_cpp_vendor</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading
Loading