From c85e08616dc7c18f4f24c808f39fcf22d2cce487 Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Thu, 8 Jan 2015 08:34:33 -0800 Subject: [PATCH 1/3] Add test for Connection.shutdown on closed socket --- OpenSSL/test/test_ssl.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index 44980d53a..79010fb3e 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -1709,6 +1709,20 @@ def test_shutdown(self): self.assertEquals(server.get_shutdown(), SENT_SHUTDOWN|RECEIVED_SHUTDOWN) + def test_shutdown_closed(self): + """ + If the underlying socket is closed, :py:obj:`Connection.shutdown` propagates the + write error from the low level write call. + """ + server, client = self._loopback() + server.sock_shutdown(2) + exc = self.assertRaises(SysCallError, server.shutdown) + if platform == "win32": + self.assertEqual(exc.args[0], ESHUTDOWN) + else: + self.assertEqual(exc.args[0], EPIPE) + + def test_set_shutdown(self): """ :py:obj:`Connection.set_shutdown` sets the state of the SSL connection shutdown From bff1d1ae72e743e41254bb31a5b50b5b63a37b85 Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Thu, 8 Jan 2015 08:36:53 -0800 Subject: [PATCH 2/3] Fixes #91 -- proper error handling in Connection.shutdown On error (return < 0), the OpenSSL documentation says to call SSL_get_error to discover the cause, as the act of trying to shutdown may raise lower-level errors (e.g. socket errors), or return SSL_ERR_WANT_WRITE or SSL_ERR_WANT_READ. --- OpenSSL/SSL.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index 7b1cbc1b4..b6c80763c 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -1183,8 +1183,7 @@ def shutdown(self): """ result = _lib.SSL_shutdown(self._ssl) if result < 0: - # TODO: This is untested. - _raise_current_error() + self._raise_ssl_error(self._ssl, result) elif result > 0: return True else: From 306b75ab0d8959e8bfb21bdad831a5610609afaa Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Thu, 8 Jan 2015 18:35:03 -0800 Subject: [PATCH 3/3] ChangeLog entry --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 291f9779e..4019c27a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-01-08 Paul Aurich + + * OpenSSL/SSL.py: ``Connection.shutdown`` now propagates errors from the + underlying socket. + 2014-08-21 Alex Gaynor * OpenSSL/crypto.py: Fixed a regression where calling ``load_pkcs7_data``