Skip to content

Commit c94803b

Browse files
author
akkshaj-rti
authored
Connext Secure Examples (#641)
1 parent 49cd8f9 commit c94803b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3628
-0
lines changed

examples/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,33 @@ option(CONNEXTDDS_BUILD_WEB_INTEGRATION_SERVICE_EXAMPLES
3434
OFF
3535
)
3636

37+
option(CONNEXTDDS_BUILD_CONNEXT_SECURE_EXAMPLES
38+
"Build Connext Secure examples"
39+
OFF
40+
)
41+
3742
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/connext_dds")
3843

3944
if(CONNEXTDDS_BUILD_PERSISTENCE_SERVICE_EXAMPLES)
4045
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/persistence_service")
4146
endif()
47+
4248
if(CONNEXTDDS_BUILD_RECORDING_SERVICE_EXAMPLES)
4349
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/recording_service")
4450
endif()
51+
4552
if(CONNEXTDDS_BUILD_ROUTING_SERVICE_EXAMPLES)
4653
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/routing_service")
4754
endif()
55+
4856
if(CONNEXTDDS_BUILD_WEB_INTEGRATION_SERVICE_EXAMPLES)
4957
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/web_integration_service")
5058
endif()
59+
5160
if(CONNEXTDDS_BUILD_CLOUD_DISCOVERY_SERVICE_EXAMPLES)
5261
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/cloud_discovery_service")
5362
endif()
63+
64+
if(CONNEXTDDS_BUILD_CONNEXT_SECURE_EXAMPLES)
65+
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/connext_secure")
66+
endif()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# (c) 2023 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
#
4+
# RTI grants Licensee a license to use, modify, compile, and create derivative
5+
# works of the Software. Licensee has the right to distribute object form
6+
# only for use with RTI products. The Software is provided "as is", with no
7+
# warranty of any type, including any warranty for fitness for any purpose.
8+
# RTI is under no obligation to maintain or support the Software. RTI shall
9+
# not be liable for any incidental or consequential damages arising out of the
10+
# use or inability to use the software.
11+
#
12+
13+
cmake_minimum_required(VERSION 3.12)
14+
project(rticonnextdds-examples-secure)
15+
list(APPEND CMAKE_MODULE_PATH
16+
"${CMAKE_CURRENT_SOURCE_DIR}/../../resources/cmake/Modules"
17+
)
18+
include(ConnextDdsConfigureCmakeUtils)
19+
connextdds_configure_cmake_utils()
20+
21+
include(ConnextDdsAddExamplesSubdirectories)
22+
23+
if(NOT DEFINED CONNEXTDDS_CONNEXT_SECURE_EXAMPLES)
24+
set(CONNEXTDDS_CONNEXT_SECURE_EXAMPLES
25+
"cds"
26+
"certificate_revocation_list"
27+
"lightweight"
28+
"whitelist"
29+
)
30+
endif()
31+
32+
connextdds_add_examples_subdirectories(
33+
EXAMPLES
34+
${CONNEXTDDS_CONNEXT_SECURE_EXAMPLES}
35+
)

examples/connext_secure/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Connext Secure
2+
3+
RTI Security Plugins allow you to address your databus security requirements in
4+
a granular and pluggable way.
5+
The Security Plugins are the Connext implementation of the OMG DDS Security
6+
builtin interoperability plugins.
7+
8+
In this directory you will find some examples that illustrate the use of RTI
9+
Security Plugins.
10+
For more information about RTI Security Plugins, please
11+
refer to the [RTI Security Plugins User's Manual](https://community.rti.com/static/documentation/connext-dds/7.2.0/doc/manuals/connext_dds_secure/users_manual/index.html).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Example Code: Lightweight Security with Cloud Discovery Service
2+
3+
## Concept
4+
5+
This example showcases protection of participant announcement messages (Data(p)
6+
packets), including those relayed by Cloud Discovery Service through lightweight
7+
security plugins. This requires Connext Secure 7.2.0 or newer. This example is
8+
based on a standard rtiddsgen publisher and subscriber example code and a basic
9+
Cloud Discovery Service configuration. Initial peers are set up so that
10+
communication can only happen in the presence of Cloud Discovery Service, and in
11+
particular the secure CDS configuration profile.
12+
A Wireshark capture is supplied as part of the example.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* (c) Copyright, Real-Time Innovations, 2023. All rights reserved.
3+
* RTI grants Licensee a license to use, modify, compile, and create derivative
4+
* works of the software solely for use with RTI Connext DDS. Licensee may
5+
* redistribute copies of the software provided that all such copies are subject
6+
* to this license. The software is provided "as is", with no warranty of any
7+
* type, including any warranty for fitness for any purpose. RTI is under no
8+
* obligation to maintain or support the software. RTI shall not be liable for
9+
* any incidental or consequential damages arising out of the use or inability
10+
* to use the software.
11+
*/
12+
13+
struct Example {
14+
int32 value;
15+
};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* (c) Copyright, Real-Time Innovations, 2023. All rights reserved.
3+
* RTI grants Licensee a license to use, modify, compile, and create derivative
4+
* works of the software solely for use with RTI Connext DDS. Licensee may
5+
* redistribute copies of the software provided that all such copies are subject
6+
* to this license. The software is provided "as is", with no warranty of any
7+
* type, including any warranty for fitness for any purpose. RTI is under no
8+
* obligation to maintain or support the software. RTI shall not be liable for
9+
* any incidental or consequential damages arising out of the use or inability
10+
* to use the software.
11+
*/
12+
13+
#include <iostream>
14+
15+
#include <dds/pub/ddspub.hpp>
16+
#include <rti/util/util.hpp> // for sleep()
17+
#include <rti/config/Logger.hpp> // for logging
18+
19+
#include "application.hpp" // for command line parsing and ctrl-c
20+
#include "CDS.hpp"
21+
22+
void run_publisher_application(
23+
unsigned int domain_id,
24+
unsigned int sample_count)
25+
{
26+
// DDS objects behave like shared pointers or value types
27+
// (see
28+
// https://community.rti.com/best-practices/use-modern-c-types-correctly)
29+
30+
// Start communicating in a domain, usually one participant per application
31+
dds::domain::DomainParticipant participant(
32+
domain_id,
33+
dds::core::QosProvider::Default().participant_qos(
34+
"lite_library::lite_peer"));
35+
36+
// Create a Topic with a name and a datatype
37+
dds::topic::Topic<Example> topic(participant, "CDS LWS Example");
38+
39+
// Create a Publisher
40+
dds::pub::Publisher publisher(participant);
41+
42+
// Create a DataWriter with default QoS
43+
dds::pub::DataWriter<Example> writer(publisher, topic);
44+
45+
Example data;
46+
// Main loop, write data
47+
for (unsigned int samples_written = 0;
48+
!application::shutdown_requested && samples_written < sample_count;
49+
samples_written++) {
50+
// Modify the data to be written here
51+
data.value(static_cast<int32_t>(samples_written));
52+
std::cout << "Writing CDS, count " << samples_written << std::endl;
53+
54+
writer.write(data);
55+
56+
// Send once every second
57+
rti::util::sleep(dds::core::Duration(1));
58+
}
59+
}
60+
61+
int main(int argc, char *argv[])
62+
{
63+
using namespace application;
64+
65+
// Parse arguments and handle control-C
66+
auto arguments = parse_arguments(argc, argv);
67+
if (arguments.parse_result == ParseReturn::exit) {
68+
return EXIT_SUCCESS;
69+
} else if (arguments.parse_result == ParseReturn::failure) {
70+
return EXIT_FAILURE;
71+
}
72+
setup_signal_handlers();
73+
74+
// Sets Connext verbosity to help debugging
75+
rti::config::Logger::instance().verbosity(arguments.verbosity);
76+
77+
try {
78+
run_publisher_application(arguments.domain_id, arguments.sample_count);
79+
} catch (const std::exception &ex) {
80+
// This will catch DDS exceptions
81+
std::cerr << "Exception in run_publisher_application(): " << ex.what()
82+
<< std::endl;
83+
return EXIT_FAILURE;
84+
}
85+
86+
// Releases the memory used by the participant factory. Optional at
87+
// application exit
88+
dds::domain::DomainParticipant::finalize_participant_factory();
89+
90+
return EXIT_SUCCESS;
91+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* (c) Copyright, Real-Time Innovations, 2023. All rights reserved.
3+
* RTI grants Licensee a license to use, modify, compile, and create derivative
4+
* works of the software solely for use with RTI Connext DDS. Licensee may
5+
* redistribute copies of the software provided that all such copies are subject
6+
* to this license. The software is provided "as is", with no warranty of any
7+
* type, including any warranty for fitness for any purpose. RTI is under no
8+
* obligation to maintain or support the software. RTI shall not be liable for
9+
* any incidental or consequential damages arising out of the use or inability
10+
* to use the software.
11+
*/
12+
13+
#include <algorithm>
14+
#include <iostream>
15+
16+
#include <dds/sub/ddssub.hpp>
17+
#include <dds/core/ddscore.hpp>
18+
#include <rti/config/Logger.hpp> // for logging
19+
20+
#include "CDS.hpp"
21+
#include "application.hpp" // for command line parsing and ctrl-c
22+
23+
void process_data(dds::sub::DataReader<Example> reader)
24+
{
25+
// Take all samples
26+
dds::sub::LoanedSamples<Example> samples = reader.take();
27+
for (auto sample : samples) {
28+
if (sample.info().valid()) {
29+
std::cout << sample.data() << std::endl;
30+
} else {
31+
std::cout << "Instance state changed to "
32+
<< sample.info().state().instance_state() << std::endl;
33+
}
34+
}
35+
} // The LoanedSamples destructor returns the loan
36+
37+
void run_subscriber_application(
38+
unsigned int domain_id,
39+
unsigned int sample_count)
40+
{
41+
// DDS objects behave like shared pointers or value types
42+
// (see
43+
// https://community.rti.com/best-practices/use-modern-c-types-correctly)
44+
45+
// Start communicating in a domain, usually one participant per application
46+
dds::domain::DomainParticipant participant(
47+
domain_id,
48+
dds::core::QosProvider::Default().participant_qos(
49+
"lite_library::lite_peer"));
50+
51+
// Create a Topic with a name and a datatype
52+
dds::topic::Topic<Example> topic(participant, "CDS LWS Example");
53+
54+
// Create a Subscriber and DataReader with default Qos
55+
dds::sub::Subscriber subscriber(participant);
56+
dds::sub::DataReader<Example> reader(subscriber, topic);
57+
58+
// Create a ReadCondition for any data received on this reader and set a
59+
// handler to process the data
60+
dds::sub::cond::ReadCondition read_condition(
61+
reader,
62+
dds::sub::status::DataState::any(),
63+
[reader]() { process_data(reader); });
64+
65+
// WaitSet will be woken when the attached condition is triggered
66+
dds::core::cond::WaitSet waitset;
67+
waitset += read_condition;
68+
69+
while (!application::shutdown_requested) {
70+
std::cout << "Example subscriber sleeping up to 1 sec..." << std::endl;
71+
72+
// Run the handlers of the active conditions. Wait for up to 1 second.
73+
waitset.dispatch(dds::core::Duration(1));
74+
}
75+
}
76+
77+
int main(int argc, char *argv[])
78+
{
79+
using namespace application;
80+
81+
// Parse arguments and handle control-C
82+
auto arguments = parse_arguments(argc, argv);
83+
if (arguments.parse_result == ParseReturn::exit) {
84+
return EXIT_SUCCESS;
85+
} else if (arguments.parse_result == ParseReturn::failure) {
86+
return EXIT_FAILURE;
87+
}
88+
setup_signal_handlers();
89+
90+
// Sets Connext verbosity to help debugging
91+
rti::config::Logger::instance().verbosity(arguments.verbosity);
92+
93+
try {
94+
run_subscriber_application(arguments.domain_id, arguments.sample_count);
95+
} catch (const std::exception &ex) {
96+
// This will catch DDS exceptions
97+
std::cerr << "Exception in run_subscriber_application(): " << ex.what()
98+
<< std::endl;
99+
return EXIT_FAILURE;
100+
}
101+
102+
// Releases the memory used by the participant factory. Optional at
103+
// application exit
104+
dds::domain::DomainParticipant::finalize_participant_factory();
105+
106+
return EXIT_SUCCESS;
107+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# (c) 2023 Copyright, Real-Time Innovations, Inc. All rights reserved.
3+
#
4+
# RTI grants Licensee a license to use, modify, compile, and create derivative
5+
# works of the Software. Licensee has the right to distribute object form
6+
# only for use with RTI products. The Software is provided "as is", with no
7+
# warranty of any type, including any warranty for fitness for any purpose.
8+
# RTI is under no obligation to maintain or support the Software. RTI shall
9+
# not be liable for any incidental or consequential damages arising out of the
10+
# use or inability to use the software.
11+
#
12+
cmake_minimum_required(VERSION 3.11)
13+
project(rtiexamples-cds-lws)
14+
list(APPEND CMAKE_MODULE_PATH
15+
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../resources/cmake/Modules"
16+
)
17+
include(ConnextDdsConfigureCmakeUtils)
18+
connextdds_configure_cmake_utils()
19+
20+
# Include ConnextDdsAddExample.cmake from resources/cmake
21+
include(ConnextDdsAddExample)
22+
23+
connextdds_add_example(
24+
IDL "CDS"
25+
LANG "C++11"
26+
)
27+
28+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/USER_QOS_PROFILES.xml" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
29+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/../cds.xml" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Example Code: Lightweight Security with Cloud Discovery Service
2+
3+
## Building the Example
4+
5+
Remember to set your environment variables with the script in your Connext
6+
installation directory before building.
7+
8+
```sh
9+
cd c++11/
10+
mkdir build
11+
cd build
12+
cmake ..
13+
cmake --build .
14+
```
15+
16+
Note: The build process also copies USER_QOS_PROFILES.xml into the build
17+
directory to ensure that it is loaded when you run the examples within the build
18+
directory.
19+
20+
## Running the example
21+
22+
This example is based on a standard rtiddsgen publisher and subscriber example
23+
code and a basic Cloud Discovery Service configuration. Initial peers are set up
24+
so that communication can only happen in the presence of Cloud Discovery
25+
Service, and in particular the secure CDS configuration profile.
26+
A Wireshark capture is supplied as part of the example.
27+
28+
Run the publisher and subscriber in separate terminal windows.
29+
30+
```sh
31+
./CDS_publisher
32+
```
33+
34+
```sh
35+
./CDS_subscriber
36+
```
37+
38+
Then, start Cloud Discovery Service (in a different terminal) using the
39+
`rticlouddiscoveryservice` script from your installation directory. Configure
40+
CDS by passing the `-cfgFile cds.xml -cfgName secure_cds` options to the
41+
application. You can also use the `insecure_cds` profile to compare the
42+
Wireshark output without lightweight security. Optionally, generate a Wireshark capture.
43+
44+
```sh
45+
rticlouddiscoveryservice -cfgFile cds.xml -cfgName secure_cds
46+
```
47+
48+
To filter traffic going to CDS in Wireshark, use udp.dstport == 9999. To filter
49+
traffic relayed by CDS, use rtps.flag.cloud_discovery_service_announcer == 1.
50+
You will that all traffic is SIGNED when using the secure configuration.
51+
This means that the secure prefix and postfix are present for all Data(p)s.

0 commit comments

Comments
 (0)