-
Notifications
You must be signed in to change notification settings - Fork 819
[23042] Bugfix: Properly delete secure endpoints if registration fails #5814
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2025 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. | ||
|
||
#include "BlackboxTests.hpp" | ||
|
||
#if HAVE_SECURITY | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <memory> | ||
#include <thread> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <fastdds/dds/log/Log.hpp> | ||
#include <fastdds/rtps/attributes/RTPSParticipantAttributes.hpp> | ||
#include <fastdds/rtps/participant/RTPSParticipant.hpp> | ||
#include <fastdds/rtps/RTPSDomain.hpp> | ||
|
||
#include "RTPSWithRegistrationReader.hpp" | ||
#include "RTPSWithRegistrationWriter.hpp" | ||
|
||
using namespace eprosima::fastdds; | ||
using namespace eprosima::fastdds::rtps; | ||
|
||
|
||
void set_authentication_config( | ||
rtps::PropertySeq& properties) | ||
{ | ||
properties.emplace_back("dds.sec.auth.plugin", "builtin.PKI-DH"); | ||
properties.emplace_back("dds.sec.auth.builtin.PKI-DH.identity_ca", | ||
"file://" + std::string(certs_path) + "/maincacert.pem"); | ||
properties.emplace_back("dds.sec.auth.builtin.PKI-DH.identity_certificate", | ||
"file://" + std::string(certs_path) + "/mainpubcert.pem"); | ||
properties.emplace_back("dds.sec.auth.builtin.PKI-DH.private_key", | ||
"file://" + std::string(certs_path) + "/mainpubkey.pem"); | ||
} | ||
|
||
void set_participant_crypto_config( | ||
rtps::PropertySeq& props, | ||
const std::string& governance_file = "governance_helloworld_all_enable.smime", | ||
const std::string& permissions_file = "permissions_helloworld.smime") | ||
{ | ||
props.emplace_back("dds.sec.crypto.plugin", "builtin.AES-GCM-GMAC"); | ||
props.emplace_back(Property("dds.sec.access.plugin", | ||
"builtin.Access-Permissions")); | ||
props.emplace_back(Property( | ||
"dds.sec.access.builtin.Access-Permissions.permissions_ca", | ||
"file://" + std::string(certs_path) + "/maincacert.pem")); | ||
props.emplace_back(Property("dds.sec.access.builtin.Access-Permissions.governance", | ||
"file://" + std::string(certs_path) + "/" + governance_file)); | ||
props.emplace_back(Property("dds.sec.access.builtin.Access-Permissions.permissions", | ||
"file://" + std::string(certs_path) + "/" + permissions_file)); | ||
} | ||
|
||
/** | ||
* This test checks that a StatefulWriter created with security, | ||
* but with a wrong permissions on topic, is properly cleaned up | ||
*/ | ||
TEST(RTPSSecurityTests, statefulwriter_wrong_permissions_properly_cleaned_up) | ||
{ | ||
RTPSWithRegistrationWriter<HelloWorldPubSubType> writer("CustomTopicName"); | ||
RTPSWithRegistrationReader<HelloWorldPubSubType> reader("CustomTopicName"); | ||
|
||
PropertyPolicy security_properties; | ||
set_authentication_config(security_properties.properties()); | ||
set_participant_crypto_config(security_properties.properties()); | ||
|
||
writer.add_participant_properties(security_properties); | ||
reader.add_participant_properties(security_properties); | ||
|
||
// This should fail but properly exit | ||
ASSERT_NO_THROW(writer.init()); | ||
ASSERT_NO_THROW(reader.init()); | ||
} | ||
|
||
void blackbox_security_init() | ||
{ | ||
certs_path = std::getenv("CERTS_PATH"); | ||
|
||
if (certs_path == nullptr) | ||
{ | ||
std::cout << "Cannot get enviroment variable CERTS_PATH" << std::endl; | ||
exit(-1); | ||
} | ||
} | ||
|
||
#endif // if HAVE_SECURITY | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a call to
local_actions_on_writer_removed()
on the StatefulWriter Destructor to ensure that events are always destroyed, instead of manually calling it here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
local_actions_on_writer_removed()
comes from the formerdeinit()
that was explicitly moved out from theStatefulPersistentWriter
destructor, in this commitHowever I dont see any reason why we should not call it from the
StatafulWriter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling virtual functions inside destructors is dangerous. We could have a proxy method that receives a pointer to a writer and performs the call to
local_actions_on_writer_removed()
and then deletes the writer