使用 SSH.NET 和强密码
Using SSH.NET with strong ciphers
我们公司有一个项目,我们使用库 SSH.NET (2016.1.0) 连接到远程服务器。我们做的连接很简单,代码如下:
var sftpClient = new Renci.SshNet.SftpClient(host,port,user,password);
然后我们执行查找文件、下载和上传等操作。
今天我们收到了一封来自我们所连接的服务器人员的电子邮件,告诉我们他们将停止使用弱密码,恐怕这不是我所涉足的领域。
根据他们的沟通,他们新的 SSH (SFTP) 标准将是:
协议套件标准允许的密码:
- aes256-ctr
- aes128-ctr
允许的 MAC:
- hmac-sha-512
- hmac-sha-256
- hmac-sha1
允许的 KEX 密码:
- diffie-hellman-group-exchange-sha256
- diffie-hellman-group14-sha1
我在网站上查看了 SSH.Net 的最新版本,他们似乎支持这些 (https://github.com/sshnet/SSH.NET/tree/2020.0.1)。
现在,我的问题是如何使用正确的密码正确使用这个库?我还没有找到关于如何指定这些设置的任何示例。
TL;DR 只要每个类别中至少有一种算法(加密、MAC、密钥交换、. ..) 客户端和服务器都支持。
Chapter 7 of RFC4253 描述 SSH 2.0 的密钥交换协议:
Key exchange (kex) begins by each side sending name-lists of
supported algorithms. Each side has a preferred algorithm in each
category, and it is assumed that most implementations, at any given
time, will use the same preferred algorithm. Each side MAY guess
which algorithm the other side is using, and MAY send an initial key
exchange packet according to the algorithm, if appropriate for the
preferred method.
第 6.3 章是这样说的:
The ciphers in each direction MUST run independently of each other.
Implementations MUST allow the algorithm for each direction to be
independently selected, if multiple algorithms are allowed by local
policy. In practice however, it is RECOMMENDED that the same
algorithm be used in both directions.
这意味着客户端和服务器分别select 对方必须了解的每个类别的算法。 selected算法必须双方都支持。
在算法协商期间交换两个列表。由于 SSH.NET 支持您服务器的算法,因此将 selected.
有些算法比其他算法好,但是您不能更改 SSH.NET 中的优先级,因为要配置支持的 ConnectionInfo
class uses Dictionary
算法。 Dictionary
具有非确定性排序,但 SSH 协议 select 是列表中靠前的那些算法。
您可以在将 ConnectionInfo
传递给 SftpClient
之前自行更改 Dictionary
的内容。
我们公司有一个项目,我们使用库 SSH.NET (2016.1.0) 连接到远程服务器。我们做的连接很简单,代码如下:
var sftpClient = new Renci.SshNet.SftpClient(host,port,user,password);
然后我们执行查找文件、下载和上传等操作。
今天我们收到了一封来自我们所连接的服务器人员的电子邮件,告诉我们他们将停止使用弱密码,恐怕这不是我所涉足的领域。
根据他们的沟通,他们新的 SSH (SFTP) 标准将是:
协议套件标准允许的密码:
- aes256-ctr
- aes128-ctr
允许的 MAC:
- hmac-sha-512
- hmac-sha-256
- hmac-sha1
允许的 KEX 密码:
- diffie-hellman-group-exchange-sha256
- diffie-hellman-group14-sha1
我在网站上查看了 SSH.Net 的最新版本,他们似乎支持这些 (https://github.com/sshnet/SSH.NET/tree/2020.0.1)。
现在,我的问题是如何使用正确的密码正确使用这个库?我还没有找到关于如何指定这些设置的任何示例。
TL;DR 只要每个类别中至少有一种算法(加密、MAC、密钥交换、. ..) 客户端和服务器都支持。
Chapter 7 of RFC4253 描述 SSH 2.0 的密钥交换协议:
Key exchange (kex) begins by each side sending name-lists of supported algorithms. Each side has a preferred algorithm in each category, and it is assumed that most implementations, at any given time, will use the same preferred algorithm. Each side MAY guess which algorithm the other side is using, and MAY send an initial key exchange packet according to the algorithm, if appropriate for the preferred method.
第 6.3 章是这样说的:
The ciphers in each direction MUST run independently of each other. Implementations MUST allow the algorithm for each direction to be independently selected, if multiple algorithms are allowed by local policy. In practice however, it is RECOMMENDED that the same algorithm be used in both directions.
这意味着客户端和服务器分别select 对方必须了解的每个类别的算法。 selected算法必须双方都支持。
在算法协商期间交换两个列表。由于 SSH.NET 支持您服务器的算法,因此将 selected.
有些算法比其他算法好,但是您不能更改 SSH.NET 中的优先级,因为要配置支持的 ConnectionInfo
class uses Dictionary
算法。 Dictionary
具有非确定性排序,但 SSH 协议 select 是列表中靠前的那些算法。
您可以在将 ConnectionInfo
传递给 SftpClient
之前自行更改 Dictionary
的内容。