mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue #20421: Add a .version() method to SSL sockets exposing the actual protocol version in use.
This commit is contained in:
parent
60a64d6812
commit
47e40429fb
5 changed files with 86 additions and 24 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue