aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/tls
diff options
context:
space:
mode:
authorHannes Rantzsch <[email protected]>2019-06-13 13:18:44 +0200
committerHannes Rantzsch <[email protected]>2019-06-13 13:31:56 +0200
commit72c6245b4a27998dab66f849a2e471b24c494eb9 (patch)
treec75cef8c40a88eb0c9796142e4c5d7489ade2eca /src/lib/tls
parent54d1dcfaab369aa764b6dadce5310634da26a15e (diff)
TLS::Context holds references rather than pointers
Parameters passed from TLS::Context to TLS::Client for initialization are now held as references in the context. Ownership of these members is thereby explicitly left with the user. Co-authored-by: Tim Oesterreich <[email protected]>
Diffstat (limited to 'src/lib/tls')
-rw-r--r--src/lib/tls/asio/asio_context.h56
-rw-r--r--src/lib/tls/asio/asio_stream.h51
2 files changed, 60 insertions, 47 deletions
diff --git a/src/lib/tls/asio/asio_context.h b/src/lib/tls/asio/asio_context.h
index c61086497..e5e99e83a 100644
--- a/src/lib/tls/asio/asio_context.h
+++ b/src/lib/tls/asio/asio_context.h
@@ -53,22 +53,24 @@ class Context
using Verify_Callback =
detail::fn_signature_helper<decltype(&Callbacks::tls_verify_cert_chain)>::type;
- Context(Credentials_Manager* credentialsManager,
- RandomNumberGenerator* randomNumberGenerator,
- Session_Manager* sessionManager,
- Policy* policy,
- Server_Information serverInfo = Server_Information()) :
- credentialsManager(credentialsManager),
- randomNumberGenerator(randomNumberGenerator),
- sessionManager(sessionManager),
- policy(policy),
- serverInfo(serverInfo)
+ Context(Credentials_Manager& credentials_manager,
+ RandomNumberGenerator& rng,
+ Session_Manager& session_manager,
+ Policy& policy,
+ Server_Information server_info = Server_Information()) :
+ m_credentials_manager(credentials_manager),
+ m_rng(rng),
+ m_session_manager(session_manager),
+ m_policy(policy),
+ m_server_info(server_info)
{}
- Context(const Context& other) = delete;
- Context& operator=(const Context& other) = delete;
- Context(Context&& other) = default;
- Context& operator=(Context&& other) = default;
+ virtual ~Context() = default;
+
+ Context(Context&&) = default;
+ Context(const Context&) = delete;
+ Context& operator=(const Context&) = delete;
+ Context& operator=(Context&&) = delete;
/**
* @brief Override the tls_verify_cert_chain callback
@@ -81,24 +83,34 @@ class Context
*/
void set_verify_callback(Verify_Callback callback)
{
- verifyCallback = std::move(callback);
+ m_verify_callback = std::move(callback);
}
bool has_verify_callback() const
{
- return static_cast<bool>(verifyCallback);
+ return static_cast<bool>(m_verify_callback);
+ }
+
+ const Verify_Callback& get_verify_callback() const
+ {
+ return m_verify_callback;
+ }
+
+ void set_server_info(const Server_Information& server_info)
+ {
+ m_server_info = server_info;
}
protected:
template <class S, class C> friend class Stream;
- Credentials_Manager* credentialsManager;
- RandomNumberGenerator* randomNumberGenerator;
- Session_Manager* sessionManager;
- Policy* policy;
+ Credentials_Manager& m_credentials_manager;
+ RandomNumberGenerator& m_rng;
+ Session_Manager& m_session_manager;
+ Policy& m_policy;
- Server_Information serverInfo;
- Verify_Callback verifyCallback;
+ Server_Information m_server_info;
+ Verify_Callback m_verify_callback;
};
} // namespace TLS
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h
index 8fd309bc7..e8d9c2930 100644
--- a/src/lib/tls/asio/asio_stream.h
+++ b/src/lib/tls/asio/asio_stream.h
@@ -52,14 +52,14 @@ class Stream
//! \name construction
//! @{
- /**
- * @brief Construct a new Stream
- *
- * @param context The context parameter is used to set up the underlying native handle. Using code is
- * responsible for lifetime management of the context and must ensure that it is available for the
- * lifetime of the stream.
- * @param args Arguments to be forwarded to the construction of the next layer.
- */
+ /**
+ * @brief Construct a new Stream
+ *
+ * @param context The context parameter is used to set up the underlying native handle. Using code is
+ * responsible for lifetime management of the context and must ensure that it is available for the
+ * lifetime of the stream.
+ * @param args Arguments to be forwarded to the construction of the next layer.
+ */
template <typename... Args>
explicit Stream(Context& context, Args&& ... args)
: m_context(context)
@@ -69,16 +69,16 @@ class Stream
, m_input_buffer(m_input_buffer_space.data(), m_input_buffer_space.size())
{}
- /**
- * @brief Construct a new Stream
- *
- * Convenience overload for boost::asio::ssl::stream compatibility.
- *
- * @param arg This argument is forwarded to the construction of the next layer.
- * @param context The context parameter is used to set up the underlying native handle. Using code is
- * responsible for lifetime management of the context and must ensure that is available for the
- * lifetime of the stream.
- */
+ /**
+ * @brief Construct a new Stream
+ *
+ * Convenience overload for boost::asio::ssl::stream compatibility.
+ *
+ * @param arg This argument is forwarded to the construction of the next layer.
+ * @param context The context parameter is used to set up the underlying native handle. Using code is
+ * responsible for lifetime management of the context and must ensure that is available for the
+ * lifetime of the stream.
+ */
template <typename Arg>
explicit Stream(Arg&& arg, Context& context)
: m_context(context)
@@ -576,7 +576,7 @@ class Stream
{
if(m_tls_context.has_verify_callback())
{
- m_tls_context.verifyCallback(cert_chain, ocsp_responses, trusted_roots, usage, hostname, policy);
+ m_tls_context.get_verify_callback()(cert_chain, ocsp_responses, trusted_roots, usage, hostname, policy);
}
else
{
@@ -637,12 +637,13 @@ class Stream
{
if(side == CLIENT)
{
- m_native_handle = std::unique_ptr<Client>(new Client(m_core,
- *m_context.sessionManager,
- *m_context.credentialsManager,
- *m_context.policy,
- *m_context.randomNumberGenerator,
- m_context.serverInfo));
+ m_native_handle = std::unique_ptr<Client>(
+ new Client(m_core,
+ m_context.m_session_manager,
+ m_context.m_credentials_manager,
+ m_context.m_policy,
+ m_context.m_rng,
+ m_context.m_server_info));
}
else
{