FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-154053: Fix compilation of the ssl module against LibreSSL by serhiy-storchaka · Pull Request #154054 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 10 additions & 1 deletion Lib/test/test_ssl.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@
PROTOCOLS = sorted(ssl._PROTOCOL_NAMES)
HOST = socket_helper.HOST
IS_AWS_LC = "AWS-LC" in ssl.OPENSSL_VERSION
IS_LIBRESSL = "LibreSSL" in ssl.OPENSSL_VERSION
IS_OPENSSL_3_0_0 = ssl.OPENSSL_VERSION_INFO >= (3, 0, 0)
CAN_GET_SELECTED_OPENSSL_GROUP = ssl.OPENSSL_VERSION_INFO >= (3, 2)
CAN_IGNORE_UNKNOWN_OPENSSL_GROUPS = ssl.OPENSSL_VERSION_INFO >= (3, 3)
CAN_GET_AVAILABLE_OPENSSL_GROUPS = ssl.OPENSSL_VERSION_INFO >= (3, 5)
CAN_GET_AVAILABLE_OPENSSL_SIGALGS = ssl.OPENSSL_VERSION_INFO >= (3, 4)
CAN_SET_CLIENT_SIGALGS = not IS_AWS_LC
# LibreSSL does not provide SSL_CTX_set1_(client_)sigalgs_list().
CAN_SET_CLIENT_SIGALGS = not IS_AWS_LC and not IS_LIBRESSL
CAN_SET_SERVER_SIGALGS = not IS_LIBRESSL
CAN_IGNORE_UNKNOWN_OPENSSL_SIGALGS = ssl.OPENSSL_VERSION_INFO >= (3, 3)
CAN_GET_SELECTED_OPENSSL_SIGALG = ssl.OPENSSL_VERSION_INFO >= (3, 5)
PY_SSL_DEFAULT_CIPHERS = sysconfig.get_config_var('PY_SSL_DEFAULT_CIPHERS')
Expand Down Expand Up @@ -1080,6 +1083,8 @@ def test_set_client_sigalgs(self):
if CAN_IGNORE_UNKNOWN_OPENSSL_SIGALGS:
self.assertIsNone(ctx.set_client_sigalgs('rsa_pss_rsae_sha256:?foo'))

@unittest.skipUnless(CAN_SET_SERVER_SIGALGS,
"SSL library doesn't support setting server sigalgs")
def test_set_server_sigalgs(self):
ctx = ssl.create_default_context()

Expand Down Expand Up @@ -4593,6 +4598,8 @@ def test_client_sigalgs_mismatch(self):
chatty=True, connectionchatty=True,
sni_name=hostname)

@unittest.skipUnless(CAN_SET_SERVER_SIGALGS,
"SSL library doesn't support setting server sigalgs")
def test_server_sigalgs(self):
# server rsa_pss_rsae_sha384, client auto
sigalg = "rsa_pss_rsae_sha384"
Expand All @@ -4613,6 +4620,8 @@ def test_server_sigalgs(self):
if CAN_GET_SELECTED_OPENSSL_SIGALG:
self.assertEqual(stats['server_sigalg'], sigalg)

@unittest.skipUnless(CAN_SET_SERVER_SIGALGS,
"SSL library doesn't support setting server sigalgs")
def test_server_sigalgs_mismatch(self):
client_context, server_context, hostname = testing_context()
client_context.set_server_sigalgs("rsa_pss_rsae_sha256")
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix compilation of the :mod:`ssl` module against LibreSSL, which does not
provide ``SSL_CTX_set1_sigalgs_list()`` and ``SSL_CTX_set1_client_sigalgs_list()``.
The :meth:`!set_server_sigalgs` and :meth:`!set_client_sigalgs` methods of
:class:`ssl.SSLContext` now raise :exc:`NotImplementedError` on LibreSSL.
10 changes: 10 additions & 0 deletions Modules/_ssl.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3863,6 +3863,10 @@ _ssl__SSLContext_set_client_sigalgs_impl(PySSLContext *self,
#ifdef OPENSSL_IS_AWSLC
_setSSLError(get_state_ctx(self), "can't set client sigalgs on AWS-LC", 0, __FILE__, __LINE__);
return NULL;
#elif defined(LIBRESSL_VERSION_NUMBER)
PyErr_SetString(PyExc_NotImplementedError,
"setting client sigalgs is not supported by LibreSSL");
return NULL;
#else
if (!SSL_CTX_set1_client_sigalgs_list(self->ctx, sigalgslist)) {
_setSSLError(get_state_ctx(self), "unrecognized signature algorithm", 0, __FILE__, __LINE__);
Expand All @@ -3884,11 +3888,17 @@ _ssl__SSLContext_set_server_sigalgs_impl(PySSLContext *self,
const char *sigalgslist)
/*[clinic end generated code: output=31ecb1d310285644 input=653b752e4f8d801b]*/
{
#ifdef LIBRESSL_VERSION_NUMBER
PyErr_SetString(PyExc_NotImplementedError,
"setting server sigalgs is not supported by LibreSSL");
return NULL;
#else
if (!SSL_CTX_set1_sigalgs_list(self->ctx, sigalgslist)) {
_setSSLError(get_state_ctx(self), "unrecognized signature algorithm", 0, __FILE__, __LINE__);
return NULL;
}
Py_RETURN_NONE;
#endif
}

static int
Expand Down
Loading

Back | FazBrowse Home | New Git URL