Skip to content

Commit 6da379b

Browse files
authored
[3.6] bpo-29781: Fix SSLObject.version before handshake (pythonGH-3364) (python#3381)
SSLObject.version() now correctly returns None when handshake over BIO has not been performed yet. Signed-off-by: Christian Heimes <[email protected]> (cherry picked from commit 6877111)
1 parent c3c3062 commit 6da379b

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/test/test_ssl.py

+2
Original file line numberDiff line numberDiff line change
@@ -1736,13 +1736,15 @@ def test_bio_handshake(self):
17361736
sslobj = ctx.wrap_bio(incoming, outgoing, False, 'localhost')
17371737
self.assertIs(sslobj._sslobj.owner, sslobj)
17381738
self.assertIsNone(sslobj.cipher())
1739+
self.assertIsNone(sslobj.version())
17391740
self.assertIsNotNone(sslobj.shared_ciphers())
17401741
self.assertRaises(ValueError, sslobj.getpeercert)
17411742
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES:
17421743
self.assertIsNone(sslobj.get_channel_binding('tls-unique'))
17431744
self.ssl_io_loop(sock, incoming, outgoing, sslobj.do_handshake)
17441745
self.assertTrue(sslobj.cipher())
17451746
self.assertIsNotNone(sslobj.shared_ciphers())
1747+
self.assertIsNotNone(sslobj.version())
17461748
self.assertTrue(sslobj.getpeercert())
17471749
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES:
17481750
self.assertTrue(sslobj.get_channel_binding('tls-unique'))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SSLObject.version() now correctly returns None when handshake over BIO has
2+
not been performed yet.

Modules/_ssl.c

+4
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,10 @@ _ssl__SSLSocket_version_impl(PySSLSocket *self)
16951695

16961696
if (self->ssl == NULL)
16971697
Py_RETURN_NONE;
1698+
if (!SSL_is_init_finished(self->ssl)) {
1699+
/* handshake not finished */
1700+
Py_RETURN_NONE;
1701+
}
16981702
version = SSL_get_version(self->ssl);
16991703
if (!strcmp(version, "unknown"))
17001704
Py_RETURN_NONE;

0 commit comments

Comments
 (0)