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 2824 by yutakakn, Tue Jun 21 13:28:26 2005 UTC revision 2825 by yutakakn, Sun Jun 26 14:26:24 2005 UTC
# Line 74  static BOOL handle_SSH2_userauth_failure Line 74  static BOOL handle_SSH2_userauth_failure
74  static BOOL handle_SSH2_userauth_banner(PTInstVar pvar);  static BOOL handle_SSH2_userauth_banner(PTInstVar pvar);
75  static BOOL handle_SSH2_open_confirm(PTInstVar pvar);  static BOOL handle_SSH2_open_confirm(PTInstVar pvar);
76  static BOOL handle_SSH2_request_success(PTInstVar pvar);  static BOOL handle_SSH2_request_success(PTInstVar pvar);
77    static BOOL handle_SSH2_request_failure(PTInstVar pvar);
78  static BOOL handle_SSH2_channel_success(PTInstVar pvar);  static BOOL handle_SSH2_channel_success(PTInstVar pvar);
79  static BOOL handle_SSH2_channel_data(PTInstVar pvar);  static BOOL handle_SSH2_channel_data(PTInstVar pvar);
80  static BOOL handle_SSH2_channel_extended_data(PTInstVar pvar);  static BOOL handle_SSH2_channel_extended_data(PTInstVar pvar);
81  static BOOL handle_SSH2_channel_eof(PTInstVar pvar);  static BOOL handle_SSH2_channel_eof(PTInstVar pvar);
82  static BOOL handle_SSH2_channel_close(PTInstVar pvar);  static BOOL handle_SSH2_channel_close(PTInstVar pvar);
83    static BOOL handle_SSH2_channel_open(PTInstVar pvar);
84  static BOOL handle_SSH2_window_adjust(PTInstVar pvar);  static BOOL handle_SSH2_window_adjust(PTInstVar pvar);
85  static BOOL handle_SSH2_channel_request(PTInstVar pvar);  static BOOL handle_SSH2_channel_request(PTInstVar pvar);
86  void SSH2_dispatch_init(int stage);  void SSH2_dispatch_init(int stage);
# Line 1275  static void init_protocol(PTInstVar pvar Line 1277  static void init_protocol(PTInstVar pvar
1277                  enque_handler(pvar, SSH2_MSG_CHANNEL_DATA, handle_SSH2_channel_data);                  enque_handler(pvar, SSH2_MSG_CHANNEL_DATA, handle_SSH2_channel_data);
1278                  enque_handler(pvar, SSH2_MSG_CHANNEL_EOF, handle_SSH2_channel_eof);                  enque_handler(pvar, SSH2_MSG_CHANNEL_EOF, handle_SSH2_channel_eof);
1279  //              enque_handler(pvar, SSH2_MSG_CHANNEL_EXTENDED_DATA, handle_SSH2_channel_extended_data);  //              enque_handler(pvar, SSH2_MSG_CHANNEL_EXTENDED_DATA, handle_SSH2_channel_extended_data);
1280  //              enque_handler(pvar, SSH2_MSG_CHANNEL_OPEN, handle_unimplemented);                  enque_handler(pvar, SSH2_MSG_CHANNEL_OPEN, handle_SSH2_channel_open);
1281                  enque_handler(pvar, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, handle_SSH2_open_confirm);                  enque_handler(pvar, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, handle_SSH2_open_confirm);
1282  //              enque_handler(pvar, SSH2_MSG_CHANNEL_OPEN_FAILURE, handle_unimplemented);  //              enque_handler(pvar, SSH2_MSG_CHANNEL_OPEN_FAILURE, handle_unimplemented);
1283                  enque_handler(pvar, SSH2_MSG_CHANNEL_REQUEST, handle_SSH2_channel_request);                  enque_handler(pvar, SSH2_MSG_CHANNEL_REQUEST, handle_SSH2_channel_request);
1284                  enque_handler(pvar, SSH2_MSG_CHANNEL_WINDOW_ADJUST, handle_SSH2_window_adjust);                  enque_handler(pvar, SSH2_MSG_CHANNEL_WINDOW_ADJUST, handle_SSH2_window_adjust);
1285                  enque_handler(pvar, SSH2_MSG_CHANNEL_SUCCESS, handle_SSH2_channel_success);                  enque_handler(pvar, SSH2_MSG_CHANNEL_SUCCESS, handle_SSH2_channel_success);
1286  //              enque_handler(pvar, SSH2_MSG_GLOBAL_REQUEST, handle_unimplemented);  //              enque_handler(pvar, SSH2_MSG_GLOBAL_REQUEST, handle_unimplemented);
1287  //              enque_handler(pvar, SSH2_MSG_REQUEST_FAILURE, handle_unimplemented);                  enque_handler(pvar, SSH2_MSG_REQUEST_FAILURE, handle_SSH2_request_failure);
1288                  enque_handler(pvar, SSH2_MSG_REQUEST_SUCCESS, handle_SSH2_request_success);                  enque_handler(pvar, SSH2_MSG_REQUEST_SUCCESS, handle_SSH2_request_success);
1289    
1290          }          }
# Line 2568  void SSH_channel_send(PTInstVar pvar, in Line 2570  void SSH_channel_send(PTInstVar pvar, in
2570    
2571  void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num)  void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num)
2572  {  {
2573          unsigned char FAR *outmsg =          if (SSHv1(pvar)) {
2574                  begin_send_packet(pvar, SSH_MSG_CHANNEL_OPEN_FAILURE, 4);                  unsigned char FAR *outmsg =
2575                            begin_send_packet(pvar, SSH_MSG_CHANNEL_OPEN_FAILURE, 4);
2576    
2577          set_uint32(outmsg, remote_channel_num);                  set_uint32(outmsg, remote_channel_num);
2578          finish_send_packet(pvar);                  finish_send_packet(pvar);
2579    
2580            } else { // SSH2 (2005.6.26 yutaka)
2581                    int len;
2582                    Channel_t *c = NULL;
2583                    buffer_t *msg;
2584                    unsigned char *outmsg;
2585    
2586                    msg = buffer_init();
2587                    if (msg == NULL) {
2588                            // TODO: error check
2589                            return;
2590                    }
2591                    buffer_put_int(msg, remote_channel_num);  
2592                    buffer_put_int(msg, SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED);  
2593    
2594                    len = buffer_len(msg);
2595                    outmsg = begin_send_packet(pvar, SSH2_MSG_CHANNEL_OPEN_FAILURE, len);
2596                    memcpy(outmsg, buffer_ptr(msg), len);
2597                    finish_send_packet(pvar);
2598                    buffer_free(msg);
2599    
2600            }
2601  }  }
2602    
2603  void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num,  void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num,
2604                                                            uint32 local_channel_num)                                                            uint32 local_channel_num)
2605  {  {
2606          unsigned char FAR *outmsg =          if (SSHv1(pvar)) {
2607                  begin_send_packet(pvar, SSH_MSG_CHANNEL_OPEN_CONFIRMATION, 8);                  unsigned char FAR *outmsg =
2608                            begin_send_packet(pvar, SSH_MSG_CHANNEL_OPEN_CONFIRMATION, 8);
2609    
2610          set_uint32(outmsg, remote_channel_num);                  set_uint32(outmsg, remote_channel_num);
2611          set_uint32(outmsg + 4, local_channel_num);                  set_uint32(outmsg + 4, local_channel_num);
2612          finish_send_packet(pvar);                  finish_send_packet(pvar);
2613    
2614            } else {
2615    
2616            }
2617  }  }
2618    
2619  void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num)  void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num)
# Line 2649  void SSH_channel_input_eof(PTInstVar pva Line 2679  void SSH_channel_input_eof(PTInstVar pva
2679  void SSH_request_forwarding(PTInstVar pvar, int from_server_port,  void SSH_request_forwarding(PTInstVar pvar, int from_server_port,
2680                                                          char FAR * to_local_host, int to_local_port)                                                          char FAR * to_local_host, int to_local_port)
2681  {  {
2682          int host_len = strlen(to_local_host);          if (SSHv1(pvar)) {
2683          unsigned char FAR *outmsg =                  int host_len = strlen(to_local_host);
2684                  begin_send_packet(pvar, SSH_CMSG_PORT_FORWARD_REQUEST,                  unsigned char FAR *outmsg =
2685                                                    12 + host_len);                          begin_send_packet(pvar, SSH_CMSG_PORT_FORWARD_REQUEST,
2686                                                            12 + host_len);
2687    
2688          set_uint32(outmsg, from_server_port);                  set_uint32(outmsg, from_server_port);
2689          set_uint32(outmsg + 4, host_len);                  set_uint32(outmsg + 4, host_len);
2690          memcpy(outmsg + 8, to_local_host, host_len);                  memcpy(outmsg + 8, to_local_host, host_len);
2691          set_uint32(outmsg + 8 + host_len, to_local_port);                  set_uint32(outmsg + 8 + host_len, to_local_port);
2692          finish_send_packet(pvar);                  finish_send_packet(pvar);
2693    
2694          enque_forwarding_request_handlers(pvar);                  enque_forwarding_request_handlers(pvar);
2695    
2696            } else {
2697                    // SSH2 port-forwading remote to local (2005.6.21 yutaka)
2698                    buffer_t *msg;
2699                    char *s;
2700                    unsigned char *outmsg;
2701                    int len;
2702    
2703                    msg = buffer_init();
2704                    if (msg == NULL) {
2705                            // TODO: error check
2706                            return;
2707                    }
2708                    s = "tcpip-forward";
2709                    buffer_put_string(msg, s, strlen(s)); // ctype
2710                    buffer_put_char(msg, 1);  // want reply
2711                    s = "0.0.0.0";
2712                    buffer_put_string(msg, s, strlen(s));
2713    
2714                    buffer_put_int(msg, from_server_port);  // listening port
2715    
2716                    len = buffer_len(msg);
2717                    outmsg = begin_send_packet(pvar, SSH2_MSG_GLOBAL_REQUEST, len);
2718                    memcpy(outmsg, buffer_ptr(msg), len);
2719                    finish_send_packet(pvar);
2720                    buffer_free(msg);
2721    
2722            }
2723  }  }
2724    
2725  void SSH_request_X11_forwarding(PTInstVar pvar,  void SSH_request_X11_forwarding(PTInstVar pvar,
# Line 5222  static BOOL handle_SSH2_userauth_success Line 5281  static BOOL handle_SSH2_userauth_success
5281          // 認証OK          // 認証OK
5282          pvar->userauth_success = 1;          pvar->userauth_success = 1;
5283    
5284          // ポートフォワーディングの準備 (2005.2.26 yutaka)          // ポートフォワーディングの準備 (2005.2.26, 2005.6.21 yutaka)
5285            FWD_prep_forwarding(pvar);      
5286          FWD_enter_interactive_mode(pvar);          FWD_enter_interactive_mode(pvar);
5287    
5288          // ディスパッチルーチンの再設定          // ディスパッチルーチンの再設定
# Line 5492  static BOOL handle_SSH2_open_confirm(PTI Line 5552  static BOOL handle_SSH2_open_confirm(PTI
5552          return TRUE;          return TRUE;
5553  }  }
5554    
5555    // SSH2 port-forwarding (remote -> local)に対するリプライ(成功)
5556  static BOOL handle_SSH2_request_success(PTInstVar pvar)  static BOOL handle_SSH2_request_success(PTInstVar pvar)
5557  {        {      
5558            // 必要であればログを取る。特に何もしなくてもよい。
5559    
5560            return TRUE;
5561    }
5562    
5563    // SSH2 port-forwarding (remote -> local)に対するリプライ(失敗)
5564    static BOOL handle_SSH2_request_failure(PTInstVar pvar)
5565    {      
5566            // 必要であればログを取る。特に何もしなくてもよい。
5567    
5568          return TRUE;          return TRUE;
5569  }  }
# Line 5697  static BOOL handle_SSH2_channel_eof(PTIn Line 5766  static BOOL handle_SSH2_channel_eof(PTIn
5766  }  }
5767    
5768    
5769    static BOOL handle_SSH2_channel_open(PTInstVar pvar)
5770    {      
5771            int len;
5772            char *data;
5773            Channel_t *c = NULL;
5774            int buflen;
5775            char *ctype;
5776            int remote_id;
5777            int remote_window;
5778            int remote_maxpacket;
5779    
5780            // 6byte(サイズ+パディング+タイプ)を取り除いた以降のペイロード
5781            data = pvar->ssh_state.payload;
5782            // パケットサイズ - (パディングサイズ+1);真のパケットサイズ
5783            len = pvar->ssh_state.payloadlen;
5784    
5785            // get string
5786            ctype = buffer_get_string(&data, &buflen);
5787    
5788            // get value
5789            remote_id = get_uint32_MSBfirst(data);
5790            data += 4;
5791            remote_window = get_uint32_MSBfirst(data);
5792            data += 4;
5793            remote_maxpacket = get_uint32_MSBfirst(data);
5794            data += 4;
5795    
5796            // check Channel Type(string)
5797            if (strcmp(ctype, "forwarded-tcpip") == 0) { // port-forwarding(remote to local)
5798                    char *listen_addr, *orig_addr;
5799                    int listen_port, orig_port;
5800    
5801                    listen_addr = buffer_get_string(&data, &buflen);  // 0.0.0.0
5802                    listen_port = get_uint32_MSBfirst(data); // 5000
5803                    data += 4;
5804    
5805                    orig_addr = buffer_get_string(&data, &buflen);  // 127.0.0.1
5806                    orig_port = get_uint32_MSBfirst(data);  // 32776
5807                    data += 4;
5808    
5809                    // searching request entry by listen_port & create_local_channel
5810                    FWD_open(pvar, remote_id, listen_addr, listen_port, orig_addr, orig_port);
5811    
5812                    free(listen_addr);
5813                    free(orig_addr);
5814    
5815            } else if (strcmp(ctype, "x11") == 0) { // port-forwarding(X11)
5816    
5817            } else {
5818                    // unknown type(unsupported)
5819    
5820            }
5821    
5822    #if 0
5823            if (c != NULL) {  // success
5824                    c->remote_id = remote_id;
5825                    c->remote_window = remote_window;
5826                    c->remote_maxpacket = remote_maxpacket;
5827    
5828                    msg = buffer_init();
5829                    if (msg == NULL) {
5830                            // TODO: error check
5831                            return FALSE;
5832                    }
5833                    buffer_put_int(msg, c->remote_id);  
5834                    buffer_put_int(msg, c->self_id);  
5835                    buffer_put_int(msg, c->local_window);  
5836                    buffer_put_int(msg, c->local_maxpacket);  
5837    
5838                    len = buffer_len(msg);
5839                    outmsg = begin_send_packet(pvar, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, len);
5840                    memcpy(outmsg, buffer_ptr(msg), len);
5841                    finish_send_packet(pvar);
5842                    buffer_free(msg);
5843    
5844            } else {  // failure
5845                    msg = buffer_init();
5846                    if (msg == NULL) {
5847                            // TODO: error check
5848                            return FALSE;
5849                    }
5850                    buffer_put_int(msg, c->remote_id);  
5851                    buffer_put_int(msg, SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED);  
5852    
5853                    len = buffer_len(msg);
5854                    outmsg = begin_send_packet(pvar, SSH2_MSG_CHANNEL_OPEN_FAILURE, len);
5855                    memcpy(outmsg, buffer_ptr(msg), len);
5856                    finish_send_packet(pvar);
5857                    buffer_free(msg);
5858    
5859            }
5860    #endif
5861    
5862            free(ctype);
5863    
5864            return(TRUE);
5865    }
5866    
5867    
5868  static BOOL handle_SSH2_channel_close(PTInstVar pvar)  static BOOL handle_SSH2_channel_close(PTInstVar pvar)
5869  {        {      
5870          int len;          int len;
# Line 5853  static BOOL handle_SSH2_window_adjust(PT Line 6021  static BOOL handle_SSH2_window_adjust(PT
6021    
6022  /*  /*
6023   * $Log: not supported by cvs2svn $   * $Log: not supported by cvs2svn $
6024     * Revision 1.28  2005/06/21 13:28:26  yutakakn
6025     * SSH2鍵交換中の(鍵交換以外の)SSH2メッセージ送信を破棄するようにした。
6026     *
6027   * Revision 1.27  2005/06/19 09:17:47  yutakakn   * Revision 1.27  2005/06/19 09:17:47  yutakakn
6028   * SSH2 port-fowarding(local to remote)をサポートした。   * SSH2 port-fowarding(local to remote)をサポートした。
6029   *   *

Legend:
Removed from v.2824  
changed lines
  Added in v.2825

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