summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-09-04 19:00:10 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-09-04 19:00:10 (GMT)
commit47e40429fbebb7c0751c5cb20d666089b05710c6 (patch)
treeb20eadff0e6aa3f3091e5931955d3e51ffbe0a4a /Modules
parent60a64d6812e5d3c3bf4291081e3db9dc6acf996c (diff)
downloadcpython-47e40429fbebb7c0751c5cb20d666089b05710c6.zip
cpython-47e40429fbebb7c0751c5cb20d666089b05710c6.tar.gz
cpython-47e40429fbebb7c0751c5cb20d666089b05710c6.tar.bz2
Issue #20421: Add a .version() method to SSL sockets exposing the actual protocol version in use.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ssl.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index d42c3ce..5b85cc7 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1402,6 +1402,18 @@ static PyObject *PySSL_cipher (PySSLSocket *self) {
return NULL;
}
+static PyObject *PySSL_version(PySSLSocket *self)
+{
+ const char *version;
+
+ if (self->ssl == NULL)
+ Py_RETURN_NONE;
+ version = SSL_get_version(self->ssl);
+ if (!strcmp(version, "unknown"))
+ Py_RETURN_NONE;
+ return PyUnicode_FromString(version);
+}
+
#ifdef OPENSSL_NPN_NEGOTIATED
static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) {
const unsigned char *out;
@@ -1939,6 +1951,7 @@ static PyMethodDef PySSLMethods[] = {
{"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS,
PySSL_peercert_doc},
{"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS},
+ {"version", (PyCFunction)PySSL_version, METH_NOARGS},
#ifdef OPENSSL_NPN_NEGOTIATED
{"selected_npn_protocol", (PyCFunction)PySSL_selected_npn_protocol, METH_NOARGS},
#endif