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 4373 by maya, Tue Mar 8 00:22:12 2011 UTC revision 4378 by maya, Tue Mar 8 14:19:03 2011 UTC
# Line 4042  const EVP_CIPHER* get_cipher_EVP_CIPHER( Line 4042  const EVP_CIPHER* get_cipher_EVP_CIPHER(
4042          return type;          return type;
4043  }  }
4044    
4045  #if 0  char* get_kex_algorithm_name(kex_algorithm kextype)
4046  static int get_mac_index(char *name)  {
4047            ssh2_kex_algorithm_t *ptr = ssh2_kex_algorithms;
4048            static char buf[64];
4049    
4050            while (ptr->name != NULL) {
4051                    if (kextype == ptr->kextype) {
4052                            strncpy_s(buf, sizeof(buf), ptr->name, _TRUNCATE);
4053                            break;
4054                    }
4055                    ptr++;
4056            }
4057            return buf;
4058    }
4059    
4060    const EVP_MD* get_kex_algorithm_EVP_MD(kex_algorithm kextype)
4061    {
4062            ssh2_kex_algorithm_t *ptr = ssh2_kex_algorithms;
4063            const EVP_MD *evp_md;
4064    
4065            while (ptr->name != NULL) {
4066                    if (kextype == ptr->kextype) {
4067                            evp_md = ptr->evp_md();
4068                            break;
4069                    }
4070                    ptr++;
4071            }
4072            return evp_md;
4073    }
4074    
4075    char* get_ssh2_mac_name(hmac_type type)
4076  {  {
4077          ssh2_mac_t *ptr = ssh2_macs;          ssh2_mac_t *ptr = ssh2_macs;
4078          int val = -1;          static char buf[64];
4079    
4080          while (ptr->name != NULL) {          while (ptr->name != NULL) {
4081                  if (strcmp(ptr->name, name) == 0) {                  if (type == ptr->type) {
4082                          val = ptr - ssh2_macs;                          strncpy_s(buf, sizeof(buf), ptr->name, _TRUNCATE);
4083                          break;                          break;
4084                  }                  }
4085                  ptr++;                  ptr++;
4086          }          }
4087          return (val);          return buf;
4088    }
4089    
4090    const EVP_MD* get_ssh2_mac_EVP_MD(hmac_type type)
4091    {
4092            ssh2_mac_t *ptr = ssh2_macs;
4093            const EVP_MD *evp_md;
4094    
4095            while (ptr->name != NULL) {
4096                    if (type == ptr->type) {
4097                            evp_md = ptr->evp_md();
4098                            break;
4099                    }
4100                    ptr++;
4101            }
4102            return evp_md;
4103    }
4104    
4105    int get_ssh2_mac_truncatebits(hmac_type type)
4106    {
4107            ssh2_mac_t *ptr = ssh2_macs;
4108            int bits;
4109    
4110            while (ptr->name != NULL) {
4111                    if (type == ptr->type) {
4112                            bits = ptr->truncatebits;
4113                            break;
4114                    }
4115                    ptr++;
4116            }
4117            return bits;
4118    }
4119    
4120    char* get_ssh2_comp_name(compression_type type)
4121    {
4122            ssh2_comp_t *ptr = ssh2_comps;
4123            static char buf[32];
4124    
4125            while (ptr->name != NULL) {
4126                    if (type == ptr->type) {
4127                            strncpy_s(buf, sizeof(buf), ptr->name, _TRUNCATE);
4128                            break;
4129                    }
4130                    ptr++;
4131            }
4132            return buf;
4133    }
4134    
4135    char* get_ssh_keytype_name(ssh_keytype type)
4136    {
4137            ssh2_host_key_t *ptr = ssh2_host_key;
4138            static char buf[32];
4139    
4140            while (ptr->name != NULL) {
4141                    if (type == ptr->type) {
4142                            strncpy_s(buf, sizeof(buf), ptr->name, _TRUNCATE);
4143                            break;
4144                    }
4145                    ptr++;
4146            }
4147            return buf;
4148  }  }
 #endif  
4149    
4150    
4151  static void do_write_buffer_file(void *buf, int len, char *file, int lineno)  static void do_write_buffer_file(void *buf, int len, char *file, int lineno)
# Line 4183  void SSH2_update_compression_myproposal( Line 4271  void SSH2_update_compression_myproposal(
4271                  index = pvar->settings.CompOrder[i] - '0';                  index = pvar->settings.CompOrder[i] - '0';
4272                  if (index == COMP_NONE) // disabled line                  if (index == COMP_NONE) // disabled line
4273                          break;                          break;
4274                  strncat_s(buf, sizeof(buf), ssh_comps[index].name, _TRUNCATE);                  strncat_s(buf, sizeof(buf), get_ssh2_comp_name(index), _TRUNCATE);
4275                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
4276          }          }
4277          len = strlen(buf);          len = strlen(buf);
# Line 4195  void SSH2_update_compression_myproposal( Line 4283  void SSH2_update_compression_myproposal(
4283          }          }
4284    
4285          if (pvar->settings.CompressionLevel == 0) {          if (pvar->settings.CompressionLevel == 0) {
4286                  _snprintf_s(buf, sizeof(buf), _TRUNCATE, ssh_comps[COMP_NONE].name);                  _snprintf_s(buf, sizeof(buf), _TRUNCATE, get_ssh2_comp_name(COMP_NOCOMP));
4287          }          }
4288          if (buf[0] != '\0') {          if (buf[0] != '\0') {
4289                  myproposal[PROPOSAL_COMP_ALGS_CTOS] = buf;  // Client To Server                  myproposal[PROPOSAL_COMP_ALGS_CTOS] = buf;  // Client To Server
# Line 4221  void SSH2_update_kex_myproposal(PTInstVa Line 4309  void SSH2_update_kex_myproposal(PTInstVa
4309                  index = pvar->settings.KexOrder[i] - '0';                  index = pvar->settings.KexOrder[i] - '0';
4310                  if (index == KEX_DH_NONE) // disabled line                  if (index == KEX_DH_NONE) // disabled line
4311                          break;                          break;
4312                  strncat_s(buf, sizeof(buf), ssh2_kex_algorithms[index].name, _TRUNCATE);                  strncat_s(buf, sizeof(buf), get_kex_algorithm_name(index), _TRUNCATE);
4313                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
4314          }          }
4315          len = strlen(buf);          len = strlen(buf);
# Line 4247  void SSH2_update_host_key_myproposal(PTI Line 4335  void SSH2_update_host_key_myproposal(PTI
4335                  index = pvar->settings.HostKeyOrder[i] - '0';                  index = pvar->settings.HostKeyOrder[i] - '0';
4336                  if (index == KEY_NONE) // disabled line                  if (index == KEY_NONE) // disabled line
4337                          break;                          break;
4338                  strncat_s(buf, sizeof(buf), ssh2_host_key[index].name, _TRUNCATE);                  strncat_s(buf, sizeof(buf), get_ssh_keytype_name(index), _TRUNCATE);
4339                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
4340          }          }
4341          len = strlen(buf);          len = strlen(buf);
# Line 4273  void SSH2_update_hmac_myproposal(PTInstV Line 4361  void SSH2_update_hmac_myproposal(PTInstV
4361                  index = pvar->settings.MacOrder[i] - '0';                  index = pvar->settings.MacOrder[i] - '0';
4362                  if (index == HMAC_NONE) // disabled line                  if (index == HMAC_NONE) // disabled line
4363                          break;                          break;
4364                  strncat_s(buf, sizeof(buf), ssh2_macs[index].name, _TRUNCATE);                  strncat_s(buf, sizeof(buf), get_ssh2_mac_name(index), _TRUNCATE);
4365                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);                  strncat_s(buf, sizeof(buf), ",", _TRUNCATE);
4366          }          }
4367          len = strlen(buf);          len = strlen(buf);
# Line 4359  found: Line 4447  found:
4447          }          }
4448  }  }
4449    
4450  static enum kex_algorithm choose_SSH2_kex_algorithm(char *server_proposal, char *my_proposal)  static kex_algorithm choose_SSH2_kex_algorithm(char *server_proposal, char *my_proposal)
4451  {  {
4452          enum kex_algorithm type = KEX_DH_UNKNOWN;          kex_algorithm type = KEX_DH_UNKNOWN;
4453          char str_kextype[40];          char str_kextype[40];
4454          ssh2_kex_algorithm_t *ptr = ssh2_kex_algorithms;          ssh2_kex_algorithm_t *ptr = ssh2_kex_algorithms;
4455    
# Line 4398  static SSHCipher choose_SSH2_cipher_algo Line 4486  static SSHCipher choose_SSH2_cipher_algo
4486  }  }
4487    
4488    
4489  static enum hmac_type choose_SSH2_hmac_algorithm(char *server_proposal, char *my_proposal)  static hmac_type choose_SSH2_hmac_algorithm(char *server_proposal, char *my_proposal)
4490  {  {
4491          enum hmac_type type = HMAC_UNKNOWN;          hmac_type type = HMAC_UNKNOWN;
4492          char str_hmac[16];          char str_hmac[16];
4493          ssh2_mac_t *ptr = ssh2_macs;          ssh2_mac_t *ptr = ssh2_macs;
4494    
# Line 4418  static enum hmac_type choose_SSH2_hmac_a Line 4506  static enum hmac_type choose_SSH2_hmac_a
4506  }  }
4507    
4508    
4509  static enum compression_type choose_SSH2_compression_algorithm(char *server_proposal, char *my_proposal)  static compression_type choose_SSH2_compression_algorithm(char *server_proposal, char *my_proposal)
4510  {  {
4511          enum compression_type type = COMP_UNKNOWN;          compression_type type = COMP_UNKNOWN;
4512          char str_comp[20];          char str_comp[20];
4513          ssh_comp_t *ptr = ssh_comps;          ssh2_comp_t *ptr = ssh2_comps;
4514    
4515          // OpenSSH 4.3では遅延パケット圧縮("zlib@openssh.com")が新規追加されているため、          // OpenSSH 4.3では遅延パケット圧縮("zlib@openssh.com")が新規追加されているため、
4516          // マッチしないように修正した。          // マッチしないように修正した。
# Line 4463  static void choose_SSH2_key_maxlength(PT Line 4551  static void choose_SSH2_key_maxlength(PT
4551                  }                  }
4552    
4553                  // current_keys[]に設定しておいて、あとで pvar->ssh2_keys[] へコピーする。                  // current_keys[]に設定しておいて、あとで pvar->ssh2_keys[] へコピーする。
4554                  md = ssh2_macs[val].func();                  md = get_ssh2_mac_EVP_MD(val);
4555                  current_keys[mode].mac.md = md;                  current_keys[mode].mac.md = md;
4556                  current_keys[mode].mac.key_len = current_keys[mode].mac.mac_len = EVP_MD_size(md);                  current_keys[mode].mac.key_len = current_keys[mode].mac.mac_len = EVP_MD_size(md);
4557                  if (ssh2_macs[val].truncatebits != 0) {                  if (get_ssh2_mac_truncatebits(val) != 0) {
4558                          current_keys[mode].mac.mac_len = ssh2_macs[val].truncatebits / 8;                          current_keys[mode].mac.mac_len = get_ssh2_mac_truncatebits(val) / 8;
4559                  }                  }
4560    
4561                  // キーサイズとブロックサイズもここで設定しておく (2004.11.7 yutaka)                  // キーサイズとブロックサイズもここで設定しておく (2004.11.7 yutaka)
# Line 4592  static BOOL handle_SSH2_kexinit(PTInstVa Line 4680  static BOOL handle_SSH2_kexinit(PTInstVa
4680                  goto error;                  goto error;
4681          }          }
4682    
4683          _snprintf_s(buf, sizeof(buf), _TRUNCATE, "KEX algorithm: %s", ssh2_kex_algorithms[pvar->kex_type].name);          _snprintf_s(buf, sizeof(buf), _TRUNCATE, "KEX algorithm: %s", get_kex_algorithm_name(pvar->kex_type));
4684          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
4685    
4686          // ホストキーアルゴリズムチェック          // ホストキーアルゴリズムチェック
# Line 4683  static BOOL handle_SSH2_kexinit(PTInstVa Line 4771  static BOOL handle_SSH2_kexinit(PTInstVa
4771    
4772          _snprintf_s(buf, sizeof(buf), _TRUNCATE,          _snprintf_s(buf, sizeof(buf), _TRUNCATE,
4773                      "MAC algorithm client to server: %s",                      "MAC algorithm client to server: %s",
4774                      ssh2_macs[pvar->ctos_hmac].name);                      get_ssh2_mac_name(pvar->ctos_hmac));
4775          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
4776    
4777          size = get_payload_uint32(pvar, offset);          size = get_payload_uint32(pvar, offset);
# Line 4703  static BOOL handle_SSH2_kexinit(PTInstVa Line 4791  static BOOL handle_SSH2_kexinit(PTInstVa
4791    
4792          _snprintf_s(buf, sizeof(buf), _TRUNCATE,          _snprintf_s(buf, sizeof(buf), _TRUNCATE,
4793                      "MAC algorithm server to client: %s",                      "MAC algorithm server to client: %s",
4794                      ssh2_macs[pvar->stoc_hmac].name);                      get_ssh2_mac_name(pvar->stoc_hmac));
4795          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
4796    
4797          // 圧縮アルゴリズムの決定          // 圧縮アルゴリズムの決定
# Line 4726  static BOOL handle_SSH2_kexinit(PTInstVa Line 4814  static BOOL handle_SSH2_kexinit(PTInstVa
4814    
4815          _snprintf_s(buf, sizeof(buf), _TRUNCATE,          _snprintf_s(buf, sizeof(buf), _TRUNCATE,
4816                      "compression algorithm client to server: %s",                      "compression algorithm client to server: %s",
4817                      ssh_comps[pvar->ctos_compression].name);                      get_ssh2_comp_name(pvar->ctos_compression));
4818          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
4819    
4820          size = get_payload_uint32(pvar, offset);          size = get_payload_uint32(pvar, offset);
# Line 4746  static BOOL handle_SSH2_kexinit(PTInstVa Line 4834  static BOOL handle_SSH2_kexinit(PTInstVa
4834    
4835          _snprintf_s(buf, sizeof(buf), _TRUNCATE,          _snprintf_s(buf, sizeof(buf), _TRUNCATE,
4836                      "compression algorithm server to client: %s",                      "compression algorithm server to client: %s",
4837                      ssh_comps[pvar->stoc_compression].name);                      get_ssh2_comp_name(pvar->stoc_compression));
4838          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);          notify_verbose_message(pvar, buf, LOG_LEVEL_VERBOSE);
4839    
4840          // we_needの決定 (2004.11.6 yutaka)          // we_needの決定 (2004.11.6 yutaka)
# Line 5390  static BOOL handle_SSH2_dh_gex_reply(PTI Line 5478  static BOOL handle_SSH2_dh_gex_reply(PTI
5478          // ハッシュの計算          // ハッシュの計算
5479          /* calc and verify H */          /* calc and verify H */
5480          hash = kex_dh_gex_hash(          hash = kex_dh_gex_hash(
5481                  ssh2_kex_algorithms[pvar->kex_type].evp_md(),                  get_kex_algorithm_EVP_MD(pvar->kex_type),
5482                  pvar->client_version_string,                  pvar->client_version_string,
5483                  pvar->server_version_string,                  pvar->server_version_string,
5484                  buffer_ptr(pvar->my_kex),  buffer_len(pvar->my_kex),                  buffer_ptr(pvar->my_kex),  buffer_len(pvar->my_kex),
# Line 5627  static BOOL handle_SSH2_ecdh_kex_reply(P Line 5715  static BOOL handle_SSH2_ecdh_kex_reply(P
5715    
5716          // ハッシュの計算          // ハッシュの計算
5717          /* calc and verify H */          /* calc and verify H */
5718          hash = kex_ecdh_hash(ssh2_kex_algorithms[pvar->kex_type].evp_md(),          hash = kex_ecdh_hash(get_kex_algorithm_EVP_MD(pvar->kex_type),
5719                               group,                               group,
5720                               pvar->client_version_string,                               pvar->client_version_string,
5721                               pvar->server_version_string,                               pvar->server_version_string,

Legend:
Removed from v.4373  
changed lines
  Added in v.4378

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