Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ssh.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9210 - (hide annotations) (download) (as text)
Sat Apr 17 08:36:59 2021 UTC (2 years, 11 months ago) by nmaya
File MIME type: text/x-chdr
File size: 21752 byte(s)
ファイルを分割・コードを移動・関数名を整理・新しい OpenSSH からインポート

- OpenSSH からインポート
  cipher-3des1.c from OpenSSH-7.5p1
  ssherr.c from OpenSSH-8.5p1
  ssherr.h from OpenSSH-8.5p1
1 maya 3227 /*
2 doda 6841 * Copyright (c) 1998-2001, Robert O'Callahan
3 nmaya 9049 * (C) 2004- TeraTerm Project
4 doda 6841 * All rights reserved.
5     *
6     * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9     *
10     * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17     *
18     * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28     */
29 maya 3227
30     /*
31     This code is copyright (C) 1998-1999 Robert O'Callahan.
32     See LICENSE.TXT for the license.
33     */
34    
35     #ifndef __SSH_H
36     #define __SSH_H
37    
38     #include "zlib.h"
39     #include <openssl/evp.h>
40    
41     #include "buffer.h"
42 doda 4433 #include "config.h"
43 nmaya 9210 #include "cipher.h"
44     #include "hostkey.h"
45     #include "mac.h"
46     #include "comp.h"
47 yutakapon 4926 #include <sys/types.h>
48     #include <sys/stat.h>
49 maya 3227
50     #define DEBUG_PRINT_TO_FILE(base, msg, len) { \
51     static int count = 0; \
52     debug_print(count + base, msg, len); \
53     count++; \
54     }
55    
56     // from OpenSSH
57     extern const EVP_CIPHER *evp_aes_128_ctr(void);
58 doda 3850 extern const EVP_CIPHER *evp_des3_ctr(void);
59     extern const EVP_CIPHER *evp_bf_ctr(void);
60     extern const EVP_CIPHER *evp_cast5_ctr(void);
61 doda 4433 extern const EVP_CIPHER *evp_camellia_128_ctr(void);
62 maya 3227
63     /* Some of this code has been adapted from Ian Goldberg's Pilot SSH */
64    
65     typedef enum {
66     SSH_MSG_NONE, SSH_MSG_DISCONNECT, SSH_SMSG_PUBLIC_KEY, //2
67     SSH_CMSG_SESSION_KEY, SSH_CMSG_USER, SSH_CMSG_AUTH_RHOSTS, // 5
68     SSH_CMSG_AUTH_RSA, SSH_SMSG_AUTH_RSA_CHALLENGE,
69     SSH_CMSG_AUTH_RSA_RESPONSE, SSH_CMSG_AUTH_PASSWORD,
70     SSH_CMSG_REQUEST_PTY, // 10
71     SSH_CMSG_WINDOW_SIZE, SSH_CMSG_EXEC_SHELL,
72     SSH_CMSG_EXEC_CMD, SSH_SMSG_SUCCESS, SSH_SMSG_FAILURE,
73     SSH_CMSG_STDIN_DATA, SSH_SMSG_STDOUT_DATA, SSH_SMSG_STDERR_DATA,
74     SSH_CMSG_EOF, SSH_SMSG_EXITSTATUS,
75     SSH_MSG_CHANNEL_OPEN_CONFIRMATION, SSH_MSG_CHANNEL_OPEN_FAILURE,
76     SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_INPUT_EOF,
77     SSH_MSG_CHANNEL_OUTPUT_CLOSED, SSH_MSG_OBSOLETED0,
78     SSH_SMSG_X11_OPEN, SSH_CMSG_PORT_FORWARD_REQUEST, SSH_MSG_PORT_OPEN,
79     SSH_CMSG_AGENT_REQUEST_FORWARDING, SSH_SMSG_AGENT_OPEN,
80     SSH_MSG_IGNORE, SSH_CMSG_EXIT_CONFIRMATION,
81     SSH_CMSG_X11_REQUEST_FORWARDING, SSH_CMSG_AUTH_RHOSTS_RSA,
82     SSH_MSG_DEBUG, SSH_CMSG_REQUEST_COMPRESSION,
83     SSH_CMSG_MAX_PACKET_SIZE, SSH_CMSG_AUTH_TIS,
84     SSH_SMSG_AUTH_TIS_CHALLENGE, SSH_CMSG_AUTH_TIS_RESPONSE,
85     SSH_CMSG_AUTH_KERBEROS, SSH_SMSG_AUTH_KERBEROS_RESPONSE
86     } SSHMessage;
87    
88     typedef enum {
89     SSH_AUTH_NONE, SSH_AUTH_RHOSTS, SSH_AUTH_RSA, SSH_AUTH_PASSWORD,
90     SSH_AUTH_RHOSTS_RSA, SSH_AUTH_TIS, SSH_AUTH_KERBEROS,
91     SSH_AUTH_PAGEANT = 16,
92 maya 4378 SSH_AUTH_MAX = SSH_AUTH_PAGEANT,
93 maya 3227 } SSHAuthMethod;
94    
95     typedef enum {
96     SSH_GENERIC_AUTHENTICATION, SSH_TIS_AUTHENTICATION
97     } SSHAuthMode;
98    
99     #define SSH_PROTOFLAG_SCREEN_NUMBER 1
100     #define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2
101    
102     enum channel_type {
103 doda 6717 TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, TYPE_SFTP, TYPE_AGENT, TYPE_SUBSYSTEM_GEN,
104 maya 3227 };
105    
106     // for SSH1
107     #define SSH_MAX_SEND_PACKET_SIZE 250000
108    
109     // for SSH2
110     /* default window/packet sizes for tcp/x11-fwd-channel */
111     // changed CHAN_SES_WINDOW_DEFAULT from 32KB to 128KB. (2007.10.29 maya)
112     #define CHAN_SES_PACKET_DEFAULT (32*1024)
113     #define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT)
114     #define CHAN_TCP_PACKET_DEFAULT (32*1024)
115     #define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT)
116     #if 0 // unused
117     #define CHAN_X11_PACKET_DEFAULT (16*1024)
118     #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT)
119     #endif
120    
121    
122     /* SSH2 constants */
123 doda 7107 #define SSH_CHANNEL_INVALID -1
124 maya 3227
125     /* SSH2 messages */
126 doda 6950 typedef enum {
127     // Transport layer protocol
128     // 1..19 Transport layer generic (RFC 4253)
129     SSH2_MSG_DISCONNECT = 1,
130     SSH2_MSG_IGNORE = 2,
131     SSH2_MSG_UNIMPLEMENTED = 3,
132     SSH2_MSG_DEBUG = 4,
133     SSH2_MSG_SERVICE_REQUEST = 5,
134     SSH2_MSG_SERVICE_ACCEPT = 6,
135 maya 3227
136 doda 6950 // 20..29 Algorithm negotiation (RFC 4253)
137     SSH2_MSG_KEXINIT = 20,
138     SSH2_MSG_NEWKEYS = 21,
139 maya 3227
140 doda 6950 // 30..49 Key excahnge method specific
141     // Diffie-Hellman Key Exchange (RFC 4253)
142     SSH2_MSG_KEXDH_INIT = 30,
143     SSH2_MSG_KEXDH_REPLY = 31,
144 maya 3227
145 doda 6950 // RFC 4419 - Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol
146     SSH2_MSG_KEX_DH_GEX_GROUP = 31,
147     SSH2_MSG_KEX_DH_GEX_INIT = 32,
148     SSH2_MSG_KEX_DH_GEX_REPLY = 33,
149     SSH2_MSG_KEX_DH_GEX_REQUEST = 34,
150 maya 3227
151 doda 6950 // RFC 5656 - Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer
152     SSH2_MSG_KEX_ECDH_INIT = 30,
153     SSH2_MSG_KEX_ECDH_REPLY = 31,
154 maya 4314
155 doda 6950 // User authentication protocol
156     // 50..59 User authentication generic (RFC 4252)
157     SSH2_MSG_USERAUTH_REQUEST = 50,
158     SSH2_MSG_USERAUTH_FAILURE = 51,
159     SSH2_MSG_USERAUTH_SUCCESS = 52,
160     SSH2_MSG_USERAUTH_BANNER = 53,
161 maya 3227
162 doda 6950 // Public key authentication (RFC 4252)
163     SSH2_MSG_USERAUTH_PK_OK = 60,
164 maya 3227
165 doda 6950 // Password authentication (RFC 4252)
166     SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ = 60,
167 maya 3227
168 doda 6950 // RFC 4256 - Generic Message Exchange Authentication for the Secure Shell Protocol (SSH)
169     // Keyboard-interactive authentication
170     SSH2_MSG_USERAUTH_INFO_REQUEST = 60,
171     SSH2_MSG_USERAUTH_INFO_RESPONSE = 61,
172    
173     // Connection protocol
174     // 80..89 Connection protocol generic (RFC 4254)
175     SSH2_MSG_GLOBAL_REQUEST = 80,
176     SSH2_MSG_REQUEST_SUCCESS = 81,
177     SSH2_MSG_REQUEST_FAILURE = 82,
178    
179     // 90..127 Channel related messages (RFC 4254)
180     SSH2_MSG_CHANNEL_OPEN = 90,
181     SSH2_MSG_CHANNEL_OPEN_CONFIRMATION = 91,
182     SSH2_MSG_CHANNEL_OPEN_FAILURE = 92,
183     SSH2_MSG_CHANNEL_WINDOW_ADJUST = 93,
184     SSH2_MSG_CHANNEL_DATA = 94,
185     SSH2_MSG_CHANNEL_EXTENDED_DATA = 95,
186     SSH2_MSG_CHANNEL_EOF = 96,
187     SSH2_MSG_CHANNEL_CLOSE = 97,
188     SSH2_MSG_CHANNEL_REQUEST = 98,
189     SSH2_MSG_CHANNEL_SUCCESS = 99,
190     SSH2_MSG_CHANNEL_FAILURE = 100
191    
192     // Reserved for client protocols
193     // 128..191 Reserved
194    
195     // Local extensions:
196     // 192..255 Local extensions
197    
198     } SSH2Message;
199    
200 maya 3227 /* SSH2 miscellaneous constants */
201 doda 6950 typedef enum {
202     SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1,
203     SSH2_DISCONNECT_PROTOCOL_ERROR,
204     SSH2_DISCONNECT_KEY_EXCHANGE_FAILED,
205     SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED,
206     SSH2_DISCONNECT_MAC_ERROR,
207     SSH2_DISCONNECT_COMPRESSION_ERROR,
208     SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE,
209     SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED,
210     SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE,
211     SSH2_DISCONNECT_CONNECTION_LOST,
212     SSH2_DISCONNECT_BY_APPLICATION,
213     SSH2_DISCONNECT_TOO_MANY_CONNECTIONS,
214     SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER,
215     SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE,
216     SSH2_DISCONNECT_ILLEGAL_USER_NAME
217     } SSH2DisconnectMessage;
218 maya 3227
219 doda 6950 typedef enum {
220     SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED = 1,
221     SSH2_OPEN_CONNECT_FAILED,
222     SSH2_OPEN_UNKNOWN_CHANNEL_TYPE,
223     SSH2_OPEN_RESOURCE_SHORTAGE
224     } SSH2ChannelFailReason;
225 maya 3227
226 doda 5587 // Terminal Modes
227 doda 6950 typedef enum {
228     SSH2_TTY_OP_END = 0,
229     SSH2_TTY_KEY_VINTR = 1,
230     SSH2_TTY_KEY_VQUIT = 2,
231     SSH2_TTY_KEY_VERASE = 3,
232     SSH2_TTY_KEY_VKILL = 4,
233     SSH2_TTY_KEY_VEOF = 5,
234     SSH2_TTY_KEY_VEOL = 6,
235     SSH2_TTY_KEY_VEOL2 = 7,
236     SSH2_TTY_KEY_VSTART = 8,
237     SSH2_TTY_KEY_VSTOP = 9,
238     SSH2_TTY_KEY_VSUSP = 10,
239     SSH2_TTY_KEY_VDSUSP = 11,
240     SSH2_TTY_KEY_VREPRINT = 12,
241     SSH2_TTY_KEY_VWERASE = 13,
242     SSH2_TTY_KEY_VLNEXT = 14,
243     SSH2_TTY_KEY_VFLUSH = 15,
244     SSH2_TTY_KEY_VSWTCH = 16,
245     SSH2_TTY_KEY_VSTATUS = 17,
246     SSH2_TTY_KEY_VDISCARD = 18,
247     SSH2_TTY_OP_IGNPAR = 30,
248     SSH2_TTY_OP_PARMRK = 31,
249     SSH2_TTY_OP_INPCK = 32,
250     SSH2_TTY_OP_ISTRIP = 33,
251     SSH2_TTY_OP_INLCR = 34,
252     SSH2_TTY_OP_IGNCR = 35,
253     SSH2_TTY_OP_ICRNL = 36,
254     SSH2_TTY_OP_IUCLC = 37,
255     SSH2_TTY_OP_IXON = 38,
256     SSH2_TTY_OP_IXANY = 39,
257     SSH2_TTY_OP_IXOFF = 40,
258     SSH2_TTY_OP_IMAXBEL = 41,
259     SSH2_TTY_OP_ISIG = 50,
260     SSH2_TTY_OP_ICANON = 51,
261     SSH2_TTY_OP_XCASE = 52,
262     SSH2_TTY_OP_ECHO = 53,
263     SSH2_TTY_OP_ECHOE = 54,
264     SSH2_TTY_OP_ECHOK = 55,
265     SSH2_TTY_OP_ECHONL = 56,
266     SSH2_TTY_OP_NOFLSH = 57,
267     SSH2_TTY_OP_TOSTOP = 58,
268     SSH2_TTY_OP_IEXTEN = 59,
269     SSH2_TTY_OP_ECHOCTL = 60,
270     SSH2_TTY_OP_ECHOKE = 61,
271     SSH2_TTY_OP_PENDIN = 62,
272     SSH2_TTY_OP_OPOST = 70,
273     SSH2_TTY_OP_OLCUC = 71,
274     SSH2_TTY_OP_ONLCR = 72,
275     SSH2_TTY_OP_OCRNL = 73,
276     SSH2_TTY_OP_ONOCR = 74,
277     SSH2_TTY_OP_ONLRET = 75,
278     SSH2_TTY_OP_CS7 = 90,
279     SSH2_TTY_OP_CS8 = 91,
280     SSH2_TTY_OP_PARENB = 92,
281     SSH2_TTY_OP_PARODD = 93,
282     SSH2_TTY_OP_ISPEED = 128,
283     SSH2_TTY_OP_OSPEED = 129
284     } SSH2TTYMode;
285 maya 3227
286 doda 5587
287 yutakapon 5545 #define isFixedLengthKey(type) ((type) >= KEY_DSA && (type) <= KEY_ED25519)
288 maya 4378
289     /* Minimum modulus size (n) for RSA keys. */
290     #define SSH_RSA_MINIMUM_MODULUS_SIZE 768
291    
292     #define SSH_KEYGEN_DEFAULT_BITS 2048
293     #define SSH_RSA_MINIMUM_KEY_SIZE 768
294     #define SSH_DSA_MINIMUM_KEY_SIZE 1024
295    
296 maya 5765 #define SSH_KEYGEN_MINIMUM_ROUNDS 1
297     #define SSH_KEYGEN_MAXIMUM_ROUNDS INT_MAX
298 maya 4378
299 maya 5765
300 maya 3227 struct Enc {
301     u_char *key;
302     u_char *iv;
303     unsigned int key_len;
304     unsigned int block_size;
305 doda 6985 unsigned int iv_len;
306     unsigned int auth_len;
307 maya 3227 };
308    
309     struct Mac {
310 doda 6984 char *name;
311     int enabled;
312 maya 3227 const EVP_MD *md;
313 doda 6984 unsigned int mac_len;
314 maya 3227 u_char *key;
315 doda 6984 unsigned int key_len;
316     int etm;
317 maya 3227 };
318    
319     struct Comp {
320     int type;
321     int enabled;
322     char *name;
323     };
324    
325     typedef struct {
326     struct Enc enc;
327     struct Mac mac;
328     struct Comp comp;
329 doda 7001 } SSHKeys;
330 maya 3227
331     #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
332    
333     enum kex_modes {
334     MODE_IN,
335     MODE_OUT,
336     MODE_MAX
337     };
338    
339    
340     // �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka)
341     typedef struct Key {
342     // host key type
343 maya 4378 ssh_keytype type;
344 maya 3227 // SSH2 RSA
345     RSA *rsa;
346     // SSH2 DSA
347     DSA *dsa;
348 maya 4321 // SSH2 ECDSA
349     EC_KEY *ecdsa;
350 maya 3227 // SSH1 RSA
351     int bits;
352     unsigned char *exp;
353     unsigned char *mod;
354 yutakapon 5545 // SSH2 ED25519
355     unsigned char *ed25519_sk;
356     unsigned char *ed25519_pk;
357     int bcrypt_kdf;
358 maya 3227 } Key;
359    
360 doda 4531
361 maya 3227 enum scp_dir {
362 r850 3375 TOREMOTE, FROMREMOTE,
363 maya 3227 };
364    
365     /* The packet handler returns TRUE to keep the handler in place,
366     FALSE to remove the handler. */
367     typedef BOOL (* SSHPacketHandler)(PTInstVar pvar);
368    
369     typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem;
370     struct _SSHPacketHandlerItem {
371     SSHPacketHandler handler;
372     /* Circular list of handlers for given message */
373 doda 6801 SSHPacketHandlerItem *next_for_message;
374     SSHPacketHandlerItem *last_for_message;
375 maya 3227 /* Circular list of handlers in set */
376 doda 6801 SSHPacketHandlerItem *next_in_set;
377 maya 3227 int active_for_message;
378     };
379    
380     typedef struct {
381 doda 6801 char *hostname;
382 maya 3227
383     int server_protocol_flags;
384 doda 6801 char *server_ID;
385 maya 3227
386     /* This buffer is used to hold the outgoing data, and encrypted in-place
387     here if necessary. */
388 doda 6801 unsigned char *outbuf;
389 maya 3227 long outbuflen;
390     /* This buffer is used by the SSH protocol processing to store uncompressed
391     packet data for compression. User data is never streamed through here;
392     it is compressed directly from the user's buffer. */
393 doda 6801 unsigned char *precompress_outbuf;
394 maya 3227 long precompress_outbuflen;
395     /* this is the length of the packet data, including the type header */
396     long outgoing_packet_len;
397    
398     /* This buffer is used by the SSH protocol processing to store decompressed
399     packet data. User data is never streamed through here; it is decompressed
400     directly to the user's buffer. */
401 doda 6801 unsigned char *postdecompress_inbuf;
402 maya 3227 long postdecompress_inbuflen;
403    
404 doda 6801 unsigned char *payload;
405 maya 3227 long payload_grabbed;
406     long payloadlen;
407     long payload_datastart;
408     long payload_datalen;
409    
410     uint32 receiver_sequence_number;
411     uint32 sender_sequence_number;
412    
413     z_stream compress_stream;
414     z_stream decompress_stream;
415     BOOL compressing;
416     BOOL decompressing;
417     int compression_level;
418    
419 doda 6801 SSHPacketHandlerItem *packet_handlers[256];
420 maya 3227 int status_flags;
421    
422     int win_cols;
423     int win_rows;
424    
425     unsigned short tcpport;
426     } SSHState;
427    
428     #define STATUS_DONT_SEND_USER_NAME 0x01
429     #define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02
430     #define STATUS_DONT_SEND_CREDENTIALS 0x04
431     #define STATUS_HOST_OK 0x08
432     #define STATUS_INTERACTIVE 0x10
433     #define STATUS_IN_PARTIAL_ID_STRING 0x20
434    
435     void SSH_init(PTInstVar pvar);
436     void SSH_open(PTInstVar pvar);
437 doda 6801 void SSH_notify_disconnecting(PTInstVar pvar, char *reason);
438 maya 3227 /* SSH_handle_server_ID returns TRUE iff a valid ID string has been
439     received. If it returns FALSE, we need to keep looking for another
440     ID string. */
441 doda 6801 BOOL SSH_handle_server_ID(PTInstVar pvar, char *ID, int ID_len);
442 maya 3227 /* SSH_handle_packet requires NO PAYLOAD on entry.
443     'len' is the size of the packet: payload + padding (+ CRC for SSHv1)
444     'padding' is the size of the padding.
445     'data' points to the start of the packet data (the length field)
446     */
447 doda 6982 void SSH1_handle_packet(PTInstVar pvar, char *data, unsigned int len, unsigned int padding);
448 doda 6985 void SSH2_handle_packet(PTInstVar pvar, char *data, unsigned int len, unsigned int aadlen, unsigned int authlen);
449 maya 3227 void SSH_notify_win_size(PTInstVar pvar, int cols, int rows);
450     void SSH_notify_user_name(PTInstVar pvar);
451     void SSH_notify_cred(PTInstVar pvar);
452     void SSH_notify_host_OK(PTInstVar pvar);
453 doda 6801 void SSH_send(PTInstVar pvar, unsigned char const *buf, unsigned int buflen);
454 maya 3227 /* SSH_extract_payload returns number of bytes extracted */
455 doda 6801 int SSH_extract_payload(PTInstVar pvar, unsigned char *dest, int len);
456 maya 3227 void SSH_end(PTInstVar pvar);
457    
458 doda 6801 void SSH_get_server_ID_info(PTInstVar pvar, char *dest, int len);
459     void SSH_get_protocol_version_info(PTInstVar pvar, char *dest, int len);
460     void SSH_get_compression_info(PTInstVar pvar, char *dest, int len);
461     void SSH_get_mac_info(PTInstVar pvar, char *dest, int len);
462 maya 3227
463     /* len must be <= SSH_MAX_SEND_PACKET_SIZE */
464     void SSH_channel_send(PTInstVar pvar, int channel_num,
465     uint32 remote_channel_num,
466 doda 6801 unsigned char *buf, int len, int retry);
467 maya 3227 void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num);
468     void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
469     void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num);
470     void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
471 doda 6801 void SSH_request_forwarding(PTInstVar pvar, char *bind_address, int from_server_port,
472     char *to_local_host, int to_local_port);
473     void SSH_cancel_request_forwarding(PTInstVar pvar, char *bind_address, int from_server_port, int reply);
474 maya 3227 void SSH_request_X11_forwarding(PTInstVar pvar,
475 doda 6801 char *auth_protocol, unsigned char *auth_data, int auth_data_len, int screen_num);
476 maya 3227 void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num,
477 doda 6801 char *to_remote_host, int to_remote_port,
478     char *originator, unsigned short originator_port);
479 maya 3227
480     int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile);
481 youlab 8924 int SSH_scp_sending_status(void);
482 maya 3227 int SSH_start_scp_receive(PTInstVar pvar, char *filename);
483     int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction);
484     int SSH_sftp_transaction(PTInstVar pvar);
485    
486     /* auxiliary SSH2 interfaces for pkt.c */
487 doda 6982 unsigned int SSH_get_min_packet_size(PTInstVar pvar);
488 maya 3227 /* data is guaranteed to be at least SSH_get_min_packet_size bytes long
489     at least 5 bytes must be decrypted */
490 doda 7109 void SSH_predecrypt_packet(PTInstVar pvar, char *data);
491 doda 6982 unsigned int SSH_get_clear_MAC_size(PTInstVar pvar);
492 doda 6985 unsigned int SSH_get_authdata_size(PTInstVar pvar, int direction);
493 maya 3227
494     #define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0)
495     #define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname)
496     #define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0)
497    
498     void SSH2_send_kexinit(PTInstVar pvar);
499     BOOL do_SSH2_userauth(PTInstVar pvar);
500     BOOL do_SSH2_authrequest(PTInstVar pvar);
501     void debug_print(int no, char *msg, int len);
502     void ssh_heartbeat_lock_initialize(void);
503     void ssh_heartbeat_lock_finalize(void);
504     void ssh_heartbeat_lock(void);
505     void ssh_heartbeat_unlock(void);
506     void halt_ssh_heartbeat_thread(PTInstVar pvar);
507     void ssh2_channel_free(void);
508 doda 6657 BOOL handle_SSH2_userauth_msg60(PTInstVar pvar);
509 maya 3227 BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar);
510 doda 6657 BOOL handle_SSH2_userauth_pkok(PTInstVar pvar);
511 yutakapon 4152 BOOL handle_SSH2_userauth_passwd_changereq(PTInstVar pvar);
512 yutakapon 4106 int SSH_notify_break_signal(PTInstVar pvar);
513 maya 3227
514 yutakapon 4926 ///
515     enum scp_state {
516     SCP_INIT, SCP_TIMESTAMP, SCP_FILEINFO, SCP_DATA, SCP_CLOSING,
517     };
518    
519     typedef struct bufchain {
520     buffer_t *msg;
521     struct bufchain *next;
522     } bufchain_t;
523    
524 yutakapon 6528 typedef struct PacketList {
525     char *buf;
526     unsigned int buflen;
527     struct PacketList *next;
528     } PacketList_t;
529    
530 yutakapon 4926 typedef struct scp {
531     enum scp_dir dir; // transfer direction
532     enum scp_state state; // SCP state
533     char localfile[MAX_PATH]; // local filename
534     char localfilefull[MAX_PATH]; // local filename fullpath
535     char remotefile[MAX_PATH]; // remote filename
536     FILE *localfp; // file pointer for local file
537     struct __stat64 filestat; // file status information
538     HWND progress_window;
539     HANDLE thread;
540     unsigned int thread_id;
541     PTInstVar pvar;
542     // for receiving file
543     long long filetotalsize;
544     long long filercvsize;
545 maya 5607 DWORD filemtime;
546     DWORD fileatime;
547 yutakapon 6528 PacketList_t *pktlist_head;
548     PacketList_t *pktlist_tail;
549 yutakapon 4926 } scp_t;
550    
551     enum sftp_state {
552 yutakapon 4930 SFTP_INIT, SFTP_CONNECTED, SFTP_REALPATH,
553 yutakapon 4926 };
554    
555     typedef struct sftp {
556     enum sftp_state state;
557 yutakapon 4930 HWND console_window;
558 yutakapon 4929 unsigned int transfer_buflen;
559     unsigned int num_requests;
560     unsigned int version;
561     unsigned int msg_id;
562     #define SFTP_EXT_POSIX_RENAME 0x00000001
563     #define SFTP_EXT_STATVFS 0x00000002
564     #define SFTP_EXT_FSTATVFS 0x00000004
565     #define SFTP_EXT_HARDLINK 0x00000008
566     unsigned int exts;
567     unsigned long long limit_kbps;
568     //struct bwlimit bwlimit_in, bwlimit_out;
569 yutakapon 4930 char path[1024];
570 yutakapon 4926 } sftp_t;
571    
572     typedef struct channel {
573     int used;
574     int self_id;
575     int remote_id;
576     unsigned int local_window;
577     unsigned int local_window_max;
578     unsigned int local_consumed;
579     unsigned int local_maxpacket;
580     unsigned int remote_window;
581     unsigned int remote_maxpacket;
582     enum channel_type type;
583     int local_num;
584     bufchain_t *bufchain;
585 yutakapon 7771 unsigned long bufchain_amount;
586     BOOL bufchain_recv_suspended;
587 yutakapon 4926 scp_t scp;
588     buffer_t *agent_msg;
589     int agent_request_len;
590     sftp_t sftp;
591 maya 5422 #define SSH_CHANNEL_STATE_CLOSE_SENT 0x00000001
592     unsigned int state;
593 yutakapon 4926 } Channel_t;
594    
595 doda 6801 unsigned char *begin_send_packet(PTInstVar pvar, int type, int len);
596 yutakapon 4926 void finish_send_packet_special(PTInstVar pvar, int skip_compress);
597 doda 6801 void SSH2_send_channel_data(PTInstVar pvar, Channel_t *c, unsigned char *buf, unsigned int buflen, int retry);
598 yutakapon 7771 Channel_t* ssh2_local_channel_lookup(int local_num);
599 nmaya 9210 void normalize_generic_order(char *buf, char default_strings[], int default_strings_len);
600     void choose_SSH2_proposal(char* server_proposal, char* my_proposal,char* dest, int dest_len);
601 yutakapon 4926
602     #define finish_send_packet(pvar) finish_send_packet_special((pvar), 0)
603     #define get_payload_uint32(pvar, offset) get_uint32_MSBfirst((pvar)->ssh_state.payload + (offset))
604     #define get_uint32(buf) get_uint32_MSBfirst((buf))
605     #define set_uint32(buf, v) set_uint32_MSBfirst((buf), (v))
606     #define get_mpint_len(pvar, offset) ((get_ushort16_MSBfirst((pvar)->ssh_state.payload + (offset)) + 7) >> 3)
607     #define get_ushort16(buf) get_ushort16_MSBfirst((buf))
608     ///
609    
610 doda 5916 /* Global request confirmation callbacks */
611     typedef void global_confirm_cb(PTInstVar pvar, int type, unsigned int seq, void *ctx);
612     void client_register_global_confirm(global_confirm_cb *cb, void *ctx);
613    
614     /* Global request success/failure callbacks */
615     struct global_confirm {
616     global_confirm_cb *cb;
617     void *ctx;
618     int ref_count;
619 yutakapon 5850 };
620    
621 yutakapon 8093 /*
622     * SSH bottom half after known_hosts
623     */
624     enum ssh_kex_known_hosts {
625     NONE_KNOWN_HOSTS = 0,
626     SSH1_PUBLIC_KEY_KNOWN_HOSTS,
627     SSH2_DH_KEX_REPLY_KNOWN_HOSTS,
628     SSH2_DH_GEX_REPLY_KNOWN_HOSTS,
629     SSH2_ECDH_KEX_REPLY_KNOWN_HOSTS,
630     };
631    
632     typedef struct bottom_half_known_hosts {
633     enum ssh_kex_known_hosts kex_type;
634    
635     unsigned char *payload;
636     int payload_len;
637     UINT_PTR payload_offset;
638    
639     BOOL SSH2_MSG_NEWKEYS_received;
640     } bottom_half_known_hosts_t;
641    
642     void handle_SSH2_canel_reply_after_known_hosts(PTInstVar pvar);
643    
644     BOOL handle_server_public_key_after_known_hosts(PTInstVar pvar);
645     BOOL handle_SSH2_dh_kex_reply_after_known_hosts(PTInstVar pvar);
646     BOOL handle_SSH2_dh_gex_reply_after_known_hosts(PTInstVar pvar);
647     BOOL handle_SSH2_ecdh_kex_reply_after_known_hosts(PTInstVar pvar);
648    
649 nmaya 9210 #endif /* __SSH_H */

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