Commit d0d34d8e authored by Daniel Sommermann's avatar Daniel Sommermann Committed by Facebook Github Bot

Add ability to set custom SSLContext on TestSSLServer

Summary:
This is needed if you want to test other scenarios where the
server has other OpenSSL settings.

Differential Revision: D4463587

fbshipit-source-id: ffd4019e921649dee703363b2ff028b4d8063210
parent 2eab3687
...@@ -21,15 +21,36 @@ const char* kTestCert = "folly/io/async/test/certs/tests-cert.pem"; ...@@ -21,15 +21,36 @@ const char* kTestCert = "folly/io/async/test/certs/tests-cert.pem";
const char* kTestKey = "folly/io/async/test/certs/tests-key.pem"; const char* kTestKey = "folly/io/async/test/certs/tests-key.pem";
const char* kTestCA = "folly/io/async/test/certs/ca-cert.pem"; const char* kTestCA = "folly/io/async/test/certs/ca-cert.pem";
TestSSLServer::~TestSSLServer() {
if (thread_.joinable()) {
evb_.runInEventBaseThread([&]() { socket_->stopAccepting(); });
LOG(INFO) << "Waiting for server thread to exit";
thread_.join();
}
}
TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb, bool enableTFO) TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb, bool enableTFO)
: ctx_(new SSLContext), : acb_(acb) {
acb_(acb), // Set up a default SSL context
socket_(AsyncServerSocket::newSocket(&evb_)) { ctx_ = std::make_shared<SSLContext>();
// Set up the SSL context
ctx_->loadCertificate(kTestCert); ctx_->loadCertificate(kTestCert);
ctx_->loadPrivateKey(kTestKey); ctx_->loadPrivateKey(kTestKey);
ctx_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); ctx_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
init(enableTFO);
}
TestSSLServer::TestSSLServer(
SSLServerAcceptCallbackBase* acb,
std::shared_ptr<SSLContext> ctx,
bool enableTFO)
: ctx_(ctx), acb_(acb) {
init(enableTFO);
}
void TestSSLServer::init(bool enableTFO) {
socket_ = AsyncServerSocket::newSocket(&evb_);
acb_->ctx_ = ctx_; acb_->ctx_ = ctx_;
acb_->base_ = &evb_; acb_->base_ = &evb_;
...@@ -46,15 +67,11 @@ TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb, bool enableTFO) ...@@ -46,15 +67,11 @@ TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb, bool enableTFO)
socket_->addAcceptCallback(acb_, &evb_); socket_->addAcceptCallback(acb_, &evb_);
socket_->startAccepting(); socket_->startAccepting();
thread_ = std::thread([&] { Main(); }); thread_ = std::thread([&] {
evb_.loop();
acb_->detach();
LOG(INFO) << "Server thread exited event loop";
});
LOG(INFO) << "Accepting connections on " << address_; LOG(INFO) << "Accepting connections on " << address_;
} }
TestSSLServer::~TestSSLServer() {
if (thread_.joinable()) {
evb_.runInEventBaseThread([&]() { socket_->stopAccepting(); });
LOG(INFO) << "Waiting for server thread to exit";
thread_.join();
}
}
} }
...@@ -99,6 +99,10 @@ class TestSSLServer { ...@@ -99,6 +99,10 @@ class TestSSLServer {
explicit TestSSLServer( explicit TestSSLServer(
SSLServerAcceptCallbackBase* acb, SSLServerAcceptCallbackBase* acb,
bool enableTFO = false); bool enableTFO = false);
explicit TestSSLServer(
SSLServerAcceptCallbackBase* acb,
std::shared_ptr<SSLContext> ctx,
bool enableTFO = false);
// Kills the thread. // Kills the thread.
virtual ~TestSSLServer(); virtual ~TestSSLServer();
...@@ -112,17 +116,14 @@ class TestSSLServer { ...@@ -112,17 +116,14 @@ class TestSSLServer {
} }
protected: protected:
void Main() {
evb_.loop();
acb_->detach();
LOG(INFO) << "Server thread exited event loop";
}
EventBase evb_; EventBase evb_;
std::shared_ptr<SSLContext> ctx_; std::shared_ptr<SSLContext> ctx_;
SSLServerAcceptCallbackBase* acb_; SSLServerAcceptCallbackBase* acb_;
std::shared_ptr<AsyncServerSocket> socket_; std::shared_ptr<AsyncServerSocket> socket_;
SocketAddress address_; SocketAddress address_;
std::thread thread_; std::thread thread_;
private:
void init(bool);
}; };
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment