Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(95)

Side by Side Diff: Modules/_ssl.c

Issue 20421: expose SSL socket protocol version
Patch Set: Created 5 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_ssl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* SSL socket module 1 /* SSL socket module
2 2
3 SSL support based on patches by Brian E Gallew and Laszlo Kovacs. 3 SSL support based on patches by Brian E Gallew and Laszlo Kovacs.
4 Re-worked a bit by Bill Janssen to add server-side support and 4 Re-worked a bit by Bill Janssen to add server-side support and
5 certificate decoding. Chris Stawarz contributed some non-blocking 5 certificate decoding. Chris Stawarz contributed some non-blocking
6 patches. 6 patches.
7 7
8 This module is imported by ssl.py. It should *not* be used 8 This module is imported by ssl.py. It should *not* be used
9 directly. 9 directly.
10 10
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 } 1393 }
1394 v = PyLong_FromLong(SSL_CIPHER_get_bits(current, NULL)); 1394 v = PyLong_FromLong(SSL_CIPHER_get_bits(current, NULL));
1395 if (v == NULL) 1395 if (v == NULL)
1396 goto fail0; 1396 goto fail0;
1397 PyTuple_SET_ITEM(retval, 2, v); 1397 PyTuple_SET_ITEM(retval, 2, v);
1398 return retval; 1398 return retval;
1399 1399
1400 fail0: 1400 fail0:
1401 Py_DECREF(retval); 1401 Py_DECREF(retval);
1402 return NULL; 1402 return NULL;
1403 }
1404
1405 static PyObject *PySSL_version(PySSLSocket *self)
1406 {
1407 const char *version;
1408
1409 if (self->ssl == NULL)
1410 Py_RETURN_NONE;
1411 version = SSL_get_version(self->ssl);
1412 if (!strcmp(version, "unknown"))
1413 Py_RETURN_NONE;
1414 return PyUnicode_FromString(version);
1403 } 1415 }
1404 1416
1405 #ifdef OPENSSL_NPN_NEGOTIATED 1417 #ifdef OPENSSL_NPN_NEGOTIATED
1406 static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) { 1418 static PyObject *PySSL_selected_npn_protocol(PySSLSocket *self) {
1407 const unsigned char *out; 1419 const unsigned char *out;
1408 unsigned int outlen; 1420 unsigned int outlen;
1409 1421
1410 SSL_get0_next_proto_negotiated(self->ssl, 1422 SSL_get0_next_proto_negotiated(self->ssl,
1411 &out, &outlen); 1423 &out, &outlen);
1412 1424
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 {"do_handshake", (PyCFunction)PySSL_SSLdo_handshake, METH_NOARGS}, 1944 {"do_handshake", (PyCFunction)PySSL_SSLdo_handshake, METH_NOARGS},
1933 {"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS, 1945 {"write", (PyCFunction)PySSL_SSLwrite, METH_VARARGS,
1934 PySSL_SSLwrite_doc}, 1946 PySSL_SSLwrite_doc},
1935 {"read", (PyCFunction)PySSL_SSLread, METH_VARARGS, 1947 {"read", (PyCFunction)PySSL_SSLread, METH_VARARGS,
1936 PySSL_SSLread_doc}, 1948 PySSL_SSLread_doc},
1937 {"pending", (PyCFunction)PySSL_SSLpending, METH_NOARGS, 1949 {"pending", (PyCFunction)PySSL_SSLpending, METH_NOARGS,
1938 PySSL_SSLpending_doc}, 1950 PySSL_SSLpending_doc},
1939 {"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS, 1951 {"peer_certificate", (PyCFunction)PySSL_peercert, METH_VARARGS,
1940 PySSL_peercert_doc}, 1952 PySSL_peercert_doc},
1941 {"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS}, 1953 {"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS},
1954 {"version", (PyCFunction)PySSL_version, METH_NOARGS},
1942 #ifdef OPENSSL_NPN_NEGOTIATED 1955 #ifdef OPENSSL_NPN_NEGOTIATED
1943 {"selected_npn_protocol", (PyCFunction)PySSL_selected_npn_protocol, METH_NOA RGS}, 1956 {"selected_npn_protocol", (PyCFunction)PySSL_selected_npn_protocol, METH_NOA RGS},
1944 #endif 1957 #endif
1945 {"compression", (PyCFunction)PySSL_compression, METH_NOARGS}, 1958 {"compression", (PyCFunction)PySSL_compression, METH_NOARGS},
1946 {"shutdown", (PyCFunction)PySSL_SSLshutdown, METH_NOARGS, 1959 {"shutdown", (PyCFunction)PySSL_SSLshutdown, METH_NOARGS,
1947 PySSL_SSLshutdown_doc}, 1960 PySSL_SSLshutdown_doc},
1948 #if HAVE_OPENSSL_FINISHED 1961 #if HAVE_OPENSSL_FINISHED
1949 {"tls_unique_cb", (PyCFunction)PySSL_tls_unique_cb, METH_NOARGS, 1962 {"tls_unique_cb", (PyCFunction)PySSL_tls_unique_cb, METH_NOARGS,
1950 PySSL_tls_unique_cb_doc}, 1963 PySSL_tls_unique_cb_doc},
1951 #endif 1964 #endif
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after
4198 return NULL; 4211 return NULL;
4199 4212
4200 libver = OPENSSL_VERSION_NUMBER; 4213 libver = OPENSSL_VERSION_NUMBER;
4201 parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); 4214 parse_openssl_version(libver, &major, &minor, &fix, &patch, &status);
4202 r = Py_BuildValue("IIIII", major, minor, fix, patch, status); 4215 r = Py_BuildValue("IIIII", major, minor, fix, patch, status);
4203 if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r)) 4216 if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r))
4204 return NULL; 4217 return NULL;
4205 4218
4206 return m; 4219 return m;
4207 } 4220 }
OLDNEW
« no previous file with comments | « Lib/test/test_ssl.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+