Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libcloud/compute/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,15 @@ def _get_pkey_object(self, key, password=None):
"""
key_types = [
(paramiko.RSAKey, "RSA"),
(paramiko.DSSKey, "DSA"),
(paramiko.ECDSAKey, "EC"),
]

paramiko_version = getattr(paramiko, "__version__", "0.0.0")
paramiko_version = tuple(int(c) for c in paramiko_version.split("."))

if paramiko_version < (4, 0, 0):
# DSSKey removed in paramiko 4.0.0
key_types.append((paramiko.DSSKey, "DSA"))
if paramiko_version >= (2, 2, 0):
# Ed25519 is only supported in paramiko >= 2.2.0
key_types.append((paramiko.ed25519key.Ed25519Key, "Ed25519"))
Expand Down
42 changes: 23 additions & 19 deletions libcloud/test/compute/test_ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,21 @@ def test_key_material_valid_pem_keys_invalid_header_auto_conversion(self):
self.assertTrue(isinstance(pkey, paramiko.RSAKey))

# 2. DSA key type with header which is not supported by paramiko
path = os.path.join(
os.path.dirname(__file__),
"fixtures",
"misc",
"test_dsa_non_paramiko_recognized_header.key",
)

with open(path) as fp:
private_key = fp.read()

pkey = client._get_pkey_object(key=private_key)
self.assertTrue(pkey)
self.assertTrue(isinstance(pkey, paramiko.DSSKey))
# ... and only for paramiko < 4
if paramiko_version < (4, 0, 0):
path = os.path.join(
os.path.dirname(__file__),
"fixtures",
"misc",
"test_dsa_non_paramiko_recognized_header.key",
)

with open(path) as fp:
private_key = fp.read()

pkey = client._get_pkey_object(key=private_key)
self.assertTrue(pkey)
self.assertTrue(isinstance(pkey, paramiko.DSSKey))

# 3. ECDSA key type with header which is not supported by paramiko
path = os.path.join(
Expand Down Expand Up @@ -361,14 +363,16 @@ def test_key_material_valid_pem_keys(self):
self.assertTrue(isinstance(pkey, paramiko.RSAKey))

# 2. DSA key type with header which is not supported by paramiko
path = os.path.join(os.path.dirname(__file__), "fixtures", "misc", "test_dsa.key")
# ... and only for paramiko < 4
if paramiko_version < (4, 0, 0):
path = os.path.join(os.path.dirname(__file__), "fixtures", "misc", "test_dsa.key")

with open(path) as fp:
private_key = fp.read()
with open(path) as fp:
private_key = fp.read()

pkey = client._get_pkey_object(key=private_key)
self.assertTrue(pkey)
self.assertTrue(isinstance(pkey, paramiko.DSSKey))
pkey = client._get_pkey_object(key=private_key)
self.assertTrue(pkey)
self.assertTrue(isinstance(pkey, paramiko.DSSKey))

# 3. ECDSA key type with header which is not supported by paramiko
path = os.path.join(os.path.dirname(__file__), "fixtures", "misc", "test_ecdsa.key")
Expand Down