def test_key_material_valid_pem_keys_invalid_header_auto_conversion(self): # Test a scenario where valid PEM keys with invalid headers which is # not recognized by paramiko are automatically converted in a format # which is recognized by paramiko conn_params = {"hostname": "dummy.host.org", "username": "******"} client = ParamikoSSHClient(**conn_params) # 1. RSA key type with header which is not supported by paramiko path = os.path.join( os.path.dirname(__file__), "fixtures", "misc", "test_rsa_non_paramiko_recognized_header.key", ) with open(path, "r") as fp: private_key = fp.read() pkey = client._get_pkey_object(key=private_key) self.assertTrue(pkey) 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, "r") 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( os.path.dirname(__file__), "fixtures", "misc", "test_ecdsa_non_paramiko_recognized_header.key", ) with open(path, "r") as fp: private_key = fp.read() pkey = client._get_pkey_object(key=private_key) self.assertTrue(pkey) self.assertTrue(isinstance(pkey, paramiko.ECDSAKey))
def test_key_material_valid_pem_keys(self): conn_params = {'hostname': 'dummy.host.org', 'username': '******'} client = ParamikoSSHClient(**conn_params) # 1. RSA key type with header which is not supported by paramiko path = os.path.join(os.path.dirname(__file__), 'fixtures', 'misc', 'test_rsa.key') with open(path, 'r') as fp: private_key = fp.read() pkey = client._get_pkey_object(key=private_key) self.assertTrue(pkey) 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') with open(path, 'r') 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(os.path.dirname(__file__), 'fixtures', 'misc', 'test_ecdsa.key') with open(path, 'r') as fp: private_key = fp.read() pkey = client._get_pkey_object(key=private_key) self.assertTrue(pkey) self.assertTrue(isinstance(pkey, paramiko.ECDSAKey))