pyOpenSSL 26.1.0__tar.gz → 26.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/CHANGELOG.rst +44 -0
  2. {pyopenssl-26.1.0/src/pyOpenSSL.egg-info → pyopenssl-26.3.0}/PKG-INFO +48 -5
  3. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/api/crypto.rst +1 -28
  4. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/introduction.rst +1 -1
  5. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/noxfile.py +1 -1
  6. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/setup.py +3 -7
  7. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/SSL.py +84 -9
  8. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/_util.py +1 -4
  9. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/crypto.py +83 -585
  10. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/version.py +1 -1
  11. {pyopenssl-26.1.0 → pyopenssl-26.3.0/src/pyOpenSSL.egg-info}/PKG-INFO +48 -5
  12. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/pyOpenSSL.egg-info/requires.txt +2 -2
  13. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/test_crypto.py +5 -530
  14. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/test_ssl.py +61 -26
  15. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/CODE_OF_CONDUCT.rst +0 -0
  16. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/CONTRIBUTING.rst +0 -0
  17. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/INSTALL.rst +0 -0
  18. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/LICENSE +0 -0
  19. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/MANIFEST.in +0 -0
  20. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/README.rst +0 -0
  21. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/ChangeLog_old.txt +0 -0
  22. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/Makefile +0 -0
  23. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/Quotes +0 -0
  24. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/README +0 -0
  25. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/api/ssl.rst +0 -0
  26. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/api.rst +0 -0
  27. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/backward-compatibility.rst +0 -0
  28. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/changelog.rst +0 -0
  29. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/conf.py +0 -0
  30. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/images/pyopenssl-brand.png +0 -0
  31. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/images/pyopenssl-icon.png +0 -0
  32. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/images/pyopenssl-logo.png +0 -0
  33. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/images/pyopenssl.svg +0 -0
  34. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/index.rst +0 -0
  35. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/install.rst +0 -0
  36. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/internals.rst +0 -0
  37. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/doc/make.bat +0 -0
  38. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/pyproject.toml +0 -0
  39. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/setup.cfg +0 -0
  40. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/__init__.py +0 -0
  41. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/debug.py +0 -0
  42. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/py.typed +0 -0
  43. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/OpenSSL/rand.py +0 -0
  44. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/pyOpenSSL.egg-info/SOURCES.txt +0 -0
  45. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/pyOpenSSL.egg-info/dependency_links.txt +0 -0
  46. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/src/pyOpenSSL.egg-info/top_level.txt +0 -0
  47. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/__init__.py +0 -0
  48. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/conftest.py +0 -0
  49. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/test_debug.py +0 -0
  50. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/test_rand.py +0 -0
  51. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/test_util.py +0 -0
  52. {pyopenssl-26.1.0 → pyopenssl-26.3.0}/tests/util.py +0 -0
@@ -4,6 +4,50 @@ Changelog
4
4
  Versions are year-based with a strict backward-compatibility policy.
5
5
  The third digit is only for regressions.
6
6
 
7
+ 26.3.0 (2026-06-12)
8
+ -------------------
9
+
10
+ Backward-incompatible changes:
11
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12
+
13
+ - Dropped support for Python 3.8.
14
+ - The minimum ``cryptography`` version is now 49.0.0.
15
+ - Removed deprecated ``OpenSSL.crypto.X509Req``, ``OpenSSL.crypto.dump_certificate_request``, and ``OpenSSL.crypto.load_certificate_request``. ``cryptography.x509`` should be used instead.
16
+ - ``OpenSSL.SSL.Connection.set_session`` now raises ``ValueError`` if the ``Session`` was obtained from a ``Connection`` that was using a different ``Context`` than this one. OpenSSL requires (but does not verify) that sessions only be re-used with a compatible ``SSL_CTX``, so this contract is now enforced.
17
+
18
+ Deprecations:
19
+ ^^^^^^^^^^^^^
20
+
21
+ - Deprecated ``OpenSSL.crypto.PKey.generate_key`` and ``OpenSSL.crypto.PKey.check``. The key generation and loading APIs in ``cryptography`` should be used instead.
22
+ - Deprecated ``OpenSSL.crypto.dump_privatekey``. The serialization APIs on ``cryptography`` private key types should be used instead.
23
+ - Deprecated all the mutable APIs on ``OpenSSL.crypto.X509``: ``set_version``, ``set_pubkey``, ``sign``, ``set_serial_number``, ``gmtime_adj_notAfter``, ``gmtime_adj_notBefore``, ``set_notBefore``, ``set_notAfter``, ``set_issuer``, and ``set_subject``. ``cryptography.x509.CertificateBuilder`` should be used instead.
24
+ - Deprecated ``OpenSSL.SSL.Context.set_passwd_cb``. Users should decrypt and load their private keys themselves, with ``cryptography``'s key loading APIs, and then call ``OpenSSL.SSL.Context.use_privatekey``.
25
+ - Deprecated ``OpenSSL.crypto.X509Name``, as well as the remaining APIs that consume or return it: ``OpenSSL.crypto.X509.get_issuer``, ``OpenSSL.crypto.X509.get_subject``, and ``OpenSSL.SSL.Context.set_client_ca_list``. The APIs in ``cryptography.x509`` should be used instead.
26
+
27
+ Changes:
28
+ ^^^^^^^^
29
+
30
+ - ``OpenSSL.SSL.Connection.get_client_ca_list`` now takes an ``as_cryptography`` keyword-argument. When ``True`` is passed then ``cryptography.x509.Name`` are returned, instead of ``OpenSSL.crypto.X509Name``. In the future, passing ``False`` (the default) will be deprecated.
31
+
32
+
33
+ 26.2.0 (2026-05-04)
34
+ -------------------
35
+
36
+ Backward-incompatible changes:
37
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38
+
39
+ - Removed deprecated ``OpenSSL.crypto.X509Extension``, ``OpenSSL.crypto.X509Req.add_extension``, ``OpenSSL.crypto.X509Req.get_extensions``, ``OpenSSL.crypto.X509.add_extension``, ``OpenSSL.crypto.X509.get_extensions``. ``cryptography.x509`` should be used instead.
40
+ - It is now an error to calling any mutating method on ``OpenSSL.SSL.Context`` after it has been used to create a ``Connection``. This was previously deprecated and has always been unsafe.
41
+
42
+ Deprecations:
43
+ ^^^^^^^^^^^^^
44
+
45
+ Changes:
46
+ ^^^^^^^^
47
+
48
+ - Maximum supported ``cryptography`` version is now 48.x.
49
+ - Added ``OpenSSL.SSL.Connection.set_options`` to set options on a per-connection basis.
50
+
7
51
  26.1.0 (2026-04-24)
8
52
  -------------------
9
53
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyOpenSSL
3
- Version: 26.1.0
3
+ Version: 26.3.0
4
4
  Summary: Python wrapper module around the OpenSSL library
5
5
  Home-page: https://pyopenssl.org/
6
6
  Author: The pyOpenSSL developers
@@ -14,7 +14,6 @@ Classifier: Operating System :: MacOS :: MacOS X
14
14
  Classifier: Operating System :: Microsoft :: Windows
15
15
  Classifier: Operating System :: POSIX
16
16
  Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.8
18
17
  Classifier: Programming Language :: Python :: 3.9
19
18
  Classifier: Programming Language :: Python :: 3.10
20
19
  Classifier: Programming Language :: Python :: 3.11
@@ -25,10 +24,10 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
25
24
  Classifier: Topic :: Security :: Cryptography
26
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
26
  Classifier: Topic :: System :: Networking
28
- Requires-Python: >=3.8
27
+ Requires-Python: >=3.9
29
28
  License-File: LICENSE
30
- Requires-Dist: cryptography<48,>=46.0.0
31
- Requires-Dist: typing-extensions>=4.9; python_version < "3.13" and python_version >= "3.8"
29
+ Requires-Dist: cryptography<50,>=49.0.0
30
+ Requires-Dist: typing-extensions>=4.9; python_version < "3.13"
32
31
  Provides-Extra: test
33
32
  Requires-Dist: pytest-rerunfailures; extra == "test"
34
33
  Requires-Dist: pretend; extra == "test"
@@ -96,6 +95,50 @@ You can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get invol
96
95
  Release Information
97
96
  ===================
98
97
 
98
+ 26.3.0 (2026-06-12)
99
+ -------------------
100
+
101
+ Backward-incompatible changes:
102
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103
+
104
+ - Dropped support for Python 3.8.
105
+ - The minimum ``cryptography`` version is now 49.0.0.
106
+ - Removed deprecated ``OpenSSL.crypto.X509Req``, ``OpenSSL.crypto.dump_certificate_request``, and ``OpenSSL.crypto.load_certificate_request``. ``cryptography.x509`` should be used instead.
107
+ - ``OpenSSL.SSL.Connection.set_session`` now raises ``ValueError`` if the ``Session`` was obtained from a ``Connection`` that was using a different ``Context`` than this one. OpenSSL requires (but does not verify) that sessions only be re-used with a compatible ``SSL_CTX``, so this contract is now enforced.
108
+
109
+ Deprecations:
110
+ ^^^^^^^^^^^^^
111
+
112
+ - Deprecated ``OpenSSL.crypto.PKey.generate_key`` and ``OpenSSL.crypto.PKey.check``. The key generation and loading APIs in ``cryptography`` should be used instead.
113
+ - Deprecated ``OpenSSL.crypto.dump_privatekey``. The serialization APIs on ``cryptography`` private key types should be used instead.
114
+ - Deprecated all the mutable APIs on ``OpenSSL.crypto.X509``: ``set_version``, ``set_pubkey``, ``sign``, ``set_serial_number``, ``gmtime_adj_notAfter``, ``gmtime_adj_notBefore``, ``set_notBefore``, ``set_notAfter``, ``set_issuer``, and ``set_subject``. ``cryptography.x509.CertificateBuilder`` should be used instead.
115
+ - Deprecated ``OpenSSL.SSL.Context.set_passwd_cb``. Users should decrypt and load their private keys themselves, with ``cryptography``'s key loading APIs, and then call ``OpenSSL.SSL.Context.use_privatekey``.
116
+ - Deprecated ``OpenSSL.crypto.X509Name``, as well as the remaining APIs that consume or return it: ``OpenSSL.crypto.X509.get_issuer``, ``OpenSSL.crypto.X509.get_subject``, and ``OpenSSL.SSL.Context.set_client_ca_list``. The APIs in ``cryptography.x509`` should be used instead.
117
+
118
+ Changes:
119
+ ^^^^^^^^
120
+
121
+ - ``OpenSSL.SSL.Connection.get_client_ca_list`` now takes an ``as_cryptography`` keyword-argument. When ``True`` is passed then ``cryptography.x509.Name`` are returned, instead of ``OpenSSL.crypto.X509Name``. In the future, passing ``False`` (the default) will be deprecated.
122
+
123
+
124
+ 26.2.0 (2026-05-04)
125
+ -------------------
126
+
127
+ Backward-incompatible changes:
128
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129
+
130
+ - Removed deprecated ``OpenSSL.crypto.X509Extension``, ``OpenSSL.crypto.X509Req.add_extension``, ``OpenSSL.crypto.X509Req.get_extensions``, ``OpenSSL.crypto.X509.add_extension``, ``OpenSSL.crypto.X509.get_extensions``. ``cryptography.x509`` should be used instead.
131
+ - It is now an error to calling any mutating method on ``OpenSSL.SSL.Context`` after it has been used to create a ``Connection``. This was previously deprecated and has always been unsafe.
132
+
133
+ Deprecations:
134
+ ^^^^^^^^^^^^^
135
+
136
+ Changes:
137
+ ^^^^^^^^
138
+
139
+ - Maximum supported ``cryptography`` version is now 48.x.
140
+ - Added ``OpenSSL.SSL.Connection.set_options`` to set options on a per-connection basis.
141
+
99
142
  26.1.0 (2026-04-24)
100
143
  -------------------
101
144
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  `pyca/cryptography`_ is likely a better choice than using this module.
14
14
  It contains a complete set of cryptographic primitives as well as a significantly better and more powerful X509 API.
15
- If necessary you can convert to and from cryptography objects using the ``to_cryptography`` and ``from_cryptography`` methods on ``X509``, ``X509Req``, ``CRL``, and ``PKey``.
15
+ If necessary you can convert to and from cryptography objects using the ``to_cryptography`` and ``from_cryptography`` methods on ``X509``, ``CRL``, and ``PKey``.
16
16
 
17
17
 
18
18
  Elliptic curves
@@ -42,13 +42,6 @@ Certificates
42
42
 
43
43
  .. autofunction:: load_certificate
44
44
 
45
- Certificate signing requests
46
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
-
48
- .. autofunction:: dump_certificate_request
49
-
50
- .. autofunction:: load_certificate_request
51
-
52
45
  Private keys
53
46
  ~~~~~~~~~~~~
54
47
 
@@ -82,16 +75,6 @@ X509Name objects
82
75
  :special-members:
83
76
  :exclude-members: __repr__, __getattr__, __weakref__
84
77
 
85
- .. _openssl-x509req:
86
-
87
- X509Req objects
88
- ---------------
89
-
90
- .. autoclass:: X509Req
91
- :members:
92
- :special-members:
93
- :exclude-members: __weakref__
94
-
95
78
  .. _openssl-x509store:
96
79
 
97
80
  X509Store objects
@@ -148,16 +131,6 @@ PKey objects
148
131
 
149
132
  Key type constants.
150
133
 
151
- .. _openssl-509ext:
152
-
153
- X509Extension objects
154
- ---------------------
155
-
156
- .. autoclass:: X509Extension
157
- :members:
158
- :special-members:
159
- :exclude-members: __weakref__
160
-
161
134
  Exceptions
162
135
  ----------
163
136
 
@@ -14,7 +14,7 @@ Other OpenSSL wrappers for Python at the time were also limited, though in diffe
14
14
  Later it was maintained by `Jean-Paul Calderone`_ who among other things managed to make pyOpenSSL a pure Python project which the current maintainers are *very* grateful for.
15
15
 
16
16
  Over the time the standard library's ``ssl`` module improved, never reaching the completeness of pyOpenSSL's API coverage.
17
- pyOpenSSL remains the only choice for full-featured TLS code in Python versions 3.8+ and PyPy_.
17
+ pyOpenSSL remains the only choice for full-featured TLS code in Python versions 3.9+ and PyPy_.
18
18
 
19
19
 
20
20
  Development
@@ -3,7 +3,7 @@ import nox
3
3
  nox.options.reuse_existing_virtualenvs = True
4
4
  nox.options.default_venv_backend = "uv|virtualenv"
5
5
 
6
- MINIMUM_CRYPTOGRAPHY_VERSION = "46.0.0"
6
+ MINIMUM_CRYPTOGRAPHY_VERSION = "49.0.0"
7
7
 
8
8
 
9
9
  @nox.session
@@ -77,7 +77,6 @@ if __name__ == "__main__":
77
77
  "Operating System :: Microsoft :: Windows",
78
78
  "Operating System :: POSIX",
79
79
  "Programming Language :: Python :: 3",
80
- "Programming Language :: Python :: 3.8",
81
80
  "Programming Language :: Python :: 3.9",
82
81
  "Programming Language :: Python :: 3.10",
83
82
  "Programming Language :: Python :: 3.11",
@@ -89,15 +88,12 @@ if __name__ == "__main__":
89
88
  "Topic :: Software Development :: Libraries :: Python Modules",
90
89
  "Topic :: System :: Networking",
91
90
  ],
92
- python_requires=">=3.8",
91
+ python_requires=">=3.9",
93
92
  packages=find_packages(where="src"),
94
93
  package_dir={"": "src"},
95
94
  install_requires=[
96
- "cryptography>=46.0.0,<48",
97
- (
98
- "typing-extensions>=4.9; "
99
- "python_version < '3.13' and python_version >= '3.8'"
100
- ),
95
+ "cryptography>=49.0.0,<50",
96
+ "typing-extensions>=4.9; python_version < '3.13'",
101
97
  ],
102
98
  extras_require={
103
99
  "test": ["pytest-rerunfailures", "pretend", "pytest>=3.0.1"],
@@ -13,6 +13,11 @@ from sys import platform
13
13
  from typing import Any, Callable, Optional, TypeVar
14
14
  from weakref import WeakValueDictionary
15
15
 
16
+ if sys.version_info >= (3, 13):
17
+ from warnings import deprecated
18
+ else:
19
+ from typing_extensions import deprecated
20
+
16
21
  from cryptography import x509
17
22
  from cryptography.hazmat.primitives.asymmetric import ec
18
23
 
@@ -847,6 +852,11 @@ class Session:
847
852
  """
848
853
 
849
854
  _session: Any
855
+ # The Context the Connection this Session came from was using. OpenSSL
856
+ # requires that a session only be re-used with a compatible SSL_CTX, but
857
+ # doesn't verify it, so we pin the Context here and enforce identity in
858
+ # Connection.set_session.
859
+ _context: Context
850
860
 
851
861
 
852
862
  F = TypeVar("F", bound=Callable[..., Any])
@@ -856,13 +866,9 @@ def _require_not_used(f: F) -> F:
856
866
  @wraps(f)
857
867
  def inner(self: Context, *args: Any, **kwargs: Any) -> Any:
858
868
  if self._used:
859
- warnings.warn(
860
- (
861
- "Attempting to mutate a Context after a Connection was "
862
- "created. In the future, this will raise an exception"
863
- ),
864
- DeprecationWarning,
865
- stacklevel=2,
869
+ raise ValueError(
870
+ "Context has already been used to create a Connection, it "
871
+ "cannot be mutated again"
866
872
  )
867
873
  return f(self, *args, **kwargs)
868
874
 
@@ -1020,6 +1026,11 @@ class Context:
1020
1026
  FILETYPE_PEM, wrapper, more_args=True, truncate=True
1021
1027
  )
1022
1028
 
1029
+ @deprecated(
1030
+ "Context.set_passwd_cb is deprecated. You should decrypt and load "
1031
+ "your private key yourself, with cryptography's key loading APIs, "
1032
+ "and then use Context.use_privatekey instead."
1033
+ )
1023
1034
  @_require_not_used
1024
1035
  def set_passwd_cb(
1025
1036
  self,
@@ -1531,6 +1542,10 @@ class Context:
1531
1542
  _lib.SSL_CTX_set_ciphersuites(self._context, ciphersuites) == 1
1532
1543
  )
1533
1544
 
1545
+ @deprecated(
1546
+ "Context.set_client_ca_list is deprecated. X509Name support in "
1547
+ "pyOpenSSL is deprecated."
1548
+ )
1534
1549
  @_require_not_used
1535
1550
  def set_client_ca_list(
1536
1551
  self, certificate_authorities: Sequence[X509Name]
@@ -2105,6 +2120,19 @@ class Connection:
2105
2120
  self._context = context
2106
2121
  self._context._used = True
2107
2122
 
2123
+ def set_options(self, options: int) -> int:
2124
+ """
2125
+ Add options. Options set before are not cleared!
2126
+ This method should be used with the :const:`OP_*` constants.
2127
+
2128
+ :param options: The options to add.
2129
+ :return: The new option bitmask.
2130
+ """
2131
+ if not isinstance(options, int):
2132
+ raise TypeError("options must be an integer")
2133
+
2134
+ return _lib.SSL_set_options(self._ssl, options)
2135
+
2108
2136
  def get_servername(self) -> bytes | None:
2109
2137
  """
2110
2138
  Retrieve the servername extension value if provided in the client hello
@@ -2619,10 +2647,30 @@ class Connection:
2619
2647
  ciphers.append(_ffi.string(result).decode("utf-8"))
2620
2648
  return ciphers
2621
2649
 
2622
- def get_client_ca_list(self) -> list[X509Name]:
2650
+ @typing.overload
2651
+ def get_client_ca_list(
2652
+ self, *, as_cryptography: typing.Literal[True]
2653
+ ) -> list[x509.Name]:
2654
+ pass
2655
+
2656
+ @typing.overload
2657
+ def get_client_ca_list(
2658
+ self, *, as_cryptography: typing.Literal[False] = False
2659
+ ) -> list[X509Name]:
2660
+ pass
2661
+
2662
+ def get_client_ca_list(
2663
+ self,
2664
+ *,
2665
+ as_cryptography: typing.Literal[True] | typing.Literal[False] = False,
2666
+ ) -> list[X509Name] | list[x509.Name]:
2623
2667
  """
2624
2668
  Get CAs whose certificates are suggested for client authentication.
2625
2669
 
2670
+ :param bool as_cryptography: Controls whether a list of
2671
+ ``cryptography.x509.Name`` or ``OpenSSL.crypto.X509Name``
2672
+ objects should be returned.
2673
+
2626
2674
  :return: If this is a server connection, the list of certificate
2627
2675
  authorities that will be sent or has been sent to the client, as
2628
2676
  controlled by this :class:`Connection`'s :class:`Context`.
@@ -2637,13 +2685,28 @@ class Connection:
2637
2685
  # TODO: This is untested.
2638
2686
  return []
2639
2687
 
2688
+ if as_cryptography:
2689
+ names = []
2690
+ for i in range(_lib.sk_X509_NAME_num(ca_names)):
2691
+ name = _lib.sk_X509_NAME_value(ca_names, i)
2692
+ result_buffer = _ffi.new("unsigned char**")
2693
+ encode_result = _lib.i2d_X509_NAME(name, result_buffer)
2694
+ _openssl_assert(encode_result >= 0)
2695
+ der = _ffi.buffer(result_buffer[0], encode_result)[:]
2696
+ _lib.OPENSSL_free(result_buffer[0])
2697
+
2698
+ names.append(x509.Name.from_bytes(der))
2699
+ return names
2700
+
2640
2701
  result = []
2641
2702
  for i in range(_lib.sk_X509_NAME_num(ca_names)):
2642
2703
  name = _lib.sk_X509_NAME_value(ca_names, i)
2643
2704
  copy = _lib.X509_NAME_dup(name)
2644
2705
  _openssl_assert(copy != _ffi.NULL)
2645
2706
 
2646
- pyname = X509Name.__new__(X509Name)
2707
+ # Bypass X509Name.__new__, which warns that X509Name is
2708
+ # deprecated -- this method is not itself deprecated.
2709
+ pyname = object.__new__(X509Name)
2647
2710
  pyname._name = _ffi.gc(copy, _lib.X509_NAME_free)
2648
2711
  result.append(pyname)
2649
2712
  return result
@@ -3023,12 +3086,18 @@ class Connection:
3023
3086
 
3024
3087
  pysession = Session.__new__(Session)
3025
3088
  pysession._session = _ffi.gc(session, _lib.SSL_SESSION_free)
3089
+ pysession._context = self._context
3026
3090
  return pysession
3027
3091
 
3028
3092
  def set_session(self, session: Session) -> None:
3029
3093
  """
3030
3094
  Set the session to be used when the TLS/SSL connection is established.
3031
3095
 
3096
+ The session must have been obtained, via :meth:`get_session`, from a
3097
+ :class:`Connection` that was using the same :class:`Context` as this
3098
+ one. OpenSSL requires (but does not verify) that sessions only be
3099
+ re-used with a compatible ``SSL_CTX``, so this is enforced here.
3100
+
3032
3101
  :param session: A Session instance representing the session to use.
3033
3102
  :returns: None
3034
3103
 
@@ -3037,6 +3106,12 @@ class Connection:
3037
3106
  if not isinstance(session, Session):
3038
3107
  raise TypeError("session must be a Session instance")
3039
3108
 
3109
+ if session._context is not self._context:
3110
+ raise ValueError(
3111
+ "session must have been created by a Connection using the "
3112
+ "same Context as this one"
3113
+ )
3114
+
3040
3115
  result = _lib.SSL_set_session(self._ssl, session._session)
3041
3116
  _openssl_assert(result == 1)
3042
3117
 
@@ -7,10 +7,7 @@ from typing import Any, Callable, NoReturn, Union
7
7
 
8
8
  from cryptography.hazmat.bindings.openssl.binding import Binding
9
9
 
10
- if sys.version_info >= (3, 9):
11
- StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
12
- else:
13
- StrOrBytesPath = Union[str, bytes, os.PathLike]
10
+ StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
14
11
 
15
12
  binding = Binding()
16
13
  ffi = binding.ffi