原始 ssh 连接(低级)

发布于 2024-09-02 05:16:22 字数 1206 浏览 7 评论 0原文

作为一个小型(大型)业余爱好项目,我开始用 C# 制作一个(非常原始的)ssh-2.0 客户端。 这是为了探索和更好地理解 DH 并帮助增强我对加密的熟悉程度:)

根据 RFC 4253,我已经开始像这样的初始连接:(

忽略不相关的变量预设等)

Random cookie_gen = new Random();
while ((ssh_response = unsecure_reader.ReadLine()) != null)
{
   MessageBox.Show(ssh_response);
   if (ssh_response.StartsWith("SSH-2.0-")
   {
      // you told me your name, now I'll tell you mine
      ssh_writer.Write("SSH-2.0-MYSSHCLIENT\r\n");
      ssh_writer.Flush();
      // now I should write up my supported (which I'll keep to the required as per rfc 4253)
      ssh_writer.Write(0x20); // SSH_MSG_KEXINIT
      byte[] cookie = new byte[16];
      for (int i = 0; i < 16; i++)
         cookie[i] = Convert.ToByte(cookie_gen.Next(0, 10));
      ssh_writer.Write(cookie); // cookie
      // and now for the name-list
      // This is where I'm troubled

      // "Footer"
      ssh_writer.Write(0x00); // first_kex_packet_follows
      ssh_writer.Write(0x00); // 0
      ssh_writer.Flush();
   }
}

正如您在 RFC 第 16 页上看到的4253,我预计会给出 10 个名单。这些是否只是假设为字符串,或者如何标记每个列表的开始/结束(仅通过换行符\n)?我在正确的轨道上吗? (请记住,在此之后我将处理 DH 和加密。我的问题仅基于迄今为止的初步接触)。

欢迎和赞赏任何帮助或评论,

PS:我知道存在库,但这与我的项目无关。

as a small (large) hobby project I've set out to make a (very primitive) ssh-2.0 client in C#.
This is to explore and better understand DH and help flourish my encryption familiarities :)

As per RFC 4253, I've begun the initial connection like this:

(leaving out irrelevant presetting of vars etc.)

Random cookie_gen = new Random();
while ((ssh_response = unsecure_reader.ReadLine()) != null)
{
   MessageBox.Show(ssh_response);
   if (ssh_response.StartsWith("SSH-2.0-")
   {
      // you told me your name, now I'll tell you mine
      ssh_writer.Write("SSH-2.0-MYSSHCLIENT\r\n");
      ssh_writer.Flush();
      // now I should write up my supported (which I'll keep to the required as per rfc 4253)
      ssh_writer.Write(0x20); // SSH_MSG_KEXINIT
      byte[] cookie = new byte[16];
      for (int i = 0; i < 16; i++)
         cookie[i] = Convert.ToByte(cookie_gen.Next(0, 10));
      ssh_writer.Write(cookie); // cookie
      // and now for the name-list
      // This is where I'm troubled

      // "Footer"
      ssh_writer.Write(0x00); // first_kex_packet_follows
      ssh_writer.Write(0x00); // 0
      ssh_writer.Flush();
   }
}

As you can see on page 16 of RFC 4253, I'm expected to give 10 name-lists. Are these simply suppose to be strings, or how do I mark start/end of each list (simply by newline \n)? Am I even on the right track here? (keep in mind I will handle DH and encryption past this point. My question is solely based on the initial contact so far).

Any help or comments are welcomed and appreciated,

PS: I'm aware libraries exist, but this is not relevant to my project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞清仓 2024-09-09 05:16:22

正如 RFC 4251 第 9 页所述:

不得使用终止空字符,也不得使用
对于单个名称,也不对于整个列表。

命名的 RFC 中也有示例。

Well, as RFC 4251 states on page 9:

Terminating null characters MUST NOT be used, neither
for the individual names, nor for the list as a whole.

There are also examples in the named RFC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文