svnno****@sourc*****
svnno****@sourc*****
2015年 5月 7日 (木) 00:57:03 JST
Revision: 5850 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/5850 Author: yutakapon Date: 2015-05-07 00:57:02 +0900 (Thu, 07 May 2015) Log Message: ----------- チケット #35047 SSH サーバホスト公開鍵の自動更新 新規の公開鍵を登録する処理に、SSH2_MSG_GLOBAL_REQUESTに対するハンドラルーチンを追加した。 現状、Host key rotationでしか使わないため、ハンドラ登録機構にリンクドリストは使用せず、単一 登録のみとしている。 Ticket Links: ------------ http://sourceforge.jp/projects/ttssh2/tracker/detail/35047 Modified Paths: -------------- trunk/ttssh2/ttxssh/key.c trunk/ttssh2/ttxssh/ssh.c trunk/ttssh2/ttxssh/ssh.h -------------- next part -------------- Modified: trunk/ttssh2/ttxssh/key.c =================================================================== --- trunk/ttssh2/ttxssh/key.c 2015-05-05 18:08:23 UTC (rev 5849) +++ trunk/ttssh2/ttxssh/key.c 2015-05-06 15:57:02 UTC (rev 5850) @@ -1950,6 +1950,15 @@ return; } +static void client_global_hostkeys_private_confirm(PTInstVar pvar, int type, u_int32_t seq, void *_ctx) +{ + struct hostkeys_update_ctx *ctx = (struct hostkeys_update_ctx *)_ctx; + + update_known_hosts(pvar, ctx); + + hostkeys_update_ctx_free(ctx); +} + // // SSH\x83T\x81[\x83o\x83z\x83X\x83g\x8C\xAE(known_hosts)\x82̎\xA9\x93\xAE\x8DX\x90V(OpenSSH 6.8 or later: host key rotation support) // @@ -1968,6 +1977,7 @@ buffer_t *b = NULL; struct hostkeys_update_ctx *ctx = NULL; Key *key = NULL, **tmp; + unsigned char *outmsg; // Tera Term\x82̐ݒ\xE8\x82ŁA\x93\x96\x8AY\x8B@\x94\\x82̃I\x83\x93\x83I\x83t\x82𐧌\xE4\x82ł\xAB\x82\xE9\x82悤\x82ɂ\xB7\x82\xE9\x81B if (pvar->settings.UpdateHostkeys == SSH_UPDATE_HOSTKEYS_NO) { @@ -2071,9 +2081,28 @@ } else if (ctx->nnew != 0) { // \x90V\x8BK\x92lj\xC1\x82\xB7\x82\xE9\x82ׂ\xAB\x8C\xAE\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9\x81B - // TODO: - update_known_hosts(pvar, ctx); + buffer_clear(b); + buffer_put_cstring(b, "hostk****@opens*****"); + buffer_put_char(b, 1); /* bool: want reply */ + + for (i = 0; i < ctx->nkeys; i++) { + if (ctx->keys_seen[i]) + continue; + key_to_blob(ctx->keys[i], &blob, &len); + buffer_put_string(b, blob, len); + free(blob); + blob = NULL; + } + + len = buffer_len(b); + outmsg = begin_send_packet(pvar, SSH2_MSG_GLOBAL_REQUEST, len); + memcpy(outmsg, buffer_ptr(b), len); + finish_send_packet(pvar); + + // SSH2_MSG_GLOBAL_REQUEST\x82̃\x8C\x83X\x83|\x83\x93\x83X\x82ɑΉ\x9E\x82\xB7\x82\xE9\x83n\x83\x93\x83h\x83\x89\x82\xF0\x93o\x98^\x82\xB7\x82\xE9\x81B + client_register_global_confirm(client_global_hostkeys_private_confirm, ctx); + ctx = NULL; // callback\x82ʼn\xF0\x95\xFA\x82\xB7\x82\xE9\x82̂ŁA\x82\xB1\x82\xB1\x82ł\xCDNULL\x82łԂ\xB5\x82Ă\xA8\x82\xAD\x81B } success = 1; Modified: trunk/ttssh2/ttxssh/ssh.c =================================================================== --- trunk/ttssh2/ttxssh/ssh.c 2015-05-05 18:08:23 UTC (rev 5849) +++ trunk/ttssh2/ttxssh/ssh.c 2015-05-06 15:57:02 UTC (rev 5850) @@ -78,6 +78,8 @@ #define CHANNEL_MAX 100 +static struct global_confirm global_confirms; + static Channel_t channels[CHANNEL_MAX]; static char ssh_ttymodes[] = "\x01\x03\x02\x1c\x03\x08\x04\x15\x05\x04"; @@ -122,6 +124,39 @@ static BOOL SSH_agent_response(PTInstVar pvar, Channel_t *c, int local_channel_num, unsigned char *data, unsigned int buflen); // +// Global request confirm +// +static void client_init_global_confirm(void) +{ + memset(&global_confirms, 0, sizeof(global_confirms)); + global_confirms.ref_count = 0; +} + +void client_register_global_confirm(global_confirm_cb *cb, void *ctx) +{ + struct global_confirm *gc = &global_confirms; + + if (gc->ref_count == 0) { + gc->cb = cb; + gc->ctx = ctx; + gc->ref_count = 1; + } +} + +static int client_global_request_reply(PTInstVar pvar, int type, unsigned int seq, void *ctxt) +{ + struct global_confirm *gc = &global_confirms; + + if (gc->ref_count >= 1) { + if (gc->cb) + gc->cb(pvar, type, seq, gc->ctx); + gc->ref_count = 0; + } + + return 0; +} + +// // channel function // static Channel_t *ssh2_channel_new(unsigned int window, unsigned int maxpack, @@ -1674,6 +1709,8 @@ enque_handler(pvar, SSH2_MSG_REQUEST_FAILURE, handle_SSH2_request_failure); enque_handler(pvar, SSH2_MSG_REQUEST_SUCCESS, handle_SSH2_request_success); + client_init_global_confirm(); + } } @@ -7495,6 +7532,8 @@ // \x95K\x97v\x82ł\xA0\x82\xEA\x82\x8D\x83O\x82\xF0\x8E\xE6\x82\xE9\x81B\x93\xC1\x82ɉ\xBD\x82\xE0\x82\xB5\x82Ȃ\xAD\x82Ă\xE0\x82悢\x81B notify_verbose_message(pvar, "SSH2_MSG_REQUEST_SUCCESS was received.", LOG_LEVEL_VERBOSE); + client_global_request_reply(pvar, SSH2_MSG_REQUEST_SUCCESS, 0, NULL); + return TRUE; } @@ -7504,6 +7543,8 @@ // \x95K\x97v\x82ł\xA0\x82\xEA\x82\x8D\x83O\x82\xF0\x8E\xE6\x82\xE9\x81B\x93\xC1\x82ɉ\xBD\x82\xE0\x82\xB5\x82Ȃ\xAD\x82Ă\xE0\x82悢\x81B notify_verbose_message(pvar, "SSH2_MSG_REQUEST_FAILURE was received.", LOG_LEVEL_VERBOSE); + client_global_request_reply(pvar, SSH2_MSG_REQUEST_FAILURE, 0, NULL); + return TRUE; } Modified: trunk/ttssh2/ttxssh/ssh.h =================================================================== --- trunk/ttssh2/ttxssh/ssh.h 2015-05-05 18:08:23 UTC (rev 5849) +++ trunk/ttssh2/ttxssh/ssh.h 2015-05-06 15:57:02 UTC (rev 5850) @@ -786,5 +786,16 @@ #define get_mpint_len(pvar, offset) ((get_ushort16_MSBfirst((pvar)->ssh_state.payload + (offset)) + 7) >> 3) #define get_ushort16(buf) get_ushort16_MSBfirst((buf)) /// + +/* Global request confirmation callbacks */ +typedef void global_confirm_cb(PTInstVar pvar, int type, unsigned int seq, void *ctx); +void client_register_global_confirm(global_confirm_cb *cb, void *ctx); +/* Global request success/failure callbacks */ +struct global_confirm { + global_confirm_cb *cb; + void *ctx; + int ref_count; +}; + #endif