Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cryptography/hazmat/primitives/serialization/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ def get_public(
point, data = _get_sshstr(data)
if curve != self.ssh_curve_name:
raise ValueError("Curve name mismatch")
if len(point) == 0:
raise ValueError("Invalid EC point: empty data")
if point[0] != 4:
raise NotImplementedError("Need uncompressed point")
return (curve, point), data
Expand Down
10 changes: 10 additions & 0 deletions tests/hazmat/primitives/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,16 @@ def test_load_ssh_public_key_ecdsa_nist_p256_compressed(self, backend):
with pytest.raises(NotImplementedError):
load_ssh_public_key(ssh_key, backend)

def test_load_ssh_public_key_ecdsa_nist_p256_empty_point(self, backend):
# Malformed key with empty point data should raise ValueError,
# not IndexError.
ssh_key = (
b"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAy"
b"NTYAAAAA"
)
with pytest.raises(ValueError):
load_ssh_public_key(ssh_key, backend)

def test_load_ssh_public_key_ecdsa_nist_p256_bad_curve_name(self, backend):
ssh_key = (
# The curve name in here is changed to be "nistp255".
Expand Down