ParticipantSecurityAttributes.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*!
  15. * @file ParticipantSecurityAttributes.h
  16. */
  17. #ifndef _FASTDDS_RTPS_SECURITY_ACCESSCONTROL_PARTICIPANTSECURITYATTRIBUTES_H_
  18. #define _FASTDDS_RTPS_SECURITY_ACCESSCONTROL_PARTICIPANTSECURITYATTRIBUTES_H_
  19. #include <fastdds/rtps/security/accesscontrol/SecurityMaskUtilities.h>
  20. namespace eprosima {
  21. namespace fastrtps {
  22. namespace rtps {
  23. namespace security {
  24. typedef uint32_t PluginParticipantSecurityAttributesMask;
  25. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ENCRYPTED (0x00000001UL << 0)
  26. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_BUILTIN_IS_DISCOVERY_ENCRYPTED (0x00000001UL << 1)
  27. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_ENCRYPTED (0x00000001UL << 2)
  28. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ORIGIN_AUTHENTICATED (0x00000001UL << 3)
  29. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_ORIGIN_AUTHENTICATED (0x00000001UL << 4)
  30. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_ORIGIN_AUTHENTICATED (0x00000001UL << 5)
  31. #define PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID (0x00000001UL << 31)
  32. struct PluginParticipantSecurityAttributes
  33. {
  34. PluginParticipantSecurityAttributes() :
  35. is_rtps_encrypted(false), is_discovery_encrypted(false), is_liveliness_encrypted(false),
  36. is_rtps_origin_authenticated(false), is_discovery_origin_authenticated(false),
  37. is_liveliness_origin_authenticated(false)
  38. {}
  39. explicit PluginParticipantSecurityAttributes(const PluginParticipantSecurityAttributesMask mask) :
  40. is_rtps_encrypted((mask & PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ENCRYPTED) != 0),
  41. is_discovery_encrypted((mask & PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_BUILTIN_IS_DISCOVERY_ENCRYPTED) != 0),
  42. is_liveliness_encrypted((mask & PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_ENCRYPTED) != 0),
  43. is_rtps_origin_authenticated((mask & PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ORIGIN_AUTHENTICATED) != 0),
  44. is_discovery_origin_authenticated((mask & PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_ORIGIN_AUTHENTICATED) != 0),
  45. is_liveliness_origin_authenticated((mask & PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_ORIGIN_AUTHENTICATED) != 0)
  46. {}
  47. bool is_rtps_encrypted;
  48. bool is_discovery_encrypted;
  49. bool is_liveliness_encrypted;
  50. bool is_rtps_origin_authenticated;
  51. bool is_discovery_origin_authenticated;
  52. bool is_liveliness_origin_authenticated;
  53. inline PluginParticipantSecurityAttributesMask mask() const
  54. {
  55. PluginParticipantSecurityAttributesMask rv = PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID;
  56. if (is_rtps_encrypted) rv |= PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ENCRYPTED;
  57. if (is_discovery_encrypted) rv |= PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_BUILTIN_IS_DISCOVERY_ENCRYPTED;
  58. if (is_liveliness_encrypted) rv |= PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_ENCRYPTED;
  59. if (is_rtps_origin_authenticated) rv |= PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_ORIGIN_AUTHENTICATED;
  60. if (is_discovery_origin_authenticated) rv |= PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_ORIGIN_AUTHENTICATED;
  61. if (is_liveliness_origin_authenticated) rv |= PLUGIN_PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_ORIGIN_AUTHENTICATED;
  62. return rv;
  63. }
  64. };
  65. typedef uint32_t ParticipantSecurityAttributesMask;
  66. #define PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_PROTECTED (0x00000001UL << 0)
  67. #define PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED (0x00000001UL << 1)
  68. #define PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED (0x00000001UL << 2)
  69. #define PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID (0x00000001UL << 31)
  70. struct ParticipantSecurityAttributes
  71. {
  72. ParticipantSecurityAttributes() :
  73. allow_unauthenticated_participants(false), is_access_protected(true),
  74. is_rtps_protected(false), is_discovery_protected(false), is_liveliness_protected(false),
  75. plugin_participant_attributes (0UL)
  76. {}
  77. explicit ParticipantSecurityAttributes(const ParticipantSecurityAttributesMask mask) :
  78. allow_unauthenticated_participants(false), is_access_protected(true),
  79. is_rtps_protected((mask & PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_PROTECTED) != 0),
  80. is_discovery_protected((mask & PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED) != 0),
  81. is_liveliness_protected((mask & PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED) != 0),
  82. plugin_participant_attributes(0UL)
  83. {}
  84. bool allow_unauthenticated_participants;
  85. bool is_access_protected;
  86. bool is_rtps_protected;
  87. bool is_discovery_protected;
  88. bool is_liveliness_protected;
  89. PluginParticipantSecurityAttributesMask plugin_participant_attributes;
  90. inline ParticipantSecurityAttributesMask mask() const
  91. {
  92. ParticipantSecurityAttributesMask rv = PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID;
  93. if (is_rtps_protected) rv |= PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_PROTECTED;
  94. if (is_discovery_protected) rv |= PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED;
  95. if (is_liveliness_protected) rv |= PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED;
  96. return rv;
  97. }
  98. inline bool match(const ParticipantSecurityAttributesMask remoteMask,
  99. const PluginParticipantSecurityAttributesMask remotePluginMask) const
  100. {
  101. return security_mask_matches(mask(), remoteMask) &&
  102. security_mask_matches(plugin_participant_attributes, remotePluginMask);
  103. }
  104. };
  105. }
  106. }
  107. }
  108. }
  109. #endif // _FASTDDS_RTPS_SECURITY_ACCESSCONTROL_PARTICIPANTSECURITYATTRIBUTES_H_