Skip to content

Commit

Permalink
Merge pull request #10 from oyarzun/ecdsa-assertion
Browse files Browse the repository at this point in the history
ecdsa: check for AssertionError
  • Loading branch information
Olli Jarva committed Apr 12, 2016
2 parents 8c8bbb3 + a161159 commit e46c4f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sshpubkeys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ def parse(self):
curve, hash_algorithm = curve_data[curve_information]

data = self.unpack_by_int()

ecdsa_key = ecdsa.VerifyingKey.from_string(data[1:], curve, hash_algorithm)
try:
ecdsa_key = ecdsa.VerifyingKey.from_string(data[1:], curve, hash_algorithm)
except AssertionError:
raise InvalidKeyException("Invalid ecdsa key")
self.bits = int(curve_information.replace(b"nistp", b"")) # TODO
self.ecdsa = ecdsa_key
elif self.key_type == b"ssh-ed25519":
Expand Down
2 changes: 2 additions & 0 deletions tests/invalid_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAH0GODBKRjsFB/1v3pDRGpA6xR+QpOJg9vat0brlbUNA=", TooShortKeyException, "too_short_ed25519"],
["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIUGODBKRjsFB/1v3pDRGpA6xR+QpOJg9vat0brlbUNDDpA==", TooLongKeyException, "too_long_ed25519"],

["ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE2gqbAChP2h3fTPx3Jy2KdOJUiBGEiqBUwoosfzllw+KrqmGiDEWlufSxdiSOFuLd4a8PSwhoWbdQgRVFrZAvFE=", InvalidKeyException, "invalid_ecdsa_key"],

["ecdsa-sha2-nistp255 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTUAAAAIbmlzdHAyNTUAAABBBE2gqbAChP2h3fTPx3Jy2KdOJUiBGEiqBUwoosfzllw+KrqmGiDEWlufSxdiSOFuLd4a8PSwhoWbdQRVFrZAvFE=", NotImplementedError, "invalid_nist_curve"],
["", InvalidKeyException, "empty_key"],
["- -", MalformedDataException, "no_content"],
Expand Down

0 comments on commit e46c4f8

Please sign in to comment.