Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ssh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4305 by maya, Mon Feb 14 14:30:19 2011 UTC revision 4306 by maya, Tue Feb 15 00:21:10 2011 UTC
# Line 4951  static BOOL handle_SSH2_dh_kex_reply(PTI Line 4951  static BOOL handle_SSH2_dh_kex_reply(PTI
4951          len = pvar->ssh_state.payloadlen;          len = pvar->ssh_state.payloadlen;
4952    
4953          // for debug          // for debug
         //write_buffer_file(data, len);  
4954          push_memdump("KEXDH_REPLY", "key exchange: receiving", data, len);          push_memdump("KEXDH_REPLY", "key exchange: receiving", data, len);
4955    
4956          bloblen = get_uint32_MSBfirst(data);          bloblen = get_uint32_MSBfirst(data);
4957          data += 4;          data += 4;
4958          server_host_key_blob = data; // for hash          server_host_key_blob = data; // for hash
4959    
4960            push_memdump("KEXDH_REPLY", "server_host_key_blob", server_host_key_blob, bloblen);
4961    
4962          // key_from_blob()#key.c の処理が以下から始まる。          // key_from_blob()#key.c の処理が以下から始まる。
4963          // known_hosts検証用の server_host_key は rsa or dsa となる。          // known_hosts検証用の server_host_key は rsa or dsa となる。
4964          keynamelen = get_uint32_MSBfirst(data);          keynamelen = get_uint32_MSBfirst(data);
# Line 4970  static BOOL handle_SSH2_dh_kex_reply(PTI Line 4971  static BOOL handle_SSH2_dh_kex_reply(PTI
4971          key[keynamelen] = 0;          key[keynamelen] = 0;
4972          data += keynamelen;          data += keynamelen;
4973    
4974            push_memdump("KEXDH_REPLY", "keyname", key, keynamelen);
4975    
4976          // RSA key          // RSA key
4977          if (strcmp(key, "ssh-rsa") == 0) {          if (strcmp(key, "ssh-rsa") == 0) {
4978                  rsa = RSA_new();                  rsa = RSA_new();
# Line 5086  static BOOL handle_SSH2_dh_kex_reply(PTI Line 5089  static BOOL handle_SSH2_dh_kex_reply(PTI
5089                             share_key,                             share_key,
5090                             &hashlen);                             &hashlen);
5091    
5092            {
5093                    push_memdump("KEXDH_REPLY kex_dh_kex_hash", "my_kex", buffer_ptr(pvar->my_kex), buffer_len(pvar->my_kex));
5094                    push_memdump("KEXDH_REPLY kex_dh_kex_hash", "peer_kex", buffer_ptr(pvar->peer_kex), buffer_len(pvar->peer_kex));
5095    
5096                    push_bignum_memdump("KEXDH_REPLY kex_dh_kex_hash", "dh_server_pub", dh_server_pub);
5097                    push_bignum_memdump("KEXDH_REPLY kex_dh_kex_hash", "share_key", share_key);
5098    
5099                    push_memdump("KEXDH_REPLY kex_dh_kex_hash", "hash", hash, hashlen);
5100            }
5101    
5102          //debug_print(30, hash, hashlen);          //debug_print(30, hash, hashlen);
5103          //debug_print(31, pvar->client_version_string, strlen(pvar->client_version_string));          //debug_print(31, pvar->client_version_string, strlen(pvar->client_version_string));
5104          //debug_print(32, pvar->server_version_string, strlen(pvar->server_version_string));          //debug_print(32, pvar->server_version_string, strlen(pvar->server_version_string));
# Line 5117  static BOOL handle_SSH2_dh_kex_reply(PTI Line 5130  static BOOL handle_SSH2_dh_kex_reply(PTI
5130                  }                  }
5131                  else {                  else {
5132                          _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,                          _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5133                                      "key verify error(%d) @ handle_SSH2_dh_kex_reply()", ret);                                      "key verify error(%d) @ handle_SSH2_dh_kex_reply()\r\n%s", ret, SENDTOME);
5134                  }                  }
5135                  emsg = emsg_tmp;                  emsg = emsg_tmp;
5136                  save_memdump(LOGDUMP);                  save_memdump(LOGDUMP);
# Line 5227  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5240  static BOOL handle_SSH2_dh_gex_reply(PTI
5240          // パケットサイズ - (パディングサイズ+1);真のパケットサイズ          // パケットサイズ - (パディングサイズ+1);真のパケットサイズ
5241          len = pvar->ssh_state.payloadlen;          len = pvar->ssh_state.payloadlen;
5242    
         push_memdump("DH_GEX_REPLY", "full dump", data, len);  
   
5243          // for debug          // for debug
5244          //write_buffer_file(data, len);          push_memdump("DH_GEX_REPLY", "key exchange: receiving", data, len);
5245    
5246          bloblen = get_uint32_MSBfirst(data);          bloblen = get_uint32_MSBfirst(data);
5247          data += 4;          data += 4;
# Line 5242  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5253  static BOOL handle_SSH2_dh_gex_reply(PTI
5253          // known_hosts検証用の server_host_key は rsa or dsa となる。          // known_hosts検証用の server_host_key は rsa or dsa となる。
5254          keynamelen = get_uint32_MSBfirst(data);          keynamelen = get_uint32_MSBfirst(data);
5255          if (keynamelen >= 128) {          if (keynamelen >= 128) {
5256                  emsg = "keyname length too big @ handle_SSH2_dh_kex_reply()";                  emsg = "keyname length too big @ handle_SSH2_dh_gex_reply()";
5257                  goto error;                  goto error;
5258          }          }
5259          data +=4 ;          data +=4 ;
# Line 5256  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5267  static BOOL handle_SSH2_dh_gex_reply(PTI
5267          if (strcmp(key, "ssh-rsa") == 0) {          if (strcmp(key, "ssh-rsa") == 0) {
5268                  rsa = RSA_new();                  rsa = RSA_new();
5269                  if (rsa == NULL) {                  if (rsa == NULL) {
5270                          emsg = "Out of memory1 @ handle_SSH2_dh_kex_reply()";                          emsg = "Out of memory1 @ handle_SSH2_dh_gex_reply()";
5271                          goto error;                          goto error;
5272                  }                  }
5273                  rsa->n = BN_new();                  rsa->n = BN_new();
5274                  rsa->e = BN_new();                  rsa->e = BN_new();
5275                  if (rsa->n == NULL || rsa->e == NULL) {                  if (rsa->n == NULL || rsa->e == NULL) {
5276                          emsg = "Out of memory2 @ handle_SSH2_dh_kex_reply()";                          emsg = "Out of memory2 @ handle_SSH2_dh_gex_reply()";
5277                          goto error;                          goto error;
5278                  }                  }
5279    
# Line 5275  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5286  static BOOL handle_SSH2_dh_gex_reply(PTI
5286          } else if (strcmp(key, "ssh-dss") == 0) { // DSA key          } else if (strcmp(key, "ssh-dss") == 0) { // DSA key
5287                  dsa = DSA_new();                  dsa = DSA_new();
5288                  if (dsa == NULL) {                  if (dsa == NULL) {
5289                          emsg = "Out of memory3 @ handle_SSH2_dh_kex_reply()";                          emsg = "Out of memory3 @ handle_SSH2_dh_gex_reply()";
5290                          goto error;                          goto error;
5291                  }                  }
5292                  dsa->p = BN_new();                  dsa->p = BN_new();
# Line 5286  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5297  static BOOL handle_SSH2_dh_gex_reply(PTI
5297                      dsa->q == NULL ||                      dsa->q == NULL ||
5298                      dsa->g == NULL ||                      dsa->g == NULL ||
5299                      dsa->pub_key == NULL) {                      dsa->pub_key == NULL) {
5300                          emsg = "Out of memory4 @ handle_SSH2_dh_kex_reply()";                          emsg = "Out of memory4 @ handle_SSH2_dh_gex_reply()";
5301                          goto error;                          goto error;
5302                  }                  }
5303    
# Line 5301  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5312  static BOOL handle_SSH2_dh_gex_reply(PTI
5312          } else {          } else {
5313                  // unknown key                  // unknown key
5314                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5315                              "Unknown key type(%s) @ handle_SSH2_dh_kex_reply()", key);                              "Unknown key type(%s) @ handle_SSH2_dh_gex_reply()", key);
5316                  emsg = emsg_tmp;                  emsg = emsg_tmp;
5317                  goto error;                  goto error;
5318    
# Line 5322  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5333  static BOOL handle_SSH2_dh_gex_reply(PTI
5333    
5334          dh_server_pub = BN_new();          dh_server_pub = BN_new();
5335          if (dh_server_pub == NULL) {          if (dh_server_pub == NULL) {
5336                  emsg = "Out of memory5 @ handle_SSH2_dh_kex_reply()";                  emsg = "Out of memory5 @ handle_SSH2_dh_gex_reply()";
5337                  goto error;                  goto error;
5338          }          }
5339    
# Line 5337  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5348  static BOOL handle_SSH2_dh_gex_reply(PTI
5348    
5349          // check DH public value          // check DH public value
5350          if (!dh_pub_is_valid(pvar->kexdh, dh_server_pub)) {          if (!dh_pub_is_valid(pvar->kexdh, dh_server_pub)) {
5351                  emsg = "DH public value invalid @ handle_SSH2_dh_kex_reply()";                  emsg = "DH public value invalid @ handle_SSH2_dh_gex_reply()";
5352                  goto error;                  goto error;
5353          }          }
5354          // 共通鍵の生成          // 共通鍵の生成
5355          dh_len = DH_size(pvar->kexdh);          dh_len = DH_size(pvar->kexdh);
5356          dh_buf = malloc(dh_len);          dh_buf = malloc(dh_len);
5357          if (dh_buf == NULL) {          if (dh_buf == NULL) {
5358                  emsg = "Out of memory6 @ handle_SSH2_dh_kex_reply()";                  emsg = "Out of memory6 @ handle_SSH2_dh_gex_reply()";
5359                  goto error;                  goto error;
5360          }          }
5361          share_len = DH_compute_key(dh_buf, dh_server_pub, pvar->kexdh);          share_len = DH_compute_key(dh_buf, dh_server_pub, pvar->kexdh);
5362          share_key = BN_new();          share_key = BN_new();
5363          if (share_key == NULL) {          if (share_key == NULL) {
5364                  emsg = "Out of memory7 @ handle_SSH2_dh_kex_reply()";                  emsg = "Out of memory7 @ handle_SSH2_dh_gex_reply()";
5365                  goto error;                  goto error;
5366          }          }
5367          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。          // 'share_key'がサーバとクライアントで共有する鍵(G^A×B mod P)となる。
# Line 5411  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5422  static BOOL handle_SSH2_dh_gex_reply(PTI
5422                          if (!pvar->settings.EnableRsaShortKeyServer) {                          if (!pvar->settings.EnableRsaShortKeyServer) {
5423                                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,                                  _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5424                                              "key verify error(remote rsa key length is too short %d-bit) "                                              "key verify error(remote rsa key length is too short %d-bit) "
5425                                              "@ SSH2_DH_GEX", BN_num_bits(rsa->n));                                              "@ handle_SSH2_dh_gex_reply", BN_num_bits(rsa->n));
5426                          }                          }
5427                          else {                          else {
5428                                  goto cont;                                  goto cont;
# Line 5419  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5430  static BOOL handle_SSH2_dh_gex_reply(PTI
5430                  }                  }
5431                  else {                  else {
5432                          _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,                          _snprintf_s(emsg_tmp, sizeof(emsg_tmp), _TRUNCATE,
5433                                      "key verify error(%d) @ SSH2_DH_GEX\r\n%s", ret, SENDTOME);                                      "key verify error(%d) @ handle_SSH2_dh_gex_reply()\r\n%s", ret, SENDTOME);
5434                  }                  }
5435                  emsg = emsg_tmp;                  emsg = emsg_tmp;
5436                  save_memdump(LOGDUMP);                  save_memdump(LOGDUMP);

Legend:
Removed from v.4305  
changed lines
  Added in v.4306

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26