Skip to content

Commit d47cd75

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

File tree

5 files changed

+289
-166
lines changed

5 files changed

+289
-166
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
@@ -854,7 +854,7 @@ class PubSubReader
854854
}
855855

856856
#if HAVE_SECURITY
857-
void waitAuthorized(
857+
void wait_authorized(
858858
std::chrono::seconds timeout = std::chrono::seconds::zero(),
859859
unsigned int expected = 1)
860860
{
@@ -880,16 +880,28 @@ class PubSubReader
880880
std::cout << "Reader authorization finished..." << std::endl;
881881
}
882882

883-
void waitUnauthorized()
883+
void wait_unauthorized(
884+
std::chrono::seconds timeout = std::chrono::seconds::zero(),
885+
unsigned int expected = 1)
884886
{
885887
std::unique_lock<std::mutex> lock(mutexAuthentication_);
886888

887889
std::cout << "Reader is waiting unauthorization..." << std::endl;
888890

889-
cvAuthentication_.wait(lock, [&]() -> bool
890-
{
891-
return unauthorized_ > 0;
892-
});
891+
if (timeout == std::chrono::seconds::zero())
892+
{
893+
cvAuthentication_.wait(lock, [&]()
894+
{
895+
return unauthorized_ >= expected;
896+
});
897+
}
898+
else
899+
{
900+
cvAuthentication_.wait_for(lock, timeout, [&]()
901+
{
902+
return unauthorized_ >= expected;
903+
});
904+
}
893905

894906
std::cout << "Reader unauthorization finished..." << std::endl;
895907
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ class PubSubWriter
731731
}
732732

733733
#if HAVE_SECURITY
734-
void waitAuthorized(
734+
void wait_authorized(
735735
std::chrono::seconds timeout = std::chrono::seconds::zero(),
736736
unsigned int expected = 1)
737737
{
@@ -757,16 +757,28 @@ class PubSubWriter
757757
std::cout << "Writer authorization finished..." << std::endl;
758758
}
759759

760-
void waitUnauthorized()
760+
void wait_unauthorized(
761+
std::chrono::seconds timeout = std::chrono::seconds::zero(),
762+
unsigned int expected = 1)
761763
{
762764
std::unique_lock<std::mutex> lock(mutexAuthentication_);
763765

764766
std::cout << "Writer is waiting unauthorization..." << std::endl;
765767

766-
cvAuthentication_.wait(lock, [&]() -> bool
767-
{
768-
return unauthorized_ > 0;
769-
});
768+
if (timeout == std::chrono::seconds::zero())
769+
{
770+
cvAuthentication_.wait(lock, [&]()
771+
{
772+
return unauthorized_ >= expected;
773+
});
774+
}
775+
else
776+
{
777+
cvAuthentication_.wait_for(lock, timeout, [&]()
778+
{
779+
return unauthorized_ >= expected;
780+
});
781+
}
770782

771783
std::cout << "Writer unauthorization finished..." << std::endl;
772784
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ class PubSubWriterReader
272272
do
273273
{
274274
wreader_.receive_one(datareader, ret);
275-
} while (ret);
275+
}
276+
while (ret);
276277
}
277278
}
278279

@@ -682,7 +683,7 @@ class PubSubWriterReader
682683
}
683684

684685
#if HAVE_SECURITY
685-
void waitAuthorized(
686+
void wait_authorized(
686687
unsigned int how_many = 1)
687688
{
688689
std::unique_lock<std::mutex> lock(mutexAuthentication_);
@@ -698,7 +699,7 @@ class PubSubWriterReader
698699
std::cout << "WReader authorization finished..." << std::endl;
699700
}
700701

701-
void waitUnauthorized(
702+
void wait_unauthorized(
702703
unsigned int how_many = 1)
703704
{
704705
std::unique_lock<std::mutex> lock(mutexAuthentication_);

0 commit comments

Comments
 (0)