Skip to content

Commit fbce364

Browse files
committed
fix X509Extension __str__() method for unknow extension types
1 parent b259bfb commit fbce364

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.rst

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Deprecations:
2525
Changes:
2626
^^^^^^^^
2727

28+
- Fix X509Extension __str__() method for unknown extension types
29+
`#1239 <https://github.com/pyca/pyopenssl/pull/1239>`_.
30+
2831
23.2.0 (2023-05-30)
2932
-------------------
3033

src/OpenSSL/crypto.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
TYPE_DH: int = _lib.EVP_PKEY_DH
9595
TYPE_EC: int = _lib.EVP_PKEY_EC
9696

97+
X509V3_EXT_ERROR_UNKNOWN = 1 << 16
9798

9899
class Error(Exception):
99100
"""
@@ -875,7 +876,7 @@ def __str__(self) -> str:
875876
return self._subjectAltNameString()
876877

877878
bio = _new_mem_buf()
878-
print_result = _lib.X509V3_EXT_print(bio, self._extension, 0, 0)
879+
print_result = _lib.X509V3_EXT_print(bio, self._extension, X509V3_EXT_ERROR_UNKNOWN, 0)
879880
_openssl_assert(print_result != 0)
880881

881882
return _bio_to_string(bio).decode("utf-8")

tests/test_crypto.py

+6
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,12 @@ def test_undef_oid(self):
16331633
).get_short_name()
16341634
== b"UNDEF"
16351635
)
1636+
assert (
1637+
str(X509Extension(
1638+
b"1.2.3.4.5.6.7", False, b"DER:05:00"
1639+
))
1640+
== "<Not Supported>"
1641+
)
16361642

16371643
def test_add_extensions_wrong_args(self):
16381644
"""

0 commit comments

Comments
 (0)