當前位置: 首頁>>代碼示例>>Python>>正文


Python paramiko.Ed25519Key方法代碼示例

本文整理匯總了Python中paramiko.Ed25519Key方法的典型用法代碼示例。如果您正苦於以下問題:Python paramiko.Ed25519Key方法的具體用法?Python paramiko.Ed25519Key怎麽用?Python paramiko.Ed25519Key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paramiko的用法示例。


在下文中一共展示了paramiko.Ed25519Key方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_pkey_obj

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def get_pkey_obj(cls, privatekey, password, filename):
        bpass = to_bytes(password) if password else None

        pkey = cls.get_specific_pkey(paramiko.RSAKey, privatekey, bpass)\
            or cls.get_specific_pkey(paramiko.DSSKey, privatekey, bpass)\
            or cls.get_specific_pkey(paramiko.ECDSAKey, privatekey, bpass)\
            or cls.get_specific_pkey(paramiko.Ed25519Key, privatekey, bpass)

        if not pkey:
            if not password:
                error = 'Invalid private key: {}'.format(filename)
            else:
                error = (
                    'Wrong password {!r} for decrypting the private key.'
                ) .format(password)
            raise InvalidValueError(error)

        return pkey 
開發者ID:guohongze,項目名稱:adminset,代碼行數:20,代碼來源:handler.py

示例2: test_get_pkey_obj_with_encrypted_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def test_get_pkey_obj_with_encrypted_key(self):
        fname = 'test_ed25519_password.key'
        password = 'abc123'
        cls = paramiko.Ed25519Key
        key = read_file(make_tests_data_path(fname))

        pkey = IndexHandler.get_pkey_obj(key, password, fname)
        self.assertIsInstance(pkey, cls)

        with self.assertRaises(InvalidValueError) as ctx:
            pkey = IndexHandler.get_pkey_obj(key, 'wrongpass', fname)
        self.assertIn('Wrong password', str(ctx.exception))

        with self.assertRaises(InvalidValueError) as ctx:
            pkey = IndexHandler.get_pkey_obj('x'+key, '', fname)
        self.assertIn('Invalid private key', str(ctx.exception))

        with self.assertRaises(paramiko.PasswordRequiredException):
            pkey = IndexHandler.get_pkey_obj(key, '', fname) 
開發者ID:guohongze,項目名稱:adminset,代碼行數:21,代碼來源:test_handler.py

示例3: connect

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def connect(self, host, user, password=None, ssh_key=None, port=22, timeout=30,
                term='xterm', pty_width=80, pty_height=24):
        try:
            ssh_client = paramiko.SSHClient()
            ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

            if ssh_key:
                key = get_key_obj(paramiko.RSAKey, pkey_obj=ssh_key, password=password) or \
                      get_key_obj(paramiko.DSSKey, pkey_obj=ssh_key, password=password) or \
                      get_key_obj(paramiko.ECDSAKey, pkey_obj=ssh_key, password=password) or \
                      get_key_obj(paramiko.Ed25519Key, pkey_obj=ssh_key, password=password)

                ssh_client.connect(username=user, hostname=host, port=port, pkey=key, timeout=timeout)
            else:
                ssh_client.connect(username=user, password=password, hostname=host, port=port, timeout=timeout)

            transport = ssh_client.get_transport()
            self.channel = transport.open_session()
            self.channel.get_pty(term=term, width=pty_width, height=pty_height)
            self.channel.invoke_shell()

            for i in range(2):
                recv = self.channel.recv(1024).decode('utf-8')
                self.message['status'] = 0
                self.message['message'] = recv
                message = json.dumps(self.message)
                self.websocker.send(message)
        except socket.timeout:
            self.message['status'] = 1
            self.message['message'] = 'ssh 連接超時'
            message = json.dumps(self.message)
            self.websocker.send(message)
            self.close()
        except:
            self.close() 
開發者ID:huyuan1999,項目名稱:django-webssh,代碼行數:37,代碼來源:ssh.py

示例4: get_pkey

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def get_pkey(self, privatekey, password):
        password = password.encode('utf-8') if password else None

        pkey = self.get_specific_pkey(paramiko.RSAKey, privatekey, password)\
            or self.get_specific_pkey(paramiko.DSSKey, privatekey, password)\
            or self.get_specific_pkey(paramiko.ECDSAKey, privatekey, password)\
            or self.get_specific_pkey(paramiko.Ed25519Key, privatekey,
                                      password)
        if not pkey:
            raise ValueError('Not a valid private key file or '
                             'wrong password for decrypting the private key.')
        return pkey 
開發者ID:hequan2017,項目名稱:chain,代碼行數:14,代碼來源:main.py

示例5: test_get_pkey_obj_with_plain_ed25519_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def test_get_pkey_obj_with_plain_ed25519_key(self):
        pk = self.get_pk_obj('test_ed25519.key')
        self.assertIsInstance(pk.get_pkey_obj(), paramiko.Ed25519Key) 
開發者ID:huashengdun,項目名稱:webssh,代碼行數:5,代碼來源:test_handler.py

示例6: test_get_pkey_obj_with_encrypted_ed25519_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def test_get_pkey_obj_with_encrypted_ed25519_key(self):
        fname = 'test_ed25519_password.key'
        password = 'abc123'
        self._test_with_encrypted_key(fname, password, paramiko.Ed25519Key) 
開發者ID:huashengdun,項目名稱:webssh,代碼行數:6,代碼來源:test_handler.py

示例7: test_get_pkey_obj_with_plain_key

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def test_get_pkey_obj_with_plain_key(self):
        fname = 'test_ed25519.key'
        cls = paramiko.Ed25519Key
        key = read_file(make_tests_data_path(fname))

        pkey = IndexHandler.get_pkey_obj(key, None, fname)
        self.assertIsInstance(pkey, cls)

        pkey = IndexHandler.get_pkey_obj(key, 'iginored', fname)
        self.assertIsInstance(pkey, cls)

        with self.assertRaises(InvalidValueError) as ctx:
            pkey = IndexHandler.get_pkey_obj('x'+key, None, fname)
        self.assertIn('Invalid private key', str(ctx.exception)) 
開發者ID:guohongze,項目名稱:adminset,代碼行數:16,代碼來源:test_handler.py

示例8: get_keys

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def get_keys(logger=None, host_pkey_directories=None, allow_agent=False):
        """
        Load public keys from any available SSH agent or local
        .ssh directory.

        Arguments:
            logger (Optional[logging.Logger])

            host_pkey_directories (Optional[list[str]]):
                List of local directories where host SSH pkeys in the format
                "id_*" are searched. For example, ['~/.ssh']

                .. versionadded:: 0.1.0

            allow_agent (Optional[boolean]):
                Whether or not load keys from agent

                Default: False

        Return:
            list
        """
        keys = SSHTunnelForwarder.get_agent_keys(logger=logger) \
            if allow_agent else []

        if host_pkey_directories is not None:
            paramiko_key_types = {'rsa': paramiko.RSAKey,
                                  'dsa': paramiko.DSSKey,
                                  'ecdsa': paramiko.ECDSAKey,
                                  'ed25519': paramiko.Ed25519Key}
            for directory in host_pkey_directories or [DEFAULT_SSH_DIRECTORY]:
                for keytype in paramiko_key_types.keys():
                    ssh_pkey_expanded = os.path.expanduser(
                        os.path.join(directory, 'id_{}'.format(keytype))
                    )
                    if os.path.isfile(ssh_pkey_expanded):
                        ssh_pkey = SSHTunnelForwarder.read_private_key_file(
                            pkey_file=ssh_pkey_expanded,
                            logger=logger,
                            key_type=paramiko_key_types[keytype]
                        )
                        if ssh_pkey:
                            keys.append(ssh_pkey)
        if logger:
            logger.info('{0} keys loaded from host directory'.format(
                len(keys))
            )

        return keys 
開發者ID:pahaz,項目名稱:sshtunnel,代碼行數:51,代碼來源:sshtunnel.py

示例9: read_private_key_file

# 需要導入模塊: import paramiko [as 別名]
# 或者: from paramiko import Ed25519Key [as 別名]
def read_private_key_file(pkey_file,
                              pkey_password=None,
                              key_type=None,
                              logger=None):
        """
        Get SSH Public key from a private key file, given an optional password

        Arguments:
            pkey_file (str):
                File containing a private key (RSA, DSS or ECDSA)
        Keyword Arguments:
            pkey_password (Optional[str]):
                Password to decrypt the private key
            logger (Optional[logging.Logger])
        Return:
            paramiko.Pkey
        """
        ssh_pkey = None
        for pkey_class in (key_type,) if key_type else (
            paramiko.RSAKey,
            paramiko.DSSKey,
            paramiko.ECDSAKey,
            paramiko.Ed25519Key
        ):
            try:
                ssh_pkey = pkey_class.from_private_key_file(
                    pkey_file,
                    password=pkey_password
                )
                if logger:
                    logger.debug('Private key file ({0}, {1}) successfully '
                                 'loaded'.format(pkey_file, pkey_class))
                break
            except paramiko.PasswordRequiredException:
                if logger:
                    logger.error('Password is required for key {0}'
                                 .format(pkey_file))
                break
            except paramiko.SSHException:
                if logger:
                    logger.debug('Private key file ({0}) could not be loaded '
                                 'as type {1} or bad password'
                                 .format(pkey_file, pkey_class))
        return ssh_pkey 
開發者ID:pahaz,項目名稱:sshtunnel,代碼行數:46,代碼來源:sshtunnel.py


注:本文中的paramiko.Ed25519Key方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。