Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ssh key type discovery in img-proof #382

Open
smarlowucf opened this issue Apr 12, 2024 · 2 comments
Open

Handle ssh key type discovery in img-proof #382

smarlowucf opened this issue Apr 12, 2024 · 2 comments

Comments

@smarlowucf
Copy link
Collaborator

Currently img-proof passes a ssh key file path to paramiko and relies on paramiko to determine the key type. This leads to cryptic errors if there is an authentication or authorization failure with the key/user being used. For example with an RSA key that is not authorized to access the test instance instead of returning auth error paramiko returns ValueError: q must be exactly 160, 224, or 256 bits long.

To better handle and prevent this type of error from bubbling up img-proof can handle the key type discovery and instead pass a pkey object to paramiko that already is typed.

@smarlowucf
Copy link
Collaborator Author

Example:

def get_key(key_path: str = "./id_rsa") -> paramiko.PKey:
    with open(key_path) as f:
        return paramiko.RSAKey.from_private_key(f)

key = get_key()
client.connect(hostname, username=username, pkey=key)

@smarlowucf
Copy link
Collaborator Author

The code in question in paramiko walks through the following types:

from paramiko.dsskey import DSSKey
from paramiko.ecdsakey import ECDSAKey
from paramiko.ed25519key import Ed25519Key
from paramiko.rsakey import RSAKey

for pkey_class in (RSAKey, DSSKey, ECDSAKey, Ed25519Key):
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant