Commit ae1594ea authored by Anirudh Ramachandran's avatar Anirudh Ramachandran Committed by Facebook Github Bot

Add a version of async_test using openssl 1.1.0

Summary:
Now that it's possible, let's add some 1.1.0 tests to avoid regressing
1.1.0 support

Reviewed By: yfeldblum

Differential Revision: D5167246

fbshipit-source-id: ba12414504131697d4e0757c9c340a66f810acd4
parent 55791684
...@@ -409,6 +409,7 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> { ...@@ -409,6 +409,7 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> {
} }
void expectProtocol(const std::string& proto) { void expectProtocol(const std::string& proto) {
expectHandshakeSuccess();
EXPECT_NE(client->nextProtoLength, 0); EXPECT_NE(client->nextProtoLength, 0);
EXPECT_EQ(client->nextProtoLength, server->nextProtoLength); EXPECT_EQ(client->nextProtoLength, server->nextProtoLength);
EXPECT_EQ( EXPECT_EQ(
...@@ -419,6 +420,7 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> { ...@@ -419,6 +420,7 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> {
} }
void expectNoProtocol() { void expectNoProtocol() {
expectHandshakeSuccess();
EXPECT_EQ(client->nextProtoLength, 0); EXPECT_EQ(client->nextProtoLength, 0);
EXPECT_EQ(server->nextProtoLength, 0); EXPECT_EQ(server->nextProtoLength, 0);
EXPECT_EQ(client->nextProto, nullptr); EXPECT_EQ(client->nextProto, nullptr);
...@@ -426,6 +428,7 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> { ...@@ -426,6 +428,7 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> {
} }
void expectProtocolType() { void expectProtocolType() {
expectHandshakeSuccess();
if (GetParam().first == SSLContext::NextProtocolType::ANY && if (GetParam().first == SSLContext::NextProtocolType::ANY &&
GetParam().second == SSLContext::NextProtocolType::ANY) { GetParam().second == SSLContext::NextProtocolType::ANY) {
EXPECT_EQ(client->protocolType, server->protocolType); EXPECT_EQ(client->protocolType, server->protocolType);
...@@ -438,10 +441,25 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> { ...@@ -438,10 +441,25 @@ class NextProtocolTest : public testing::TestWithParam<NextProtocolTypePair> {
} }
void expectProtocolType(NextProtocolTypePair expected) { void expectProtocolType(NextProtocolTypePair expected) {
expectHandshakeSuccess();
EXPECT_EQ(client->protocolType, expected.first); EXPECT_EQ(client->protocolType, expected.first);
EXPECT_EQ(server->protocolType, expected.second); EXPECT_EQ(server->protocolType, expected.second);
} }
void expectHandshakeSuccess() {
EXPECT_FALSE(client->except.hasValue())
<< "client handshake error: " << client->except->what();
EXPECT_FALSE(server->except.hasValue())
<< "server handshake error: " << server->except->what();
}
void expectHandshakeError() {
EXPECT_TRUE(client->except.hasValue())
<< "Expected client handshake error!";
EXPECT_TRUE(server->except.hasValue())
<< "Expected server handshake error!";
}
EventBase eventBase; EventBase eventBase;
std::shared_ptr<SSLContext> clientCtx{std::make_shared<SSLContext>()}; std::shared_ptr<SSLContext> clientCtx{std::make_shared<SSLContext>()};
std::shared_ptr<SSLContext> serverCtx{std::make_shared<SSLContext>()}; std::shared_ptr<SSLContext> serverCtx{std::make_shared<SSLContext>()};
...@@ -505,27 +523,32 @@ TEST_P(NextProtocolTest, NpnTestNoOverlap) { ...@@ -505,27 +523,32 @@ TEST_P(NextProtocolTest, NpnTestNoOverlap) {
clientCtx->setAdvertisedNextProtocols({"blub"}, GetParam().first); clientCtx->setAdvertisedNextProtocols({"blub"}, GetParam().first);
serverCtx->setAdvertisedNextProtocols({"foo", "bar", "baz"}, serverCtx->setAdvertisedNextProtocols({"foo", "bar", "baz"},
GetParam().second); GetParam().second);
connect(); connect();
if (GetParam().first == SSLContext::NextProtocolType::ALPN || if (GetParam().first == SSLContext::NextProtocolType::ALPN ||
GetParam().second == SSLContext::NextProtocolType::ALPN) { GetParam().second == SSLContext::NextProtocolType::ALPN) {
// This is arguably incorrect behavior since RFC7301 states an ALPN protocol // This is arguably incorrect behavior since RFC7301 states an ALPN protocol
// mismatch should result in a fatal alert, but this is OpenSSL's current // mismatch should result in a fatal alert, but this is the current behavior
// behavior and we want to know if it changes. // on all OpenSSL versions/variants, and we want to know if it changes.
expectNoProtocol(); expectNoProtocol();
} }
#if defined(OPENSSL_IS_BORINGSSL) #if FOLLY_OPENSSL_IS_110 || defined(OPENSSL_IS_BORINGSSL)
// BoringSSL also doesn't fatal on mismatch but behaves slightly differently
// from OpenSSL 1.0.2h+ - it doesn't select a protocol if both ends support
// NPN *and* ALPN
else if ( else if (
GetParam().first == SSLContext::NextProtocolType::ANY && GetParam().first == SSLContext::NextProtocolType::ANY &&
GetParam().second == SSLContext::NextProtocolType::ANY) { GetParam().second == SSLContext::NextProtocolType::ANY) {
# if FOLLY_OPENSSL_IS_110
// OpenSSL 1.1.0 sends a fatal alert on mismatch, which is probavbly the
// correct behavior per RFC7301
expectHandshakeError();
# else
// BoringSSL also doesn't fatal on mismatch but behaves slightly differently
// from OpenSSL 1.0.2h+ - it doesn't select a protocol if both ends support
// NPN *and* ALPN
expectNoProtocol(); expectNoProtocol();
# endif
} }
#endif #endif
else { else {
expectProtocol("blub"); expectProtocol("blub");
expectProtocolType( expectProtocolType(
{SSLContext::NextProtocolType::NPN, SSLContext::NextProtocolType::NPN}); {SSLContext::NextProtocolType::NPN, SSLContext::NextProtocolType::NPN});
...@@ -1647,9 +1670,13 @@ TEST(AsyncSSLSocketTest, ConnEOFErrorString) { ...@@ -1647,9 +1670,13 @@ TEST(AsyncSSLSocketTest, ConnEOFErrorString) {
socket->close(); socket->close();
handshakeCallback.waitForHandshake(); handshakeCallback.waitForHandshake();
#if FOLLY_OPENSSL_IS_110
EXPECT_NE(
handshakeCallback.errorString_.find("Network error"), std::string::npos);
#else
EXPECT_NE( EXPECT_NE(
handshakeCallback.errorString_.find("Connection EOF"), std::string::npos); handshakeCallback.errorString_.find("Connection EOF"), std::string::npos);
EXPECT_NE(handshakeCallback.errorString_.find("EOF"), std::string::npos); #endif
} }
TEST(AsyncSSLSocketTest, ConnOpenSSLErrorString) { TEST(AsyncSSLSocketTest, ConnOpenSSLErrorString) {
...@@ -1675,6 +1702,9 @@ TEST(AsyncSSLSocketTest, ConnOpenSSLErrorString) { ...@@ -1675,6 +1702,9 @@ TEST(AsyncSSLSocketTest, ConnOpenSSLErrorString) {
EXPECT_NE( EXPECT_NE(
handshakeCallback.errorString_.find("ENCRYPTED_LENGTH_TOO_LONG"), handshakeCallback.errorString_.find("ENCRYPTED_LENGTH_TOO_LONG"),
std::string::npos); std::string::npos);
#elif FOLLY_OPENSSL_IS_110
EXPECT_NE(handshakeCallback.errorString_.find("packet length too long"),
std::string::npos);
#else #else
EXPECT_NE(handshakeCallback.errorString_.find("unknown protocol"), EXPECT_NE(handshakeCallback.errorString_.find("unknown protocol"),
std::string::npos); std::string::npos);
......
...@@ -968,6 +968,7 @@ class NpnClient : ...@@ -968,6 +968,7 @@ class NpnClient :
const unsigned char* nextProto; const unsigned char* nextProto;
unsigned nextProtoLength; unsigned nextProtoLength;
SSLContext::NextProtocolType protocolType; SSLContext::NextProtocolType protocolType;
folly::Optional<AsyncSocketException> except;
private: private:
void handshakeSuc(AsyncSSLSocket*) noexcept override { void handshakeSuc(AsyncSSLSocket*) noexcept override {
...@@ -977,7 +978,7 @@ class NpnClient : ...@@ -977,7 +978,7 @@ class NpnClient :
void handshakeErr( void handshakeErr(
AsyncSSLSocket*, AsyncSSLSocket*,
const AsyncSocketException& ex) noexcept override { const AsyncSocketException& ex) noexcept override {
ADD_FAILURE() << "client handshake error: " << ex.what(); except = ex;
} }
void writeSuccess() noexcept override { void writeSuccess() noexcept override {
socket_->close(); socket_->close();
...@@ -1004,6 +1005,7 @@ class NpnServer : ...@@ -1004,6 +1005,7 @@ class NpnServer :
const unsigned char* nextProto; const unsigned char* nextProto;
unsigned nextProtoLength; unsigned nextProtoLength;
SSLContext::NextProtocolType protocolType; SSLContext::NextProtocolType protocolType;
folly::Optional<AsyncSocketException> except;
private: private:
void handshakeSuc(AsyncSSLSocket*) noexcept override { void handshakeSuc(AsyncSSLSocket*) noexcept override {
...@@ -1013,7 +1015,7 @@ class NpnServer : ...@@ -1013,7 +1015,7 @@ class NpnServer :
void handshakeErr( void handshakeErr(
AsyncSSLSocket*, AsyncSSLSocket*,
const AsyncSocketException& ex) noexcept override { const AsyncSocketException& ex) noexcept override {
ADD_FAILURE() << "server handshake error: " << ex.what(); except = ex;
} }
void getReadBuffer(void** /* bufReturn */, size_t* lenReturn) override { void getReadBuffer(void** /* bufReturn */, size_t* lenReturn) override {
*lenReturn = 0; *lenReturn = 0;
......
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