-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add socket injection into client #147
Changes from 9 commits
c243cac
bcde298
14470fb
1bef85c
d612802
d7d5399
0dca48d
e26d785
aa8a7d0
f0aa52b
b173a4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "sslsocket.h" | ||
#include "../client.h" | ||
|
||
#include <stdexcept> | ||
|
||
|
@@ -135,9 +136,11 @@ SSL_CTX * SSLContext::getContext() { | |
<< "\n\t handshake state: " << SSL_get_state(ssl_) \ | ||
<< std::endl | ||
*/ | ||
SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, SSLContext& context) | ||
SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, | ||
std::unique_ptr<SSLContext> context) | ||
: Socket(addr) | ||
, ssl_(SSL_new(context.getContext()), &SSL_free) | ||
, context_(std::move(context)) | ||
, ssl_(SSL_new(context_->getContext()), &SSL_free) | ||
{ | ||
auto ssl = ssl_.get(); | ||
if (!ssl) | ||
|
@@ -181,6 +184,33 @@ SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, S | |
} | ||
} | ||
|
||
SSLSocketFactory::~SSLSocketFactory() {} | ||
|
||
#if defined(WITH_OPENSSL) | ||
std::unique_ptr<Socket> SSLSocketFactory::doConnect(const ClientOptions& opts, | ||
const NetworkAddress& address) { | ||
std::unique_ptr<SSLContext> ssl_context; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it would make sense to store |
||
const auto ssl_options = opts.ssl_options; | ||
const auto ssl_params = SSLParams{ | ||
ssl_options.path_to_ca_files, | ||
ssl_options.path_to_ca_directory, | ||
ssl_options.use_default_ca_locations, | ||
ssl_options.context_options, | ||
ssl_options.min_protocol_version, | ||
ssl_options.max_protocol_version, | ||
ssl_options.use_sni | ||
}; | ||
|
||
if (ssl_options.ssl_context) | ||
ssl_context = std::make_unique<SSLContext>(*ssl_options.ssl_context); | ||
else { | ||
ssl_context = std::make_unique<SSLContext>(ssl_params); | ||
} | ||
|
||
return std::make_unique<SSLSocket>(address, ssl_params, std::move(ssl_context)); | ||
} | ||
#endif | ||
|
||
std::unique_ptr<InputStream> SSLSocket::makeInputStream() const { | ||
return std::make_unique<SSLSocketInput>(ssl_.get()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,10 @@ class SSLContext | |
|
||
class SSLSocket : public Socket { | ||
public: | ||
explicit SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, SSLContext& context); | ||
explicit SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, | ||
std::unique_ptr<SSLContext> context); | ||
SSLSocket(SSLSocket &&) = default; | ||
~SSLSocket() = default; | ||
~SSLSocket() override = default; | ||
|
||
SSLSocket(const SSLSocket & ) = delete; | ||
SSLSocket& operator=(const SSLSocket & ) = delete; | ||
|
@@ -53,9 +54,21 @@ class SSLSocket : public Socket { | |
std::unique_ptr<OutputStream> makeOutputStream() const override; | ||
|
||
private: | ||
std::unique_ptr<SSLContext> context_; | ||
std::unique_ptr<SSL, void (*)(SSL *s)> ssl_; | ||
}; | ||
|
||
class SSLSocketFactory : public NonSecureSocketFactory { | ||
public: | ||
~SSLSocketFactory() override; | ||
|
||
#if defined(WITH_OPENSSL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole file is not event visible to the build-system, if |
||
protected: | ||
std::unique_ptr<Socket> doConnect(const ClientOptions& opts, | ||
const NetworkAddress& address) override; | ||
#endif | ||
}; | ||
|
||
class SSLSocketInput : public InputStream { | ||
public: | ||
explicit SSLSocketInput(SSL *ssl); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To simplify issue with reconnecting and timeouts (and to provide a framework for upcoming multiple-hosts #139 ). Please consider updating the interface:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a problem with
NetworkAddress
- its constructor uses blockinggetaddrinfo
; one way of soling this is to make some base class forNetworkAddress
, but i feel like this would complicate the interface too much (and we already have some Java-style abstract factories here)Introducing
ConnectionOptions
seems like a good enhancement for me, but i believe it has to be done in #139, or at least on the receiving end of upcoming merge conflict. SinceSocketFactory
is a new feature, there shouldn't be a concern with backwards compatibility