pyOpenSSL 26.0.0__tar.gz → 26.2.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.
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/CHANGELOG.rst +33 -0
- {pyopenssl-26.0.0/src/pyOpenSSL.egg-info → pyopenssl-26.2.0}/PKG-INFO +35 -2
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/api/crypto.rst +0 -10
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/backward-compatibility.rst +7 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/setup.py +1 -1
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/SSL.py +16 -7
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/crypto.py +2 -309
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/version.py +1 -1
- {pyopenssl-26.0.0 → pyopenssl-26.2.0/src/pyOpenSSL.egg-info}/PKG-INFO +35 -2
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/requires.txt +1 -1
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/test_crypto.py +18 -327
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/test_ssl.py +24 -1
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/CODE_OF_CONDUCT.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/CONTRIBUTING.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/INSTALL.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/LICENSE +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/MANIFEST.in +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/README.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/ChangeLog_old.txt +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/Makefile +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/Quotes +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/README +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/api/ssl.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/api.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/changelog.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/conf.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/images/pyopenssl-brand.png +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/images/pyopenssl-icon.png +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/images/pyopenssl-logo.png +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/images/pyopenssl.svg +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/index.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/install.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/internals.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/introduction.rst +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/doc/make.bat +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/noxfile.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/pyproject.toml +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/setup.cfg +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/__init__.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/_util.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/debug.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/py.typed +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/OpenSSL/rand.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/SOURCES.txt +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/dependency_links.txt +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/top_level.txt +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/__init__.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/conftest.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/test_debug.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/test_rand.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/test_util.py +0 -0
- {pyopenssl-26.0.0 → pyopenssl-26.2.0}/tests/util.py +0 -0
|
@@ -4,6 +4,39 @@ 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.2.0 (2026-05-04)
|
|
8
|
+
-------------------
|
|
9
|
+
|
|
10
|
+
Backward-incompatible changes:
|
|
11
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
- 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.
|
|
15
|
+
|
|
16
|
+
Deprecations:
|
|
17
|
+
^^^^^^^^^^^^^
|
|
18
|
+
|
|
19
|
+
Changes:
|
|
20
|
+
^^^^^^^^
|
|
21
|
+
|
|
22
|
+
- Maximum supported ``cryptography`` version is now 48.x.
|
|
23
|
+
- Added ``OpenSSL.SSL.Connection.set_options`` to set options on a per-connection basis.
|
|
24
|
+
|
|
25
|
+
26.1.0 (2026-04-24)
|
|
26
|
+
-------------------
|
|
27
|
+
|
|
28
|
+
Backward-incompatible changes:
|
|
29
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
30
|
+
|
|
31
|
+
Deprecations:
|
|
32
|
+
^^^^^^^^^^^^^
|
|
33
|
+
|
|
34
|
+
Changes:
|
|
35
|
+
^^^^^^^^
|
|
36
|
+
|
|
37
|
+
- Maximum supported ``cryptography`` version is now 47.x.
|
|
38
|
+
- Fixed ``X509Name`` field setters to correctly pass the value length to OpenSSL. Previously, values containing NUL bytes would be silently truncated, causing a divergence between the stored ASN.1 value and the value visible from Python. Credit to **BudongJW** for reporting the issue. **CVE-2026-40475**
|
|
39
|
+
|
|
7
40
|
26.0.0 (2026-03-15)
|
|
8
41
|
-------------------
|
|
9
42
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyOpenSSL
|
|
3
|
-
Version: 26.
|
|
3
|
+
Version: 26.2.0
|
|
4
4
|
Summary: Python wrapper module around the OpenSSL library
|
|
5
5
|
Home-page: https://pyopenssl.org/
|
|
6
6
|
Author: The pyOpenSSL developers
|
|
@@ -27,7 +27,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
27
27
|
Classifier: Topic :: System :: Networking
|
|
28
28
|
Requires-Python: >=3.8
|
|
29
29
|
License-File: LICENSE
|
|
30
|
-
Requires-Dist: cryptography<
|
|
30
|
+
Requires-Dist: cryptography<49,>=46.0.0
|
|
31
31
|
Requires-Dist: typing-extensions>=4.9; python_version < "3.13" and python_version >= "3.8"
|
|
32
32
|
Provides-Extra: test
|
|
33
33
|
Requires-Dist: pytest-rerunfailures; extra == "test"
|
|
@@ -96,6 +96,39 @@ You can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get invol
|
|
|
96
96
|
Release Information
|
|
97
97
|
===================
|
|
98
98
|
|
|
99
|
+
26.2.0 (2026-05-04)
|
|
100
|
+
-------------------
|
|
101
|
+
|
|
102
|
+
Backward-incompatible changes:
|
|
103
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
104
|
+
|
|
105
|
+
- 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.
|
|
106
|
+
- 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.
|
|
107
|
+
|
|
108
|
+
Deprecations:
|
|
109
|
+
^^^^^^^^^^^^^
|
|
110
|
+
|
|
111
|
+
Changes:
|
|
112
|
+
^^^^^^^^
|
|
113
|
+
|
|
114
|
+
- Maximum supported ``cryptography`` version is now 48.x.
|
|
115
|
+
- Added ``OpenSSL.SSL.Connection.set_options`` to set options on a per-connection basis.
|
|
116
|
+
|
|
117
|
+
26.1.0 (2026-04-24)
|
|
118
|
+
-------------------
|
|
119
|
+
|
|
120
|
+
Backward-incompatible changes:
|
|
121
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
122
|
+
|
|
123
|
+
Deprecations:
|
|
124
|
+
^^^^^^^^^^^^^
|
|
125
|
+
|
|
126
|
+
Changes:
|
|
127
|
+
^^^^^^^^
|
|
128
|
+
|
|
129
|
+
- Maximum supported ``cryptography`` version is now 47.x.
|
|
130
|
+
- Fixed ``X509Name`` field setters to correctly pass the value length to OpenSSL. Previously, values containing NUL bytes would be silently truncated, causing a divergence between the stored ASN.1 value and the value visible from Python. Credit to **BudongJW** for reporting the issue. **CVE-2026-40475**
|
|
131
|
+
|
|
99
132
|
26.0.0 (2026-03-15)
|
|
100
133
|
-------------------
|
|
101
134
|
|
|
@@ -148,16 +148,6 @@ PKey objects
|
|
|
148
148
|
|
|
149
149
|
Key type constants.
|
|
150
150
|
|
|
151
|
-
.. _openssl-509ext:
|
|
152
|
-
|
|
153
|
-
X509Extension objects
|
|
154
|
-
---------------------
|
|
155
|
-
|
|
156
|
-
.. autoclass:: X509Extension
|
|
157
|
-
:members:
|
|
158
|
-
:special-members:
|
|
159
|
-
:exclude-members: __weakref__
|
|
160
|
-
|
|
161
151
|
Exceptions
|
|
162
152
|
----------
|
|
163
153
|
|
|
@@ -9,3 +9,10 @@ If breaking changes are needed do be done, they are:
|
|
|
9
9
|
#. …announced in the :doc:`changelog`.
|
|
10
10
|
#. …the old behavior raises a :exc:`DeprecationWarning` for a year.
|
|
11
11
|
#. …are done with another announcement in the :doc:`changelog`.
|
|
12
|
+
|
|
13
|
+
Versioning Policy
|
|
14
|
+
=================
|
|
15
|
+
|
|
16
|
+
pyOpenSSL follows `CalVer <https://calver.org>`_ in `YY.MINOR.MICRO` format.
|
|
17
|
+
Unlike SemVer, major versions represent the year, and are not indicative of
|
|
18
|
+
breaking changes.
|
|
@@ -93,7 +93,7 @@ if __name__ == "__main__":
|
|
|
93
93
|
packages=find_packages(where="src"),
|
|
94
94
|
package_dir={"": "src"},
|
|
95
95
|
install_requires=[
|
|
96
|
-
"cryptography>=46.0.0,<
|
|
96
|
+
"cryptography>=46.0.0,<49",
|
|
97
97
|
(
|
|
98
98
|
"typing-extensions>=4.9; "
|
|
99
99
|
"python_version < '3.13' and python_version >= '3.8'"
|
|
@@ -856,13 +856,9 @@ def _require_not_used(f: F) -> F:
|
|
|
856
856
|
@wraps(f)
|
|
857
857
|
def inner(self: Context, *args: Any, **kwargs: Any) -> Any:
|
|
858
858
|
if self._used:
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
"created. In the future, this will raise an exception"
|
|
863
|
-
),
|
|
864
|
-
DeprecationWarning,
|
|
865
|
-
stacklevel=2,
|
|
859
|
+
raise ValueError(
|
|
860
|
+
"Context has already been used to create a Connection, it "
|
|
861
|
+
"cannot be mutated again"
|
|
866
862
|
)
|
|
867
863
|
return f(self, *args, **kwargs)
|
|
868
864
|
|
|
@@ -2105,6 +2101,19 @@ class Connection:
|
|
|
2105
2101
|
self._context = context
|
|
2106
2102
|
self._context._used = True
|
|
2107
2103
|
|
|
2104
|
+
def set_options(self, options: int) -> int:
|
|
2105
|
+
"""
|
|
2106
|
+
Add options. Options set before are not cleared!
|
|
2107
|
+
This method should be used with the :const:`OP_*` constants.
|
|
2108
|
+
|
|
2109
|
+
:param options: The options to add.
|
|
2110
|
+
:return: The new option bitmask.
|
|
2111
|
+
"""
|
|
2112
|
+
if not isinstance(options, int):
|
|
2113
|
+
raise TypeError("options must be an integer")
|
|
2114
|
+
|
|
2115
|
+
return _lib.SSL_set_options(self._ssl, options)
|
|
2116
|
+
|
|
2108
2117
|
def get_servername(self) -> bytes | None:
|
|
2109
2118
|
"""
|
|
2110
2119
|
Retrieve the servername extension value if provided in the client hello
|
|
@@ -5,9 +5,8 @@ import datetime
|
|
|
5
5
|
import functools
|
|
6
6
|
import sys
|
|
7
7
|
import typing
|
|
8
|
-
import warnings
|
|
9
8
|
from base64 import b16encode
|
|
10
|
-
from collections.abc import
|
|
9
|
+
from collections.abc import Sequence
|
|
11
10
|
from functools import partial
|
|
12
11
|
from typing import (
|
|
13
12
|
Any,
|
|
@@ -63,7 +62,6 @@ __all__ = [
|
|
|
63
62
|
"X509",
|
|
64
63
|
"Error",
|
|
65
64
|
"PKey",
|
|
66
|
-
"X509Extension",
|
|
67
65
|
"X509Name",
|
|
68
66
|
"X509Req",
|
|
69
67
|
"X509Store",
|
|
@@ -651,7 +649,7 @@ class X509Name:
|
|
|
651
649
|
value = value.encode("utf-8")
|
|
652
650
|
|
|
653
651
|
add_result = _lib.X509_NAME_add_entry_by_NID(
|
|
654
|
-
self._name, nid, _lib.MBSTRING_UTF8, value,
|
|
652
|
+
self._name, nid, _lib.MBSTRING_UTF8, value, len(value), -1, 0
|
|
655
653
|
)
|
|
656
654
|
if not add_result:
|
|
657
655
|
_raise_current_error()
|
|
@@ -776,182 +774,6 @@ class X509Name:
|
|
|
776
774
|
return result
|
|
777
775
|
|
|
778
776
|
|
|
779
|
-
@deprecated(
|
|
780
|
-
"X509Extension support in pyOpenSSL is deprecated. You should use the "
|
|
781
|
-
"APIs in cryptography."
|
|
782
|
-
)
|
|
783
|
-
class X509Extension:
|
|
784
|
-
"""
|
|
785
|
-
An X.509 v3 certificate extension.
|
|
786
|
-
|
|
787
|
-
.. deprecated:: 23.3.0
|
|
788
|
-
Use cryptography's X509 APIs instead.
|
|
789
|
-
"""
|
|
790
|
-
|
|
791
|
-
def __init__(
|
|
792
|
-
self,
|
|
793
|
-
type_name: bytes,
|
|
794
|
-
critical: bool,
|
|
795
|
-
value: bytes,
|
|
796
|
-
subject: X509 | None = None,
|
|
797
|
-
issuer: X509 | None = None,
|
|
798
|
-
) -> None:
|
|
799
|
-
"""
|
|
800
|
-
Initializes an X509 extension.
|
|
801
|
-
|
|
802
|
-
:param type_name: The name of the type of extension_ to create.
|
|
803
|
-
:type type_name: :py:data:`bytes`
|
|
804
|
-
|
|
805
|
-
:param bool critical: A flag indicating whether this is a critical
|
|
806
|
-
extension.
|
|
807
|
-
|
|
808
|
-
:param value: The OpenSSL textual representation of the extension's
|
|
809
|
-
value.
|
|
810
|
-
:type value: :py:data:`bytes`
|
|
811
|
-
|
|
812
|
-
:param subject: Optional X509 certificate to use as subject.
|
|
813
|
-
:type subject: :py:class:`X509`
|
|
814
|
-
|
|
815
|
-
:param issuer: Optional X509 certificate to use as issuer.
|
|
816
|
-
:type issuer: :py:class:`X509`
|
|
817
|
-
|
|
818
|
-
.. _extension: https://www.openssl.org/docs/manmaster/man5/
|
|
819
|
-
x509v3_config.html#STANDARD-EXTENSIONS
|
|
820
|
-
"""
|
|
821
|
-
ctx = _ffi.new("X509V3_CTX*")
|
|
822
|
-
|
|
823
|
-
# A context is necessary for any extension which uses the r2i
|
|
824
|
-
# conversion method. That is, X509V3_EXT_nconf may segfault if passed
|
|
825
|
-
# a NULL ctx. Start off by initializing most of the fields to NULL.
|
|
826
|
-
_lib.X509V3_set_ctx(ctx, _ffi.NULL, _ffi.NULL, _ffi.NULL, _ffi.NULL, 0)
|
|
827
|
-
|
|
828
|
-
# We have no configuration database - but perhaps we should (some
|
|
829
|
-
# extensions may require it).
|
|
830
|
-
_lib.X509V3_set_ctx_nodb(ctx)
|
|
831
|
-
|
|
832
|
-
# Initialize the subject and issuer, if appropriate. ctx is a local,
|
|
833
|
-
# and as far as I can tell none of the X509V3_* APIs invoked here steal
|
|
834
|
-
# any references, so no need to mess with reference counts or
|
|
835
|
-
# duplicates.
|
|
836
|
-
if issuer is not None:
|
|
837
|
-
if not isinstance(issuer, X509):
|
|
838
|
-
raise TypeError("issuer must be an X509 instance")
|
|
839
|
-
ctx.issuer_cert = issuer._x509
|
|
840
|
-
if subject is not None:
|
|
841
|
-
if not isinstance(subject, X509):
|
|
842
|
-
raise TypeError("subject must be an X509 instance")
|
|
843
|
-
ctx.subject_cert = subject._x509
|
|
844
|
-
|
|
845
|
-
if critical:
|
|
846
|
-
# There are other OpenSSL APIs which would let us pass in critical
|
|
847
|
-
# separately, but they're harder to use, and since value is already
|
|
848
|
-
# a pile of crappy junk smuggling a ton of utterly important
|
|
849
|
-
# structured data, what's the point of trying to avoid nasty stuff
|
|
850
|
-
# with strings? (However, X509V3_EXT_i2d in particular seems like
|
|
851
|
-
# it would be a better API to invoke. I do not know where to get
|
|
852
|
-
# the ext_struc it desires for its last parameter, though.)
|
|
853
|
-
value = b"critical," + value
|
|
854
|
-
|
|
855
|
-
extension = _lib.X509V3_EXT_nconf(_ffi.NULL, ctx, type_name, value)
|
|
856
|
-
if extension == _ffi.NULL:
|
|
857
|
-
_raise_current_error()
|
|
858
|
-
self._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
|
|
859
|
-
|
|
860
|
-
@property
|
|
861
|
-
def _nid(self) -> Any:
|
|
862
|
-
return _lib.OBJ_obj2nid(
|
|
863
|
-
_lib.X509_EXTENSION_get_object(self._extension)
|
|
864
|
-
)
|
|
865
|
-
|
|
866
|
-
_prefixes: typing.ClassVar[dict[int, str]] = {
|
|
867
|
-
_lib.GEN_EMAIL: "email",
|
|
868
|
-
_lib.GEN_DNS: "DNS",
|
|
869
|
-
_lib.GEN_URI: "URI",
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
def _subjectAltNameString(self) -> str:
|
|
873
|
-
names = _ffi.cast(
|
|
874
|
-
"GENERAL_NAMES*", _lib.X509V3_EXT_d2i(self._extension)
|
|
875
|
-
)
|
|
876
|
-
|
|
877
|
-
names = _ffi.gc(names, _lib.GENERAL_NAMES_free)
|
|
878
|
-
parts = []
|
|
879
|
-
for i in range(_lib.sk_GENERAL_NAME_num(names)):
|
|
880
|
-
name = _lib.sk_GENERAL_NAME_value(names, i)
|
|
881
|
-
try:
|
|
882
|
-
label = self._prefixes[name.type]
|
|
883
|
-
except KeyError:
|
|
884
|
-
bio = _new_mem_buf()
|
|
885
|
-
_lib.GENERAL_NAME_print(bio, name)
|
|
886
|
-
parts.append(_bio_to_string(bio).decode("utf-8"))
|
|
887
|
-
else:
|
|
888
|
-
asn1_string = _ffi.cast("ASN1_STRING*", name.d.ia5)
|
|
889
|
-
value = _ffi.buffer(
|
|
890
|
-
_lib.ASN1_STRING_get0_data(asn1_string),
|
|
891
|
-
_lib.ASN1_STRING_length(asn1_string),
|
|
892
|
-
)[:].decode("utf-8")
|
|
893
|
-
parts.append(label + ":" + value)
|
|
894
|
-
return ", ".join(parts)
|
|
895
|
-
|
|
896
|
-
def __str__(self) -> str:
|
|
897
|
-
"""
|
|
898
|
-
:return: a nice text representation of the extension
|
|
899
|
-
"""
|
|
900
|
-
if _lib.NID_subject_alt_name == self._nid:
|
|
901
|
-
return self._subjectAltNameString()
|
|
902
|
-
|
|
903
|
-
bio = _new_mem_buf()
|
|
904
|
-
print_result = _lib.X509V3_EXT_print(bio, self._extension, 0, 0)
|
|
905
|
-
_openssl_assert(print_result != 0)
|
|
906
|
-
|
|
907
|
-
return _bio_to_string(bio).decode("utf-8")
|
|
908
|
-
|
|
909
|
-
def get_critical(self) -> bool:
|
|
910
|
-
"""
|
|
911
|
-
Returns the critical field of this X.509 extension.
|
|
912
|
-
|
|
913
|
-
:return: The critical field.
|
|
914
|
-
"""
|
|
915
|
-
return _lib.X509_EXTENSION_get_critical(self._extension)
|
|
916
|
-
|
|
917
|
-
def get_short_name(self) -> bytes:
|
|
918
|
-
"""
|
|
919
|
-
Returns the short type name of this X.509 extension.
|
|
920
|
-
|
|
921
|
-
The result is a byte string such as :py:const:`b"basicConstraints"`.
|
|
922
|
-
|
|
923
|
-
:return: The short type name.
|
|
924
|
-
:rtype: :py:data:`bytes`
|
|
925
|
-
|
|
926
|
-
.. versionadded:: 0.12
|
|
927
|
-
"""
|
|
928
|
-
obj = _lib.X509_EXTENSION_get_object(self._extension)
|
|
929
|
-
nid = _lib.OBJ_obj2nid(obj)
|
|
930
|
-
# OpenSSL 3.1.0 has a bug where nid2sn returns NULL for NIDs that
|
|
931
|
-
# previously returned UNDEF. This is a workaround for that issue.
|
|
932
|
-
# https://github.com/openssl/openssl/commit/908ba3ed9adbb3df90f76
|
|
933
|
-
buf = _lib.OBJ_nid2sn(nid)
|
|
934
|
-
if buf != _ffi.NULL:
|
|
935
|
-
return _ffi.string(buf)
|
|
936
|
-
else:
|
|
937
|
-
return b"UNDEF"
|
|
938
|
-
|
|
939
|
-
def get_data(self) -> bytes:
|
|
940
|
-
"""
|
|
941
|
-
Returns the data of the X509 extension, encoded as ASN.1.
|
|
942
|
-
|
|
943
|
-
:return: The ASN.1 encoded data of this X509 extension.
|
|
944
|
-
:rtype: :py:data:`bytes`
|
|
945
|
-
|
|
946
|
-
.. versionadded:: 0.12
|
|
947
|
-
"""
|
|
948
|
-
octet_result = _lib.X509_EXTENSION_get_data(self._extension)
|
|
949
|
-
string_result = _ffi.cast("ASN1_STRING*", octet_result)
|
|
950
|
-
char_result = _lib.ASN1_STRING_get0_data(string_result)
|
|
951
|
-
result_length = _lib.ASN1_STRING_length(string_result)
|
|
952
|
-
return _ffi.buffer(char_result, result_length)[:]
|
|
953
|
-
|
|
954
|
-
|
|
955
777
|
@deprecated(
|
|
956
778
|
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
|
|
957
779
|
"in cryptography."
|
|
@@ -1081,77 +903,6 @@ class X509Req:
|
|
|
1081
903
|
|
|
1082
904
|
return name
|
|
1083
905
|
|
|
1084
|
-
def add_extensions(self, extensions: Iterable[X509Extension]) -> None:
|
|
1085
|
-
"""
|
|
1086
|
-
Add extensions to the certificate signing request.
|
|
1087
|
-
|
|
1088
|
-
:param extensions: The X.509 extensions to add.
|
|
1089
|
-
:type extensions: iterable of :py:class:`X509Extension`
|
|
1090
|
-
:return: ``None``
|
|
1091
|
-
"""
|
|
1092
|
-
warnings.warn(
|
|
1093
|
-
(
|
|
1094
|
-
"This API is deprecated and will be removed in a future "
|
|
1095
|
-
"version of pyOpenSSL. You should use pyca/cryptography's "
|
|
1096
|
-
"X.509 APIs instead."
|
|
1097
|
-
),
|
|
1098
|
-
DeprecationWarning,
|
|
1099
|
-
stacklevel=2,
|
|
1100
|
-
)
|
|
1101
|
-
|
|
1102
|
-
stack = _lib.sk_X509_EXTENSION_new_null()
|
|
1103
|
-
_openssl_assert(stack != _ffi.NULL)
|
|
1104
|
-
|
|
1105
|
-
stack = _ffi.gc(stack, _lib.sk_X509_EXTENSION_free)
|
|
1106
|
-
|
|
1107
|
-
for ext in extensions:
|
|
1108
|
-
if not isinstance(ext, X509Extension):
|
|
1109
|
-
raise ValueError("One of the elements is not an X509Extension")
|
|
1110
|
-
|
|
1111
|
-
# TODO push can fail (here and elsewhere)
|
|
1112
|
-
_lib.sk_X509_EXTENSION_push(stack, ext._extension)
|
|
1113
|
-
|
|
1114
|
-
add_result = _lib.X509_REQ_add_extensions(self._req, stack)
|
|
1115
|
-
_openssl_assert(add_result == 1)
|
|
1116
|
-
|
|
1117
|
-
def get_extensions(self) -> list[X509Extension]:
|
|
1118
|
-
"""
|
|
1119
|
-
Get X.509 extensions in the certificate signing request.
|
|
1120
|
-
|
|
1121
|
-
:return: The X.509 extensions in this request.
|
|
1122
|
-
:rtype: :py:class:`list` of :py:class:`X509Extension` objects.
|
|
1123
|
-
|
|
1124
|
-
.. versionadded:: 0.15
|
|
1125
|
-
"""
|
|
1126
|
-
warnings.warn(
|
|
1127
|
-
(
|
|
1128
|
-
"This API is deprecated and will be removed in a future "
|
|
1129
|
-
"version of pyOpenSSL. You should use pyca/cryptography's "
|
|
1130
|
-
"X.509 APIs instead."
|
|
1131
|
-
),
|
|
1132
|
-
DeprecationWarning,
|
|
1133
|
-
stacklevel=2,
|
|
1134
|
-
)
|
|
1135
|
-
|
|
1136
|
-
exts = []
|
|
1137
|
-
native_exts_obj = _lib.X509_REQ_get_extensions(self._req)
|
|
1138
|
-
native_exts_obj = _ffi.gc(
|
|
1139
|
-
native_exts_obj,
|
|
1140
|
-
lambda x: _lib.sk_X509_EXTENSION_pop_free(
|
|
1141
|
-
x,
|
|
1142
|
-
_ffi.addressof(_lib._original_lib, "X509_EXTENSION_free"),
|
|
1143
|
-
),
|
|
1144
|
-
)
|
|
1145
|
-
|
|
1146
|
-
for i in range(_lib.sk_X509_EXTENSION_num(native_exts_obj)):
|
|
1147
|
-
ext = X509Extension.__new__(X509Extension)
|
|
1148
|
-
extension = _lib.X509_EXTENSION_dup(
|
|
1149
|
-
_lib.sk_X509_EXTENSION_value(native_exts_obj, i)
|
|
1150
|
-
)
|
|
1151
|
-
ext._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
|
|
1152
|
-
exts.append(ext)
|
|
1153
|
-
return exts
|
|
1154
|
-
|
|
1155
906
|
def sign(self, pkey: PKey, digest: str) -> None:
|
|
1156
907
|
"""
|
|
1157
908
|
Sign the certificate signing request with this key and digest type.
|
|
@@ -1629,64 +1380,6 @@ class X509:
|
|
|
1629
1380
|
"""
|
|
1630
1381
|
return _lib.X509_get_ext_count(self._x509)
|
|
1631
1382
|
|
|
1632
|
-
def add_extensions(self, extensions: Iterable[X509Extension]) -> None:
|
|
1633
|
-
"""
|
|
1634
|
-
Add extensions to the certificate.
|
|
1635
|
-
|
|
1636
|
-
:param extensions: The extensions to add.
|
|
1637
|
-
:type extensions: An iterable of :py:class:`X509Extension` objects.
|
|
1638
|
-
:return: ``None``
|
|
1639
|
-
"""
|
|
1640
|
-
warnings.warn(
|
|
1641
|
-
(
|
|
1642
|
-
"This API is deprecated and will be removed in a future "
|
|
1643
|
-
"version of pyOpenSSL. You should use pyca/cryptography's "
|
|
1644
|
-
"X.509 APIs instead."
|
|
1645
|
-
),
|
|
1646
|
-
DeprecationWarning,
|
|
1647
|
-
stacklevel=2,
|
|
1648
|
-
)
|
|
1649
|
-
|
|
1650
|
-
for ext in extensions:
|
|
1651
|
-
if not isinstance(ext, X509Extension):
|
|
1652
|
-
raise ValueError("One of the elements is not an X509Extension")
|
|
1653
|
-
|
|
1654
|
-
add_result = _lib.X509_add_ext(self._x509, ext._extension, -1)
|
|
1655
|
-
_openssl_assert(add_result == 1)
|
|
1656
|
-
|
|
1657
|
-
def get_extension(self, index: int) -> X509Extension:
|
|
1658
|
-
"""
|
|
1659
|
-
Get a specific extension of the certificate by index.
|
|
1660
|
-
|
|
1661
|
-
Extensions on a certificate are kept in order. The index
|
|
1662
|
-
parameter selects which extension will be returned.
|
|
1663
|
-
|
|
1664
|
-
:param int index: The index of the extension to retrieve.
|
|
1665
|
-
:return: The extension at the specified index.
|
|
1666
|
-
:rtype: :py:class:`X509Extension`
|
|
1667
|
-
:raises IndexError: If the extension index was out of bounds.
|
|
1668
|
-
|
|
1669
|
-
.. versionadded:: 0.12
|
|
1670
|
-
"""
|
|
1671
|
-
warnings.warn(
|
|
1672
|
-
(
|
|
1673
|
-
"This API is deprecated and will be removed in a future "
|
|
1674
|
-
"version of pyOpenSSL. You should use pyca/cryptography's "
|
|
1675
|
-
"X.509 APIs instead."
|
|
1676
|
-
),
|
|
1677
|
-
DeprecationWarning,
|
|
1678
|
-
stacklevel=2,
|
|
1679
|
-
)
|
|
1680
|
-
|
|
1681
|
-
ext = X509Extension.__new__(X509Extension)
|
|
1682
|
-
ext._extension = _lib.X509_get_ext(self._x509, index)
|
|
1683
|
-
if ext._extension == _ffi.NULL:
|
|
1684
|
-
raise IndexError("extension index out of bounds")
|
|
1685
|
-
|
|
1686
|
-
extension = _lib.X509_EXTENSION_dup(ext._extension)
|
|
1687
|
-
ext._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
|
|
1688
|
-
return ext
|
|
1689
|
-
|
|
1690
1383
|
|
|
1691
1384
|
class X509StoreFlags:
|
|
1692
1385
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyOpenSSL
|
|
3
|
-
Version: 26.
|
|
3
|
+
Version: 26.2.0
|
|
4
4
|
Summary: Python wrapper module around the OpenSSL library
|
|
5
5
|
Home-page: https://pyopenssl.org/
|
|
6
6
|
Author: The pyOpenSSL developers
|
|
@@ -27,7 +27,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
27
27
|
Classifier: Topic :: System :: Networking
|
|
28
28
|
Requires-Python: >=3.8
|
|
29
29
|
License-File: LICENSE
|
|
30
|
-
Requires-Dist: cryptography<
|
|
30
|
+
Requires-Dist: cryptography<49,>=46.0.0
|
|
31
31
|
Requires-Dist: typing-extensions>=4.9; python_version < "3.13" and python_version >= "3.8"
|
|
32
32
|
Provides-Extra: test
|
|
33
33
|
Requires-Dist: pytest-rerunfailures; extra == "test"
|
|
@@ -96,6 +96,39 @@ You can also join ``#pyca`` on ``irc.libera.chat`` to ask questions or get invol
|
|
|
96
96
|
Release Information
|
|
97
97
|
===================
|
|
98
98
|
|
|
99
|
+
26.2.0 (2026-05-04)
|
|
100
|
+
-------------------
|
|
101
|
+
|
|
102
|
+
Backward-incompatible changes:
|
|
103
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
104
|
+
|
|
105
|
+
- 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.
|
|
106
|
+
- 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.
|
|
107
|
+
|
|
108
|
+
Deprecations:
|
|
109
|
+
^^^^^^^^^^^^^
|
|
110
|
+
|
|
111
|
+
Changes:
|
|
112
|
+
^^^^^^^^
|
|
113
|
+
|
|
114
|
+
- Maximum supported ``cryptography`` version is now 48.x.
|
|
115
|
+
- Added ``OpenSSL.SSL.Connection.set_options`` to set options on a per-connection basis.
|
|
116
|
+
|
|
117
|
+
26.1.0 (2026-04-24)
|
|
118
|
+
-------------------
|
|
119
|
+
|
|
120
|
+
Backward-incompatible changes:
|
|
121
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
122
|
+
|
|
123
|
+
Deprecations:
|
|
124
|
+
^^^^^^^^^^^^^
|
|
125
|
+
|
|
126
|
+
Changes:
|
|
127
|
+
^^^^^^^^
|
|
128
|
+
|
|
129
|
+
- Maximum supported ``cryptography`` version is now 47.x.
|
|
130
|
+
- Fixed ``X509Name`` field setters to correctly pass the value length to OpenSSL. Previously, values containing NUL bytes would be silently truncated, causing a divergence between the stored ASN.1 value and the value visible from Python. Credit to **BudongJW** for reporting the issue. **CVE-2026-40475**
|
|
131
|
+
|
|
99
132
|
26.0.0 (2026-03-15)
|
|
100
133
|
-------------------
|
|
101
134
|
|
|
@@ -36,7 +36,6 @@ from OpenSSL.crypto import (
|
|
|
36
36
|
X509,
|
|
37
37
|
Error,
|
|
38
38
|
PKey,
|
|
39
|
-
X509Extension,
|
|
40
39
|
X509Name,
|
|
41
40
|
X509Req,
|
|
42
41
|
X509Store,
|
|
@@ -822,198 +821,6 @@ def x509_data() -> tuple[PKey, X509]:
|
|
|
822
821
|
return pkey, x509
|
|
823
822
|
|
|
824
823
|
|
|
825
|
-
class TestX509Ext:
|
|
826
|
-
"""
|
|
827
|
-
Tests for `OpenSSL.crypto.X509Extension`.
|
|
828
|
-
"""
|
|
829
|
-
|
|
830
|
-
def test_str(self) -> None:
|
|
831
|
-
"""
|
|
832
|
-
The string representation of `X509Extension` instances as
|
|
833
|
-
returned by `str` includes stuff.
|
|
834
|
-
"""
|
|
835
|
-
# This isn't necessarily the best string representation. Perhaps it
|
|
836
|
-
# will be changed/improved in the future.
|
|
837
|
-
assert (
|
|
838
|
-
str(X509Extension(b"basicConstraints", True, b"CA:false"))
|
|
839
|
-
== "CA:FALSE"
|
|
840
|
-
)
|
|
841
|
-
|
|
842
|
-
def test_construction(self) -> None:
|
|
843
|
-
"""
|
|
844
|
-
`X509Extension` accepts an extension type name, a critical flag,
|
|
845
|
-
and an extension value and returns an `X509Extension` instance.
|
|
846
|
-
"""
|
|
847
|
-
basic = X509Extension(b"basicConstraints", True, b"CA:true")
|
|
848
|
-
assert isinstance(basic, X509Extension)
|
|
849
|
-
|
|
850
|
-
comment = X509Extension(b"nsComment", False, b"pyOpenSSL unit test")
|
|
851
|
-
assert isinstance(comment, X509Extension)
|
|
852
|
-
|
|
853
|
-
@pytest.mark.parametrize(
|
|
854
|
-
"type_name, critical, value",
|
|
855
|
-
[
|
|
856
|
-
(b"thisIsMadeUp", False, b"hi"),
|
|
857
|
-
(b"basicConstraints", False, b"blah blah"),
|
|
858
|
-
# Exercise a weird one (an extension which uses the r2i method).
|
|
859
|
-
# This exercises the codepath that requires a non-NULL ctx to be
|
|
860
|
-
# passed to X509V3_EXT_nconf. It can't work now because we provide
|
|
861
|
-
# no configuration database. It might be made to work in the
|
|
862
|
-
# future.
|
|
863
|
-
(
|
|
864
|
-
b"proxyCertInfo",
|
|
865
|
-
True,
|
|
866
|
-
b"language:id-ppl-anyLanguage,pathlen:1,policy:text:AB",
|
|
867
|
-
),
|
|
868
|
-
],
|
|
869
|
-
)
|
|
870
|
-
def test_invalid_extension(
|
|
871
|
-
self, type_name: bytes, critical: bool, value: bytes
|
|
872
|
-
) -> None:
|
|
873
|
-
"""
|
|
874
|
-
`X509Extension` raises something if it is passed a bad
|
|
875
|
-
extension name or value.
|
|
876
|
-
"""
|
|
877
|
-
with pytest.raises(Error):
|
|
878
|
-
X509Extension(type_name, critical, value)
|
|
879
|
-
|
|
880
|
-
@pytest.mark.parametrize("critical_flag", [True, False])
|
|
881
|
-
def test_get_critical(self, critical_flag: bool) -> None:
|
|
882
|
-
"""
|
|
883
|
-
`X509ExtensionType.get_critical` returns the value of the
|
|
884
|
-
extension's critical flag.
|
|
885
|
-
"""
|
|
886
|
-
ext = X509Extension(b"basicConstraints", critical_flag, b"CA:true")
|
|
887
|
-
assert ext.get_critical() == critical_flag
|
|
888
|
-
|
|
889
|
-
@pytest.mark.parametrize(
|
|
890
|
-
"short_name, value",
|
|
891
|
-
[(b"basicConstraints", b"CA:true"), (b"nsComment", b"foo bar")],
|
|
892
|
-
)
|
|
893
|
-
def test_get_short_name(self, short_name: bytes, value: bytes) -> None:
|
|
894
|
-
"""
|
|
895
|
-
`X509ExtensionType.get_short_name` returns a string giving the
|
|
896
|
-
short type name of the extension.
|
|
897
|
-
"""
|
|
898
|
-
ext = X509Extension(short_name, True, value)
|
|
899
|
-
assert ext.get_short_name() == short_name
|
|
900
|
-
|
|
901
|
-
def test_get_data(self) -> None:
|
|
902
|
-
"""
|
|
903
|
-
`X509Extension.get_data` returns a string giving the data of
|
|
904
|
-
the extension.
|
|
905
|
-
"""
|
|
906
|
-
ext = X509Extension(b"basicConstraints", True, b"CA:true")
|
|
907
|
-
# Expect to get back the DER encoded form of CA:true.
|
|
908
|
-
assert ext.get_data() == b"0\x03\x01\x01\xff"
|
|
909
|
-
|
|
910
|
-
def test_unused_subject(self, x509_data: tuple[PKey, X509]) -> None:
|
|
911
|
-
"""
|
|
912
|
-
The `subject` parameter to `X509Extension` may be provided for an
|
|
913
|
-
extension which does not use it and is ignored in this case.
|
|
914
|
-
"""
|
|
915
|
-
pkey, x509 = x509_data
|
|
916
|
-
ext1 = X509Extension(
|
|
917
|
-
b"basicConstraints", False, b"CA:TRUE", subject=x509
|
|
918
|
-
)
|
|
919
|
-
x509.add_extensions([ext1])
|
|
920
|
-
x509.sign(pkey, "sha256")
|
|
921
|
-
# This is a little lame. Can we think of a better way?
|
|
922
|
-
text = dump_certificate(FILETYPE_TEXT, x509)
|
|
923
|
-
assert b"X509v3 Basic Constraints:" in text
|
|
924
|
-
assert b"CA:TRUE" in text
|
|
925
|
-
|
|
926
|
-
def test_subject(self, x509_data: tuple[PKey, X509]) -> None:
|
|
927
|
-
"""
|
|
928
|
-
If an extension requires a subject, the `subject` parameter to
|
|
929
|
-
`X509Extension` provides its value.
|
|
930
|
-
"""
|
|
931
|
-
pkey, x509 = x509_data
|
|
932
|
-
ext3 = X509Extension(
|
|
933
|
-
b"subjectKeyIdentifier", False, b"hash", subject=x509
|
|
934
|
-
)
|
|
935
|
-
x509.add_extensions([ext3])
|
|
936
|
-
x509.sign(pkey, "sha256")
|
|
937
|
-
text = dump_certificate(FILETYPE_TEXT, x509)
|
|
938
|
-
assert b"X509v3 Subject Key Identifier:" in text
|
|
939
|
-
|
|
940
|
-
def test_missing_subject(self) -> None:
|
|
941
|
-
"""
|
|
942
|
-
If an extension requires a subject and the `subject` parameter
|
|
943
|
-
is given no value, something happens.
|
|
944
|
-
"""
|
|
945
|
-
with pytest.raises(Error):
|
|
946
|
-
X509Extension(b"subjectKeyIdentifier", False, b"hash")
|
|
947
|
-
|
|
948
|
-
@pytest.mark.parametrize("bad_obj", [True, object(), "hello", []])
|
|
949
|
-
def test_invalid_subject(self, bad_obj: object) -> None:
|
|
950
|
-
"""
|
|
951
|
-
If the `subject` parameter is given a value which is not an
|
|
952
|
-
`X509` instance, `TypeError` is raised.
|
|
953
|
-
"""
|
|
954
|
-
with pytest.raises(TypeError):
|
|
955
|
-
X509Extension(
|
|
956
|
-
b"basicConstraints",
|
|
957
|
-
False,
|
|
958
|
-
b"CA:TRUE",
|
|
959
|
-
subject=bad_obj, # type: ignore[arg-type]
|
|
960
|
-
)
|
|
961
|
-
|
|
962
|
-
def test_unused_issuer(self, x509_data: tuple[PKey, X509]) -> None:
|
|
963
|
-
"""
|
|
964
|
-
The `issuer` parameter to `X509Extension` may be provided for an
|
|
965
|
-
extension which does not use it and is ignored in this case.
|
|
966
|
-
"""
|
|
967
|
-
pkey, x509 = x509_data
|
|
968
|
-
ext1 = X509Extension(
|
|
969
|
-
b"basicConstraints", False, b"CA:TRUE", issuer=x509
|
|
970
|
-
)
|
|
971
|
-
x509.add_extensions([ext1])
|
|
972
|
-
x509.sign(pkey, "sha256")
|
|
973
|
-
text = dump_certificate(FILETYPE_TEXT, x509)
|
|
974
|
-
assert b"X509v3 Basic Constraints:" in text
|
|
975
|
-
assert b"CA:TRUE" in text
|
|
976
|
-
|
|
977
|
-
def test_issuer(self, x509_data: tuple[PKey, X509]) -> None:
|
|
978
|
-
"""
|
|
979
|
-
If an extension requires an issuer, the `issuer` parameter to
|
|
980
|
-
`X509Extension` provides its value.
|
|
981
|
-
"""
|
|
982
|
-
pkey, x509 = x509_data
|
|
983
|
-
ext2 = X509Extension(
|
|
984
|
-
b"authorityKeyIdentifier", False, b"issuer:always", issuer=x509
|
|
985
|
-
)
|
|
986
|
-
x509.add_extensions([ext2])
|
|
987
|
-
x509.sign(pkey, "sha256")
|
|
988
|
-
text = dump_certificate(FILETYPE_TEXT, x509)
|
|
989
|
-
assert b"X509v3 Authority Key Identifier:" in text
|
|
990
|
-
assert b"DirName:/CN=Yoda root CA" in text
|
|
991
|
-
|
|
992
|
-
def test_missing_issuer(self) -> None:
|
|
993
|
-
"""
|
|
994
|
-
If an extension requires an issue and the `issuer` parameter is
|
|
995
|
-
given no value, something happens.
|
|
996
|
-
"""
|
|
997
|
-
with pytest.raises(Error):
|
|
998
|
-
X509Extension(
|
|
999
|
-
b"authorityKeyIdentifier", False, b"keyid:always,issuer:always"
|
|
1000
|
-
)
|
|
1001
|
-
|
|
1002
|
-
@pytest.mark.parametrize("bad_obj", [True, object(), "hello", []])
|
|
1003
|
-
def test_invalid_issuer(self, bad_obj: object) -> None:
|
|
1004
|
-
"""
|
|
1005
|
-
If the `issuer` parameter is given a value which is not an
|
|
1006
|
-
`X509` instance, `TypeError` is raised.
|
|
1007
|
-
"""
|
|
1008
|
-
with pytest.raises(TypeError):
|
|
1009
|
-
X509Extension(
|
|
1010
|
-
b"basicConstraints",
|
|
1011
|
-
False,
|
|
1012
|
-
b"keyid:always,issuer:always",
|
|
1013
|
-
issuer=bad_obj, # type: ignore[arg-type]
|
|
1014
|
-
)
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
824
|
class TestPKey:
|
|
1018
825
|
"""
|
|
1019
826
|
Tests for `OpenSSL.crypto.PKey`.
|
|
@@ -1403,6 +1210,14 @@ class TestX509Name:
|
|
|
1403
1210
|
name.emailAddress = "quux@example.com"
|
|
1404
1211
|
assert copy.emailAddress == "bar@example.com"
|
|
1405
1212
|
|
|
1213
|
+
def test_null_bytes_preserved(self) -> None:
|
|
1214
|
+
"""
|
|
1215
|
+
Null bytes in X509Name field values are round-tripped correctly.
|
|
1216
|
+
"""
|
|
1217
|
+
name = x509_name()
|
|
1218
|
+
name.CN = "a\x00b"
|
|
1219
|
+
assert name.CN == "a\x00b"
|
|
1220
|
+
|
|
1406
1221
|
def test_repr(self) -> None:
|
|
1407
1222
|
"""
|
|
1408
1223
|
`repr` passed an `X509Name` instance should return a string containing
|
|
@@ -1679,67 +1494,6 @@ class TestX509Req:
|
|
|
1679
1494
|
subject.commonName = "bar"
|
|
1680
1495
|
assert subject.commonName == "bar"
|
|
1681
1496
|
|
|
1682
|
-
def test_add_extensions(self) -> None:
|
|
1683
|
-
"""
|
|
1684
|
-
`X509Req.add_extensions` accepts a `list` of `X509Extension` instances
|
|
1685
|
-
and adds them to the X509 request.
|
|
1686
|
-
"""
|
|
1687
|
-
request = X509Req()
|
|
1688
|
-
request.add_extensions(
|
|
1689
|
-
[X509Extension(b"basicConstraints", True, b"CA:false")]
|
|
1690
|
-
)
|
|
1691
|
-
exts = request.get_extensions()
|
|
1692
|
-
assert len(exts) == 1
|
|
1693
|
-
assert exts[0].get_short_name() == b"basicConstraints"
|
|
1694
|
-
assert exts[0].get_critical() == 1
|
|
1695
|
-
assert exts[0].get_data() == b"0\x00"
|
|
1696
|
-
|
|
1697
|
-
def test_get_extensions(self) -> None:
|
|
1698
|
-
"""
|
|
1699
|
-
`X509Req.get_extensions` returns a `list` of extensions added to this
|
|
1700
|
-
X509 request.
|
|
1701
|
-
"""
|
|
1702
|
-
request = X509Req()
|
|
1703
|
-
exts = request.get_extensions()
|
|
1704
|
-
assert exts == []
|
|
1705
|
-
request.add_extensions(
|
|
1706
|
-
[
|
|
1707
|
-
X509Extension(b"basicConstraints", True, b"CA:true"),
|
|
1708
|
-
X509Extension(b"keyUsage", False, b"digitalSignature"),
|
|
1709
|
-
]
|
|
1710
|
-
)
|
|
1711
|
-
exts = request.get_extensions()
|
|
1712
|
-
assert len(exts) == 2
|
|
1713
|
-
assert exts[0].get_short_name() == b"basicConstraints"
|
|
1714
|
-
assert exts[0].get_critical() == 1
|
|
1715
|
-
assert exts[0].get_data() == b"0\x03\x01\x01\xff"
|
|
1716
|
-
assert exts[1].get_short_name() == b"keyUsage"
|
|
1717
|
-
assert exts[1].get_critical() == 0
|
|
1718
|
-
assert exts[1].get_data() == b"\x03\x02\x07\x80"
|
|
1719
|
-
# Requesting it a second time should return the same list
|
|
1720
|
-
exts = request.get_extensions()
|
|
1721
|
-
assert len(exts) == 2
|
|
1722
|
-
|
|
1723
|
-
def test_undef_oid(self) -> None:
|
|
1724
|
-
assert (
|
|
1725
|
-
X509Extension(
|
|
1726
|
-
b"1.2.3.4.5.6.7", False, b"DER:05:00"
|
|
1727
|
-
).get_short_name()
|
|
1728
|
-
== b"UNDEF"
|
|
1729
|
-
)
|
|
1730
|
-
|
|
1731
|
-
def test_add_extensions_wrong_args(self) -> None:
|
|
1732
|
-
"""
|
|
1733
|
-
`X509Req.add_extensions` raises `TypeError` if called with a
|
|
1734
|
-
non-`list`. Or it raises `ValueError` if called with a `list`
|
|
1735
|
-
containing objects other than `X509Extension` instances.
|
|
1736
|
-
"""
|
|
1737
|
-
request = X509Req()
|
|
1738
|
-
with pytest.raises(TypeError):
|
|
1739
|
-
request.add_extensions(object()) # type: ignore[arg-type]
|
|
1740
|
-
with pytest.raises(ValueError):
|
|
1741
|
-
request.add_extensions([object()]) # type: ignore[list-item]
|
|
1742
|
-
|
|
1743
1497
|
def test_verify_wrong_args(self) -> None:
|
|
1744
1498
|
"""
|
|
1745
1499
|
`X509Req.verify` raises `TypeError` if passed anything other than a
|
|
@@ -1995,16 +1749,17 @@ class TestX509:
|
|
|
1995
1749
|
current time plus the number of seconds passed in.
|
|
1996
1750
|
"""
|
|
1997
1751
|
cert = load_certificate(FILETYPE_PEM, self.pemData)
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
)
|
|
1752
|
+
utc_now = utcnow().replace(microsecond=0)
|
|
1753
|
+
# -1 second tolerance for clock adjustments
|
|
1754
|
+
not_before_min = utc_now + timedelta(seconds=99)
|
|
2001
1755
|
cert.gmtime_adj_notBefore(100)
|
|
2002
1756
|
not_before_str = cert.get_notBefore()
|
|
2003
1757
|
assert not_before_str is not None
|
|
2004
1758
|
not_before = datetime.strptime(
|
|
2005
1759
|
not_before_str.decode(), "%Y%m%d%H%M%SZ"
|
|
2006
1760
|
)
|
|
2007
|
-
|
|
1761
|
+
# +1 second tolerance for clock adjustments
|
|
1762
|
+
not_before_max = utc_now + timedelta(seconds=101)
|
|
2008
1763
|
assert not_before_min <= not_before <= not_before_max
|
|
2009
1764
|
|
|
2010
1765
|
def test_gmtime_adj_notAfter_wrong_args(self) -> None:
|
|
@@ -2023,14 +1778,15 @@ class TestX509:
|
|
|
2023
1778
|
to be the current time plus the number of seconds passed in.
|
|
2024
1779
|
"""
|
|
2025
1780
|
cert = load_certificate(FILETYPE_PEM, self.pemData)
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
)
|
|
1781
|
+
utc_now = utcnow().replace(microsecond=0)
|
|
1782
|
+
# -1 second tolerance for clock adjustments
|
|
1783
|
+
not_after_min = utc_now + timedelta(seconds=99)
|
|
2029
1784
|
cert.gmtime_adj_notAfter(100)
|
|
2030
1785
|
not_after_str = cert.get_notAfter()
|
|
2031
1786
|
assert not_after_str is not None
|
|
2032
1787
|
not_after = datetime.strptime(not_after_str.decode(), "%Y%m%d%H%M%SZ")
|
|
2033
|
-
|
|
1788
|
+
# +1 second tolerance for clock adjustments
|
|
1789
|
+
not_after_max = utc_now + timedelta(seconds=101)
|
|
2034
1790
|
assert not_after_min <= not_after <= not_after_max
|
|
2035
1791
|
|
|
2036
1792
|
def test_has_expired(self) -> None:
|
|
@@ -2139,71 +1895,6 @@ class TestX509:
|
|
|
2139
1895
|
c = self._extcert(pkey, [ca, key, san])
|
|
2140
1896
|
assert c.get_extension_count() == 3
|
|
2141
1897
|
|
|
2142
|
-
def test_get_extension(self) -> None:
|
|
2143
|
-
"""
|
|
2144
|
-
`X509.get_extension` takes an integer and returns an
|
|
2145
|
-
`X509Extension` corresponding to the extension at that index.
|
|
2146
|
-
"""
|
|
2147
|
-
pkey = load_privatekey(
|
|
2148
|
-
FILETYPE_PEM, client_key_pem
|
|
2149
|
-
).to_cryptography_key()
|
|
2150
|
-
assert isinstance(pkey, rsa.RSAPrivateKey)
|
|
2151
|
-
ca = x509.BasicConstraints(ca=False, path_length=None)
|
|
2152
|
-
key = x509.KeyUsage(
|
|
2153
|
-
digital_signature=True,
|
|
2154
|
-
content_commitment=False,
|
|
2155
|
-
key_encipherment=False,
|
|
2156
|
-
data_encipherment=False,
|
|
2157
|
-
key_agreement=False,
|
|
2158
|
-
key_cert_sign=False,
|
|
2159
|
-
crl_sign=False,
|
|
2160
|
-
encipher_only=False,
|
|
2161
|
-
decipher_only=False,
|
|
2162
|
-
)
|
|
2163
|
-
san = x509.SubjectAlternativeName([x509.DNSName("example.com")])
|
|
2164
|
-
|
|
2165
|
-
cert = self._extcert(pkey, [ca, key, san])
|
|
2166
|
-
|
|
2167
|
-
ext = cert.get_extension(0)
|
|
2168
|
-
assert isinstance(ext, X509Extension)
|
|
2169
|
-
assert ext.get_critical()
|
|
2170
|
-
assert ext.get_short_name() == b"basicConstraints"
|
|
2171
|
-
|
|
2172
|
-
ext = cert.get_extension(1)
|
|
2173
|
-
assert isinstance(ext, X509Extension)
|
|
2174
|
-
assert not ext.get_critical()
|
|
2175
|
-
assert ext.get_short_name() == b"keyUsage"
|
|
2176
|
-
|
|
2177
|
-
ext = cert.get_extension(2)
|
|
2178
|
-
assert isinstance(ext, X509Extension)
|
|
2179
|
-
assert ext.get_critical()
|
|
2180
|
-
assert ext.get_short_name() == b"subjectAltName"
|
|
2181
|
-
|
|
2182
|
-
with pytest.raises(IndexError):
|
|
2183
|
-
cert.get_extension(-1)
|
|
2184
|
-
with pytest.raises(IndexError):
|
|
2185
|
-
cert.get_extension(4)
|
|
2186
|
-
with pytest.raises(TypeError):
|
|
2187
|
-
cert.get_extension("hello") # type: ignore[arg-type]
|
|
2188
|
-
|
|
2189
|
-
def test_nullbyte_subjectAltName(self) -> None:
|
|
2190
|
-
"""
|
|
2191
|
-
The fields of a `subjectAltName` extension on an X509 may contain NUL
|
|
2192
|
-
bytes and this value is reflected in the string representation of the
|
|
2193
|
-
extension object.
|
|
2194
|
-
"""
|
|
2195
|
-
cert = load_certificate(FILETYPE_PEM, nulbyteSubjectAltNamePEM)
|
|
2196
|
-
|
|
2197
|
-
ext = cert.get_extension(3)
|
|
2198
|
-
assert ext.get_short_name() == b"subjectAltName"
|
|
2199
|
-
assert (
|
|
2200
|
-
b"DNS:altnull.python.org\x00example.com, "
|
|
2201
|
-
b"email:null@python.org\x00user@example.org, "
|
|
2202
|
-
b"URI:http://null.python.org\x00http://example.org, "
|
|
2203
|
-
b"IP Address:192.0.2.1, IP Address:2001:DB8:0:0:0:0:0:1"
|
|
2204
|
-
== str(ext).encode("ascii").strip()
|
|
2205
|
-
)
|
|
2206
|
-
|
|
2207
1898
|
def test_invalid_digest_algorithm(self) -> None:
|
|
2208
1899
|
"""
|
|
2209
1900
|
`X509.digest` raises `ValueError` if called with an unrecognized hash
|
|
@@ -2572,6 +2572,25 @@ class TestConnection:
|
|
|
2572
2572
|
connection.set_context(1) # type: ignore[arg-type]
|
|
2573
2573
|
assert ctx is connection.get_context()
|
|
2574
2574
|
|
|
2575
|
+
def test_set_options_wrong_args(self) -> None:
|
|
2576
|
+
"""
|
|
2577
|
+
`Connection.set_options` raises `TypeError` if called with
|
|
2578
|
+
a non-`int` argument.
|
|
2579
|
+
"""
|
|
2580
|
+
context = Context(SSLv23_METHOD)
|
|
2581
|
+
connection = Connection(context, None)
|
|
2582
|
+
with pytest.raises(TypeError):
|
|
2583
|
+
connection.set_options(None) # type: ignore[arg-type]
|
|
2584
|
+
|
|
2585
|
+
def test_set_options(self) -> None:
|
|
2586
|
+
"""
|
|
2587
|
+
`Connection.set_options` returns the new options value.
|
|
2588
|
+
"""
|
|
2589
|
+
context = Context(SSLv23_METHOD)
|
|
2590
|
+
connection = Connection(context, None)
|
|
2591
|
+
options = connection.set_options(OP_NO_SSLv2)
|
|
2592
|
+
assert options & OP_NO_SSLv2 == OP_NO_SSLv2
|
|
2593
|
+
|
|
2575
2594
|
def test_set_context(self) -> None:
|
|
2576
2595
|
"""
|
|
2577
2596
|
`Connection.set_context` specifies a new `Context` instance to be
|
|
@@ -4686,7 +4705,11 @@ class TestOCSP:
|
|
|
4686
4705
|
Tests for PyOpenSSL's OCSP stapling support.
|
|
4687
4706
|
"""
|
|
4688
4707
|
|
|
4689
|
-
|
|
4708
|
+
# Minimal valid DER-encoded OCSPResponse with status "unauthorized"
|
|
4709
|
+
# (SEQUENCE { ENUMERATED 6 }). Required by OpenSSL 4.0+, which parses
|
|
4710
|
+
# the bytes via d2i_OCSP_RESPONSE before stapling and silently drops
|
|
4711
|
+
# unparseable input.
|
|
4712
|
+
sample_ocsp_data = b"\x30\x03\x0a\x01\x06"
|
|
4690
4713
|
|
|
4691
4714
|
def _client_connection(
|
|
4692
4715
|
self,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|