diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2016-04-23 13:45:11 -0400 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2016-04-23 13:45:11 -0400 |
commit | f133db64b23649111c7d485825b9f45d7f3f07a5 (patch) | |
tree | 13a4b6f62b21af9495adf4f1153163b9f8c95162 | |
parent | eac11dc5453153a0cf67d6f780553c80e53c58c3 (diff) |
handle invalid keys
-rw-r--r-- | paramiko/rsakey.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py index 1836b681..bc9053f5 100644 --- a/paramiko/rsakey.py +++ b/paramiko/rsakey.py @@ -29,8 +29,6 @@ from paramiko.message import Message from paramiko.pkey import PKey from paramiko.ssh_exception import SSHException -SHA1_DIGESTINFO = b'\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14' - class RSAKey(PKey): """ @@ -170,8 +168,12 @@ class RSAKey(PKey): self._decode_key(data) def _decode_key(self, data): - key = serialization.load_der_private_key( - data, password=None, backend=default_backend() - ) + try: + key = serialization.load_der_private_key( + data, password=None, backend=default_backend() + ) + except ValueError as e: + raise SSHException(str(e)) + assert isinstance(key, rsa.RSAPrivateKey) self.key = key |