Skip to content

Commit

Permalink
Reject invalid versions in X509Req.set_version
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Mar 31, 2023
1 parent da18a74 commit 63abbfb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Deprecations:
Changes:
^^^^^^^^

- Invalid versions are now rejected in ``OpenSSL.crypt.X509Req.set_version``.

23.1.1 (2023-03-28)
-------------------

Expand Down
6 changes: 6 additions & 0 deletions src/OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,12 @@ def set_version(self, version: int) -> None:
:param int version: The version number.
:return: ``None``
"""
if not isinstance(version, int):
raise TypeError("version must be an int")
if version != 0:
raise ValueError(
"Invalid version. The only valid version for X509Req is 0."
)
set_result = _lib.X509_REQ_set_version(self._req, version)
_openssl_assert(set_result == 1)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,8 @@ def test_version_wrong_args(self):
request = X509Req()
with pytest.raises(TypeError):
request.set_version("foo")
with pytest.raises(ValueError):
request.set_version(2)

def test_get_subject(self):
"""
Expand Down

0 comments on commit 63abbfb

Please sign in to comment.