From f297881e239953c788cedfaa37bf81fb54d10ff6 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 10 Sep 2018 16:10:16 +0200 Subject: [PATCH] Call SSL_shutdown() at least twice --- lib/base/tlsstream.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index 33d72d465..0c6a76525 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -401,7 +401,20 @@ void TlsStream::CloseInternal(bool inDestructor) if (!m_SSL) return; - (void)SSL_shutdown(m_SSL.get()); + /* https://www.openssl.org/docs/manmaster/man3/SSL_shutdown.html + * + * It is recommended to do a bidirectional shutdown by checking + * the return value of SSL_shutdown() and call it again until + * it returns 1 or a fatal error. A maximum of 2x pending + 2x data + * is recommended. + */ + int rc = 0; + + for (int i = 0; i < 4; i++) { + if ((rc = SSL_shutdown(m_SSL.get()))) + break; + } + m_SSL.reset(); m_Socket->Close(); -- 2.40.0