gpt4 book ai didi

Python Paramiko - 确定可用的密码和 key 交换算法

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:34 27 4
gpt4 key购买 nike

我有一个使用 Paramiko 库用 Python 编写的自动化 SFTP 程序。如果建立连接,我可以显示传输使用的密码和 key 交换算法。但是,我不确定这与可用的算法和密码是否相同。

例子:

>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.load_system_host_keys()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect("myhost.example.com", 22, username="xyzzy")
>>> t = ssh.get_transport()
>>> so = t.get_security_options()
>>> so.kex
('diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group1-sha1')
>>> so.ciphers
('aes128-ctr', 'aes256-ctr', 'aes128-cbc', 'blowfish-cbc', 'aes256-cbc', '3des-cbc', 'arcfour128', 'arcfour256')

这与可用的相同吗?如果不是,是否有任何方法可以确定以编程方式提供的内容?

最佳答案

SecurityOptions class Transport.get_security_options() 返回的是:

Simple object containing the security preferences of an ssh transport.These are tuples of acceptable ciphers, digests, key types, and keyexchange algorithms, listed in order of preference.

因此它列出了 Paramiko 库支持的密码和 kex 算法(或您已配置/允许的子集)。

它是您(和 Paramiko)为连接提供的可用

最终实际使用的是服务器也支持的(可用)服务器最喜欢的密​​码/kex 算法。


要获取支持的算法列表,无需连接,您可以使用:

import paramiko
import socket

opts = paramiko.transport.Transport(socket.socket()).get_security_options()
print(opts.ciphers)
print(opts.kex)

关于Python Paramiko - 确定可用的密码和 key 交换算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31298529/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com