Skip to content

Commit

Permalink
fix X509Extension __str__() method for unknow extension types
Browse files Browse the repository at this point in the history
  • Loading branch information
ich199 committed Sep 5, 2023
1 parent dca21f2 commit a037ec9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Deprecations:
Changes:
^^^^^^^^

- Fix X509Extension __str__() method for unknown extension types
`#1239 <https://github.com/pyca/pyopenssl/pull/1239>`_.

23.2.0 (2023-05-30)
-------------------

Expand Down
6 changes: 5 additions & 1 deletion src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
TYPE_DH: int = _lib.EVP_PKEY_DH
TYPE_EC: int = _lib.EVP_PKEY_EC

X509V3_EXT_ERROR_UNKNOWN = 1 << 16


class Error(Exception):
"""
Expand Down Expand Up @@ -890,7 +892,9 @@ def __str__(self) -> str:
return self._subjectAltNameString()

bio = _new_mem_buf()
print_result = _lib.X509V3_EXT_print(bio, self._extension, 0, 0)
print_result = _lib.X509V3_EXT_print(
bio, self._extension, X509V3_EXT_ERROR_UNKNOWN, 0
)
_openssl_assert(print_result != 0)

return _bio_to_string(bio).decode("utf-8")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,10 @@ def test_undef_oid(self):
).get_short_name()
== b"UNDEF"
)
assert (
str(X509Extension(b"1.2.3.4.5.6.7", False, b"DER:05:00"))
== "<Not Supported>"
)

def test_add_extensions_wrong_args(self):
"""
Expand Down

0 comments on commit a037ec9

Please sign in to comment.