| 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++) { |
| 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; |
| 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; |
| 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; |
| 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; |
| 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; |
| 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; |
| 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; |
| 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 |
|
|
| 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 |
|
|
| 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); |
| 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 |
{ |
{ |
| 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) { |
| 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 |
|
|
| 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; |
| 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 |
|
|
| 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; |
| 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; |
| 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(); |
| 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; |
| 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); |
| 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; |
| 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); |
| 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]; |
| 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; |
| 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 |
|
|
| 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; |
| 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, |
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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に登録されている鍵 |