Python paramiko.HostKeys() Examples

The following are 7 code examples of paramiko.HostKeys(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module paramiko , or try the search function .
Example #1
Source File: test_hostkeys.py    From python-hpedockerplugin with Apache License 2.0 6 votes vote down vote up
def test_4_dict_set(self):
        hostdict = paramiko.HostKeys('hostfile.temp')
        key = paramiko.RSAKey(data=decodebytes(keyblob))
        key_dss = paramiko.DSSKey(data=decodebytes(keyblob_dss))
        hostdict['secure.example.com'] = {
            'ssh-rsa': key,
            'ssh-dss': key_dss
        }
        hostdict['fake.example.com'] = {}
        hostdict['fake.example.com']['ssh-rsa'] = key
        
        self.assertEqual(3, len(hostdict))
        self.assertEqual(2, len(list(hostdict.values())[0]))
        self.assertEqual(1, len(list(hostdict.values())[1]))
        self.assertEqual(1, len(list(hostdict.values())[2]))
        fp = hexlify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()).upper()
        self.assertEqual(b'7EC91BB336CB6D810B124B1353C32396', fp)
        fp = hexlify(hostdict['secure.example.com']['ssh-dss'].get_fingerprint()).upper()
        self.assertEqual(b'4478F0B9A23CC5182009FF755BC1D26C', fp) 
Example #2
Source File: ssh.py    From ryu with Apache License 2.0 5 votes vote down vote up
def __init__(self, capabilities):
        Session.__init__(self, capabilities)
        self._host_keys = paramiko.HostKeys()
        self._transport = None
        self._connected = False
        self._channel = None
        self._buffer = StringIO() # for incoming data
        # parsing-related, see _parse()
        self._parsing_state = 0
        self._parsing_pos = 0 
Example #3
Source File: netconf.py    From warriorframework with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        '''
        initialize
        '''
        self.__t = None
        self.__chan = None
        self.__sock = None
        self.__temp_buf = ""
        Thread.__init__(self)
        self.setDaemon(True)
        self.__host_keys = paramiko.HostKeys()
        self.__wait_resp = Event()
        self.__wait_resp.clear()
        self.__wait_rept = Event()
        self.__wait_rept.clear()
        self.__response_buffer = ""
        self.__hello_buffer = ""
        self.__session_id = None
        self.__isCOMPLD = False
        self.__error_message = ""
        self.__isOpen = False
        self.__send_data = ""
        self.__protocol_ver = "1.0"
        self.__notification_list = []
        self.__wait_string = ("", {})
        self.__host_name = ""
        self.__exp_protocol_version = ""
        self.__notification_list_print = [] 
Example #4
Source File: test_hostkeys.py    From python-hpedockerplugin with Apache License 2.0 5 votes vote down vote up
def test_1_load(self):
        hostdict = paramiko.HostKeys('hostfile.temp')
        self.assertEqual(2, len(hostdict))
        self.assertEqual(1, len(list(hostdict.values())[0]))
        self.assertEqual(1, len(list(hostdict.values())[1]))
        fp = hexlify(hostdict['secure.example.com']['ssh-rsa'].get_fingerprint()).upper()
        self.assertEqual(b'E6684DB30E109B67B70FF1DC5C7F1363', fp) 
Example #5
Source File: test_hostkeys.py    From python-hpedockerplugin with Apache License 2.0 5 votes vote down vote up
def test_2_add(self):
        hostdict = paramiko.HostKeys('hostfile.temp')
        hh = '|1|BMsIC6cUIP2zBuXR3t2LRcJYjzM=|hpkJMysjTk/+zzUUzxQEa2ieq6c='
        key = paramiko.RSAKey(data=decodebytes(keyblob))
        hostdict.add(hh, 'ssh-rsa', key)
        self.assertEqual(3, len(list(hostdict)))
        x = hostdict['foo.example.com']
        fp = hexlify(x['ssh-rsa'].get_fingerprint()).upper()
        self.assertEqual(b'7EC91BB336CB6D810B124B1353C32396', fp)
        self.assertTrue(hostdict.check('foo.example.com', key)) 
Example #6
Source File: test_hostkeys.py    From python-hpedockerplugin with Apache License 2.0 5 votes vote down vote up
def test_3_dict(self):
        hostdict = paramiko.HostKeys('hostfile.temp')
        self.assertTrue('secure.example.com' in hostdict)
        self.assertTrue('not.example.com' not in hostdict)
        self.assertTrue('secure.example.com' in hostdict)
        self.assertTrue('not.example.com' not in hostdict)
        x = hostdict.get('secure.example.com', None)
        self.assertTrue(x is not None)
        fp = hexlify(x['ssh-rsa'].get_fingerprint()).upper()
        self.assertEqual(b'E6684DB30E109B67B70FF1DC5C7F1363', fp)
        i = 0
        for key in hostdict:
            i += 1
        self.assertEqual(2, i) 
Example #7
Source File: test_hostkeys.py    From python-hpedockerplugin with Apache License 2.0 5 votes vote down vote up
def test_delitem(self):
        hostdict = paramiko.HostKeys('hostfile.temp')
        target = 'happy.example.com'
        entry = hostdict[target] # will KeyError if not present
        del hostdict[target]
        try:
            entry = hostdict[target]
        except KeyError:
            pass # Good
        else:
            assert False, "Entry was not deleted from HostKeys on delitem!"