TCPTransportDescriptor.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // Copyright 2019 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. #ifndef _FASTDDS_TCP_TRANSPORT_DESCRIPTOR_H_
  15. #define _FASTDDS_TCP_TRANSPORT_DESCRIPTOR_H_
  16. #include <fastdds/rtps/transport/SocketTransportDescriptor.h>
  17. #include <fastrtps/fastrtps_dll.h>
  18. #include <iostream>
  19. namespace eprosima{
  20. namespace fastdds{
  21. namespace rtps{
  22. /**
  23. * Transport configuration
  24. * @ingroup TRANSPORT_MODULE
  25. */
  26. typedef struct TCPTransportDescriptor : public SocketTransportDescriptor
  27. {
  28. struct TLSConfig
  29. {
  30. enum TLSOptions : uint32_t
  31. {
  32. NONE = 0, // 0000 0000 0000
  33. DEFAULT_WORKAROUNDS = 1 << 0, // 0000 0000 0001
  34. NO_COMPRESSION = 1 << 1, // 0000 0000 0010
  35. NO_SSLV2 = 1 << 2, // 0000 0000 0100
  36. NO_SSLV3 = 1 << 3, // 0000 0000 1000
  37. NO_TLSV1 = 1 << 4, // 0000 0001 0000
  38. NO_TLSV1_1 = 1 << 5, // 0000 0010 0000
  39. NO_TLSV1_2 = 1 << 6, // 0000 0100 0000
  40. NO_TLSV1_3 = 1 << 7, // 0000 1000 0000
  41. SINGLE_DH_USE = 1 << 8 // 0001 0000 0000
  42. };
  43. enum TLSVerifyMode : uint8_t
  44. {
  45. UNUSED = 0, // 0000 0000
  46. VERIFY_NONE = 1 << 0, // 0000 0001
  47. VERIFY_PEER = 1 << 1, // 0000 0010
  48. VERIFY_FAIL_IF_NO_PEER_CERT = 1 << 2, // 0000 0100
  49. VERIFY_CLIENT_ONCE = 1 << 3 // 0000 1000
  50. };
  51. enum TLSHandShakeRole : uint8_t
  52. {
  53. DEFAULT = 0, // 0000 0000
  54. CLIENT = 1 << 0, // 0000 0001
  55. SERVER = 1 << 1 // 0000 0010
  56. };
  57. std::string password;
  58. uint32_t options;
  59. std::string cert_chain_file;
  60. std::string private_key_file;
  61. std::string tmp_dh_file;
  62. std::string verify_file;
  63. uint8_t verify_mode;
  64. std::vector<std::string> verify_paths;
  65. bool default_verify_path = false; // don't invoque
  66. int32_t verify_depth = -1; // don't override
  67. std::string rsa_private_key_file;
  68. TLSHandShakeRole handshake_role;
  69. void add_verify_mode(const TLSVerifyMode verify)
  70. {
  71. verify_mode |= verify;
  72. }
  73. bool get_verify_mode(const TLSVerifyMode verify) const
  74. {
  75. return (verify_mode & verify) == verify;
  76. }
  77. void add_option(const TLSOptions option)
  78. {
  79. options |= option;
  80. }
  81. bool get_option(const TLSOptions option) const
  82. {
  83. return (options & option) == option;
  84. }
  85. TLSConfig()
  86. : options(TCPTransportDescriptor::TLSConfig::TLSOptions::NONE)
  87. , verify_mode(TCPTransportDescriptor::TLSConfig::TLSVerifyMode::UNUSED)
  88. , handshake_role(DEFAULT)
  89. {
  90. }
  91. TLSConfig(const TLSConfig& t)
  92. : password(t.password)
  93. , options(t.options)
  94. , cert_chain_file(t.cert_chain_file)
  95. , private_key_file(t.private_key_file)
  96. , tmp_dh_file(t.tmp_dh_file)
  97. , verify_file(t.verify_file)
  98. , verify_mode(t.verify_mode)
  99. , verify_paths(t.verify_paths)
  100. , default_verify_path(t.default_verify_path)
  101. , verify_depth(t.verify_depth)
  102. , rsa_private_key_file(t.rsa_private_key_file)
  103. , handshake_role(t.handshake_role)
  104. {
  105. }
  106. TLSConfig(TLSConfig&& t)
  107. : password(std::move(t.password))
  108. , options(std::move(t.options))
  109. , cert_chain_file(std::move(t.cert_chain_file))
  110. , private_key_file(std::move(t.private_key_file))
  111. , tmp_dh_file(std::move(t.tmp_dh_file))
  112. , verify_file(std::move(t.verify_file))
  113. , verify_mode(std::move(t.verify_mode))
  114. , verify_paths(std::move(t.verify_paths))
  115. , default_verify_path(std::move(t.default_verify_path))
  116. , verify_depth(std::move(t.verify_depth))
  117. , rsa_private_key_file(std::move(t.rsa_private_key_file))
  118. , handshake_role(std::move(t.handshake_role))
  119. {
  120. }
  121. TLSConfig& operator=(const TLSConfig& t)
  122. {
  123. password = t.password;
  124. options = t.options;
  125. cert_chain_file = t.cert_chain_file;
  126. private_key_file = t.private_key_file;
  127. tmp_dh_file = t.tmp_dh_file;
  128. verify_file = t.verify_file;
  129. verify_mode = t.verify_mode;
  130. verify_paths = t.verify_paths;
  131. default_verify_path = t.default_verify_path;
  132. verify_depth = t.verify_depth;
  133. rsa_private_key_file = t.rsa_private_key_file;
  134. handshake_role = t.handshake_role;
  135. return *this;
  136. }
  137. };
  138. std::vector<uint16_t> listening_ports;
  139. uint32_t keep_alive_frequency_ms;
  140. uint32_t keep_alive_timeout_ms;
  141. uint16_t max_logical_port;
  142. uint16_t logical_port_range;
  143. uint16_t logical_port_increment;
  144. uint32_t tcp_negotiation_timeout;
  145. bool enable_tcp_nodelay;
  146. bool wait_for_tcp_negotiation;
  147. bool calculate_crc;
  148. bool check_crc;
  149. bool apply_security;
  150. TLSConfig tls_config;
  151. void add_listener_port(uint16_t port)
  152. {
  153. listening_ports.push_back(port);
  154. }
  155. RTPS_DllAPI TCPTransportDescriptor();
  156. RTPS_DllAPI TCPTransportDescriptor(const TCPTransportDescriptor& t);
  157. RTPS_DllAPI TCPTransportDescriptor& operator=(const TCPTransportDescriptor& t);
  158. virtual ~TCPTransportDescriptor() {}
  159. } TCPTransportDescriptor;
  160. } // namespace rtps
  161. } // namespace fastdds
  162. } // namespace eprosima
  163. #endif // _FASTDDS_TCP_TRANSPORT_DESCRIPTOR_H_