2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include <folly/io/async/test/TestSSLServer.h>
20 const char* kTestCert = "folly/io/async/test/certs/tests-cert.pem";
21 const char* kTestKey = "folly/io/async/test/certs/tests-key.pem";
22 const char* kTestCA = "folly/io/async/test/certs/ca-cert.pem";
24 TestSSLServer::~TestSSLServer() {
25 if (thread_.joinable()) {
26 evb_.runInEventBaseThread([&]() { socket_->stopAccepting(); });
27 LOG(INFO) << "Waiting for server thread to exit";
32 TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb, bool enableTFO)
34 // Set up a default SSL context
35 ctx_ = std::make_shared<SSLContext>();
36 ctx_->loadCertificate(kTestCert);
37 ctx_->loadPrivateKey(kTestKey);
38 ctx_->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
43 TestSSLServer::TestSSLServer(
44 SSLServerAcceptCallbackBase* acb,
45 std::shared_ptr<SSLContext> ctx,
47 : ctx_(ctx), acb_(acb) {
51 void TestSSLServer::init(bool enableTFO) {
52 socket_ = AsyncServerSocket::newSocket(&evb_);
59 LOG(INFO) << "server TFO enabled";
60 socket_->setTFOEnabled(true, 1000);
63 // set up the listening socket
65 socket_->getAddress(&address_);
67 socket_->addAcceptCallback(acb_, &evb_);
68 socket_->startAccepting();
70 thread_ = std::thread([&] {
73 LOG(INFO) << "Server thread exited event loop";
75 LOG(INFO) << "Accepting connections on " << address_;