Skip to content

Commit 4d63eb7

Browse files
committed
Refs #24365: Force presence of all 3 Security plugins
Signed-off-by: Carlos Ferreira González <carlosferreira@eprosima.com>
1 parent 7f3a805 commit 4d63eb7

1 file changed

Lines changed: 46 additions & 6 deletions

File tree

src/cpp/rtps/security/SecurityManager.cpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ bool SecurityManager::init(
123123
try
124124
{
125125
domain_id_ = participant_->get_domain_id();
126+
127+
// All three security plugin properties must be configured together, or none at all (non-secure participant)
128+
{
129+
const std::string* auth_plugin_property = PropertyPolicyHelper::find_property(
130+
participant_properties, "dds.sec.auth.plugin");
131+
const std::string* access_plugin_property = PropertyPolicyHelper::find_property(
132+
participant_properties, "dds.sec.access.plugin");
133+
const std::string* crypto_plugin_property = PropertyPolicyHelper::find_property(
134+
participant_properties, "dds.sec.crypto.plugin");
135+
136+
const int configured_count =
137+
(auth_plugin_property != nullptr ? 1 : 0) +
138+
(access_plugin_property != nullptr ? 1 : 0) +
139+
(crypto_plugin_property != nullptr ? 1 : 0);
140+
141+
if (configured_count == 0)
142+
{
143+
// Non-secure participant: skip security setup entirely.
144+
enable_security_manager();
145+
return true;
146+
}
147+
148+
if (configured_count != 3)
149+
{
150+
EPROSIMA_LOG_ERROR(SECURITY,
151+
"All three security plugin properties must be configured together: "
152+
"dds.sec.auth.plugin, dds.sec.access.plugin, dds.sec.crypto.plugin");
153+
return false;
154+
}
155+
}
156+
126157
const PropertyPolicy log_properties = PropertyPolicyHelper::get_properties_with_prefix(
127158
participant_->get_const_attributes().properties,
128159
"dds.sec.log.builtin.DDS_LogTopic.");
@@ -319,7 +350,7 @@ bool SecurityManager::init(
319350
log_info_message("Access control plugin not configured");
320351
}
321352

322-
if (access_plugin_ == nullptr || local_permissions_handle_ != nullptr)
353+
if (access_plugin_ != nullptr && local_permissions_handle_ != nullptr)
323354
{
324355
crypto_plugin_ = factory_.create_cryptography_plugin(participant_properties);
325356

@@ -354,20 +385,28 @@ bool SecurityManager::init(
354385
log_info_message("Cryptography plugin not configured");
355386
}
356387

357-
if ((access_plugin_ == nullptr || local_permissions_handle_ != nullptr) &&
358-
(crypto_plugin_ == nullptr || local_participant_crypto_handle_))
388+
if (access_plugin_ != nullptr && local_permissions_handle_ != nullptr &&
389+
crypto_plugin_ != nullptr && local_participant_crypto_handle_)
359390
{
360391
// Should be activated here, to enable encription buffer on created entities
361392
throw true;
362393
}
363394
else
364395
{
365-
if (access_plugin_ != nullptr && local_permissions_handle_ == nullptr)
396+
if (access_plugin_ == nullptr)
397+
{
398+
EPROSIMA_LOG_ERROR(SECURITY, "Access control plugin could not be created.");
399+
}
400+
else if (local_permissions_handle_ == nullptr)
366401
{
367402
EPROSIMA_LOG_ERROR(SECURITY, "Participant is not allowed with its own permissions file.");
368403
}
369404

370-
if (crypto_plugin_ != nullptr && local_participant_crypto_handle_ == nullptr)
405+
if (crypto_plugin_ == nullptr)
406+
{
407+
EPROSIMA_LOG_ERROR(SECURITY, "Cryptography plugin could not be created.");
408+
}
409+
else if (local_participant_crypto_handle_ == nullptr)
371410
{
372411
EPROSIMA_LOG_ERROR(SECURITY, "Participant cryptography could not be configured.");
373412
}
@@ -382,7 +421,8 @@ bool SecurityManager::init(
382421
}
383422
else
384423
{
385-
log_info_message("Authentication plugin not configured. Security will be disabled");
424+
EPROSIMA_LOG_ERROR(SECURITY, "Authentication plugin could not be created.");
425+
throw false;
386426
}
387427
}
388428
catch (const SecurityException& e)

0 commit comments

Comments
 (0)