Skip to content

Commit 5055dec

Browse files
mergify[bot]Barry-Xu-2018Mario-DL
authored
Release change while authentication fails (#5935) (#6020)
* Release change while authentication fails * Fix uncrustify error * Refs #23431: Refactor PubSubReader/Writer (un)authorized() methods * Refs #23431: Add regression test * Refs #23431: Apply Miguel's suggestions * Refs #23431: Fix windows compilation * Refs #23431: Uncrustify * Fix a memory leak on handshake handle * Fix an Uncrustify error --------- (cherry picked from commit db64a12) Signed-off-by: Barry Xu <[email protected]> Signed-off-by: Mario Dominguez <[email protected]> Co-authored-by: Barry Xu <[email protected]> Co-authored-by: Mario Dominguez <[email protected]>
1 parent 8ca0161 commit 5055dec

File tree

5 files changed

+287
-165
lines changed

5 files changed

+287
-165
lines changed

src/cpp/rtps/security/SecurityManager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,19 @@ void SecurityManager::resend_handshake_message_token(
42554255
remote_participant_info->event_->cancel_timer();
42564256
remote_participant_info->auth_status_ = AUTHENTICATION_FAILED;
42574257
on_validation_failed(dp_it->second->participant_data(), exception);
4258+
if (remote_participant_info->change_sequence_number_ != SequenceNumber_t::unknown())
4259+
{
4260+
participant_stateless_message_writer_history_->remove_change(
4261+
remote_participant_info->change_sequence_number_);
4262+
remote_participant_info->change_sequence_number_ = SequenceNumber_t::unknown();
4263+
// Return the handshake handle
4264+
if (remote_participant_info->handshake_handle_ != nullptr)
4265+
{
4266+
authentication_plugin_->return_handshake_handle(
4267+
remote_participant_info->handshake_handle_, exception);
4268+
remote_participant_info->handshake_handle_ = nullptr;
4269+
}
4270+
}
42584271
}
42594272
}
42604273
else

test/blackbox/api/dds-pim/PubSubReader.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ class PubSubReader
865865
}
866866

867867
#if HAVE_SECURITY
868-
void waitAuthorized(
868+
void wait_authorized(
869869
std::chrono::seconds timeout = std::chrono::seconds::zero(),
870870
unsigned int expected = 1)
871871
{
@@ -891,16 +891,28 @@ class PubSubReader
891891
std::cout << "Reader authorization finished..." << std::endl;
892892
}
893893

894-
void waitUnauthorized()
894+
void wait_unauthorized(
895+
std::chrono::seconds timeout = std::chrono::seconds::zero(),
896+
unsigned int expected = 1)
895897
{
896898
std::unique_lock<std::mutex> lock(mutexAuthentication_);
897899

898900
std::cout << "Reader is waiting unauthorization..." << std::endl;
899901

900-
cvAuthentication_.wait(lock, [&]() -> bool
901-
{
902-
return unauthorized_ > 0;
903-
});
902+
if (timeout == std::chrono::seconds::zero())
903+
{
904+
cvAuthentication_.wait(lock, [&]()
905+
{
906+
return unauthorized_ >= expected;
907+
});
908+
}
909+
else
910+
{
911+
cvAuthentication_.wait_for(lock, timeout, [&]()
912+
{
913+
return unauthorized_ >= expected;
914+
});
915+
}
904916

905917
std::cout << "Reader unauthorization finished..." << std::endl;
906918
}

test/blackbox/api/dds-pim/PubSubWriter.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ class PubSubWriter
768768
}
769769

770770
#if HAVE_SECURITY
771-
void waitAuthorized(
771+
void wait_authorized(
772772
std::chrono::seconds timeout = std::chrono::seconds::zero(),
773773
unsigned int expected = 1)
774774
{
@@ -794,16 +794,28 @@ class PubSubWriter
794794
std::cout << "Writer authorization finished..." << std::endl;
795795
}
796796

797-
void waitUnauthorized()
797+
void wait_unauthorized(
798+
std::chrono::seconds timeout = std::chrono::seconds::zero(),
799+
unsigned int expected = 1)
798800
{
799801
std::unique_lock<std::mutex> lock(mutexAuthentication_);
800802

801803
std::cout << "Writer is waiting unauthorization..." << std::endl;
802804

803-
cvAuthentication_.wait(lock, [&]() -> bool
804-
{
805-
return unauthorized_ > 0;
806-
});
805+
if (timeout == std::chrono::seconds::zero())
806+
{
807+
cvAuthentication_.wait(lock, [&]()
808+
{
809+
return unauthorized_ >= expected;
810+
});
811+
}
812+
else
813+
{
814+
cvAuthentication_.wait_for(lock, timeout, [&]()
815+
{
816+
return unauthorized_ >= expected;
817+
});
818+
}
807819

808820
std::cout << "Writer unauthorization finished..." << std::endl;
809821
}

test/blackbox/api/dds-pim/PubSubWriterReader.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ class PubSubWriterReader
685685
}
686686

687687
#if HAVE_SECURITY
688-
void waitAuthorized(
688+
void wait_authorized(
689689
unsigned int how_many = 1)
690690
{
691691
std::unique_lock<std::mutex> lock(mutexAuthentication_);
@@ -701,7 +701,7 @@ class PubSubWriterReader
701701
std::cout << "WReader authorization finished..." << std::endl;
702702
}
703703

704-
void waitUnauthorized(
704+
void wait_unauthorized(
705705
unsigned int how_many = 1)
706706
{
707707
std::unique_lock<std::mutex> lock(mutexAuthentication_);

0 commit comments

Comments
 (0)