We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TLS logging broken with new cryptography
https://github.com/pyca/cryptography/pull/8391 dropped `SSL_get_server_tmp_key()` so we need to disable the code that uses it if it's not available.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scrapy/utils/ssl.py`
Content:
```
1 import OpenSSL._util as pyOpenSSLutil
2 import OpenSSL.SSL
3 
4 from scrapy.utils.python import to_unicode
5 
6 
7 def ffi_buf_to_string(buf):
8     return to_unicode(pyOpenSSLutil.ffi.string(buf))
9 
10 
11 def x509name_to_string(x509name):
12     # from OpenSSL.crypto.X509Name.__repr__
13     result_buffer = pyOpenSSLutil.ffi.new("char[]", 512)
14     pyOpenSSLutil.lib.X509_NAME_oneline(
15         x509name._name, result_buffer, len(result_buffer)
16     )
17 
18     return ffi_buf_to_string(result_buffer)
19 
20 
21 def get_temp_key_info(ssl_object):
22     # adapted from OpenSSL apps/s_cb.c::ssl_print_tmp_key()
23     temp_key_p = pyOpenSSLutil.ffi.new("EVP_PKEY **")
24     if not pyOpenSSLutil.lib.SSL_get_server_tmp_key(ssl_object, temp_key_p):
25         return None
26     temp_key = temp_key_p[0]
27     if temp_key == pyOpenSSLutil.ffi.NULL:
28         return None
29     temp_key = pyOpenSSLutil.ffi.gc(temp_key, pyOpenSSLutil.lib.EVP_PKEY_free)
30     key_info = []
31     key_type = pyOpenSSLutil.lib.EVP_PKEY_id(temp_key)
32     if key_type == pyOpenSSLutil.lib.EVP_PKEY_RSA:
33         key_info.append("RSA")
34     elif key_type == pyOpenSSLutil.lib.EVP_PKEY_DH:
35         key_info.append("DH")
36     elif key_type == pyOpenSSLutil.lib.EVP_PKEY_EC:
37         key_info.append("ECDH")
38         ec_key = pyOpenSSLutil.lib.EVP_PKEY_get1_EC_KEY(temp_key)
39         ec_key = pyOpenSSLutil.ffi.gc(ec_key, pyOpenSSLutil.lib.EC_KEY_free)
40         nid = pyOpenSSLutil.lib.EC_GROUP_get_curve_name(
41             pyOpenSSLutil.lib.EC_KEY_get0_group(ec_key)
42         )
43         cname = pyOpenSSLutil.lib.EC_curve_nid2nist(nid)
44         if cname == pyOpenSSLutil.ffi.NULL:
45             cname = pyOpenSSLutil.lib.OBJ_nid2sn(nid)
46         key_info.append(ffi_buf_to_string(cname))
47     else:
48         key_info.append(ffi_buf_to_string(pyOpenSSLutil.lib.OBJ_nid2sn(key_type)))
49     key_info.append(f"{pyOpenSSLutil.lib.EVP_PKEY_bits(temp_key)} bits")
50     return ", ".join(key_info)
51 
52 
53 def get_openssl_version():
54     system_openssl = OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION).decode(
55         "ascii", errors="replace"
56     )
57     return f"{OpenSSL.version.__version__} ({system_openssl})"
58
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scrapy/utils/ssl.py b/scrapy/utils/ssl.py
--- a/scrapy/utils/ssl.py
+++ b/scrapy/utils/ssl.py
@@ -20,6 +20,9 @@
 
 def get_temp_key_info(ssl_object):
     # adapted from OpenSSL apps/s_cb.c::ssl_print_tmp_key()
+    if not hasattr(pyOpenSSLutil.lib, "SSL_get_server_tmp_key"):
+        # removed in cryptography 40.0.0
+        return None
     temp_key_p = pyOpenSSLutil.ffi.new("EVP_PKEY **")
     if not pyOpenSSLutil.lib.SSL_get_server_tmp_key(ssl_object, temp_key_p):
         return None

{"golden_diff": "diff --git a/scrapy/utils/ssl.py b/scrapy/utils/ssl.py\n--- a/scrapy/utils/ssl.py\n+++ b/scrapy/utils/ssl.py\n@@ -20,6 +20,9 @@\n \n def get_temp_key_info(ssl_object):\n     # adapted from OpenSSL apps/s_cb.c::ssl_print_tmp_key()\n+    if not hasattr(pyOpenSSLutil.lib, \"SSL_get_server_tmp_key\"):\n+        # removed in cryptography 40.0.0\n+        return None\n     temp_key_p = pyOpenSSLutil.ffi.new(\"EVP_PKEY **\")\n     if not pyOpenSSLutil.lib.SSL_get_server_tmp_key(ssl_object, temp_key_p):\n         return None\n", "issue": "TLS logging broken with new cryptography\nhttps://github.com/pyca/cryptography/pull/8391 dropped `SSL_get_server_tmp_key()` so we need to disable the code that uses it if it's not available.\n", "before_files": [{"content": "import OpenSSL._util as pyOpenSSLutil\nimport OpenSSL.SSL\n\nfrom scrapy.utils.python import to_unicode\n\n\ndef ffi_buf_to_string(buf):\n    return to_unicode(pyOpenSSLutil.ffi.string(buf))\n\n\ndef x509name_to_string(x509name):\n    # from OpenSSL.crypto.X509Name.__repr__\n    result_buffer = pyOpenSSLutil.ffi.new(\"char[]\", 512)\n    pyOpenSSLutil.lib.X509_NAME_oneline(\n        x509name._name, result_buffer, len(result_buffer)\n    )\n\n    return ffi_buf_to_string(result_buffer)\n\n\ndef get_temp_key_info(ssl_object):\n    # adapted from OpenSSL apps/s_cb.c::ssl_print_tmp_key()\n    temp_key_p = pyOpenSSLutil.ffi.new(\"EVP_PKEY **\")\n    if not pyOpenSSLutil.lib.SSL_get_server_tmp_key(ssl_object, temp_key_p):\n        return None\n    temp_key = temp_key_p[0]\n    if temp_key == pyOpenSSLutil.ffi.NULL:\n        return None\n    temp_key = pyOpenSSLutil.ffi.gc(temp_key, pyOpenSSLutil.lib.EVP_PKEY_free)\n    key_info = []\n    key_type = pyOpenSSLutil.lib.EVP_PKEY_id(temp_key)\n    if key_type == pyOpenSSLutil.lib.EVP_PKEY_RSA:\n        key_info.append(\"RSA\")\n    elif key_type == pyOpenSSLutil.lib.EVP_PKEY_DH:\n        key_info.append(\"DH\")\n    elif key_type == pyOpenSSLutil.lib.EVP_PKEY_EC:\n        key_info.append(\"ECDH\")\n        ec_key = pyOpenSSLutil.lib.EVP_PKEY_get1_EC_KEY(temp_key)\n        ec_key = pyOpenSSLutil.ffi.gc(ec_key, pyOpenSSLutil.lib.EC_KEY_free)\n        nid = pyOpenSSLutil.lib.EC_GROUP_get_curve_name(\n            pyOpenSSLutil.lib.EC_KEY_get0_group(ec_key)\n        )\n        cname = pyOpenSSLutil.lib.EC_curve_nid2nist(nid)\n        if cname == pyOpenSSLutil.ffi.NULL:\n            cname = pyOpenSSLutil.lib.OBJ_nid2sn(nid)\n        key_info.append(ffi_buf_to_string(cname))\n    else:\n        key_info.append(ffi_buf_to_string(pyOpenSSLutil.lib.OBJ_nid2sn(key_type)))\n    key_info.append(f\"{pyOpenSSLutil.lib.EVP_PKEY_bits(temp_key)} bits\")\n    return \", \".join(key_info)\n\n\ndef get_openssl_version():\n    system_openssl = OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION).decode(\n        \"ascii\", errors=\"replace\"\n    )\n    return f\"{OpenSSL.version.__version__} ({system_openssl})\"\n", "path": "scrapy/utils/ssl.py"}], "after_files": [{"content": "import OpenSSL._util as pyOpenSSLutil\nimport OpenSSL.SSL\n\nfrom scrapy.utils.python import to_unicode\n\n\ndef ffi_buf_to_string(buf):\n    return to_unicode(pyOpenSSLutil.ffi.string(buf))\n\n\ndef x509name_to_string(x509name):\n    # from OpenSSL.crypto.X509Name.__repr__\n    result_buffer = pyOpenSSLutil.ffi.new(\"char[]\", 512)\n    pyOpenSSLutil.lib.X509_NAME_oneline(\n        x509name._name, result_buffer, len(result_buffer)\n    )\n\n    return ffi_buf_to_string(result_buffer)\n\n\ndef get_temp_key_info(ssl_object):\n    # adapted from OpenSSL apps/s_cb.c::ssl_print_tmp_key()\n    if not hasattr(pyOpenSSLutil.lib, \"SSL_get_server_tmp_key\"):\n        # removed in cryptography 40.0.0\n        return None\n    temp_key_p = pyOpenSSLutil.ffi.new(\"EVP_PKEY **\")\n    if not pyOpenSSLutil.lib.SSL_get_server_tmp_key(ssl_object, temp_key_p):\n        return None\n    temp_key = temp_key_p[0]\n    if temp_key == pyOpenSSLutil.ffi.NULL:\n        return None\n    temp_key = pyOpenSSLutil.ffi.gc(temp_key, pyOpenSSLutil.lib.EVP_PKEY_free)\n    key_info = []\n    key_type = pyOpenSSLutil.lib.EVP_PKEY_id(temp_key)\n    if key_type == pyOpenSSLutil.lib.EVP_PKEY_RSA:\n        key_info.append(\"RSA\")\n    elif key_type == pyOpenSSLutil.lib.EVP_PKEY_DH:\n        key_info.append(\"DH\")\n    elif key_type == pyOpenSSLutil.lib.EVP_PKEY_EC:\n        key_info.append(\"ECDH\")\n        ec_key = pyOpenSSLutil.lib.EVP_PKEY_get1_EC_KEY(temp_key)\n        ec_key = pyOpenSSLutil.ffi.gc(ec_key, pyOpenSSLutil.lib.EC_KEY_free)\n        nid = pyOpenSSLutil.lib.EC_GROUP_get_curve_name(\n            pyOpenSSLutil.lib.EC_KEY_get0_group(ec_key)\n        )\n        cname = pyOpenSSLutil.lib.EC_curve_nid2nist(nid)\n        if cname == pyOpenSSLutil.ffi.NULL:\n            cname = pyOpenSSLutil.lib.OBJ_nid2sn(nid)\n        key_info.append(ffi_buf_to_string(cname))\n    else:\n        key_info.append(ffi_buf_to_string(pyOpenSSLutil.lib.OBJ_nid2sn(key_type)))\n    key_info.append(f\"{pyOpenSSLutil.lib.EVP_PKEY_bits(temp_key)} bits\")\n    return \", \".join(key_info)\n\n\ndef get_openssl_version():\n    system_openssl = OpenSSL.SSL.SSLeay_version(OpenSSL.SSL.SSLEAY_VERSION).decode(\n        \"ascii\", errors=\"replace\"\n    )\n    return f\"{OpenSSL.version.__version__} ({system_openssl})\"\n", "path": "scrapy/utils/ssl.py"}]}