Commit c894977f authored by Kyle Nekritz's avatar Kyle Nekritz Committed by Facebook GitHub Bot

Pass handshake exception to pending write and read callbacks.

Summary:
If we already have pending application reads or writes when we have a
handshake error (eg when using a null connect callback), we should pass the
handshake error to finishFail to give a more helpful error message.

Reviewed By: mingtaoy

Differential Revision: D33415008

fbshipit-source-id: fc14ef774d09c0af975e177b24185f78c4e4139e
parent 0ec02d48
...@@ -707,7 +707,7 @@ void AsyncSSLSocket::failHandshake( ...@@ -707,7 +707,7 @@ void AsyncSSLSocket::failHandshake(
handshakeTimeout_.cancelTimeout(); handshakeTimeout_.cancelTimeout();
} }
invokeHandshakeErr(ex); invokeHandshakeErr(ex);
finishFail(); finishFail(ex);
} }
void AsyncSSLSocket::invokeHandshakeErr(const AsyncSocketException& ex) { void AsyncSSLSocket::invokeHandshakeErr(const AsyncSocketException& ex) {
......
...@@ -3078,6 +3078,37 @@ TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) { ...@@ -3078,6 +3078,37 @@ TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) {
serverSSLSock->getRawBytesReceived(), clientSock->getRawBytesWritten()); serverSSLSock->getRawBytesReceived(), clientSock->getRawBytesWritten());
} }
TEST(AsyncSSLSocketTest, TestNullConnectCallbackError) {
EventBase eventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto serverCtx = std::make_shared<SSLContext>();
std::array<NetworkSocket, 2> fds;
getfds(fds.data());
getctx(clientCtx, serverCtx);
// Mismatched ciphers
clientCtx->ciphers(
"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256");
serverCtx->ciphers(
"ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384");
AsyncSSLSocket::UniquePtr clientSockPtr(
new AsyncSSLSocket(clientCtx, &eventBase, fds[0], false));
AsyncSSLSocket::UniquePtr serverSockPtr(
new AsyncSSLSocket(serverCtx, &eventBase, fds[1], true));
auto clientSock = clientSockPtr.get();
clientSock->sslConn(nullptr);
ExpectSSLWriteErrorCallback wcb;
wcb.setSocket(std::move(clientSockPtr));
clientSock->write(&wcb, "abc", 3);
SSLHandshakeServer server(std::move(serverSockPtr), true, true);
eventBase.loop();
EXPECT_FALSE(server.handshakeSuccess_);
}
/** /**
* Test overriding the flags passed to "sendmsg()" system call, * Test overriding the flags passed to "sendmsg()" system call,
* and verifying that write requests fail properly. * and verifying that write requests fail properly.
......
...@@ -209,6 +209,21 @@ class ExpectWriteErrorCallback : public WriteCallbackBase { ...@@ -209,6 +209,21 @@ class ExpectWriteErrorCallback : public WriteCallbackBase {
} }
}; };
class ExpectSSLWriteErrorCallback : public WriteCallbackBase {
public:
explicit ExpectSSLWriteErrorCallback(SendMsgParamsCallbackBase* mcb = nullptr)
: WriteCallbackBase(mcb) {}
~ExpectSSLWriteErrorCallback() override {
EXPECT_EQ(STATE_FAILED, state);
EXPECT_EQ(
exception.getType(),
AsyncSocketException::AsyncSocketExceptionType::SSL_ERROR);
// Suppress the assert in ~WriteCallbackBase()
state = STATE_SUCCEEDED;
}
};
class ReadCallbackBase : public AsyncTransport::ReadCallback { class ReadCallbackBase : public AsyncTransport::ReadCallback {
public: public:
explicit ReadCallbackBase(WriteCallbackBase* wcb) explicit ReadCallbackBase(WriteCallbackBase* wcb)
......
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