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


Python RSAKey.from_private_key_file方法代码示例

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


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

示例1: __init__

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def __init__(self, host, port, tun_host, tun_port, tun_user, tun_password, pkey_path, pkey_password):
        self.host = host
        self.port = int(port)
        self.tun_host = tun_host
        self.tun_port = int(tun_port)
        self.tun_user = tun_user
        self.tun_password = tun_password

        if pkey_path:
            self.private_key = RSAKey.from_private_key_file(pkey_path, password=pkey_password)
            self.server = SSHTunnelForwarder(
                ssh_address_or_host=(self.tun_host, self.tun_port),
                ssh_username=self.tun_user,
                ssh_pkey=self.private_key,
                remote_bind_address=(self.host, self.port),
            )
        else:
            self.server = SSHTunnelForwarder(
                ssh_address_or_host=(self.tun_host, self.tun_port),
                ssh_username=self.tun_user,
                ssh_password=self.tun_password,
                remote_bind_address=(self.host, self.port),
            )
        self.server.start() 
开发者ID:hhyo,项目名称:Archery,代码行数:26,代码来源:ssh_tunnel.py

示例2: test_18_load_ecdsa_521

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_18_load_ecdsa_521(self):
        key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_521.key'))
        self.assertEqual('ecdsa-sha2-nistp521', key.get_name())
        exp_ecdsa = b(FINGER_ECDSA_521.split()[1].replace(':', ''))
        my_ecdsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_ecdsa, my_ecdsa)
        self.assertEqual(PUB_ECDSA_521.split()[1], key.get_base64())
        self.assertEqual(521, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        # Different versions of OpenSSL (SSLeay versions 0x1000100f and
        # 0x1000207f for instance) use different apparently valid (as far as
        # ssh-keygen is concerned) padding. So we can't check the actual value
        # of the pem encoded key.
        s.seek(0)
        key2 = ECDSAKey.from_private_key(s)
        self.assertEqual(key, key2) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:20,代码来源:test_pkey.py

示例3: ensure_local_ssh_key

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def ensure_local_ssh_key(name):
    from paramiko import RSAKey
    if os.path.exists(get_ssh_key_path(name)):
        ssh_key = RSAKey.from_private_key_file(get_ssh_key_path(name))
    else:
        logger.info("Creating key pair %s", name)
        ssh_key = new_ssh_key()
        makedirs(os.path.dirname(get_ssh_key_path(name)), exist_ok=True)
        ssh_key.write_private_key_file(get_ssh_key_path(name))
    return ssh_key 
开发者ID:kislyuk,项目名称:aegea,代码行数:12,代码来源:crypto.py

示例4: _load_rsa_key

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def _load_rsa_key(self, path, passphrase):
        return RSAKey.from_private_key_file(path, password=passphrase) 
开发者ID:Kitware,项目名称:cumulus,代码行数:4,代码来源:ssh.py

示例5: run_ssh_command

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def run_ssh_command(self, command):
    key = task_key(self.request.id)
    redis.set(key, "")
    client = SSHClient()
    client.set_missing_host_key_policy(AutoAddPolicy)
    known_hosts = os.path.expanduser('~/.ssh/known_hosts')
    try:
        client.load_host_keys(known_hosts) # So that we also save back the new host
    except FileNotFoundError:
        if not os.path.exists(os.path.dirname(known_hosts)):
            os.mkdir(os.path.dirname(known_hosts))
        open(known_hosts, "w").write("") # so connect doesn't barf when trying to save
    if type(command) == list:
        commands = command
    else:
        commands = [command]
    for c in commands:
        if os.path.exists(keyfile):
            pkey = RSAKey.from_private_key_file(keyfile)
        else:
            pkey = None
        client.connect(settings.DOKKU_HOST, port=settings.DOKKU_SSH_PORT, username="dokku", pkey=pkey, allow_agent=False, look_for_keys=False)
        transport = client.get_transport()
        channel = transport.open_session()
        channel.exec_command(c)
        while True:
            anything = False
            while channel.recv_ready():
                data = channel.recv(1024)
                handle_data(key, data)
                anything = True
            while channel.recv_stderr_ready():
                data = channel.recv_stderr(1024)
                handle_data(key, data)
                anything = True
            if not anything:
                if channel.exit_status_ready():
                    break
                time.sleep(0.1)
    return redis.get(key).decode("utf-8") 
开发者ID:palfrey,项目名称:wharf,代码行数:42,代码来源:tasks.py

示例6: test_2_load_rsa

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_2_load_rsa(self):
        key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
        self.assertEqual('ssh-rsa', key.get_name())
        exp_rsa = b(FINGER_RSA.split()[1].replace(':', ''))
        my_rsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_rsa, my_rsa)
        self.assertEqual(PUB_RSA.split()[1], key.get_base64())
        self.assertEqual(1024, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(RSA_PRIVATE_OUT, s.getvalue())
        s.seek(0)
        key2 = RSAKey.from_private_key(s)
        self.assertEqual(key, key2) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:17,代码来源:test_pkey.py

示例7: test_3_load_rsa_password

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_3_load_rsa_password(self):
        key = RSAKey.from_private_key_file(test_path('test_rsa_password.key'), 'television')
        self.assertEqual('ssh-rsa', key.get_name())
        exp_rsa = b(FINGER_RSA.split()[1].replace(':', ''))
        my_rsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_rsa, my_rsa)
        self.assertEqual(PUB_RSA.split()[1], key.get_base64())
        self.assertEqual(1024, key.get_bits()) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:10,代码来源:test_pkey.py

示例8: test_4_load_dss

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_4_load_dss(self):
        key = DSSKey.from_private_key_file(test_path('test_dss.key'))
        self.assertEqual('ssh-dss', key.get_name())
        exp_dss = b(FINGER_DSS.split()[1].replace(':', ''))
        my_dss = hexlify(key.get_fingerprint())
        self.assertEqual(exp_dss, my_dss)
        self.assertEqual(PUB_DSS.split()[1], key.get_base64())
        self.assertEqual(1024, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(DSS_PRIVATE_OUT, s.getvalue())
        s.seek(0)
        key2 = DSSKey.from_private_key(s)
        self.assertEqual(key, key2) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:17,代码来源:test_pkey.py

示例9: test_5_load_dss_password

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_5_load_dss_password(self):
        key = DSSKey.from_private_key_file(test_path('test_dss_password.key'), 'television')
        self.assertEqual('ssh-dss', key.get_name())
        exp_dss = b(FINGER_DSS.split()[1].replace(':', ''))
        my_dss = hexlify(key.get_fingerprint())
        self.assertEqual(exp_dss, my_dss)
        self.assertEqual(PUB_DSS.split()[1], key.get_base64())
        self.assertEqual(1024, key.get_bits()) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:10,代码来源:test_pkey.py

示例10: test_6_compare_rsa

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_6_compare_rsa(self):
        # verify that the private & public keys compare equal
        key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
        self.assertEqual(key, key)
        pub = RSAKey(data=key.asbytes())
        self.assertTrue(key.can_sign())
        self.assertTrue(not pub.can_sign())
        self.assertEqual(key, pub) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:10,代码来源:test_pkey.py

示例11: test_8_sign_rsa

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_8_sign_rsa(self):
        # verify that the rsa private key can sign and verify
        key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
        msg = key.sign_ssh_data(b'ice weasels')
        self.assertTrue(type(msg) is Message)
        msg.rewind()
        self.assertEqual('ssh-rsa', msg.get_text())
        sig = bytes().join([byte_chr(int(x, 16)) for x in SIGNED_RSA.split(':')])
        self.assertEqual(sig, msg.get_binary())
        msg.rewind()
        pub = RSAKey(data=key.asbytes())
        self.assertTrue(pub.verify_ssh_sig(b'ice weasels', msg)) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:14,代码来源:test_pkey.py

示例12: test_9_sign_dss

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_9_sign_dss(self):
        # verify that the dss private key can sign and verify
        key = DSSKey.from_private_key_file(test_path('test_dss.key'))
        msg = key.sign_ssh_data(b'ice weasels')
        self.assertTrue(type(msg) is Message)
        msg.rewind()
        self.assertEqual('ssh-dss', msg.get_text())
        # can't do the same test as we do for RSA, because DSS signatures
        # are usually different each time.  but we can test verification
        # anyway so it's ok.
        self.assertEqual(40, len(msg.get_binary()))
        msg.rewind()
        pub = DSSKey(data=key.asbytes())
        self.assertTrue(pub.verify_ssh_sig(b'ice weasels', msg)) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:16,代码来源:test_pkey.py

示例13: test_10_load_ecdsa_256

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_10_load_ecdsa_256(self):
        key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_256.key'))
        self.assertEqual('ecdsa-sha2-nistp256', key.get_name())
        exp_ecdsa = b(FINGER_ECDSA_256.split()[1].replace(':', ''))
        my_ecdsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_ecdsa, my_ecdsa)
        self.assertEqual(PUB_ECDSA_256.split()[1], key.get_base64())
        self.assertEqual(256, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(ECDSA_PRIVATE_OUT_256, s.getvalue())
        s.seek(0)
        key2 = ECDSAKey.from_private_key(s)
        self.assertEqual(key, key2) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:17,代码来源:test_pkey.py

示例14: test_11_load_ecdsa_password_256

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_11_load_ecdsa_password_256(self):
        key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_password_256.key'), b'television')
        self.assertEqual('ecdsa-sha2-nistp256', key.get_name())
        exp_ecdsa = b(FINGER_ECDSA_256.split()[1].replace(':', ''))
        my_ecdsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_ecdsa, my_ecdsa)
        self.assertEqual(PUB_ECDSA_256.split()[1], key.get_base64())
        self.assertEqual(256, key.get_bits()) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:10,代码来源:test_pkey.py

示例15: test_12_compare_ecdsa_256

# 需要导入模块: from paramiko import RSAKey [as 别名]
# 或者: from paramiko.RSAKey import from_private_key_file [as 别名]
def test_12_compare_ecdsa_256(self):
        # verify that the private & public keys compare equal
        key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_256.key'))
        self.assertEqual(key, key)
        pub = ECDSAKey(data=key.asbytes())
        self.assertTrue(key.can_sign())
        self.assertTrue(not pub.can_sign())
        self.assertEqual(key, pub) 
开发者ID:hpe-storage,项目名称:python-hpedockerplugin,代码行数:10,代码来源:test_pkey.py


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