Skip to content

Commit

Permalink
Secure DS POC (#3189)
Browse files Browse the repository at this point in the history
* Refs #16498: system test correction

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #16498: compiation errors when compiling with NO_SECURITY

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #16498: SecurityAuthentication tests corrections refactor pdpsimple() with pdp()

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #16498: Windows warning in PDP.cpp

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

* Refs #16498: Uncrustify

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>

Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL authored and MiguelCompany committed Jan 11, 2023
1 parent c502517 commit 213a360
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 58 deletions.
13 changes: 5 additions & 8 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,17 @@ bool PDP::data_matches_with_prefix(
const GuidPrefix_t& guid_prefix,
const ParticipantProxyData& participant_data)
{
if (guid_prefix == participant_data.m_guid.guidPrefix)
{
return true;
}
#ifdef HAVE_SECURITY
else
bool ret_val = (guid_prefix == participant_data.m_guid.guidPrefix);

#if HAVE_SECURITY
if (!ret_val)
{
GUID_t guid = GUID_t(guid_prefix, c_EntityId_RTPSParticipant);
return getRTPSParticipant()->security_manager().check_guid_comes_from(participant_data.m_guid, guid);
}
#endif // HAVE_SECURITY

return false;

return ret_val;
}

void PDP::initializeParticipantProxyData(
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void PDPServer::initializeParticipantProxyData(
| DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_DETECTOR
| DISC_BUILTIN_ENDPOINT_PUBLICATION_DETECTOR
| DISC_BUILTIN_ENDPOINT_SUBSCRIPTION_ANNOUNCER;
#ifdef HAVE_SECURITY
#if HAVE_SECURITY
if (getRTPSParticipant()->is_secure())
{
participant_data->m_availableBuiltinEndpoints
Expand Down Expand Up @@ -678,6 +678,7 @@ void PDPServer::assignRemoteEndpoints(
void PDPServer::notifyAboveRemoteEndpoints(
const ParticipantProxyData& pdata)
{
static_cast<void>(pdata);
#if HAVE_SECURITY
match_reliable_pdp_endpoints(pdata);
#endif // HAVE_SECURITY
Expand Down
2 changes: 1 addition & 1 deletion test/communication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ if(PYTHONINTERP_FOUND)
--xml-pub secure_ds_simple_secure_msg_crypto_pub.xml
--sub $<TARGET_FILE:SimpleCommunicationSubscriber>
--xml-sub secure_ds_simple_secure_msg_crypto_sub.xml
--samples 10 --wait 2
--samples 10
--ds $<TARGET_FILE:fast-discovery-server>
--xml-ds secure_simple_ds_server.xml
--server-id 0)
Expand Down
44 changes: 22 additions & 22 deletions test/unittest/rtps/security/SecurityHandshakeProcessTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ TEST_F(SecurityTest, discovered_participant_begin_handshake_request_fail_and_the
info.status = ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT;
info.guid = participant_data.m_guid;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ASSERT_FALSE(manager_.discovered_participant(participant_data));

Expand All @@ -57,8 +57,8 @@ TEST_F(SecurityTest, discovered_participant_begin_handshake_request_fail_and_the
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ASSERT_TRUE(manager_.discovered_participant(participant_data));

Expand Down Expand Up @@ -157,8 +157,8 @@ TEST_F(SecurityTest, discovered_participant_process_message_not_expecting_reques

ParticipantProxyData participant_data;
fill_participant_key(participant_data.m_guid);
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);

ParticipantAuthenticationInfo info;
info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT;
Expand Down Expand Up @@ -254,8 +254,8 @@ TEST_F(SecurityTest, discovered_participant_process_message_fail_begin_handshake
info.status = ParticipantAuthenticationInfo::UNAUTHORIZED_PARTICIPANT;
info.guid = participant_data.m_guid;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

Expand Down Expand Up @@ -316,9 +316,9 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_begin_handshake_r
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(2).WillRepeatedly(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down Expand Up @@ -399,8 +399,8 @@ TEST_F(SecurityTest, discovered_participant_process_message_new_change_fail)
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

Expand Down Expand Up @@ -466,8 +466,8 @@ TEST_F(SecurityTest, discovered_participant_process_message_add_change_fail)
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

Expand Down Expand Up @@ -573,9 +573,9 @@ TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_re
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(2).WillRepeatedly(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down Expand Up @@ -702,8 +702,8 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle_), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down Expand Up @@ -1096,8 +1096,8 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle_), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down
12 changes: 6 additions & 6 deletions test/unittest/rtps/security/SecurityTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void SecurityTest::request_process_ok(
WillOnce(Return(change));
EXPECT_CALL(*stateless_writer_->history_, add_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

fill_participant_key(participant_data_.m_guid);
ASSERT_TRUE(manager_.discovered_participant(participant_data_));
Expand Down Expand Up @@ -152,8 +152,8 @@ void SecurityTest::reply_process_ok(
WillOnce(Return(true));
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

Expand Down Expand Up @@ -221,8 +221,8 @@ void SecurityTest::final_message_process_ok(
EXPECT_CALL(*stateless_reader_->history_, remove_change_mock(change)).Times(1).
WillOnce(Return(true));
//TODO(Ricardo) Verify parameter passed to notifyAboveRemoteEndpoints
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle_), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down
4 changes: 2 additions & 2 deletions test/unittest/rtps/security/SecurityTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <rtps/security/SecurityPluginFactory.h>
#include <rtps/security/SecurityManager.h>
#include <fastrtps/rtps/security/accesscontrol/ParticipantSecurityAttributes.h>
#include <fastrtps/rtps/builtin/discovery/participant/PDPSimple.h>
#include <fastrtps/rtps/builtin/discovery/participant/PDP.h>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -161,7 +161,7 @@ class SecurityTest : public ::testing::Test
::testing::NiceMock<StatelessReader>* stateless_reader_;
::testing::NiceMock<StatefulWriter>* volatile_writer_;
::testing::NiceMock<StatefulReader>* volatile_reader_;
PDPSimple pdpsimple_;
PDP pdp_;
SecurityManager manager_;

// handles
Expand Down
36 changes: 18 additions & 18 deletions test/unittest/rtps/security/SecurityValidationRemoteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_ok)
WillOnce(Return(true));
EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);

ParticipantAuthenticationInfo info;
info.status = ParticipantAuthenticationInfo::AUTHORIZED_PARTICIPANT;
Expand Down Expand Up @@ -97,8 +97,8 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h
WillOnce(Return(true));
EXPECT_CALL(*auth_plugin_, return_identity_handle(&remote_identity_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ParticipantProxyData participant_data;
fill_participant_key(participant_data.m_guid);
Expand Down Expand Up @@ -136,9 +136,9 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillRepeatedly(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(2).WillRepeatedly(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down Expand Up @@ -187,8 +187,8 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_new_chang
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ParticipantProxyData participant_data;
fill_participant_key(participant_data.m_guid);
Expand Down Expand Up @@ -224,8 +224,8 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_add_chang
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ParticipantProxyData participant_data;
fill_participant_key(participant_data.m_guid);
Expand Down Expand Up @@ -303,9 +303,9 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(2).WillRepeatedly(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(2).WillRepeatedly(Return(&pdp_));
EXPECT_CALL(pdp_, notifyAboveRemoteEndpoints(_)).Times(1);
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(*auth_plugin_, get_shared_secret(Ref(handshake_handle), _)).Times(1).
WillOnce(Return(shared_secret_handle));
EXPECT_CALL(*auth_plugin_, return_sharedsecret_handle(shared_secret_handle, _)).Times(1).
Expand Down Expand Up @@ -359,8 +359,8 @@ TEST_F(SecurityTest, discovered_participant_ok)
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ParticipantProxyData participant_data;
fill_participant_key(participant_data.m_guid);
Expand Down Expand Up @@ -410,8 +410,8 @@ TEST_F(SecurityTest, discovered_participant_validate_remote_fail_and_then_ok)
WillRepeatedly(Return(true));
EXPECT_CALL(*auth_plugin_, return_handshake_handle(&handshake_handle, _)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(participant_, pdpsimple()).Times(1).WillOnce(Return(&pdpsimple_));
EXPECT_CALL(pdpsimple_, get_participant_proxy_data_serialized(BIGEND)).Times(1);
EXPECT_CALL(participant_, pdp()).Times(1).WillOnce(Return(&pdp_));
EXPECT_CALL(pdp_, get_participant_proxy_data_serialized(BIGEND)).Times(1);

ASSERT_TRUE(manager_.discovered_participant(participant_data));

Expand Down

0 comments on commit 213a360

Please sign in to comment.