LCOV - code coverage report
Current view: top level - DCPS/security/framework - HandleRegistry.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 183 0.0 %
Date: 2023-04-30 01:32:43 Functions: 0 27 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #include <DCPS/DdsDcps_pch.h> //Only the _pch include should start with DCPS/
       7             : 
       8             : #ifdef OPENDDS_SECURITY
       9             : 
      10             : #include "HandleRegistry.h"
      11             : 
      12             : #include <dds/DCPS/debug.h>
      13             : #include <dds/DCPS/GuidConverter.h>
      14             : 
      15             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      16             : 
      17             : namespace OpenDDS {
      18             : namespace Security {
      19             : 
      20           0 : HandleRegistry::HandleRegistry()
      21             : {
      22           0 :   default_endpoint_security_attributes_.base.is_read_protected = false;
      23           0 :   default_endpoint_security_attributes_.base.is_write_protected = false;
      24           0 :   default_endpoint_security_attributes_.base.is_discovery_protected = false;
      25           0 :   default_endpoint_security_attributes_.base.is_liveliness_protected = false;
      26           0 :   default_endpoint_security_attributes_.is_submessage_protected = false;
      27           0 :   default_endpoint_security_attributes_.is_payload_protected = false;
      28           0 :   default_endpoint_security_attributes_.is_key_protected = false;
      29           0 :   default_endpoint_security_attributes_.plugin_endpoint_attributes = 0;
      30           0 : }
      31             : 
      32           0 : HandleRegistry::~HandleRegistry()
      33             : {
      34           0 :   if (DCPS::security_debug.bookkeeping) {
      35           0 :     ACE_DEBUG((LM_DEBUG, "(%P|%t) {bookkeeping} "
      36             :                "HandleRegistry::~HandleRegistry local datareader %B local datawriter %B "
      37             :                "remote participant %B remote datareader %B remote datawriter %B\n",
      38             :                local_datareader_crypto_handles_.size(),
      39             :                local_datawriter_crypto_handles_.size(),
      40             :                remote_participant_crypto_handles_.size(),
      41             :                remote_datareader_crypto_handles_.size(),
      42             :                remote_datawriter_crypto_handles_.size()));
      43             :   }
      44           0 : }
      45             : 
      46             : void
      47           0 : HandleRegistry::insert_local_datareader_crypto_handle(const DCPS::GUID_t& id,
      48             :                                                       DDS::Security::DatareaderCryptoHandle handle,
      49             :                                                       const DDS::Security::EndpointSecurityAttributes& attributes)
      50             : {
      51           0 :   if (handle != DDS::HANDLE_NIL) {
      52           0 :     ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
      53           0 :     local_datareader_crypto_handles_[id] = std::make_pair(handle, attributes);
      54             : 
      55           0 :     if (DCPS::security_debug.bookkeeping) {
      56           0 :       ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
      57             :                  ACE_TEXT("HandleRegistry::insert_local_datareader_crypto_handle %C %d (total %B)\n"),
      58             :                  DCPS::LogGuid(id).c_str(),
      59             :                  handle,
      60             :                  local_datareader_crypto_handles_.size()));
      61             :     }
      62           0 :   }
      63             : }
      64             : 
      65             : DDS::Security::DatareaderCryptoHandle
      66           0 : HandleRegistry::get_local_datareader_crypto_handle(const DCPS::GUID_t& id) const
      67             : {
      68           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, DDS::HANDLE_NIL);
      69           0 :   DatareaderCryptoHandleMap::const_iterator pos = local_datareader_crypto_handles_.find(id);
      70           0 :   if (pos != local_datareader_crypto_handles_.end()) {
      71           0 :     return pos->second.first;
      72             :   }
      73           0 :   return DDS::HANDLE_NIL;
      74           0 : }
      75             : 
      76             : const DDS::Security::EndpointSecurityAttributes&
      77           0 : HandleRegistry::get_local_datareader_security_attributes(const DCPS::GUID_t& id) const
      78             : {
      79           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, default_endpoint_security_attributes_);
      80           0 :   DatareaderCryptoHandleMap::const_iterator pos = local_datareader_crypto_handles_.find(id);
      81           0 :   if (pos != local_datareader_crypto_handles_.end()) {
      82           0 :     return pos->second.second;
      83             :   }
      84           0 :   return default_endpoint_security_attributes_;
      85           0 : }
      86             : 
      87             : void
      88           0 : HandleRegistry::erase_local_datareader_crypto_handle(const DCPS::GUID_t& id)
      89             : {
      90           0 :   ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
      91           0 :   local_datareader_crypto_handles_.erase(id);
      92             : 
      93           0 :   if (DCPS::security_debug.bookkeeping) {
      94           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
      95             :                ACE_TEXT("HandleRegistry::erase_local_datareader_crypto_handle %C (%B)\n"),
      96             :                DCPS::LogGuid(id).c_str(),
      97             :                local_datareader_crypto_handles_.size()));
      98             :   }
      99           0 : }
     100             : 
     101             : void
     102           0 : HandleRegistry::insert_local_datawriter_crypto_handle(const DCPS::GUID_t& id,
     103             :                                                       DDS::Security::DatawriterCryptoHandle handle,
     104             :                                                       const DDS::Security::EndpointSecurityAttributes& attributes)
     105             : {
     106           0 :   if (handle != DDS::HANDLE_NIL) {
     107           0 :     ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     108           0 :     local_datawriter_crypto_handles_[id] = std::make_pair(handle, attributes);
     109             : 
     110           0 :     if (DCPS::security_debug.bookkeeping) {
     111           0 :       ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     112             :                  ACE_TEXT("HandleRegistry::insert_local_datawriter_crypto_handle %C %d (total %B)\n"),
     113             :                  DCPS::LogGuid(id).c_str(),
     114             :                  handle,
     115             :                  local_datawriter_crypto_handles_.size()));
     116             :     }
     117           0 :   }
     118             : }
     119             : 
     120             : DDS::Security::DatawriterCryptoHandle
     121           0 : HandleRegistry::get_local_datawriter_crypto_handle(const DCPS::GUID_t& id) const
     122             : {
     123           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, DDS::HANDLE_NIL);
     124           0 :   DatawriterCryptoHandleMap::const_iterator pos = local_datawriter_crypto_handles_.find(id);
     125           0 :   if (pos != local_datawriter_crypto_handles_.end()) {
     126           0 :     return pos->second.first;
     127             :   }
     128           0 :   return DDS::HANDLE_NIL;
     129           0 : }
     130             : 
     131             : const DDS::Security::EndpointSecurityAttributes&
     132           0 : HandleRegistry::get_local_datawriter_security_attributes(const DCPS::GUID_t& id) const
     133             : {
     134           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, default_endpoint_security_attributes_);
     135           0 :   DatawriterCryptoHandleMap::const_iterator pos = local_datawriter_crypto_handles_.find(id);
     136           0 :   if (pos != local_datawriter_crypto_handles_.end()) {
     137           0 :     return pos->second.second;
     138             :   }
     139           0 :   return default_endpoint_security_attributes_;
     140           0 : }
     141             : 
     142             : void
     143           0 : HandleRegistry::erase_local_datawriter_crypto_handle(const DCPS::GUID_t& id)
     144             : {
     145           0 :   ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     146           0 :   local_datawriter_crypto_handles_.erase(id);
     147             : 
     148           0 :   if (DCPS::security_debug.bookkeeping) {
     149           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     150             :                ACE_TEXT("HandleRegistry::erase_local_datawriter_crypto_handle %C (total %B)\n"),
     151             :                DCPS::LogGuid(id).c_str(),
     152             :                local_datawriter_crypto_handles_.size()));
     153             :   }
     154           0 : }
     155             : 
     156             : void
     157           0 : HandleRegistry::insert_remote_participant_crypto_handle(const DCPS::GUID_t& id,
     158             :                                                         DDS::Security::ParticipantCryptoHandle handle)
     159             : {
     160           0 :   if (handle != DDS::HANDLE_NIL) {
     161           0 :     ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     162           0 :     remote_participant_crypto_handles_[id] = handle;
     163             : 
     164           0 :     if (DCPS::security_debug.bookkeeping) {
     165           0 :       ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     166             :                  ACE_TEXT("HandleRegistry::insert_remote_participant_crypto_handle %C %d (total %B)\n"),
     167             :                  DCPS::LogGuid(id).c_str(),
     168             :                  handle,
     169             :                  remote_participant_crypto_handles_.size()));
     170             :     }
     171           0 :   }
     172             : }
     173             : 
     174             : DDS::Security::ParticipantCryptoHandle
     175           0 : HandleRegistry::get_remote_participant_crypto_handle(const DCPS::GUID_t& id) const
     176             : {
     177           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, DDS::HANDLE_NIL);
     178           0 :   ParticipantCryptoHandleMap::const_iterator pos = remote_participant_crypto_handles_.find(id);
     179           0 :   if (pos != remote_participant_crypto_handles_.end()) {
     180           0 :     return pos->second;
     181             :   }
     182           0 :   return DDS::HANDLE_NIL;
     183           0 : }
     184             : 
     185             : void
     186           0 : HandleRegistry::erase_remote_participant_crypto_handle(const DCPS::GUID_t& id)
     187             : {
     188           0 :   ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     189           0 :   remote_participant_crypto_handles_.erase(id);
     190             : 
     191           0 :   if (DCPS::security_debug.bookkeeping) {
     192           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     193             :                ACE_TEXT("HandleRegistry::erase_remote_participant_crypto_handle %C (total %B)\n"),
     194             :                DCPS::LogGuid(id).c_str(),
     195             :                remote_participant_crypto_handles_.size()));
     196             :   }
     197           0 : }
     198             : 
     199             : void
     200           0 : HandleRegistry::insert_remote_participant_permissions_handle(const DCPS::GUID_t& id,
     201             :                                                         DDS::Security::PermissionsHandle handle)
     202             : {
     203           0 :   if (handle != DDS::HANDLE_NIL) {
     204           0 :     ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     205           0 :     remote_participant_permissions_handles_[id] = handle;
     206             : 
     207           0 :     if (DCPS::security_debug.bookkeeping) {
     208           0 :       ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     209             :                  ACE_TEXT("HandleRegistry::insert_remote_participant_permissions_handle %C %d (total %B)\n"),
     210             :                  DCPS::LogGuid(id).c_str(),
     211             :                  handle,
     212             :                  remote_participant_permissions_handles_.size()));
     213             :     }
     214           0 :   }
     215             : }
     216             : 
     217             : DDS::Security::PermissionsHandle
     218           0 : HandleRegistry::get_remote_participant_permissions_handle(const DCPS::GUID_t& id) const
     219             : {
     220           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, DDS::HANDLE_NIL);
     221           0 :   PermissionsHandleMap::const_iterator pos = remote_participant_permissions_handles_.find(id);
     222           0 :   if (pos != remote_participant_permissions_handles_.end()) {
     223           0 :     return pos->second;
     224             :   }
     225           0 :   return DDS::HANDLE_NIL;
     226           0 : }
     227             : 
     228             : void
     229           0 : HandleRegistry::erase_remote_participant_permissions_handle(const DCPS::GUID_t& id)
     230             : {
     231           0 :   ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     232           0 :   remote_participant_permissions_handles_.erase(id);
     233             : 
     234           0 :   if (DCPS::security_debug.bookkeeping) {
     235           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     236             :                ACE_TEXT("HandleRegistry::erase_remote_participant_permissions_handle %C (total %B)\n"),
     237             :                DCPS::LogGuid(id).c_str(),
     238             :                remote_participant_permissions_handles_.size()));
     239             :   }
     240           0 : }
     241             : 
     242             : void
     243           0 : HandleRegistry::insert_remote_datareader_crypto_handle(const DCPS::GUID_t& id,
     244             :                                                        DDS::Security::DatareaderCryptoHandle handle,
     245             :                                                        const DDS::Security::EndpointSecurityAttributes& attributes)
     246             : {
     247           0 :   if (handle != DDS::HANDLE_NIL) {
     248           0 :     ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     249           0 :     remote_datareader_crypto_handles_[id] = std::make_pair(handle, attributes);
     250           0 :   }
     251             : 
     252           0 :   if (DCPS::security_debug.bookkeeping) {
     253           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     254             :                ACE_TEXT("HandleRegistry::insert_remote_datareader_crypto_handle %C %d (total %B)\n"),
     255             :                DCPS::LogGuid(id).c_str(),
     256             :                handle,
     257             :                remote_datareader_crypto_handles_.size()));
     258             :   }
     259             : }
     260             : 
     261             : DDS::Security::DatareaderCryptoHandle
     262           0 : HandleRegistry::get_remote_datareader_crypto_handle(const DCPS::GUID_t& id) const
     263             : {
     264           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, DDS::HANDLE_NIL);
     265           0 :   DatareaderCryptoHandleMap::const_iterator pos = remote_datareader_crypto_handles_.find(id);
     266           0 :   if (pos != remote_datareader_crypto_handles_.end()) {
     267           0 :     return pos->second.first;
     268             :   }
     269           0 :   return DDS::HANDLE_NIL;
     270           0 : }
     271             : 
     272             : const DDS::Security::EndpointSecurityAttributes&
     273           0 : HandleRegistry::get_remote_datareader_security_attributes(const DCPS::GUID_t& id) const
     274             : {
     275           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, default_endpoint_security_attributes_);
     276           0 :   DatareaderCryptoHandleMap::const_iterator pos = remote_datareader_crypto_handles_.find(id);
     277           0 :   if (pos != remote_datareader_crypto_handles_.end()) {
     278           0 :     return pos->second.second;
     279             :   }
     280           0 :   return default_endpoint_security_attributes_;
     281           0 : }
     282             : 
     283             : HandleRegistry::DatareaderCryptoHandleList
     284           0 : HandleRegistry::get_all_remote_datareaders(const DCPS::GUID_t& prefix) const
     285             : {
     286           0 :   DatareaderCryptoHandleList retval;
     287           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, retval);
     288           0 :   for (DatareaderCryptoHandleMap::const_iterator pos =
     289           0 :          remote_datareader_crypto_handles_.lower_bound(DCPS::make_id(prefix, DCPS::ENTITYID_UNKNOWN)),
     290           0 :          limit = remote_datareader_crypto_handles_.end();
     291           0 :        pos != limit && DCPS::equal_guid_prefixes(pos->first, prefix); ++pos) {
     292           0 :     retval.push_back(std::make_pair(pos->first, pos->second.first));
     293             :   }
     294           0 :   return retval;
     295           0 : }
     296             : 
     297             : void
     298           0 : HandleRegistry::erase_remote_datareader_crypto_handle(const DCPS::GUID_t& id)
     299             : {
     300           0 :   ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     301           0 :   remote_datareader_crypto_handles_.erase(id);
     302             : 
     303           0 :   if (DCPS::security_debug.bookkeeping) {
     304           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     305             :                ACE_TEXT("HandleRegistry::erase_remote_datareader_crypto_handle %C (total %B)\n"),
     306             :                DCPS::LogGuid(id).c_str(),
     307             :                remote_datareader_crypto_handles_.size()));
     308             :   }
     309           0 : }
     310             : 
     311             : void
     312           0 : HandleRegistry::insert_remote_datawriter_crypto_handle(const DCPS::GUID_t& id,
     313             :                                                        DDS::Security::DatawriterCryptoHandle handle,
     314             :                                                        const DDS::Security::EndpointSecurityAttributes& attributes)
     315             : {
     316           0 :   OPENDDS_ASSERT(id.entityId != DCPS::ENTITYID_UNKNOWN);
     317           0 :   if (handle != DDS::HANDLE_NIL) {
     318           0 :     ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     319           0 :     remote_datawriter_crypto_handles_[id] = std::make_pair(handle, attributes);
     320             : 
     321           0 :     if (DCPS::security_debug.bookkeeping) {
     322           0 :       ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     323             :                  ACE_TEXT("HandleRegistry::insert_remote_datawriter_crypto_handle %C %d (total %B)\n"),
     324             :                  DCPS::LogGuid(id).c_str(),
     325             :                  handle,
     326             :                  remote_datawriter_crypto_handles_.size()));
     327             :     }
     328           0 :   }
     329             : }
     330             : 
     331             : DDS::Security::DatawriterCryptoHandle
     332           0 : HandleRegistry::get_remote_datawriter_crypto_handle(const DCPS::GUID_t& id) const
     333             : {
     334           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, DDS::HANDLE_NIL);
     335           0 :   DatawriterCryptoHandleMap::const_iterator pos = remote_datawriter_crypto_handles_.find(id);
     336           0 :   if (pos != remote_datawriter_crypto_handles_.end()) {
     337           0 :     return pos->second.first;
     338             :   }
     339           0 :   return DDS::HANDLE_NIL;
     340           0 : }
     341             : 
     342             : const DDS::Security::EndpointSecurityAttributes&
     343           0 : HandleRegistry::get_remote_datawriter_security_attributes(const DCPS::GUID_t& id) const
     344             : {
     345           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, default_endpoint_security_attributes_);
     346           0 :   DatawriterCryptoHandleMap::const_iterator pos = remote_datawriter_crypto_handles_.find(id);
     347           0 :   if (pos != remote_datawriter_crypto_handles_.end()) {
     348           0 :     return pos->second.second;
     349             :   }
     350           0 :   return default_endpoint_security_attributes_;
     351           0 : }
     352             : 
     353             : HandleRegistry::DatawriterCryptoHandleList
     354           0 : HandleRegistry::get_all_remote_datawriters(const DCPS::GUID_t& prefix) const
     355             : {
     356           0 :   DatawriterCryptoHandleList retval;
     357           0 :   ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, retval);
     358           0 :   for (DatawriterCryptoHandleMap::const_iterator pos =
     359           0 :          remote_datawriter_crypto_handles_.lower_bound(DCPS::make_id(prefix, DCPS::ENTITYID_UNKNOWN)),
     360           0 :          limit = remote_datawriter_crypto_handles_.end();
     361           0 :        pos != limit && DCPS::equal_guid_prefixes(pos->first, prefix); ++pos) {
     362           0 :     retval.push_back(std::make_pair(pos->first, pos->second.first));
     363             :   }
     364           0 :   return retval;
     365           0 : }
     366             : 
     367             : void
     368           0 : HandleRegistry::erase_remote_datawriter_crypto_handle(const DCPS::GUID_t& id)
     369             : {
     370           0 :   ACE_GUARD(ACE_Thread_Mutex, guard, mutex_);
     371           0 :   remote_datawriter_crypto_handles_.erase(id);
     372             : 
     373           0 :   if (DCPS::security_debug.bookkeeping) {
     374           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
     375             :                ACE_TEXT("HandleRegistry::erase_remote_datawriter_crypto_handle %C (total %B)\n"),
     376             :                DCPS::LogGuid(id).c_str(),
     377             :                remote_datawriter_crypto_handles_.size()));
     378             :   }
     379           0 : }
     380             : 
     381             : } // Security
     382             : } // OpenDDS
     383             : 
     384             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     385             : 
     386             : #endif // OPENDDS_SECURITY

Generated by: LCOV version 1.16