SecurityHelpers.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_SECURITY_HELPERS_H
00009 #define OPENDDS_SECURITY_HELPERS_H
00010 
00011 #include "dds/DdsSecurityCoreC.h"
00012 
00013 namespace OpenDDS {
00014 namespace RTPS {
00015 
00016 /*
00017  * The below entities are from the security spec. V1.1
00018  * section 7.3.7.1 "Mapping of the EntityIds for the Builtin DataWriters and DataReaders"
00019  */
00020 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_SECURE_WRITER = {{0xff, 0x00, 0x03}, 0xc2};
00021 const EntityId_t ENTITYID_SEDP_BUILTIN_PUBLICATIONS_SECURE_READER = {{0xff, 0x00, 0x03}, 0xc7};
00022 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_SECURE_WRITER = {{0xff, 0x00, 0x04}, 0xc2};
00023 const EntityId_t ENTITYID_SEDP_BUILTIN_SUBSCRIPTIONS_SECURE_READER = {{0xff, 0x00, 0x04}, 0xc7};
00024 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_WRITER = {{0xff, 0x02, 0x00}, 0xc2};
00025 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_MESSAGE_SECURE_READER = {{0xff, 0x02, 0x00}, 0xc7};
00026 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_STATELESS_WRITER = {{0x00, 0x02, 0x01}, 0xc3};
00027 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_STATELESS_READER = {{0x00, 0x02, 0x01}, 0xc4};
00028 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_SECURE_WRITER = {{0xff, 0x02, 0x02}, 0xc3};
00029 const EntityId_t ENTITYID_P2P_BUILTIN_PARTICIPANT_VOLATILE_SECURE_READER = {{0xff, 0x02, 0x02}, 0xc4};
00030 const EntityId_t ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_WRITER = {{0xff, 0x01, 0x01}, 0xc2};
00031 const EntityId_t ENTITYID_SPDP_RELIABLE_BUILTIN_PARTICIPANT_SECURE_READER = {{0xff, 0x01, 0x01}, 0xc7};
00032 
00033 const DDS::Security::ParticipantSecurityInfo PARTICIPANT_SECURITY_ATTRIBUTES_INFO_DEFAULT = {0, 0};
00034 const DDS::Security::EndpointSecurityInfo ENDPOINT_SECURITY_ATTRIBUTES_INFO_DEFAULT = {0, 0};
00035 
00036 inline DDS::Security::ParticipantSecurityAttributesMask
00037 security_attributes_to_bitmask(const DDS::Security::ParticipantSecurityAttributes& sec_attr)
00038 {
00039   using namespace DDS::Security;
00040 
00041   ParticipantSecurityAttributesMask result = PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_VALID;
00042   if (sec_attr.is_rtps_protected) {
00043     result |= PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_RTPS_PROTECTED;
00044   }
00045   if (sec_attr.is_discovery_protected) {
00046     result |= PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED;
00047   }
00048   if (sec_attr.is_liveliness_protected) {
00049     result |= PARTICIPANT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED;
00050   }
00051   return result;
00052 }
00053 
00054 inline DDS::Security::EndpointSecurityAttributesMask
00055 security_attributes_to_bitmask(const DDS::Security::EndpointSecurityAttributes& sec_attr)
00056 {
00057   using namespace DDS::Security;
00058 
00059   EndpointSecurityAttributesMask result = ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_VALID;
00060 
00061   if (sec_attr.base.is_read_protected)
00062     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_READ_PROTECTED;
00063 
00064   if (sec_attr.base.is_write_protected)
00065     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_WRITE_PROTECTED;
00066 
00067   if (sec_attr.base.is_discovery_protected)
00068     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_DISCOVERY_PROTECTED;
00069 
00070   if (sec_attr.base.is_liveliness_protected)
00071     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_LIVELINESS_PROTECTED;
00072 
00073   if (sec_attr.is_submessage_protected)
00074     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_SUBMESSAGE_PROTECTED;
00075 
00076   if (sec_attr.is_payload_protected)
00077     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_PAYLOAD_PROTECTED;
00078 
00079   if (sec_attr.is_key_protected)
00080     result |= ENDPOINT_SECURITY_ATTRIBUTES_FLAG_IS_KEY_PROTECTED;
00081 
00082   return result;
00083 }
00084 
00085 inline DDS::OctetSeq
00086 handle_to_octets(DDS::Security::NativeCryptoHandle handle)
00087 {
00088   DDS::OctetSeq handleOctets(sizeof handle);
00089   handleOctets.length(handleOctets.maximum());
00090   unsigned char* rawHandleOctets = handleOctets.get_buffer();
00091   unsigned int handleTmp = handle;
00092   for (unsigned int j = sizeof handle; j > 0; --j) {
00093     rawHandleOctets[j - 1] = handleTmp & 0xff;
00094     handleTmp >>= 8;
00095   }
00096   return handleOctets;
00097 }
00098 
00099 struct DiscoveredWriterData_SecurityWrapper {
00100   DCPS::DiscoveredWriterData data;
00101   DDS::Security::EndpointSecurityInfo security_info;
00102   DDS::Security::DataTags data_tags;
00103 };
00104 
00105 struct DiscoveredReaderData_SecurityWrapper {
00106   DCPS::DiscoveredReaderData data;
00107   DDS::Security::EndpointSecurityInfo security_info;
00108   DDS::Security::DataTags data_tags;
00109 };
00110 
00111 }
00112 }
00113 
00114 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1