diff --git a/src/cryptography/hazmat/primitives/serialization/ssh.py b/src/cryptography/hazmat/primitives/serialization/ssh.py index cb10cf89d66c..411113bc42bf 100644 --- a/src/cryptography/hazmat/primitives/serialization/ssh.py +++ b/src/cryptography/hazmat/primitives/serialization/ssh.py @@ -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 diff --git a/tests/hazmat/primitives/test_ssh.py b/tests/hazmat/primitives/test_ssh.py index 0865461c6b5f..16e1aabff71e 100644 --- a/tests/hazmat/primitives/test_ssh.py +++ b/tests/hazmat/primitives/test_ssh.py @@ -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".