Skip to content

Commit

Permalink
Handle error generating DH params with very very large key size (#7666)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Oct 1, 2022
1 parent df9c587 commit 9ad715a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cryptography/hazmat/backends/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,9 @@ def generate_dh_parameters(
res = self._lib.DH_generate_parameters_ex(
dh_param_cdata, key_size, generator, self._ffi.NULL
)
self.openssl_assert(res == 1)
if res != 1:
errors = self._consume_errors_with_text()
raise ValueError("Unable to generate DH parameters", errors)

return _DHParameters(self, dh_param_cdata)

Expand Down
4 changes: 4 additions & 0 deletions tests/hazmat/primitives/test_dh.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def test_unsupported_generator_generate_dh(self, backend):
with pytest.raises(ValueError):
dh.generate_parameters(7, 512, backend)

def test_large_key_generate_dh(self):
with pytest.raises(ValueError):
dh.generate_parameters(2, 1 << 30)

@pytest.mark.skip_fips(reason="non-FIPS parameters")
def test_dh_parameters_supported(self, backend):
valid_p = int(
Expand Down

0 comments on commit 9ad715a

Please sign in to comment.