primitive ssh connection (lowlevel)

耗尽温柔 提交于 2019-12-10 13:35:47

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2872279/primitive-ssh-connection-lowlevel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!