Skip to content

Commit cb56dc5

Browse files
committed
Revert upstream PR python#102918
It adds an ill-advised feature that BoringSSL can't support.
1 parent 3a9a06b commit cb56dc5

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

Doc/library/ssl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ SSL sockets also have the following additional methods and attributes:
12421242

12431243
.. method:: SSLSocket.shared_ciphers()
12441244

1245-
Return the list of ciphers available in both the client and server. Each
1245+
Return the list of ciphers shared by the client during the handshake. Each
12461246
entry of the returned list is a three-value tuple containing the name of the
12471247
cipher, the version of the SSL protocol that defines its use, and the number
12481248
of secret bits the cipher uses. :meth:`~SSLSocket.shared_ciphers` returns

Lib/test/test_ssl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,13 +2151,13 @@ def test_bio_handshake(self):
21512151
self.assertIs(sslobj._sslobj.owner, sslobj)
21522152
self.assertIsNone(sslobj.cipher())
21532153
self.assertIsNone(sslobj.version())
2154-
self.assertIsNone(sslobj.shared_ciphers())
2154+
self.assertIsNotNone(sslobj.shared_ciphers())
21552155
self.assertRaises(ValueError, sslobj.getpeercert)
21562156
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES:
21572157
self.assertIsNone(sslobj.get_channel_binding('tls-unique'))
21582158
self.ssl_io_loop(sock, incoming, outgoing, sslobj.do_handshake)
21592159
self.assertTrue(sslobj.cipher())
2160-
self.assertIsNone(sslobj.shared_ciphers())
2160+
self.assertIsNotNone(sslobj.shared_ciphers())
21612161
self.assertIsNotNone(sslobj.version())
21622162
self.assertTrue(sslobj.getpeercert())
21632163
if 'tls-unique' in ssl.CHANNEL_BINDING_TYPES:
@@ -4166,7 +4166,7 @@ def cb_wrong_return_type(ssl_sock, server_name, initial_context):
41664166
def test_shared_ciphers(self):
41674167
client_context, server_context, hostname = testing_context()
41684168
client_context.set_ciphers("AES128:AES256")
4169-
server_context.set_ciphers("AES256:eNULL")
4169+
server_context.set_ciphers("AES256")
41704170
expected_algs = [
41714171
"AES256", "AES-256",
41724172
# TLS 1.3 ciphers are always enabled

Modules/_ssl.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,44 +2041,25 @@ static PyObject *
20412041
_ssl__SSLSocket_shared_ciphers_impl(PySSLSocket *self)
20422042
/*[clinic end generated code: output=3d174ead2e42c4fd input=0bfe149da8fe6306]*/
20432043
{
2044-
STACK_OF(SSL_CIPHER) *server_ciphers;
2045-
STACK_OF(SSL_CIPHER) *client_ciphers;
2046-
int i, len;
2044+
STACK_OF(SSL_CIPHER) *ciphers;
2045+
int i;
20472046
PyObject *res;
2048-
const SSL_CIPHER* cipher;
2049-
2050-
/* Rather than use SSL_get_shared_ciphers, we use an equivalent algorithm because:
2051-
2052-
1) It returns a colon separated list of strings, in an undefined
2053-
order, that we would have to post process back into tuples.
2054-
2) It will return a truncated string with no indication that it has
2055-
done so, if the buffer is too small.
2056-
*/
20572047

2058-
server_ciphers = SSL_get_ciphers(self->ssl);
2059-
if (!server_ciphers)
2060-
Py_RETURN_NONE;
2061-
client_ciphers = SSL_get_client_ciphers(self->ssl);
2062-
if (!client_ciphers)
2048+
ciphers = SSL_get_ciphers(self->ssl);
2049+
if (!ciphers)
20632050
Py_RETURN_NONE;
20642051

2065-
res = PyList_New(sk_SSL_CIPHER_num(server_ciphers));
2052+
res = PyList_New(sk_SSL_CIPHER_num(ciphers));
20662053
if (!res)
20672054
return NULL;
2068-
len = 0;
2069-
for (i = 0; i < sk_SSL_CIPHER_num(server_ciphers); i++) {
2070-
cipher = sk_SSL_CIPHER_value(server_ciphers, i);
2071-
if (sk_SSL_CIPHER_find(client_ciphers, cipher) < 0)
2072-
continue;
2073-
2074-
PyObject *tup = cipher_to_tuple(cipher);
2055+
for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
2056+
PyObject *tup = cipher_to_tuple(sk_SSL_CIPHER_value(ciphers, i));
20752057
if (!tup) {
20762058
Py_DECREF(res);
20772059
return NULL;
20782060
}
2079-
PyList_SET_ITEM(res, len++, tup);
2061+
PyList_SET_ITEM(res, i, tup);
20802062
}
2081-
Py_SET_SIZE(res, len);
20822063
return res;
20832064
}
20842065

0 commit comments

Comments
 (0)