Skip to content

Commit

Permalink
bpo-29781: Fix SSLObject.version before handshake (python#3364)
Browse files Browse the repository at this point in the history
SSLObject.version() now correctly returns None when handshake over BIO has
not been performed yet.

Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran authored Sep 6, 2017
1 parent 3463ee3 commit 6877111
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,13 +1746,15 @@ def test_bio_handshake(self):
sslobj = ctx.wrap_bio(incoming, outgoing, False, 'localhost')
self.assertIs(sslobj._sslobj.owner, sslobj)
self.assertIsNone(sslobj.cipher())
self.assertIsNone(sslobj.version())
self.assertIsNotNone(sslobj.shared_ciphers())
self.assertRaises(ValueError, sslobj.getpeercert)
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES:
self.assertIsNone(sslobj.get_channel_binding('tls-unique'))
self.ssl_io_loop(sock, incoming, outgoing, sslobj.do_handshake)
self.assertTrue(sslobj.cipher())
self.assertIsNotNone(sslobj.shared_ciphers())
self.assertIsNotNone(sslobj.version())
self.assertTrue(sslobj.getpeercert())
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES:
self.assertTrue(sslobj.get_channel_binding('tls-unique'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SSLObject.version() now correctly returns None when handshake over BIO has
not been performed yet.
4 changes: 4 additions & 0 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,10 @@ _ssl__SSLSocket_version_impl(PySSLSocket *self)

if (self->ssl == NULL)
Py_RETURN_NONE;
if (!SSL_is_init_finished(self->ssl)) {
/* handshake not finished */
Py_RETURN_NONE;
}
version = SSL_get_version(self->ssl);
if (!strcmp(version, "unknown"))
Py_RETURN_NONE;
Expand Down

0 comments on commit 6877111

Please sign in to comment.