diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2019-12-03 15:51:36 -0500 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2019-12-03 15:51:36 -0500 |
commit | b133afaecffe5e2cc3bbc78d8a7e2cdcf40f0191 (patch) | |
tree | 06151039f36812916c33625dc116f83cf648463f | |
parent | c67cf36c6596879b7e161d5c99db8c4e1c2a9c44 (diff) |
Modify exception raised by weird key subclasses w/ bad pkformat
Not sure this can even really happen though
-rw-r--r-- | paramiko/dsskey.py | 2 | ||||
-rw-r--r-- | paramiko/ecdsakey.py | 2 | ||||
-rw-r--r-- | paramiko/pkey.py | 4 | ||||
-rw-r--r-- | paramiko/rsakey.py | 2 |
4 files changed, 7 insertions, 3 deletions
diff --git a/paramiko/dsskey.py b/paramiko/dsskey.py index f1bb330f..4d85b8ca 100644 --- a/paramiko/dsskey.py +++ b/paramiko/dsskey.py @@ -241,7 +241,7 @@ class DSSKey(PKey): 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)" diff --git a/paramiko/ecdsakey.py b/paramiko/ecdsakey.py index 912795b6..28d1222b 100644 --- a/paramiko/ecdsakey.py +++ b/paramiko/ecdsakey.py @@ -298,7 +298,7 @@ class ECDSAKey(PKey): 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() diff --git a/paramiko/pkey.py b/paramiko/pkey.py index 32b696b2..b9e6c613 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -333,6 +333,10 @@ class PKey(object): 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 diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py index f372a4cb..9707b268 100644 --- a/paramiko/rsakey.py +++ b/paramiko/rsakey.py @@ -201,6 +201,6 @@ class RSAKey(PKey): 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 |