Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/ttssh2/ttxssh/hosts.c

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

revision 6688 by doda, Mon Apr 24 11:49:42 2017 UTC revision 6801 by doda, Tue Jun 13 10:30:12 2017 UTC
# Line 59  static HFONT DlgHostsReplaceFont; Line 59  static HFONT DlgHostsReplaceFont;
59  static char base64[] ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";  static char base64[] ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
60    
61    
62  static char FAR *FAR * parse_multi_path(char FAR * buf)  static char **parse_multi_path(char *buf)
63  {  {
64          int i;          int i;
65          int ch;          int ch;
66          int num_paths = 1;          int num_paths = 1;
67          char FAR *FAR * result;          char ** result;
68          int last_path_index;          int last_path_index;
69    
70          for (i = 0; (ch = buf[i]) != 0; i++) {          for (i = 0; (ch = buf[i]) != 0; i++) {
# Line 74  static char FAR *FAR * parse_multi_path( Line 74  static char FAR *FAR * parse_multi_path(
74          }          }
75    
76          result =          result =
77                  (char FAR * FAR *) malloc(sizeof(char FAR *) * (num_paths + 1));                  (char **) malloc(sizeof(char *) * (num_paths + 1));
78    
79          last_path_index = 0;          last_path_index = 0;
80          num_paths = 0;          num_paths = 0;
# Line 112  void HOSTS_open(PTInstVar pvar) Line 112  void HOSTS_open(PTInstVar pvar)
112  //  //
113  // known_hostsファイルの内容をすべて pvar->hosts_state.file_data へ読み込む  // known_hostsファイルの内容をすべて pvar->hosts_state.file_data へ読み込む
114  //  //
115  static int begin_read_file(PTInstVar pvar, char FAR * name,  static int begin_read_file(PTInstVar pvar, char *name,
116                             int suppress_errors)                             int suppress_errors)
117  {  {
118          int fd;          int fd;
# Line 196  static int begin_read_host_files(PTInstV Line 196  static int begin_read_host_files(PTInstV
196  }  }
197    
198  // MIME64の文字列をスキップする  // MIME64の文字列をスキップする
199  static int eat_base64(char FAR * data)  static int eat_base64(char *data)
200  {  {
201          int index = 0;          int index = 0;
202          int ch;          int ch;
# Line 214  static int eat_base64(char FAR * data) Line 214  static int eat_base64(char FAR * data)
214          return index;          return index;
215  }  }
216    
217  static int eat_spaces(char FAR * data)  static int eat_spaces(char *data)
218  {  {
219          int index = 0;          int index = 0;
220          int ch;          int ch;
# Line 225  static int eat_spaces(char FAR * data) Line 225  static int eat_spaces(char FAR * data)
225          return index;          return index;
226  }  }
227    
228  static int eat_digits(char FAR * data)  static int eat_digits(char *data)
229  {  {
230          int index = 0;          int index = 0;
231          int ch;          int ch;
# Line 236  static int eat_digits(char FAR * data) Line 236  static int eat_digits(char FAR * data)
236          return index;          return index;
237  }  }
238    
239  static int eat_to_end_of_line(char FAR * data)  static int eat_to_end_of_line(char *data)
240  {  {
241          int index = 0;          int index = 0;
242          int ch;          int ch;
# Line 252  static int eat_to_end_of_line(char FAR * Line 252  static int eat_to_end_of_line(char FAR *
252          return index;          return index;
253  }  }
254    
255  static int eat_to_end_of_pattern(char FAR * data)  static int eat_to_end_of_pattern(char *data)
256  {  {
257          int index = 0;          int index = 0;
258          int ch;          int ch;
# Line 301  error: Line 301  error:
301  }  }
302    
303    
304  static char FAR *parse_bignum(char FAR * data)  static char *parse_bignum(char *data)
305  {  {
306          uint32 digits = 0;          uint32 digits = 0;
307          BIGNUM *num = BN_new();          BIGNUM *num = BN_new();
308          BIGNUM *billion = BN_new();          BIGNUM *billion = BN_new();
309          BIGNUM *digits_num = BN_new();          BIGNUM *digits_num = BN_new();
310          BN_CTX *ctx = BN_CTX_new();          BN_CTX *ctx = BN_CTX_new();
311          char FAR *result;          char *result;
312          int ch;          int ch;
313          int leftover_digits = 1;          int leftover_digits = 1;
314    
# Line 335  static char FAR *parse_bignum(char FAR * Line 335  static char FAR *parse_bignum(char FAR *
335          BN_mul(num, num, billion, ctx);          BN_mul(num, num, billion, ctx);
336          BN_add(num, num, digits_num);          BN_add(num, num, digits_num);
337    
338          result = (char FAR *) malloc(2 + BN_num_bytes(num));          result = (char *) malloc(2 + BN_num_bytes(num));
339          set_ushort16_MSBfirst(result, BN_num_bits(num));          set_ushort16_MSBfirst(result, BN_num_bits(num));
340          BN_bn2bin(num, result + 2);          BN_bn2bin(num, result + 2);
341    
# Line 350  static char FAR *parse_bignum(char FAR * Line 350  static char FAR *parse_bignum(char FAR *
350  //  //
351  // known_hostsファイルの内容を解析し、指定したホストの公開鍵を探す。  // known_hostsファイルの内容を解析し、指定したホストの公開鍵を探す。
352  //  //
353  static int check_host_key(PTInstVar pvar, char FAR * hostname,  static int check_host_key(PTInstVar pvar, char *hostname,
354                            unsigned short tcpport, char FAR * data,                            unsigned short tcpport, char *data,
355                            Key *key)                            Key *key)
356  {  {
357          int index = eat_spaces(data);          int index = eat_spaces(data);
# Line 504  static int check_host_key(PTInstVar pvar Line 504  static int check_host_key(PTInstVar pvar
504  //     1: 1行だけ探して戻る  //     1: 1行だけ探して戻る
505  //  //
506  static int read_host_key(PTInstVar pvar,  static int read_host_key(PTInstVar pvar,
507                           char FAR * hostname, unsigned short tcpport,                           char *hostname, unsigned short tcpport,
508                           int suppress_errors, int return_always,                           int suppress_errors, int return_always,
509                           Key *key)                           Key *key)
510  {  {
# Line 541  static int read_host_key(PTInstVar pvar, Line 541  static int read_host_key(PTInstVar pvar,
541          do {          do {
542                  if (pvar->hosts_state.file_data == NULL                  if (pvar->hosts_state.file_data == NULL
543                   || pvar->hosts_state.file_data[pvar->hosts_state.file_data_index] == 0) {                   || pvar->hosts_state.file_data[pvar->hosts_state.file_data_index] == 0) {
544                          char FAR *filename;                          char *filename;
545                          int keep_going = 1;                          int keep_going = 1;
546    
547                          if (pvar->hosts_state.file_data != NULL) {                          if (pvar->hosts_state.file_data != NULL) {
# Line 593  static void finish_read_host_files(PTIns Line 593  static void finish_read_host_files(PTIns
593  }  }
594    
595  // サーバへ接続する前に、known_hostsファイルからホスト公開鍵を先読みしておく。  // サーバへ接続する前に、known_hostsファイルからホスト公開鍵を先読みしておく。
596  void HOSTS_prefetch_host_key(PTInstVar pvar, char FAR * hostname, unsigned short tcpport)  void HOSTS_prefetch_host_key(PTInstVar pvar, char *hostname, unsigned short tcpport)
597  {  {
598          Key key; // known_hostsに登録されている鍵          Key key; // known_hostsに登録されている鍵
599    
# Line 621  void HOSTS_prefetch_host_key(PTInstVar p Line 621  void HOSTS_prefetch_host_key(PTInstVar p
621  // return:  // return:
622  //   *keyptr != NULL  取得成功  //   *keyptr != NULL  取得成功
623  //  //
624  static int parse_hostkey_file(PTInstVar pvar, char FAR * hostname,  static int parse_hostkey_file(PTInstVar pvar, char *hostname,
625          unsigned short tcpport, char FAR * data, Key **keyptr)          unsigned short tcpport, char *data, Key **keyptr)
626  {  {
627          int index = eat_spaces(data);          int index = eat_spaces(data);
628          int matched = 0;          int matched = 0;
# Line 778  int HOSTS_hostkey_foreach(PTInstVar pvar Line 778  int HOSTS_hostkey_foreach(PTInstVar pvar
778          int success = 0;          int success = 0;
779          int suppress_errors = 1;          int suppress_errors = 1;
780          unsigned short tcpport;          unsigned short tcpport;
781          char FAR *filename;          char *filename;
782          char *hostname;          char *hostname;
783          Key *key;          Key *key;
784    
# Line 831  error: Line 831  error:
831  }  }
832    
833    
834  static BOOL equal_mp_ints(unsigned char FAR * num1,  static BOOL equal_mp_ints(unsigned char *num1,
835                            unsigned char FAR * num2)                            unsigned char *num2)
836  {  {
837          if (num1 == NULL || num2 == NULL) {          if (num1 == NULL || num2 == NULL) {
838                  return FALSE;                  return FALSE;
# Line 857  static BOOL equal_mp_ints(unsigned char Line 857  static BOOL equal_mp_ints(unsigned char
857  int HOSTS_compare_public_key(Key *src, Key *key)  int HOSTS_compare_public_key(Key *src, Key *key)
858  {  {
859          int bits;          int bits;
860          unsigned char FAR * exp;          unsigned char *exp;
861          unsigned char FAR * mod;          unsigned char *mod;
862          const EC_GROUP *group;          const EC_GROUP *group;
863          const EC_POINT *pa, *pb;          const EC_POINT *pa, *pb;
864          Key *a, *b;          Key *a, *b;
# Line 984  static void init_hosts_dlg(PTInstVar pva Line 984  static void init_hosts_dlg(PTInstVar pva
984          hosts_dlg_set_fingerprint(pvar, dlg, SSH_DIGEST_SHA256);          hosts_dlg_set_fingerprint(pvar, dlg, SSH_DIGEST_SHA256);
985  }  }
986    
987  static int print_mp_int(char FAR * buf, unsigned char FAR * mp)  static int print_mp_int(char *buf, unsigned char *mp)
988  {  {
989          int i = 0, j, k;          int i = 0, j, k;
990          BIGNUM *num = BN_new();          BIGNUM *num = BN_new();
# Line 1011  static int print_mp_int(char FAR * buf, Line 1011  static int print_mp_int(char FAR * buf,
1011  //  //
1012  // known_hosts ファイルへ保存するエントリを作成する。  // known_hosts ファイルへ保存するエントリを作成する。
1013  //  //
1014  static char FAR *format_host_key(PTInstVar pvar)  static char *format_host_key(PTInstVar pvar)
1015  {  {
1016          int host_len = strlen(pvar->hosts_state.prefetched_hostname);          int host_len = strlen(pvar->hosts_state.prefetched_hostname);
1017          char *result = NULL;          char *result = NULL;
# Line 1024  static char FAR *format_host_key(PTInstV Line 1024  static char FAR *format_host_key(PTInstV
1024                  int result_len = host_len + 50 + 8 +                  int result_len = host_len + 50 + 8 +
1025                                   get_ushort16_MSBfirst(pvar->hosts_state.hostkey.exp) / 3 +                                   get_ushort16_MSBfirst(pvar->hosts_state.hostkey.exp) / 3 +
1026                                   get_ushort16_MSBfirst(pvar->hosts_state.hostkey.mod) / 3;                                   get_ushort16_MSBfirst(pvar->hosts_state.hostkey.mod) / 3;
1027                  result = (char FAR *) malloc(result_len);                  result = (char *) malloc(result_len);
1028    
1029                  if (pvar->ssh_state.tcpport == 22) {                  if (pvar->ssh_state.tcpport == 22) {
1030                          strncpy_s(result, result_len, pvar->hosts_state.prefetched_hostname, _TRUNCATE);                          strncpy_s(result, result_len, pvar->hosts_state.prefetched_hostname, _TRUNCATE);
# Line 1107  error: Line 1107  error:
1107          return result;          return result;
1108  }  }
1109    
1110  static char FAR *format_specified_host_key(Key *key, char *hostname, unsigned short tcpport)  static char *format_specified_host_key(Key *key, char *hostname, unsigned short tcpport)
1111  {  {
1112          int host_len = strlen(hostname);          int host_len = strlen(hostname);
1113          char *result = NULL;          char *result = NULL;
# Line 1120  static char FAR *format_specified_host_k Line 1120  static char FAR *format_specified_host_k
1120                  int result_len = host_len + 50 + 8 +                  int result_len = host_len + 50 + 8 +
1121                          get_ushort16_MSBfirst(key->exp) / 3 +                          get_ushort16_MSBfirst(key->exp) / 3 +
1122                          get_ushort16_MSBfirst(key->mod) / 3;                          get_ushort16_MSBfirst(key->mod) / 3;
1123                  result = (char FAR *) malloc(result_len);                  result = (char *) malloc(result_len);
1124    
1125                  if (tcpport == 22) {                  if (tcpport == 22) {
1126                          strncpy_s(result, result_len, hostname, _TRUNCATE);                          strncpy_s(result, result_len, hostname, _TRUNCATE);
# Line 1206  static char FAR *format_specified_host_k Line 1206  static char FAR *format_specified_host_k
1206    
1207  static void add_host_key(PTInstVar pvar)  static void add_host_key(PTInstVar pvar)
1208  {  {
1209          char FAR *name = NULL;          char *name = NULL;
1210    
1211          if ( pvar->hosts_state.file_names != NULL)          if ( pvar->hosts_state.file_names != NULL)
1212                  name = pvar->hosts_state.file_names[0];                  name = pvar->hosts_state.file_names[0];
# Line 1217  static void add_host_key(PTInstVar pvar) Line 1217  static void add_host_key(PTInstVar pvar)
1217                                    "Restart Tera Term and specify a read/write known-hosts file in the TTSSH Setup dialog box.");                                    "Restart Tera Term and specify a read/write known-hosts file in the TTSSH Setup dialog box.");
1218                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1219          } else {          } else {
1220                  char FAR *keydata = format_host_key(pvar);                  char *keydata = format_host_key(pvar);
1221                  int length = strlen(keydata);                  int length = strlen(keydata);
1222                  int fd;                  int fd;
1223                  int amount_written;                  int amount_written;
# Line 1259  static void add_host_key(PTInstVar pvar) Line 1259  static void add_host_key(PTInstVar pvar)
1259  // 指定したキーを known_hosts に追加する。  // 指定したキーを known_hosts に追加する。
1260  void HOSTS_add_host_key(PTInstVar pvar, Key *key)  void HOSTS_add_host_key(PTInstVar pvar, Key *key)
1261  {  {
1262          char FAR *name = NULL;          char *name = NULL;
1263          char *hostname;          char *hostname;
1264          unsigned short tcpport;          unsigned short tcpport;
1265    
# Line 1276  void HOSTS_add_host_key(PTInstVar pvar, Line 1276  void HOSTS_add_host_key(PTInstVar pvar,
1276                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1277          }          }
1278          else {          else {
1279                  char FAR *keydata = format_specified_host_key(key, hostname, tcpport);                  char *keydata = format_specified_host_key(key, hostname, tcpport);
1280                  int length = strlen(keydata);                  int length = strlen(keydata);
1281                  int fd;                  int fd;
1282                  int amount_written;                  int amount_written;
# Line 1322  void HOSTS_add_host_key(PTInstVar pvar, Line 1322  void HOSTS_add_host_key(PTInstVar pvar,
1322  //  //
1323  static void delete_different_key(PTInstVar pvar)  static void delete_different_key(PTInstVar pvar)
1324  {  {
1325          char FAR *name = pvar->hosts_state.file_names[0];          char *name = pvar->hosts_state.file_names[0];
1326    
1327          if (name == NULL || name[0] == 0) {          if (name == NULL || name[0] == 0) {
1328                  UTIL_get_lang_msg("MSG_HOSTS_FILE_UNSPECIFY_ERROR", pvar,                  UTIL_get_lang_msg("MSG_HOSTS_FILE_UNSPECIFY_ERROR", pvar,
# Line 1371  static void delete_different_key(PTInstV Line 1371  static void delete_different_key(PTInstV
1371                          int host_index = 0;                          int host_index = 0;
1372                          int matched = 0;                          int matched = 0;
1373                          int keybits = 0;                          int keybits = 0;
1374                          char FAR *data;                          char *data;
1375                          int do_write = 0;                          int do_write = 0;
1376                          length = amount_written = 0;                          length = amount_written = 0;
1377    
# Line 1506  error2: Line 1506  error2:
1506    
1507  void HOSTS_delete_all_hostkeys(PTInstVar pvar)  void HOSTS_delete_all_hostkeys(PTInstVar pvar)
1508  {  {
1509          char FAR *name = pvar->hosts_state.file_names[0];          char *name = pvar->hosts_state.file_names[0];
1510          char *hostname;          char *hostname;
1511          unsigned short tcpport;          unsigned short tcpport;
1512    
# Line 1561  void HOSTS_delete_all_hostkeys(PTInstVar Line 1561  void HOSTS_delete_all_hostkeys(PTInstVar
1561                          int host_index = 0;                          int host_index = 0;
1562                          int matched = 0;                          int matched = 0;
1563                          int keybits = 0;                          int keybits = 0;
1564                          char FAR *data;                          char *data;
1565                          int do_write = 0;                          int do_write = 0;
1566                          length = amount_written = 0;                          length = amount_written = 0;
1567    
# Line 2229  void HOSTS_do_different_type_key_dialog( Line 2229  void HOSTS_do_different_type_key_dialog(
2229  //  //
2230  // SSH2対応を追加 (2006.3.24 yutaka)  // SSH2対応を追加 (2006.3.24 yutaka)
2231  //  //
2232  BOOL HOSTS_check_host_key(PTInstVar pvar, char FAR * hostname, unsigned short tcpport, Key *key)  BOOL HOSTS_check_host_key(PTInstVar pvar, char *hostname, unsigned short tcpport, Key *key)
2233  {  {
2234          int found_different_key = 0, found_different_type_key = 0;          int found_different_key = 0, found_different_type_key = 0;
2235          Key key2; // known_hostsに登録されている鍵          Key key2; // known_hostsに登録されている鍵

Legend:
Removed from v.6688  
changed lines
  Added in v.6801

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