本文整理汇总了Python中paramiko.DSSKey.from_private_key方法的典型用法代码示例。如果您正苦于以下问题:Python DSSKey.from_private_key方法的具体用法?Python DSSKey.from_private_key怎么用?Python DSSKey.from_private_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko.DSSKey
的用法示例。
在下文中一共展示了DSSKey.from_private_key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_4_load_dss
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import from_private_key [as 别名]
def test_4_load_dss(self):
key = DSSKey.from_private_key_file('tests/test_dss.key')
self.assertEquals('ssh-dss', key.get_name())
exp_dss = FINGER_DSS.split()[1].replace(':', '')
my_dss = hexlify(key.get_fingerprint())
self.assertEquals(exp_dss, my_dss)
self.assertEquals(PUB_DSS.split()[1], key.get_base64())
self.assertEquals(1024, key.get_bits())
s = StringIO()
key.write_private_key(s)
self.assertEquals(DSS_PRIVATE_OUT, s.getvalue())
s.seek(0)
key2 = DSSKey.from_private_key(s)
self.assertEquals(key, key2)
示例2: test_4_load_dss
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import from_private_key [as 别名]
def test_4_load_dss(self):
key = DSSKey.from_private_key_file(_support("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)
示例3: apply_config
# 需要导入模块: from paramiko import DSSKey [as 别名]
# 或者: from paramiko.DSSKey import from_private_key [as 别名]
def apply_config(self, user, timestamp, passphrase):
""" Apply the configuration
This will check the Affectedlog and generates proper authorized_keys
file for each host affected.
"""
retval = {
"status": "success",
"ssh_messages": []
}
# Add note about that.
ActionLog(
timestamp=timestamp,
user=user,
action="APPLY"
).save()
# Do some initialisation
affected_hosts = self.all()
public_key = Configuration.objects.get(
key="sshkey_public"
)
private_key_config = Configuration.objects.get(
key="sshkey_private"
)
keytype = Configuration.objects.get(
key="sshkey_type"
)
if not public_key or not private_key_config or not keytype:
raise _("Invalid configuration. Did you run setup already?")
if passphrase == "":
passphrase = None
private_key = None
try:
# Generate private key to use
private_key_file = StringIO.StringIO(
str(private_key_config.value)
)
if keytype.value == "dsa":
# noinspection PyTypeChecker
private_key = DSSKey.from_private_key(
private_key_file, passphrase
)
else:
# noinspection PyTypeChecker
private_key = RSAKey.from_private_key(
private_key_file, passphrase
)
private_key_file.close()
except SSHException:
retval['ssh_messages'].append(_(
"Cannot open skd private key. Perhaps you specified the "
"wrong passphrase?"
))
retval['status'] = "error"
hosts_applied = []
if private_key:
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy)
for apply_line in affected_hosts:
host = apply_line.host
if host in hosts_applied:
continue
workload = []
# Find all users, that have access to this host.
user_keys = UserKey.objects.filter(
**{
#.........这里部分代码省略.........