当前位置: 首页>>代码示例>>Python>>正文


Python RSAKey.from_private_key方法代码示例

本文整理汇总了Python中paramiko.rsakey.RSAKey.from_private_key方法的典型用法代码示例。如果您正苦于以下问题:Python RSAKey.from_private_key方法的具体用法?Python RSAKey.from_private_key怎么用?Python RSAKey.from_private_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在paramiko.rsakey.RSAKey的用法示例。


在下文中一共展示了RSAKey.from_private_key方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _op_user

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
 def _op_user(self, op, server, cmd_subs, quiet=False):
     """common code for adding/removing users."""
     
     pkey_f = StringIO(self.private_key)
     pkey = RSAKey.from_private_key(pkey_f)
     pkey_f.close()
     
     cmd = getattr(self, "%s_user_command" % op) % cmd_subs
     cmd = cmd + "; echo $?"
     out, err = server.exec_command(
         cmd,
         username=str(self.admin_username),
         pkey=pkey,
     )
     
     lines = out.strip().split("\n")
     ret = int(lines[-1])
     
     if ret != 0:
         error = "".join(lines[:-1])
         if not quiet:
             # msg example
             msg = "Failed to %s user on %s. Output was:\n%s" \
                 % (op, server, error),
             post_message_to_current_user(
                 msg,
                 msg_type=DatedMessage.TYPE_ERROR,
             )
             # end msg example
         raise Exception(msg)
开发者ID:fp7-alien,项目名称:C-BAS,代码行数:32,代码来源:models.py

示例2: gen_keys

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
def gen_keys(key="", key_path_dir=""):
    """
    在KEY_DIR下创建一个 uuid命名的目录,
    并且在该目录下 生产一对秘钥
    :return: 返回目录名(uuid)
    """
    key_basename = "key-" + uuid4().hex
    if not key_path_dir:
        key_path_dir = os.path.join(KEY_DIR, 'role_key', key_basename)
    private_key = os.path.join(key_path_dir, 'id_rsa')
    public_key = os.path.join(key_path_dir, 'id_rsa.pub')
    mkdir(key_path_dir, mode=755)
    if not key:
        key = RSAKey.generate(2048)
        key.write_private_key_file(private_key)
    else:
        key_file = os.path.join(key_path_dir, 'id_rsa')
        with open(key_file, 'w') as f:
            f.write(key)
            f.close()
        with open(key_file) as f:
            try:
                key = RSAKey.from_private_key(f)
            except SSHException, e:
                shutil.rmtree(key_path_dir, ignore_errors=True)
                raise SSHException(e)
开发者ID:xrogzu,项目名称:opsplatform,代码行数:28,代码来源:utils.py

示例3: __init__

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
    def __init__(self,
                 hostname,
                 username=None,
                 password=None,
                 port=22,
                 private_key=None,
                 connect_timeout=None,
                 missing_host_key=None,
                 sock=None):
        super(SshShell, self).__init__(hostname=hostname,
                                       username=username,
                                       password=password,
                                       port=port,
                                       connect_timeout=connect_timeout,
                                       missing_host_key=missing_host_key)

        try:
            self._pkey = RSAKey.from_private_key(StringIO(private_key))
        except SSHException:
            try:
                self._pkey = DSSKey.from_private_key(StringIO(private_key))
            except SSHException:
                raise ValidatorException("Unknown private key format")

        self._sock = sock
开发者ID:plomakin,项目名称:rubick,代码行数:27,代码来源:discovery.py

示例4: parse_private_key

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
def parse_private_key(private_key):
    try:
        return RSAKey.from_private_key(StringIO(private_key))
    except SSHException:
        try:
            return DSSKey.from_private_key(StringIO(private_key))
        except SSHException:
            return None
开发者ID:MirantisLabs,项目名称:rubick,代码行数:10,代码来源:discovery.py

示例5: test_sftp_key_connect

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
    def test_sftp_key_connect(self):
        server_interface = MyTServerInterface()
        pub_key_str = (
            "AAAAB3NzaC1yc2EAAAADAQABAAAAgQCzvWE391K1pyBvePGpwDWMboSLIp"
            "5L5sMq+bXPPeJPSLOm9dnm8XexZOpeg14UpsYcmrkzVPeooaqz5PqtaHO46CdK11dS"
            "cs2a8PLnavGkJRf25/PDXxlHkiZXXbAfW+6t5aVJxSJ4Jt4FV0aDqMaaYxy4ikw6da"
            "BCkvug2OZQqQ=="
        )

        priv_key_str = u"""-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQCzvWE391K1pyBvePGpwDWMboSLIp5L5sMq+bXPPeJPSLOm9dnm
8XexZOpeg14UpsYcmrkzVPeooaqz5PqtaHO46CdK11dScs2a8PLnavGkJRf25/PD
XxlHkiZXXbAfW+6t5aVJxSJ4Jt4FV0aDqMaaYxy4ikw6daBCkvug2OZQqQIDAQAB
AoGASpK9XlIQD+wqafWdFpf3368O8QdI9CbnPNJkG3sKhWidmR0R7l6rEX/UOah5
hUn4km+jfWe4ZU/GGmNbmkznDdOWspDKs7eeYl7saeRzuX2CdTVvrdU7qmD5+JLk
mXlWWd6rgRIfrFYXYeDVd8p6/kPR4SJe7dTTHuEKKIt9njECQQDhMqjyoNxftpl4
+mwQu0ZDLCZ4afDCGcsf73W3oSmqLyf401vQ6KAp/PmfxqGXY0ewGMzUJn9LFOyP
WOGcDFglAkEAzFL/DI3SYmsvLMt6/vK4qwEwSiJU8byUBj3CL3eL0xjn895GXPzb
9CUMu0fz60Tn7UhbohynPLmQ2w6npbZ9NQJBAN+uujGFpl9LuFV6KCzWV4wRJoUk
dYfWpvQpnfuvkPsBq+pzxhdTeQM7y5bwbUE509MOTyXKt1WUiwQ3fKDLgiECQQCb
Z4zhSYT4ojlRQrqb6pSWS+Mkn5QoAJw9Wv+1BqHsvwa8rxSpaREKUpuqXgGhsdkM
2noHhO+V+jW4xx6vpWr5AkEAgHoSbQUR5uY8ib3N3mNowVi9NhvBN1FkwGStM9W8
QKHf8Ha+rOx3B7Dbljc+Xdpcn9VyRmDlSqzX9aCkr18mNg==
-----END RSA PRIVATE KEY-----"""
        private_key = RSAKey.from_private_key(file_obj=StringIO(priv_key_str))

        # Fail if public key not registered
        self.assertEqual(
            server_interface.check_auth_publickey(self.username, private_key),
            AUTH_FAILED
        )

        pub_key_rec = SFTPPublicKey.objects.create(
            user = self.user,
            name = "TestKey",
            key_type = "ssh-rsa",
            public_key = pub_key_str
        )

        # Succeed if public key is registered
        self.assertEqual(
            server_interface.check_auth_publickey(self.username, private_key),
            AUTH_SUCCESSFUL
        )

        # Should fail if user is inactive
        self.user.is_active = False
        self.user.save()

        self.assertEqual(
            server_interface.check_auth_publickey(self.username, private_key),
            AUTH_FAILED
        )
        self.user.is_active = True
        self.user.save()
开发者ID:mytardis,项目名称:mytardis,代码行数:57,代码来源:test_sftp.py

示例6: _exec_ssh_cmd

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
 def _exec_ssh_cmd(self, cmdline):
     pkey_buf = StringIO(self.state.pkey)
     client = SSHClient()
     client.set_missing_host_key_policy(AutoAddPolicy())
     client.connect(self.droplet_ip, username='root',
                    pkey=RSAKey.from_private_key(pkey_buf))
     stdin, stdout, stderr = client.exec_command(cmdline)
     for line in stdout:
         logging.info(line)
     for line in stderr:
         logging.info(line)
开发者ID:markrcote,项目名称:ood,代码行数:13,代码来源:droplet.py

示例7: assignKey

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
    def assignKey(self, key):
        self.origKey = key
        # dump key to file
        self.dumpKey(self.keyPath, self.origKey)

        try:
            self._pkey = RSAKey.from_private_key(StringIO(self.origKey))
        except paramiko.SSHException:
            try:
                self._pkey = DSSKey.from_private_key(StringIO(self.origKey))
            except paramiko.SSHException:
                raise "Unknown private key format"
开发者ID:ogelbukh,项目名称:rubick,代码行数:14,代码来源:nodes.py

示例8: key_pair

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
    def key_pair(self):
        """(:class:`boto.ec2.keypair.KeyPair`) The EC2 key pair matched to
        :attr:`private_key`.

        """
        try:
            return self._key_pair
        except AttributeError:
            self._key_pair = self.ec2_connection.create_key_pair(self.key_name)
            private_key = str(self._key_pair.material)
            self._private_key = RSAKey.from_private_key(io.BytesIO(private_key))
            self._create_github_deploy_key()
开发者ID:crosspop,项目名称:asuka,代码行数:14,代码来源:app.py

示例9: connect

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
    def connect(self):
        """ Открываем низкоуровневое соединение """
        self.logger.debug(u'Open SSH connection {server} (reuse={reuse})'.format(
            server=self.server_name, reuse=self.reuse_connection))

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        if self.pkey:
            rsakey = RSAKey.from_private_key(StringIO(self.pkey))
            ssh.connect(hostname=self.hostname, port=self.port, username=self.username,
                        pkey=rsakey, timeout=self.timeout)
        else:
            ssh.connect(hostname=self.hostname, port=self.port, username=self.username,
                        password=self.password,
                        timeout=self.timeout)

        ssh.get_transport().window_size = 1024**2

        # Возвращаем соединение
        self.ssh = ssh
开发者ID:LTD-Beget,项目名称:sprutio-rpc,代码行数:22,代码来源:ssh.py

示例10: create_ssh_key_for_bitbucket

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
def create_ssh_key_for_bitbucket(env_name):
    """
    Creates an SSH key, deploys it to bitbucket for bulbasaur, then returns
    the private key.
    """
    import requests
    from requests.auth import HTTPBasicAuth
    import json
    import StringIO

    from paramiko.rsakey import RSAKey

    logger.debug("generating RSA keypair")
    private_key = RSAKey.generate(4096)
    private_key_file = StringIO.StringIO()
    private_key.write_private_key(private_key_file)
    private_key_file.seek(0)
    public_key = RSAKey.from_private_key(private_key_file)
    public_key_str = "%s %s" % (public_key.get_name(), public_key.get_base64())
    # rewind the private_key_file
    private_key_file.seek(0)
    logger.debug("successfully generated RSA keypair")

    bitbucket_url = "https://api.bitbucket.org/1.0/repositories/importthis/bulbasaur/deploy-keys/"
    bitbucket_payload = json.dumps({'label': 'bulbasaur-deploy-%s' % env_name,
                                    'key': public_key_str})
    auth = HTTPBasicAuth(os.environ['BITBUCKET_ID'],
                         os.environ['BITBUCKET_PASSWORD'])
    headers = {'content-type': 'application/json'}
    params = {'format': 'json'}
    response = requests.post(bitbucket_url, data=bitbucket_payload,
                             verify=True, auth=auth,
                             params=params, headers=headers)
    logger.debug("updating bulbasaur deploy keys")
    if response.status_code != 200:
        logger.debug(response.text)
        raise Exception("Bitbucket deploy key creation was not successful")
    logger.debug("bulbasaur deploy keys successfully updated!")
    return private_key_file
开发者ID:jslusher,项目名称:miniseed,代码行数:41,代码来源:bitbucket.py

示例11: gen_keys

# 需要导入模块: from paramiko.rsakey import RSAKey [as 别名]
# 或者: from paramiko.rsakey.RSAKey import from_private_key [as 别名]
def gen_keys(key=""):
    """
    生成公钥 私钥
    """
    output = StringIO.StringIO()
    sbuffer = StringIO.StringIO()
    key_content = {}
    if not key:
        try:
            key = RSAKey.generate(2048)
            key.write_private_key(output)
            private_key = output.getvalue()
        except IOError:
            raise IOError('gen_keys: there was an error writing to the file')
        except SSHException:
            raise SSHException('gen_keys: the key is invalid')
    else:
        private_key = key
        output.write(key)
        try:
            key = RSAKey.from_private_key(output)
        except SSHException, e:
            raise SSHException(e)
开发者ID:AutoOps,项目名称:MagicStack,代码行数:25,代码来源:utils.py


注:本文中的paramiko.rsakey.RSAKey.from_private_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。