Skip to content

Commit 717a82a

Browse files
authored
Bug fix, small refactor and tests in TlsConfiguration (#244)
* Refs #15012: Refactor in TLS configurations Signed-off-by: Anton Rey <aanton.rv@gmail.com> * Refs #15012: TlsConfiguration interfaces changes Signed-off-by: Anton Rey <aanton.rv@gmail.com> * Refs #15012: Added unit tests on TlsConfiguration Signed-off-by: Anton Rey <aanton.rv@gmail.com> * uncrustify Signed-off-by: Anton Rey <aanton.rv@gmail.com> * Refs #15012: Review changes Signed-off-by: Anton Rey <aanton.rv@gmail.com> * Refs #15012: Win build fix Signed-off-by: Anton Rey <aanton.rv@gmail.com> * Refs #15012: Add release notes Signed-off-by: Anton Rey <aanton.rv@gmail.com>
1 parent ce4904f commit 717a82a

17 files changed

Lines changed: 467 additions & 611 deletions

File tree

ddsrouter_core/include/ddsrouter_core/configuration/participant/DiscoveryServerParticipantConfiguration.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigur
4747
const std::set<types::Address>& listening_addresses,
4848
const std::set<types::DiscoveryServerConnectionAddress>& connection_addresses,
4949
const types::ParticipantKind& kind = types::ParticipantKind::local_discovery_server,
50-
std::shared_ptr<types::security::TlsConfiguration> tls_configuration =
51-
std::make_shared<types::security::TlsConfiguration>(),
50+
const types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration(),
5251
const types::DomainId& domain_id = DEFAULT_DS_DOMAIN_ID_);
5352

5453
// TODO
@@ -59,8 +58,7 @@ class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigur
5958
const std::set<types::DiscoveryServerConnectionAddress>& connection_addresses,
6059
const types::DomainId& domain_id,
6160
const types::ParticipantKind& kind = types::ParticipantKind::local_discovery_server,
62-
std::shared_ptr<types::security::TlsConfiguration> tls_configuration =
63-
std::make_shared<types::security::TlsConfiguration>());
61+
const types::security::TlsConfiguration tls_configuration = types::security::TlsConfiguration());
6462

6563
DDSROUTER_CORE_DllAPI types::GuidPrefix discovery_server_guid_prefix() const noexcept;
6664

@@ -70,7 +68,7 @@ class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigur
7068

7169
DDSROUTER_CORE_DllAPI bool tls_active() const noexcept;
7270

73-
DDSROUTER_CORE_DllAPI std::shared_ptr<types::security::TlsConfiguration> tls_configuration() const;
71+
DDSROUTER_CORE_DllAPI const types::security::TlsConfiguration& tls_configuration() const noexcept;
7472

7573
DDSROUTER_CORE_DllAPI virtual bool is_valid(
7674
utils::Formatter& error_msg) const noexcept override;
@@ -85,7 +83,7 @@ class DiscoveryServerParticipantConfiguration : public SimpleParticipantConfigur
8583
types::GuidPrefix discovery_server_guid_prefix_;
8684
std::set<types::Address> listening_addresses_;
8785
std::set<types::DiscoveryServerConnectionAddress> connection_addresses_;
88-
std::shared_ptr<types::security::TlsConfiguration> tls_configuration_;
86+
const types::security::TlsConfiguration tls_configuration_;
8987

9088
DDSROUTER_CORE_DllAPI static const types::DomainId DEFAULT_DS_DOMAIN_ID_; // 66
9189
};

ddsrouter_core/include/ddsrouter_core/types/security/tls/TlsConfiguration.hpp

Lines changed: 134 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,151 @@ namespace core {
2929
namespace types {
3030
namespace security {
3131

32-
enum TlsConfigurationKind
32+
/**
33+
* @brief Enumeration of kinds of TLS configurations.
34+
*/
35+
enum class TlsKind
3336
{
34-
TLS_INVALID,
35-
TLS_CLIENT,
36-
TLS_SERVER,
37-
TLS_BOTH,
37+
inactive,
38+
client,
39+
server,
40+
both,
3841
};
3942

43+
4044
/**
41-
* This class joins data to configure TLS
42-
*
43-
* TODO: comment
45+
* Configuration holding TLS parameters.
4446
*/
4547
class TlsConfiguration
4648
{
4749
public:
4850

51+
/**
52+
* @brief Constructs an undefined or inactive (valid nonetheless) TLSConfiguration
53+
*
54+
*/
4955
DDSROUTER_CORE_DllAPI TlsConfiguration();
5056

51-
DDSROUTER_CORE_DllAPI virtual bool is_valid() const noexcept;
52-
53-
DDSROUTER_CORE_DllAPI virtual bool is_active() const noexcept;
54-
55-
DDSROUTER_CORE_DllAPI virtual bool can_be_client() const noexcept;
56-
57-
DDSROUTER_CORE_DllAPI virtual bool can_be_server() const noexcept;
58-
59-
DDSROUTER_CORE_DllAPI virtual TlsConfigurationKind tls_kind() const noexcept;
60-
61-
protected:
62-
63-
TlsConfiguration(
64-
TlsConfigurationKind kind);
65-
66-
TlsConfigurationKind kind_;
57+
/**
58+
* @brief Constructs client-oriented TLSConfiguration
59+
*
60+
* @param certificate_authority_file for the client
61+
*
62+
* @throw \c InitializationException if file is invalid.
63+
*/
64+
DDSROUTER_CORE_DllAPI TlsConfiguration(
65+
std::string certificate_authority_file);
66+
67+
/**
68+
* @brief Constructs server-oriented TLSConfiguration
69+
*
70+
* @param std::string private_key_file_password file for the server
71+
* @param std::string private_key_file file for the server
72+
* @param std::string certificate_chain_file file for the server
73+
* @param std::string dh_params_file file for the server
74+
*
75+
* @throw \c InitializationException if any file is invalid.
76+
*/
77+
DDSROUTER_CORE_DllAPI TlsConfiguration(
78+
std::string private_key_file_password,
79+
std::string private_key_file,
80+
std::string certificate_chain_file,
81+
std::string dh_params_file);
82+
83+
/**
84+
* @brief Constructs client-and-server-oriented TLSConfiguration
85+
*
86+
* @param certificate_authority_file for the client
87+
* @param std::string private_key_file_password file for the server
88+
* @param std::string private_key_file for the server
89+
* @param std::string certificate_chain_file for the server
90+
* @param std::string dh_params_file for the server
91+
*
92+
* @throw \c InitializationException if any file is invalid.
93+
*/
94+
DDSROUTER_CORE_DllAPI TlsConfiguration(
95+
std::string certificate_authority_file,
96+
std::string private_key_file_password,
97+
std::string private_key_file,
98+
std::string certificate_chain_file,
99+
std::string dh_params_file);
100+
101+
/**
102+
* @brief Returns whether configuration is active
103+
*/
104+
DDSROUTER_CORE_DllAPI bool is_active() const noexcept;
105+
106+
/**
107+
* @brief Check configuration kind compatibility
108+
*
109+
* @tparam Kind TlsConfiguration kind
110+
*
111+
* @return Whether configuration is compatible with parameter \c TlsKind
112+
*/
113+
template <TlsKind Kind>
114+
bool compatible() const noexcept
115+
{
116+
return this->kind_ != TlsKind::inactive &&
117+
(Kind == this->kind_ || (this->kind_ == TlsKind::both && Kind != TlsKind::inactive));
118+
}
119+
120+
/**
121+
* @brief certificate_authority_file getter
122+
*
123+
* @throw \c InconsistencyException if configuration is not client-compatible
124+
*/
125+
DDSROUTER_CORE_DllAPI const std::string& certificate_authority_file() const;
126+
127+
/**
128+
* @brief private_key_file_password getter
129+
*
130+
* @throw \c InconsistencyException if configuration is not server-compatible
131+
*/
132+
DDSROUTER_CORE_DllAPI const std::string& private_key_file_password() const;
133+
134+
/**
135+
* @brief private_key_file getter
136+
*
137+
* @throw \c InconsistencyException if configuration is not server-compatible
138+
*/
139+
DDSROUTER_CORE_DllAPI const std::string& private_key_file() const;
140+
141+
/**
142+
* @brief certificate_chain_file getter
143+
*
144+
* @throw \c InconsistencyException if configuration is not server-compatible
145+
*/
146+
DDSROUTER_CORE_DllAPI const std::string& certificate_chain_file() const;
147+
148+
/**
149+
* @brief dh_params_file getter
150+
*
151+
* @throw \c InconsistencyException if configuration is not server-compatible
152+
*/
153+
DDSROUTER_CORE_DllAPI const std::string& dh_params_file() const;
154+
155+
private:
156+
157+
//! Internal throwing check
158+
template <TlsKind Kind>
159+
void check_valid_() const;
160+
161+
////////
162+
// MEMBERS
163+
164+
//! Configuration Kind
165+
TlsKind kind_;
166+
167+
////////
168+
// CLIENT-ONLY VARIABLES
169+
std::string certificate_authority_file_;
170+
171+
////////
172+
// SERVER-ONLY VARIABLES
173+
std::string private_key_file_password_;
174+
std::string private_key_file_;
175+
std::string certificate_chain_file_;
176+
std::string dh_params_file_;
67177
};
68178

69179
} /* namespace security */

ddsrouter_core/include/ddsrouter_core/types/security/tls/TlsConfigurationBoth.hpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

ddsrouter_core/include/ddsrouter_core/types/security/tls/TlsConfigurationClient.hpp

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)