40 ctx_->setOptions(SSL_OP_NO_TICKET);
41 ctx_->ciphers(
"ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
54 socket.attachSSLContext(
ctx_);
58 std::shared_ptr<SSLContext>
ctx_;
78 sslSocket_->detachEventBase();
79 sslSocket_->detachSSLContext();
84 : address_(address), bytesRead_(0) {}
96 for (
int i = 0;
i < 1000; ++
i) {
97 sslSocket_->detachSSLContext();
98 sslSocket_->attachSSLContext(t1_.
ctx_);
105 sslSocket_->connect(
this, address_);
113 cerr <<
"client SSL socket connected" << endl;
114 for (
int i = 0;
i < 1000; ++
i) {
115 sslSocket_->detachSSLContext();
116 sslSocket_->attachSSLContext(t2_.
ctx_);
120 t2Evb->runInEventBaseThread([
this] {
125 sslSocket_->write(
this, buf_,
sizeof(buf_));
126 sslSocket_->setReadCB(
this);
127 memset(readbuf_,
'b',
sizeof(readbuf_));
134 cerr <<
"AttachDetachClient::connectError: " << ex.what() << endl;
139 cerr <<
"client write success" << endl;
145 cerr <<
"client writeError: " << ex.what() << endl;
149 *bufReturn = readbuf_ + bytesRead_;
150 *lenReturn =
sizeof(readbuf_) - bytesRead_;
153 cerr <<
"client readEOF" << endl;
157 cerr <<
"client readError: " << ex.what() << endl;
164 cerr <<
"client read data: " << len << endl;
166 if (len ==
sizeof(buf_)) {
167 EXPECT_EQ(memcmp(buf_, readbuf_, bytesRead_), 0);
168 sslSocket_->closeNow();
178 TEST(AsyncSSLSocketTest2, AttachDetachSSLContext) {
186 std::shared_ptr<AttachDetachClient> client(
189 auto f = client->getFuture();
203 t1_.getEventBase()->runInEventBaseThread([&] {
219 void setCtx(std::shared_ptr<SSLContext> ctx) {
245 TEST(AsyncSSLSocketTest2, TestTLS12DefaultClient) {
252 server.loadTestCerts();
255 auto c1 = std::make_unique<ConnectClient>();
256 auto f1 = c1->getFuture();
257 c1->connect(server.getAddress());
261 TEST(AsyncSSLSocketTest2, TestTLS12BadClient) {
269 server.loadTestCerts();
272 auto c2 = std::make_unique<ConnectClient>();
273 auto clientCtx = std::make_shared<SSLContext>();
274 clientCtx->setOptions(SSL_OP_NO_TLSv1_2);
275 c2->setCtx(clientCtx);
276 auto f2 = c2->getFuture();
277 c2->connect(server.getAddress());
286 signal(SIGPIPE, SIG_IGN);
EventBase * getEventBase() const
void setCtx(std::shared_ptr< SSLContext > ctx)
Future< bool > getFuture()
void getReadBuffer(void **bufReturn, size_t *lenReturn) override
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
std::shared_ptr< SSLContext > ctx_
std::shared_ptr< AsyncSSLSocket > createSocket()
void setException(exception_wrapper ew)
std::shared_ptr< AsyncSSLSocket > socket_
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
folly::Promise< bool > promise_
void connectSuccess() noexceptoverride
static std::shared_ptr< AsyncSSLSocket > newSocket(const std::shared_ptr< folly::SSLContext > &ctx, EventBase *evb, int fd, bool server=true, bool deferSecurityNegotiation=false)
void init(int *argc, char ***argv, bool removeFlags)
AttachDetachClient(const folly::SocketAddress &address)
bool isInEventBaseThread() const
folly::Promise< bool > promise_
void readDataAvailable(size_t) noexceptoverride
int main(int argc, char *argv[])
AsyncServerSocket::UniquePtr socket_
Encoder::MutableCompressedList list
bool runInEventBaseThread(void(*fn)(T *), T *arg)
void writeSuccess() noexceptoverride
NetworkSocket socket(int af, int type, int protocol)
void readEOF() noexceptoverride
void attachEventBase(EventBase *eventBase) override
folly::ScopedEventBaseThread evb_
#define EXPECT_TRUE(condition)
void connectErr(const AsyncSocketException &) noexceptoverride
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
void connectSuccess() noexceptoverride
void readErr(const AsyncSocketException &ex) noexceptoverride
void connectErr(const AsyncSocketException &ex) noexceptoverride
void connect(const folly::SocketAddress &addr)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
#define EXPECT_FALSE(condition)
folly::SocketAddress address_
void getReadBuffer(void **buf, size_t *lenReturn) override
void readDataAvailable(size_t len) noexceptoverride
void writeErr(size_t, const AsyncSocketException &ex) noexceptoverride
std::shared_ptr< AsyncSSLSocket > sslSocket_
std::unique_ptr< unsigned char[]> buffer_
ThreadPoolListHook * addr
TEST(SequencedExecutor, CPUThreadPoolExecutor)
const SocketAddress & getAddress() const
void attach(AsyncSSLSocket &socket)
Future< bool > getFuture()
EventBase * getEventBase()