]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103242: Migrate SSLContext.set_ecdh_curve not to use deprecated APIs (#103378)
authorDong-hee Na <donghee.na@python.org>
Sat, 8 Apr 2023 17:56:42 +0000 (02:56 +0900)
committerGitHub <noreply@github.com>
Sat, 8 Apr 2023 17:56:42 +0000 (10:56 -0700)
Migrate `SSLContext.set_ecdh_curve()` not to use deprecated OpenSSL APIs.

Misc/NEWS.d/next/Core and Builtins/2023-04-08-17-13-07.gh-issue-103242.ysI1b3.rst [new file with mode: 0644]
Modules/_ssl.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-04-08-17-13-07.gh-issue-103242.ysI1b3.rst b/Misc/NEWS.d/next/Core and Builtins/2023-04-08-17-13-07.gh-issue-103242.ysI1b3.rst
new file mode 100644 (file)
index 0000000..38b107f
--- /dev/null
@@ -0,0 +1,2 @@
+Migrate :meth:`~ssl.SSLContext.set_ecdh_curve` method not to use deprecated
+OpenSSL APIs. Patch by Dong-hee Na.
index 5f17cd502d4598a997da7a8ccc86cd6802d45b9c..c9e2f24d66cc00edb72b4fdc16972cab4219a873 100644 (file)
@@ -4336,8 +4336,6 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
 {
     PyObject *name_bytes;
     int nid;
-    EC_KEY *key;
-
     if (!PyUnicode_FSConverter(name, &name_bytes))
         return NULL;
     assert(PyBytes_Check(name_bytes));
@@ -4348,13 +4346,20 @@ _ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name)
                      "unknown elliptic curve name %R", name);
         return NULL;
     }
-    key = EC_KEY_new_by_curve_name(nid);
+#if OPENSSL_VERSION_MAJOR < 3
+    EC_KEY *key = EC_KEY_new_by_curve_name(nid);
     if (key == NULL) {
         _setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
         return NULL;
     }
     SSL_CTX_set_tmp_ecdh(self->ctx, key);
     EC_KEY_free(key);
+#else
+    if (!SSL_CTX_set1_groups(self->ctx, &nid, 1)) {
+        _setSSLError(get_state_ctx(self), NULL, 0, __FILE__, __LINE__);
+        return NULL;
+    }
+#endif
     Py_RETURN_NONE;
 }