Skip to content

Commit

Permalink
Modify exception raised by weird key subclasses w/ bad pkformat
Browse files Browse the repository at this point in the history
Not sure this can even really happen though
  • Loading branch information
bitprophet committed Dec 3, 2019
1 parent c67cf36 commit b133afa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion paramiko/dsskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _decode_key(self, data):
keylist = self._uint32_cstruct_unpack(data, "iiiii")
keylist = [0] + list(keylist)
else:
raise SSHException("private key format.")
self._got_bad_key_format_id(pkformat)
if type(keylist) is not list or len(keylist) < 6 or keylist[0] != 0:
raise SSHException(
"not a valid DSA private key file (bad ber encoding)"
Expand Down
2 changes: 1 addition & 1 deletion paramiko/ecdsakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _decode_key(self, data):
except (AttributeError, TypeError) as e:
raise SSHException(str(e))
else:
raise SSHException("unknown private key format.")
self._got_bad_key_format_id(pkformat)

self.signing_key = key
self.verifying_key = key.public_key()
Expand Down
4 changes: 4 additions & 0 deletions paramiko/pkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ def _read_private_key(self, tag, f, password=None):

return pkformat, data

def _got_bad_key_format_id(self, id_):
err = "{}._read_private_key() spat out an unknown key format id '{}'"
raise SSHException(err.format(self.__class__.__name__, id_))

def _read_private_key_old_format(self, lines, end, password):
start = 0
# parse any headers first
Expand Down
2 changes: 1 addition & 1 deletion paramiko/rsakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,6 @@ def _decode_key(self, data):
public_numbers=public_numbers,
).private_key(default_backend())
else:
raise SSHException("unknown private key format.")
self._got_bad_key_format_id(pkformat)
assert isinstance(key, rsa.RSAPrivateKey)
self.key = key

0 comments on commit b133afa

Please sign in to comment.