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

[16501] PKI exchange finished #3170

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4243e56
Refs #16500. PDPServer: Empty methods for secure endpoints creation.
MiguelCompany Dec 14, 2022
be2e86a
Refs #16500. Implementing PDPServer::should_protect_discovery()
MiguelCompany Dec 14, 2022
b439285
Refs #16500. Added DiscoveryServerPDPEndpointsSecure container.
MiguelCompany Dec 19, 2022
07f8b68
Refs #16500. Added constants for new entity ids.
MiguelCompany Dec 19, 2022
15e2ad3
Refs #16500. Create reliable endpoints refactor.
MiguelCompany Dec 19, 2022
3ee3bde
Refs #16500. Avoid automatically matching endpoints when secure.
MiguelCompany Dec 19, 2022
72267c8
Refs #16500. Stateless reader creation on PDPServer.
MiguelCompany Dec 19, 2022
e7f6974
Refs #16500. Logs improved.
MiguelCompany Dec 19, 2022
cf1b750
Refs #16501: Added PDPSecurityInitiatorListener
Mario-DL Dec 19, 2022
5f6ecc1
Refs #16501: Take reader mutex upwards
Mario-DL Dec 20, 2022
17e66b4
Refs #16501: removed createparticipant() and LOG comment
Mario-DL Dec 20, 2022
8ecb15f
Refs #16501: Added PDPClient SecureEndpoints
Mario-DL Dec 20, 2022
58afef7
Refs #16501: Removed if(pdata != nullptr)
Mario-DL Dec 20, 2022
40a65bd
Refs #16500. Setting writer guid inside message group.
MiguelCompany Dec 20, 2022
4a44f93
Refs #16500. FakeWriter class for direct sending of DATA(p).
MiguelCompany Dec 20, 2022
c5a1673
Refs #16500. Using FakeWriter on PDPClient.
MiguelCompany Dec 20, 2022
a7a1276
Refs #16500. Using FakeWriter on PDPServer.
MiguelCompany Dec 20, 2022
9584f18
Refs #16501: Added pdp() method on RTPSParticipantImpl
Mario-DL Dec 21, 2022
287cd86
Refs #16501: pdp() instead of pdpsimple() in SecurityManager
Mario-DL Dec 21, 2022
e6358eb
Refs #16501: PDP.h header in SecurityManager.cpp & couple of forward …
Mario-DL Dec 21, 2022
dd2fed2
Refs #16501: Security Unittests Fixed
Mario-DL Dec 21, 2022
c98c56c
Fix assertion when built with statistics (#3169)
MiguelCompany Dec 21, 2022
8f2510f
Refs #16501: Added functor cb to PDPSecurityInitiatorListener
Mario-DL Dec 21, 2022
3b00d43
Refs #16501: Added PDPSecurityInitiatorListener Functor response call…
Mario-DL Dec 21, 2022
ec9335b
Refs #16501: Uncrustify
Mario-DL Dec 21, 2022
af9e0d8
Refs #16501. Fix build without security.
MiguelCompany Dec 21, 2022
853268c
Refs #16501: Address requested changes
Mario-DL Dec 21, 2022
464c399
Refs #16501: Build PDPSecurityInitiatorListener only If SECURITY Is E…
Mario-DL Dec 21, 2022
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
7 changes: 7 additions & 0 deletions include/fastdds/rtps/builtin/discovery/participant/PDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class PDPEndpoints;
} // namespace fastdds

namespace fastrtps {
namespace types {

class TypeObject;
class TypeIdentifier;

} // namespace types
namespace rtps {

class RTPSWriter;
Expand Down Expand Up @@ -76,6 +82,7 @@ class PDP
friend class PDPListener;
friend class PDPServerListener;
friend class fastdds::rtps::PDPServerListener;
friend class PDPSecurityInitiatorListener;

public:

Expand Down
5 changes: 5 additions & 0 deletions include/fastdds/rtps/common/EntityId_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ const EntityId_t participant_volatile_message_secure_reader_entity_id =

const EntityId_t c_EntityId_WriterLivelinessSecure = ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_WRITER;
const EntityId_t c_EntityId_ReaderLivelinessSecure = ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_READER;

const EntityId_t c_EntityId_spdp_reliable_participant_secure_reader =
ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_READER;
const EntityId_t c_EntityId_spdp_reliable_participant_secure_writer =
ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_WRITER;
#endif // if HAVE_SECURITY

const EntityId_t ds_server_virtual_writer = ENTITYID_DS_SERVER_VIRTUAL_WRITER;
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ set(${PROJECT_NAME}_security_source_files
rtps/security/logging/Logging.cpp
rtps/security/SecurityManager.cpp
rtps/security/SecurityPluginFactory.cpp
rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.cpp
security/authentication/PKIDH.cpp
security/accesscontrol/Permissions.cpp
security/cryptography/AESGCMGMAC.cpp
Expand Down Expand Up @@ -390,7 +391,7 @@ find_package(Atomic MODULE)
# prioritizes writes

# try_run cannot manage targets yet
get_target_property(CMAKE_ATOMIC_LIB eProsima_atomic INTERFACE_LINK_LIBRARIES)
get_target_property(CMAKE_ATOMIC_LIB eProsima_atomic INTERFACE_LINK_LIBRARIES)
if(NOT CMAKE_ATOMIC_LIB)
set(CMAKE_ATOMIC_LIB)
endif()
Expand Down Expand Up @@ -508,7 +509,7 @@ if(MSVC OR MSVC_IDE)
endif()

# Get OpenSSL version suitable manifest format
execute_process( COMMAND PowerShell -NoLogo -Command "&{ param([string]$original)
execute_process( COMMAND PowerShell -NoLogo -Command "&{ param([string]$original)
if ($original -notmatch '\\d+$')
{ $res = $original.Substring(0,$original.length-1) + '.' +
([int]$original[$original.length-1]-[int][char]'a'+1); }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file DiscoveryServerPDPEndpointsSecure.hpp
*/

#ifndef FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_DS__DISCOVERYSERVERPDPENDPOINTSSECURE_HPP_
#define FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_DS__DISCOVERYSERVERPDPENDPOINTSSECURE_HPP_

#include <memory>

#include <fastdds/rtps/builtin/data/BuiltinEndpoints.hpp>
#include <fastdds/rtps/common/EntityId_t.hpp>
#include <fastdds/rtps/reader/StatelessReader.h>

#include <rtps/builtin/BuiltinReader.hpp>
#include <rtps/builtin/discovery/participant/DS/DiscoveryServerPDPEndpoints.hpp>

namespace eprosima {
namespace fastdds {
namespace rtps {

/**
* Container for the builtin endpoints of secure PDPClient and PDPServer
*/
struct DiscoveryServerPDPEndpointsSecure : public DiscoveryServerPDPEndpoints
{
~DiscoveryServerPDPEndpointsSecure() override = default;

fastrtps::rtps::BuiltinEndpointSet_t builtin_endpoints() const override
{
return DiscoveryServerPDPEndpoints::builtin_endpoints() |
DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_ANNOUNCER | DISC_BUILTIN_ENDPOINT_PARTICIPANT_SECURE_DETECTOR;
}

bool enable_pdp_readers(
fastrtps::rtps::RTPSParticipantImpl* participant) override
{
return DiscoveryServerPDPEndpoints::enable_pdp_readers(participant) &&
participant->enableReader(stateless_reader.reader_);
}

void disable_pdp_readers(
fastrtps::rtps::RTPSParticipantImpl* participant) override
{
participant->disableReader(stateless_reader.reader_);
DiscoveryServerPDPEndpoints::disable_pdp_readers(participant);
}

void delete_pdp_endpoints(
fastrtps::rtps::RTPSParticipantImpl* participant) override
{
participant->deleteUserEndpoint(stateless_reader.reader_->getGuid());
DiscoveryServerPDPEndpoints::delete_pdp_endpoints(participant);
}

void remove_from_pdp_reader_history(
const fastrtps::rtps::InstanceHandle_t& remote_participant) override
{
stateless_reader.remove_from_history(remote_participant);
DiscoveryServerPDPEndpoints::remove_from_pdp_reader_history(remote_participant);
}

void remove_from_pdp_reader_history(
fastrtps::rtps::CacheChange_t* change) override
{
assert(nullptr != change);
if (change->writerGUID.entityId == fastrtps::rtps::c_EntityId_SPDPWriter)
{
stateless_reader.history_->remove_change(change);
}
else
{
DiscoveryServerPDPEndpoints::remove_from_pdp_reader_history(change);
}
}

//! Builtin Simple PDP reader
BuiltinReader<fastrtps::rtps::StatelessReader> stateless_reader;
//! Listener for stateless_reader
std::unique_ptr<fastrtps::rtps::ReaderListener> stateless_listener;
};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif // FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_DS__DISCOVERYSERVERPDPENDPOINTSSECURE_HPP_
55 changes: 55 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/DS/FakeWriter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file FakeWriter.hpp
*/

#ifndef FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_DS__FAKEWRITER_HPP_
#define FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_DS__FAKEWRITER_HPP_

#include <fastdds/rtps/Endpoint.h>

#include <rtps/participant/RTPSParticipantImpl.h>

namespace eprosima {
namespace fastdds {
namespace rtps {

/**
* An RTPS writer simulator used to send messages with a \ref DirectMessageSender.
*/
class FakeWriter : public fastrtps::rtps::Endpoint
{
public:

FakeWriter(
fastrtps::rtps::RTPSParticipantImpl* participant,
const fastrtps::rtps::EntityId_t& entity_id)
: fastrtps::rtps::Endpoint(participant, { participant->getGuid().guidPrefix, entity_id }, {})
{
m_att.endpointKind = fastrtps::rtps::EndpointKind_t::WRITER;
#if HAVE_SECURITY
participant->set_endpoint_rtps_protection_supports(this, false);
#endif // HAVE_SECURITY
}

virtual ~FakeWriter() override = default;
};

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

#endif /* FASTDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_DS__FAKEWRITER_HPP_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file PDPSecurityInitiatorListener.cpp
*
*/

#include <rtps/builtin/discovery/participant/DS/PDPSecurityInitiatorListener.hpp>

#include <fastdds/dds/log/Log.hpp>

#include <fastdds/rtps/builtin/discovery/endpoint/EDP.h>
#include <fastdds/rtps/builtin/discovery/participant/PDP.h>
#include <fastdds/rtps/history/ReaderHistory.h>
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.h>
#include <fastdds/rtps/participant/RTPSParticipantListener.h>
#include <fastdds/rtps/reader/RTPSReader.h>
#include <fastdds/rtps/resources/TimedEvent.h>

#include <fastrtps/utils/TimeConversion.h>

#include <fastdds/core/policy/ParameterList.hpp>
#include <rtps/builtin/discovery/participant/PDPEndpoints.hpp>
#include <rtps/network/ExternalLocatorsProcessor.hpp>
#include <rtps/participant/RTPSParticipantImpl.h>

#include <mutex>

using ParameterList = eprosima::fastdds::dds::ParameterList;

namespace eprosima {
namespace fastrtps {
namespace rtps {

PDPSecurityInitiatorListener::PDPSecurityInitiatorListener(
PDP* parent,
SecurityInitiatedCallback response_cb)
: parent_pdp_(parent)
, temp_participant_data_(parent->getRTPSParticipant()->getRTPSParticipantAttributes().allocation)
, response_cb_(response_cb)
{
}

void PDPSecurityInitiatorListener::onNewCacheChangeAdded(
RTPSReader* reader,
const CacheChange_t* const change_in)
{
CacheChange_t* change = const_cast<CacheChange_t*>(change_in);
GUID_t writer_guid = change->writerGUID;
EPROSIMA_LOG_INFO(RTPS_PDP, "SPDP Message received from: " << change_in->writerGUID);

// Make sure we have an instance handle (i.e GUID)
if (change->instanceHandle == c_InstanceHandle_Unknown)
{
if (!this->get_key(change))
{
EPROSIMA_LOG_WARNING(RTPS_PDP, "Problem getting the key of the change, removing");
parent_pdp_->builtin_endpoints_->remove_from_pdp_reader_history(change);
return;
}
}

// Take GUID from instance handle
GUID_t guid;
iHandle2GUID(guid, change->instanceHandle);

if (change->kind == ALIVE)
{
// Ignore announcement from own RTPSParticipant
if (guid == parent_pdp_->getRTPSParticipant()->getGuid())
{
EPROSIMA_LOG_INFO(RTPS_PDP, "Message from own RTPSParticipant, removing");
parent_pdp_->builtin_endpoints_->remove_from_pdp_reader_history(change);
return;
}

// Release reader lock to avoid ABBA lock. PDP mutex should always be first.
// Keep change information on local variables to check consistency later
SequenceNumber_t seq_num = change->sequenceNumber;
reader->getMutex().unlock();
std::unique_lock<std::recursive_mutex> lock(*parent_pdp_->getMutex());
reader->getMutex().lock();

// If change is not consistent, it will be processed on the thread that has overriten it
if ((ALIVE != change->kind) || (seq_num != change->sequenceNumber) || (writer_guid != change->writerGUID))
{
return;
}

// Access to temp_participant_data_ is protected by reader lock

// Load information on temp_participant_data_
CDRMessage_t msg(change->serializedPayload);
temp_participant_data_.clear();
if (temp_participant_data_.readFromCDRMessage(&msg, true, parent_pdp_->getRTPSParticipant()->network_factory(),
parent_pdp_->getRTPSParticipant()->has_shm_transport()))
{
// After correctly reading it
change->instanceHandle = temp_participant_data_.m_key;
guid = temp_participant_data_.m_guid;

// Filter locators
const auto& pattr = parent_pdp_->getRTPSParticipant()->getAttributes();
fastdds::rtps::ExternalLocatorsProcessor::filter_remote_locators(temp_participant_data_,
pattr.builtin.metatraffic_external_unicast_locators, pattr.default_external_unicast_locators,
pattr.ignore_non_matching_locators);

// Check if participant already exists (updated info)
ParticipantProxyData* pdata = nullptr;
for (ParticipantProxyData* it : parent_pdp_->participant_proxies_)
{
if (guid == it->m_guid)
{
pdata = it;
break;
}
}

if (pdata == nullptr)
{
// Create a new one when not found

reader->getMutex().unlock();
lock.unlock();

//! notify security manager in order to start handshake
parent_pdp_->getRTPSParticipant()->security_manager().discovered_participant(temp_participant_data_);

//! Reply to the remote participant
response_cb_(temp_participant_data_);

// Take again the reader lock
reader->getMutex().lock();

} //! Do nothing if already discovered

}

} //! Do nothing on participant removal

//Remove change form history.
parent_pdp_->builtin_endpoints_->remove_from_pdp_reader_history(change);
}

bool PDPSecurityInitiatorListener::get_key(
CacheChange_t* change)
{
return ParameterList::readInstanceHandleFromCDRMsg(change, fastdds::dds::PID_PARTICIPANT_GUID);
}

} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */
Loading