EndpointSecurityAttributes.h 6.2 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 EndpointSecurityAttributes.h
  16. */
  17. #ifndef _FASTDDS_RTPS_SECURITY_ACCESSCONTROL_ENDPOINTSECURITYATTRIBUTES_H_
  18. #define _FASTDDS_RTPS_SECURITY_ACCESSCONTROL_ENDPOINTSECURITYATTRIBUTES_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 PluginEndpointSecurityAttributesMask;
  25. #define PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED (0x00000001UL << 0)
  26. #define PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED (0x00000001UL << 1)
  27. #define PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED (0x00000001UL << 2)
  28. #define PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID (0x00000001UL << 31)
  29. #define PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_MASK_DEFAULT PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID
  30. struct PluginEndpointSecurityAttributes
  31. {
  32. PluginEndpointSecurityAttributes() :
  33. is_submessage_encrypted(false), is_submessage_origin_authenticated(false), is_payload_encrypted(false)
  34. { }
  35. explicit PluginEndpointSecurityAttributes(const PluginEndpointSecurityAttributesMask mask) :
  36. is_submessage_encrypted((mask & PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED) != 0),
  37. is_submessage_origin_authenticated((mask & PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED) != 0),
  38. is_payload_encrypted((mask & PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED) != 0)
  39. {
  40. }
  41. bool is_submessage_encrypted;
  42. bool is_submessage_origin_authenticated;
  43. bool is_payload_encrypted;
  44. inline PluginEndpointSecurityAttributesMask mask() const
  45. {
  46. PluginEndpointSecurityAttributesMask rv = PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID;
  47. if (is_submessage_encrypted) rv |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ENCRYPTED;
  48. if (is_submessage_origin_authenticated) rv |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_ORIGIN_AUTHENTICATED;
  49. if (is_payload_encrypted) rv |= PLUGIN_ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_ENCRYPTED;
  50. return rv;
  51. }
  52. };
  53. typedef uint32_t EndpointSecurityAttributesMask;
  54. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_READ_PROTECTED (0x00000001UL << 0)
  55. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_WRITE_PROTECTED (0x00000001UL << 1)
  56. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED (0x00000001UL << 2)
  57. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_PROTECTED (0x00000001UL << 3)
  58. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_PROTECTED (0x00000001UL << 4)
  59. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_KEY_PROTECTED (0x00000001UL << 5)
  60. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED (0x00000001UL << 6)
  61. #define ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID (0x00000001UL << 31)
  62. struct EndpointSecurityAttributes
  63. {
  64. EndpointSecurityAttributes() :
  65. is_read_protected(true), is_write_protected(true),
  66. is_discovery_protected(false), is_liveliness_protected(false),
  67. is_submessage_protected(false), is_payload_protected(false), is_key_protected(false),
  68. plugin_endpoint_attributes(0UL)
  69. {}
  70. explicit EndpointSecurityAttributes(const EndpointSecurityAttributesMask mask) :
  71. is_read_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_READ_PROTECTED) != 0),
  72. is_write_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_WRITE_PROTECTED) != 0),
  73. is_discovery_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED) != 0),
  74. is_liveliness_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED) != 0),
  75. is_submessage_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_PROTECTED) != 0),
  76. is_payload_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_PROTECTED) != 0),
  77. is_key_protected((mask & ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_KEY_PROTECTED) != 0),
  78. plugin_endpoint_attributes(0UL)
  79. {}
  80. bool is_read_protected;
  81. bool is_write_protected;
  82. bool is_discovery_protected;
  83. bool is_liveliness_protected;
  84. bool is_submessage_protected;
  85. bool is_payload_protected;
  86. bool is_key_protected;
  87. PluginEndpointSecurityAttributesMask plugin_endpoint_attributes;
  88. inline EndpointSecurityAttributesMask mask() const
  89. {
  90. EndpointSecurityAttributesMask rv = ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID;
  91. if (is_read_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_READ_PROTECTED;
  92. if (is_write_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_WRITE_PROTECTED;
  93. if (is_discovery_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED;
  94. if (is_liveliness_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED;
  95. if (is_submessage_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_PROTECTED;
  96. if (is_payload_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_PROTECTED;
  97. if (is_key_protected) rv |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_KEY_PROTECTED;
  98. return rv;
  99. }
  100. inline bool match(const EndpointSecurityAttributesMask remoteMask,
  101. const PluginEndpointSecurityAttributesMask remotePluginMask) const
  102. {
  103. return security_mask_matches(mask(), remoteMask) &&
  104. security_mask_matches(plugin_endpoint_attributes, remotePluginMask);
  105. }
  106. };
  107. }
  108. }
  109. }
  110. }
  111. #endif // _FASTDDS_RTPS_SECURITY_ACCESSCONTROL_ENDPOINTSECURITYATTRIBUTES_H_