Add support for passing "key_password" argument to the paramiko client
constructor.
This argument can contain password for encrypted key files when
key_material argument is provided.
@@ -237,6 +237,7 @@ class ParamikoSSHClient(BaseSSHClient):
key=None, # type: Optional[str]
key_files=None, # type: Optional[Union[str, List[str]]]
key_material=None, # type: Optional[str]
+ key_password=None, # type: Optional[str]
timeout=None # type: Optional[float]
):
"""
@@ -262,6 +263,7 @@ class ParamikoSSHClient(BaseSSHClient):
timeout=timeout)
self.key_material = key_material
+ self.key_password = key_password
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
@@ -281,7 +283,8 @@ class ParamikoSSHClient(BaseSSHClient):
conninfo['key_filename'] = self.key_files
if self.key_material:
- conninfo['pkey'] = self._get_pkey_object(key=self.key_material)
+ conninfo['pkey'] = self._get_pkey_object(key=self.key_material,
+ passpharse=self.key_password)
if not self.password and not (self.key_files or self.key_material):
conninfo['allow_agent'] = True
@@ -300,7 +303,9 @@ class ParamikoSSHClient(BaseSSHClient):
key_material = fp.read()
try:
- pkey = self._get_pkey_object(key=key_material)
+ pkey = self._get_pkey_object(key=key_material, passpharse=self.key_password)
+ except paramiko.ssh_exception.PasswordRequiredException as e:
+ raise e
except Exception:
pass
else:
