Skip to content

Commit 3e1f19a

Browse files
authored
Deprecate a few more extensions APIs (#1357)
They really should have been deprecated previously.
1 parent ec7f67b commit 3e1f19a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Deprecations:
1414
^^^^^^^^^^^^^
1515

1616
- Deprecated ``OpenSSL.rand`` - callers should use ``os.urandom()`` instead.
17+
- Deprecated ``add_extensions`` and ``get_extensions`` on ``OpenSSL.crypto.X509Req`` and ``OpenSSL.crypto.X509``. These should have been deprecated at the same time ``X509Extension`` was. Users should use pyca/cryptography's X.509 APIs instead.
1718
- Deprecated ``OpenSSL.crypto.get_elliptic_curves`` and ``OpenSSL.crypto.get_elliptic_curve``, as well as passing the reult of them to ``OpenSSL.SSL.Context.set_tmp_ecdh``, users should instead pass curves from ``cryptography``.
1819
- Deprecated passing ``X509`` objects to ``OpenSSL.SSL.Context.use_certificate``, ``OpenSSL.SSL.Connection.use_certificate``, ``OpenSSL.SSL.Context.add_extra_chain_cert``, and ``OpenSSL.SSL.Context.add_client_ca``, users should instead pass ``cryptography.x509.Certificate`` instances. This is in preparation for deprecating pyOpenSSL's ``X509`` entirely.
1920
- Deprecated passing ``PKey`` objects to ``OpenSSL.SSL.Context.use_privatekey`` and ``OpenSSL.SSL.Connection.use_privatekey``, users should instead pass ``cryptography`` priate key instances. This is in preparation for deprecating pyOpenSSL's ``PKey`` entirely.

src/OpenSSL/crypto.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime
55
import functools
66
import typing
7+
import warnings
78
from base64 import b16encode
89
from functools import partial
910
from os import PathLike
@@ -1108,6 +1109,16 @@ def add_extensions(
11081109
:type extensions: iterable of :py:class:`X509Extension`
11091110
:return: ``None``
11101111
"""
1112+
warnings.warn(
1113+
(
1114+
"This API is deprecated and will be removed in a future "
1115+
"version of pyOpenSSL. You should use pyca/cryptography's "
1116+
"X.509 APIs instead."
1117+
),
1118+
DeprecationWarning,
1119+
stacklevel=2,
1120+
)
1121+
11111122
stack = _lib.sk_X509_EXTENSION_new_null()
11121123
_openssl_assert(stack != _ffi.NULL)
11131124

@@ -1132,6 +1143,16 @@ def get_extensions(self) -> list[_X509ExtensionInternal]:
11321143
11331144
.. versionadded:: 0.15
11341145
"""
1146+
warnings.warn(
1147+
(
1148+
"This API is deprecated and will be removed in a future "
1149+
"version of pyOpenSSL. You should use pyca/cryptography's "
1150+
"X.509 APIs instead."
1151+
),
1152+
DeprecationWarning,
1153+
stacklevel=2,
1154+
)
1155+
11351156
exts = []
11361157
native_exts_obj = _lib.X509_REQ_get_extensions(self._req)
11371158
native_exts_obj = _ffi.gc(
@@ -1652,6 +1673,16 @@ def add_extensions(
16521673
:type extensions: An iterable of :py:class:`X509Extension` objects.
16531674
:return: ``None``
16541675
"""
1676+
warnings.warn(
1677+
(
1678+
"This API is deprecated and will be removed in a future "
1679+
"version of pyOpenSSL. You should use pyca/cryptography's "
1680+
"X.509 APIs instead."
1681+
),
1682+
DeprecationWarning,
1683+
stacklevel=2,
1684+
)
1685+
16551686
for ext in extensions:
16561687
if not isinstance(ext, _X509ExtensionInternal):
16571688
raise ValueError("One of the elements is not an X509Extension")
@@ -1673,6 +1704,16 @@ def get_extension(self, index: int) -> _X509ExtensionInternal:
16731704
16741705
.. versionadded:: 0.12
16751706
"""
1707+
warnings.warn(
1708+
(
1709+
"This API is deprecated and will be removed in a future "
1710+
"version of pyOpenSSL. You should use pyca/cryptography's "
1711+
"X.509 APIs instead."
1712+
),
1713+
DeprecationWarning,
1714+
stacklevel=2,
1715+
)
1716+
16761717
ext = _X509ExtensionInternal.__new__(_X509ExtensionInternal)
16771718
ext._extension = _lib.X509_get_ext(self._x509, index)
16781719
if ext._extension == _ffi.NULL:

0 commit comments

Comments
 (0)