pyOpenSSL 26.1.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.1.0 → pyopenssl-26.2.0}/CHANGELOG.rst +18 -0
- {pyopenssl-26.1.0/src/pyOpenSSL.egg-info → pyopenssl-26.2.0}/PKG-INFO +20 -2
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/api/crypto.rst +0 -10
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/setup.py +1 -1
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/SSL.py +16 -7
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/crypto.py +1 -308
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/version.py +1 -1
- {pyopenssl-26.1.0 → pyopenssl-26.2.0/src/pyOpenSSL.egg-info}/PKG-INFO +20 -2
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/requires.txt +1 -1
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/test_crypto.py +0 -319
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/test_ssl.py +19 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/CODE_OF_CONDUCT.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/CONTRIBUTING.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/INSTALL.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/LICENSE +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/MANIFEST.in +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/README.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/ChangeLog_old.txt +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/Makefile +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/Quotes +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/README +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/api/ssl.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/api.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/backward-compatibility.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/changelog.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/conf.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/images/pyopenssl-brand.png +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/images/pyopenssl-icon.png +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/images/pyopenssl-logo.png +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/images/pyopenssl.svg +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/index.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/install.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/internals.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/introduction.rst +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/doc/make.bat +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/noxfile.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/pyproject.toml +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/setup.cfg +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/__init__.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/_util.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/debug.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/py.typed +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/OpenSSL/rand.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/SOURCES.txt +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/dependency_links.txt +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/src/pyOpenSSL.egg-info/top_level.txt +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/__init__.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/conftest.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/test_debug.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/test_rand.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/test_util.py +0 -0
- {pyopenssl-26.1.0 → pyopenssl-26.2.0}/tests/util.py +0 -0
|
@@ -4,6 +4,24 @@ 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
|
+
|
|
7
25
|
26.1.0 (2026-04-24)
|
|
8
26
|
-------------------
|
|
9
27
|
|
|
@@ -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,24 @@ 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
|
+
|
|
99
117
|
26.1.0 (2026-04-24)
|
|
100
118
|
-------------------
|
|
101
119
|
|
|
@@ -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
|
|
|
@@ -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",
|
|
@@ -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,24 @@ 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
|
+
|
|
99
117
|
26.1.0 (2026-04-24)
|
|
100
118
|
-------------------
|
|
101
119
|
|
|
@@ -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`.
|
|
@@ -1687,67 +1494,6 @@ class TestX509Req:
|
|
|
1687
1494
|
subject.commonName = "bar"
|
|
1688
1495
|
assert subject.commonName == "bar"
|
|
1689
1496
|
|
|
1690
|
-
def test_add_extensions(self) -> None:
|
|
1691
|
-
"""
|
|
1692
|
-
`X509Req.add_extensions` accepts a `list` of `X509Extension` instances
|
|
1693
|
-
and adds them to the X509 request.
|
|
1694
|
-
"""
|
|
1695
|
-
request = X509Req()
|
|
1696
|
-
request.add_extensions(
|
|
1697
|
-
[X509Extension(b"basicConstraints", True, b"CA:false")]
|
|
1698
|
-
)
|
|
1699
|
-
exts = request.get_extensions()
|
|
1700
|
-
assert len(exts) == 1
|
|
1701
|
-
assert exts[0].get_short_name() == b"basicConstraints"
|
|
1702
|
-
assert exts[0].get_critical() == 1
|
|
1703
|
-
assert exts[0].get_data() == b"0\x00"
|
|
1704
|
-
|
|
1705
|
-
def test_get_extensions(self) -> None:
|
|
1706
|
-
"""
|
|
1707
|
-
`X509Req.get_extensions` returns a `list` of extensions added to this
|
|
1708
|
-
X509 request.
|
|
1709
|
-
"""
|
|
1710
|
-
request = X509Req()
|
|
1711
|
-
exts = request.get_extensions()
|
|
1712
|
-
assert exts == []
|
|
1713
|
-
request.add_extensions(
|
|
1714
|
-
[
|
|
1715
|
-
X509Extension(b"basicConstraints", True, b"CA:true"),
|
|
1716
|
-
X509Extension(b"keyUsage", False, b"digitalSignature"),
|
|
1717
|
-
]
|
|
1718
|
-
)
|
|
1719
|
-
exts = request.get_extensions()
|
|
1720
|
-
assert len(exts) == 2
|
|
1721
|
-
assert exts[0].get_short_name() == b"basicConstraints"
|
|
1722
|
-
assert exts[0].get_critical() == 1
|
|
1723
|
-
assert exts[0].get_data() == b"0\x03\x01\x01\xff"
|
|
1724
|
-
assert exts[1].get_short_name() == b"keyUsage"
|
|
1725
|
-
assert exts[1].get_critical() == 0
|
|
1726
|
-
assert exts[1].get_data() == b"\x03\x02\x07\x80"
|
|
1727
|
-
# Requesting it a second time should return the same list
|
|
1728
|
-
exts = request.get_extensions()
|
|
1729
|
-
assert len(exts) == 2
|
|
1730
|
-
|
|
1731
|
-
def test_undef_oid(self) -> None:
|
|
1732
|
-
assert (
|
|
1733
|
-
X509Extension(
|
|
1734
|
-
b"1.2.3.4.5.6.7", False, b"DER:05:00"
|
|
1735
|
-
).get_short_name()
|
|
1736
|
-
== b"UNDEF"
|
|
1737
|
-
)
|
|
1738
|
-
|
|
1739
|
-
def test_add_extensions_wrong_args(self) -> None:
|
|
1740
|
-
"""
|
|
1741
|
-
`X509Req.add_extensions` raises `TypeError` if called with a
|
|
1742
|
-
non-`list`. Or it raises `ValueError` if called with a `list`
|
|
1743
|
-
containing objects other than `X509Extension` instances.
|
|
1744
|
-
"""
|
|
1745
|
-
request = X509Req()
|
|
1746
|
-
with pytest.raises(TypeError):
|
|
1747
|
-
request.add_extensions(object()) # type: ignore[arg-type]
|
|
1748
|
-
with pytest.raises(ValueError):
|
|
1749
|
-
request.add_extensions([object()]) # type: ignore[list-item]
|
|
1750
|
-
|
|
1751
1497
|
def test_verify_wrong_args(self) -> None:
|
|
1752
1498
|
"""
|
|
1753
1499
|
`X509Req.verify` raises `TypeError` if passed anything other than a
|
|
@@ -2149,71 +1895,6 @@ class TestX509:
|
|
|
2149
1895
|
c = self._extcert(pkey, [ca, key, san])
|
|
2150
1896
|
assert c.get_extension_count() == 3
|
|
2151
1897
|
|
|
2152
|
-
def test_get_extension(self) -> None:
|
|
2153
|
-
"""
|
|
2154
|
-
`X509.get_extension` takes an integer and returns an
|
|
2155
|
-
`X509Extension` corresponding to the extension at that index.
|
|
2156
|
-
"""
|
|
2157
|
-
pkey = load_privatekey(
|
|
2158
|
-
FILETYPE_PEM, client_key_pem
|
|
2159
|
-
).to_cryptography_key()
|
|
2160
|
-
assert isinstance(pkey, rsa.RSAPrivateKey)
|
|
2161
|
-
ca = x509.BasicConstraints(ca=False, path_length=None)
|
|
2162
|
-
key = x509.KeyUsage(
|
|
2163
|
-
digital_signature=True,
|
|
2164
|
-
content_commitment=False,
|
|
2165
|
-
key_encipherment=False,
|
|
2166
|
-
data_encipherment=False,
|
|
2167
|
-
key_agreement=False,
|
|
2168
|
-
key_cert_sign=False,
|
|
2169
|
-
crl_sign=False,
|
|
2170
|
-
encipher_only=False,
|
|
2171
|
-
decipher_only=False,
|
|
2172
|
-
)
|
|
2173
|
-
san = x509.SubjectAlternativeName([x509.DNSName("example.com")])
|
|
2174
|
-
|
|
2175
|
-
cert = self._extcert(pkey, [ca, key, san])
|
|
2176
|
-
|
|
2177
|
-
ext = cert.get_extension(0)
|
|
2178
|
-
assert isinstance(ext, X509Extension)
|
|
2179
|
-
assert ext.get_critical()
|
|
2180
|
-
assert ext.get_short_name() == b"basicConstraints"
|
|
2181
|
-
|
|
2182
|
-
ext = cert.get_extension(1)
|
|
2183
|
-
assert isinstance(ext, X509Extension)
|
|
2184
|
-
assert not ext.get_critical()
|
|
2185
|
-
assert ext.get_short_name() == b"keyUsage"
|
|
2186
|
-
|
|
2187
|
-
ext = cert.get_extension(2)
|
|
2188
|
-
assert isinstance(ext, X509Extension)
|
|
2189
|
-
assert ext.get_critical()
|
|
2190
|
-
assert ext.get_short_name() == b"subjectAltName"
|
|
2191
|
-
|
|
2192
|
-
with pytest.raises(IndexError):
|
|
2193
|
-
cert.get_extension(-1)
|
|
2194
|
-
with pytest.raises(IndexError):
|
|
2195
|
-
cert.get_extension(4)
|
|
2196
|
-
with pytest.raises(TypeError):
|
|
2197
|
-
cert.get_extension("hello") # type: ignore[arg-type]
|
|
2198
|
-
|
|
2199
|
-
def test_nullbyte_subjectAltName(self) -> None:
|
|
2200
|
-
"""
|
|
2201
|
-
The fields of a `subjectAltName` extension on an X509 may contain NUL
|
|
2202
|
-
bytes and this value is reflected in the string representation of the
|
|
2203
|
-
extension object.
|
|
2204
|
-
"""
|
|
2205
|
-
cert = load_certificate(FILETYPE_PEM, nulbyteSubjectAltNamePEM)
|
|
2206
|
-
|
|
2207
|
-
ext = cert.get_extension(3)
|
|
2208
|
-
assert ext.get_short_name() == b"subjectAltName"
|
|
2209
|
-
assert (
|
|
2210
|
-
b"DNS:altnull.python.org\x00example.com, "
|
|
2211
|
-
b"email:null@python.org\x00user@example.org, "
|
|
2212
|
-
b"URI:http://null.python.org\x00http://example.org, "
|
|
2213
|
-
b"IP Address:192.0.2.1, IP Address:2001:DB8:0:0:0:0:0:1"
|
|
2214
|
-
== str(ext).encode("ascii").strip()
|
|
2215
|
-
)
|
|
2216
|
-
|
|
2217
1898
|
def test_invalid_digest_algorithm(self) -> None:
|
|
2218
1899
|
"""
|
|
2219
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
|
|
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
|
|
File without changes
|