LCOV - code coverage report
Current view: top level - DCPS/security/AccessControl - LocalAccessCredentialData.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 39 64.1 %
Date: 2023-04-30 01:32:43 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.OpenDDS.org/license.html
       4             :  */
       5             : 
       6             : #include "LocalAccessCredentialData.h"
       7             : 
       8             : #include "dds/DCPS/security/CommonUtilities.h"
       9             : #include "dds/DCPS/security/framework/Properties.h"
      10             : 
      11             : #include "dds/DCPS/debug.h"
      12             : 
      13             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      14             : 
      15             : namespace OpenDDS {
      16             : namespace Security {
      17             : 
      18          22 : LocalAccessCredentialData::LocalAccessCredentialData()
      19             : {
      20             : 
      21          22 : }
      22             : 
      23          44 : LocalAccessCredentialData::~LocalAccessCredentialData()
      24             : {
      25          44 : }
      26             : 
      27          22 : bool LocalAccessCredentialData::load(const DDS::PropertySeq& props,
      28             :                                      DDS::Security::SecurityException& ex)
      29             : {
      30          88 :   for (unsigned int i = 0; i < props.length(); ++i) {
      31          66 :     const std::string name(props[i].name);
      32          66 :     const std::string value(props[i].value);
      33             : 
      34          66 :     if (name == DDS::Security::Properties::AccessPermissionsCA) {
      35          22 :       ca_cert_.reset(new SSL::Certificate(value));
      36             : 
      37          44 :     } else if (name == DDS::Security::Properties::AccessGovernance) {
      38          22 :       if (!governance_doc_.load(value, ex)) {
      39           0 :         return false;
      40             :       }
      41             : 
      42          22 :     } else if (name == DDS::Security::Properties::AccessPermissions) {
      43          22 :       if (!permissions_doc_.load(value, ex)) {
      44           0 :         return false;
      45             :       }
      46             :     }
      47          66 :   }
      48             : 
      49          22 :   if (! ca_cert_) {
      50           0 :     CommonUtilities::set_security_error(ex, -1, 0, "LocalAccessCredentialData::load: CA certificate data not provided");
      51           0 :     return false;
      52             :   }
      53             : 
      54          22 :   if (governance_doc_.original().length() == 0) {
      55           0 :     CommonUtilities::set_security_error(ex, -1, 0, "LocalAccessCredentialData::load: Governance data not provided");
      56           0 :     return false;
      57             :   }
      58             : 
      59          22 :   if (permissions_doc_.original().length() == 0) {
      60           0 :     CommonUtilities::set_security_error(ex, -1, 0, "LocalAccessCredentialData::load: Permissions data not provided");
      61           0 :     return false;
      62             :   }
      63             : 
      64          22 :   return true;
      65             : }
      66             : 
      67          22 : bool LocalAccessCredentialData::verify(DDS::Security::SecurityException& ex)
      68             : {
      69          22 :   if (!governance_doc_.verify(*ca_cert_)) {
      70           0 :     CommonUtilities::set_security_error(ex, -1, 0, "LocalAccessCredentialData::verify: Governance signature not verified");
      71           0 :     return false;
      72          22 :   } else if (DCPS::DCPS_debug_level) {
      73           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) LocalAccessCredentialData::verify: Governance signature verified\n")));
      74             :   }
      75             : 
      76          22 :   if (!permissions_doc_.verify(*ca_cert_)) {
      77           0 :     CommonUtilities::set_security_error(ex, -1, 0, "LocalAccessCredentialData::verify: Permissions signature not verified");
      78           0 :     return false;
      79          22 :   } else if (DCPS::DCPS_debug_level) {
      80           0 :     ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) AccessControlBuiltInImpl::validate_local_permissions: Permissions signature verified\n")));
      81             :   }
      82             : 
      83          22 :   return true;
      84             : }
      85             : 
      86             : }
      87             : }
      88             : 
      89             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16