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 4929 - (hide annotations) (download) (as text)
Thu May 3 16:17:09 2012 UTC (11 years, 11 months ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/ssh.h
File MIME type: text/x-chdr
File size: 26108 byte(s)
SFTP: 最初のネゴシエーションまで完了。

1 maya 3227 /*
2     Copyright (c) 1998-2001, Robert O'Callahan
3     All rights reserved.
4    
5     Redistribution and use in source and binary forms, with or without modification,
6     are permitted provided that the following conditions are met:
7    
8     Redistributions of source code must retain the above copyright notice, this list of
9     conditions and the following disclaimer.
10    
11     Redistributions in binary form must reproduce the above copyright notice, this list
12     of conditions and the following disclaimer in the documentation and/or other materials
13     provided with the distribution.
14    
15     The name of Robert O'Callahan may not be used to endorse or promote products derived from
16     this software without specific prior written permission.
17    
18     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21     THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    
29     /*
30     This code is copyright (C) 1998-1999 Robert O'Callahan.
31     See LICENSE.TXT for the license.
32     */
33    
34     #ifndef __SSH_H
35     #define __SSH_H
36    
37     #include "zlib.h"
38     #include <openssl/evp.h>
39    
40     #include "buffer.h"
41 doda 4433 #include "config.h"
42 yutakapon 4926 #include <sys/types.h>
43     #include <sys/stat.h>
44 maya 3227
45     #define DEBUG_PRINT_TO_FILE(base, msg, len) { \
46     static int count = 0; \
47     debug_print(count + base, msg, len); \
48     count++; \
49     }
50    
51     // from OpenSSH
52     extern const EVP_CIPHER *evp_aes_128_ctr(void);
53 doda 3850 extern const EVP_CIPHER *evp_des3_ctr(void);
54     extern const EVP_CIPHER *evp_bf_ctr(void);
55     extern const EVP_CIPHER *evp_cast5_ctr(void);
56 doda 4433 extern const EVP_CIPHER *evp_camellia_128_ctr(void);
57 maya 3227
58     /* Some of this code has been adapted from Ian Goldberg's Pilot SSH */
59    
60     typedef enum {
61     SSH_MSG_NONE, SSH_MSG_DISCONNECT, SSH_SMSG_PUBLIC_KEY, //2
62     SSH_CMSG_SESSION_KEY, SSH_CMSG_USER, SSH_CMSG_AUTH_RHOSTS, // 5
63     SSH_CMSG_AUTH_RSA, SSH_SMSG_AUTH_RSA_CHALLENGE,
64     SSH_CMSG_AUTH_RSA_RESPONSE, SSH_CMSG_AUTH_PASSWORD,
65     SSH_CMSG_REQUEST_PTY, // 10
66     SSH_CMSG_WINDOW_SIZE, SSH_CMSG_EXEC_SHELL,
67     SSH_CMSG_EXEC_CMD, SSH_SMSG_SUCCESS, SSH_SMSG_FAILURE,
68     SSH_CMSG_STDIN_DATA, SSH_SMSG_STDOUT_DATA, SSH_SMSG_STDERR_DATA,
69     SSH_CMSG_EOF, SSH_SMSG_EXITSTATUS,
70     SSH_MSG_CHANNEL_OPEN_CONFIRMATION, SSH_MSG_CHANNEL_OPEN_FAILURE,
71     SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_INPUT_EOF,
72     SSH_MSG_CHANNEL_OUTPUT_CLOSED, SSH_MSG_OBSOLETED0,
73     SSH_SMSG_X11_OPEN, SSH_CMSG_PORT_FORWARD_REQUEST, SSH_MSG_PORT_OPEN,
74     SSH_CMSG_AGENT_REQUEST_FORWARDING, SSH_SMSG_AGENT_OPEN,
75     SSH_MSG_IGNORE, SSH_CMSG_EXIT_CONFIRMATION,
76     SSH_CMSG_X11_REQUEST_FORWARDING, SSH_CMSG_AUTH_RHOSTS_RSA,
77     SSH_MSG_DEBUG, SSH_CMSG_REQUEST_COMPRESSION,
78     SSH_CMSG_MAX_PACKET_SIZE, SSH_CMSG_AUTH_TIS,
79     SSH_SMSG_AUTH_TIS_CHALLENGE, SSH_CMSG_AUTH_TIS_RESPONSE,
80     SSH_CMSG_AUTH_KERBEROS, SSH_SMSG_AUTH_KERBEROS_RESPONSE
81     } SSHMessage;
82    
83     typedef enum {
84     SSH_CIPHER_NONE, SSH_CIPHER_IDEA, SSH_CIPHER_DES, SSH_CIPHER_3DES,
85     SSH_CIPHER_TSS, SSH_CIPHER_RC4, SSH_CIPHER_BLOWFISH,
86     // for SSH2
87     SSH2_CIPHER_3DES_CBC, SSH2_CIPHER_AES128_CBC,
88     SSH2_CIPHER_AES192_CBC, SSH2_CIPHER_AES256_CBC,
89     SSH2_CIPHER_BLOWFISH_CBC, SSH2_CIPHER_AES128_CTR,
90     SSH2_CIPHER_AES192_CTR, SSH2_CIPHER_AES256_CTR,
91     SSH2_CIPHER_ARCFOUR, SSH2_CIPHER_ARCFOUR128, SSH2_CIPHER_ARCFOUR256,
92     SSH2_CIPHER_CAST128_CBC,
93 doda 3850 SSH2_CIPHER_3DES_CTR, SSH2_CIPHER_BLOWFISH_CTR, SSH2_CIPHER_CAST128_CTR,
94 doda 4433 SSH2_CIPHER_CAMELLIA128_CBC, SSH2_CIPHER_CAMELLIA192_CBC, SSH2_CIPHER_CAMELLIA256_CBC,
95     SSH2_CIPHER_CAMELLIA128_CTR, SSH2_CIPHER_CAMELLIA192_CTR, SSH2_CIPHER_CAMELLIA256_CTR,
96     SSH_CIPHER_MAX = SSH2_CIPHER_CAMELLIA256_CTR,
97 maya 3227 } SSHCipher;
98    
99     typedef enum {
100     SSH_AUTH_NONE, SSH_AUTH_RHOSTS, SSH_AUTH_RSA, SSH_AUTH_PASSWORD,
101     SSH_AUTH_RHOSTS_RSA, SSH_AUTH_TIS, SSH_AUTH_KERBEROS,
102     SSH_AUTH_PAGEANT = 16,
103 maya 4378 SSH_AUTH_MAX = SSH_AUTH_PAGEANT,
104 maya 3227 } SSHAuthMethod;
105    
106     typedef enum {
107     SSH_GENERIC_AUTHENTICATION, SSH_TIS_AUTHENTICATION
108     } SSHAuthMode;
109    
110     #define SSH_PROTOFLAG_SCREEN_NUMBER 1
111     #define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2
112    
113     enum channel_type {
114     TYPE_SHELL, TYPE_PORTFWD, TYPE_SCP, TYPE_SFTP, TYPE_AGENT,
115     };
116    
117     // for SSH1
118     #define SSH_MAX_SEND_PACKET_SIZE 250000
119    
120     // for SSH2
121     /* default window/packet sizes for tcp/x11-fwd-channel */
122     // changed CHAN_SES_WINDOW_DEFAULT from 32KB to 128KB. (2007.10.29 maya)
123     #define CHAN_SES_PACKET_DEFAULT (32*1024)
124     #define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT)
125     #define CHAN_TCP_PACKET_DEFAULT (32*1024)
126     #define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT)
127     #if 0 // unused
128     #define CHAN_X11_PACKET_DEFAULT (16*1024)
129     #define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT)
130     #endif
131    
132    
133     /* SSH2 constants */
134    
135     /* SSH2 messages */
136     #define SSH2_MSG_DISCONNECT 1
137     #define SSH2_MSG_IGNORE 2
138     #define SSH2_MSG_UNIMPLEMENTED 3
139     #define SSH2_MSG_DEBUG 4
140     #define SSH2_MSG_SERVICE_REQUEST 5
141     #define SSH2_MSG_SERVICE_ACCEPT 6
142    
143     #define SSH2_MSG_KEXINIT 20
144     #define SSH2_MSG_NEWKEYS 21
145    
146     #define SSH2_MSG_KEXDH_INIT 30
147     #define SSH2_MSG_KEXDH_REPLY 31
148    
149     #define SSH2_MSG_KEX_DH_GEX_GROUP 31
150     #define SSH2_MSG_KEX_DH_GEX_INIT 32
151     #define SSH2_MSG_KEX_DH_GEX_REPLY 33
152     #define SSH2_MSG_KEX_DH_GEX_REQUEST 34
153    
154 maya 4314 #define SSH2_MSG_KEX_ECDH_INIT 30
155     #define SSH2_MSG_KEX_ECDH_REPLY 31
156    
157 maya 3227 #define SSH2_MSG_USERAUTH_REQUEST 50
158     #define SSH2_MSG_USERAUTH_FAILURE 51
159     #define SSH2_MSG_USERAUTH_SUCCESS 52
160     #define SSH2_MSG_USERAUTH_BANNER 53
161    
162     #define SSH2_MSG_USERAUTH_PK_OK 60
163     #define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60
164     #define SSH2_MSG_USERAUTH_INFO_REQUEST 60
165     #define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
166    
167     #define SSH2_MSG_GLOBAL_REQUEST 80
168     #define SSH2_MSG_REQUEST_SUCCESS 81
169     #define SSH2_MSG_REQUEST_FAILURE 82
170     #define SSH2_MSG_CHANNEL_OPEN 90
171     #define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
172     #define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
173     #define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
174     #define SSH2_MSG_CHANNEL_DATA 94
175     #define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
176     #define SSH2_MSG_CHANNEL_EOF 96
177     #define SSH2_MSG_CHANNEL_CLOSE 97
178     #define SSH2_MSG_CHANNEL_REQUEST 98
179     #define SSH2_MSG_CHANNEL_SUCCESS 99
180     #define SSH2_MSG_CHANNEL_FAILURE 100
181    
182     /* SSH2 miscellaneous constants */
183     #define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
184     #define SSH2_DISCONNECT_PROTOCOL_ERROR 2
185     #define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED 3
186     #define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4
187     #define SSH2_DISCONNECT_MAC_ERROR 5
188     #define SSH2_DISCONNECT_COMPRESSION_ERROR 6
189     #define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE 7
190     #define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
191     #define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
192     #define SSH2_DISCONNECT_CONNECTION_LOST 10
193     #define SSH2_DISCONNECT_BY_APPLICATION 11
194    
195     #define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED 1
196     #define SSH2_OPEN_CONNECT_FAILED 2
197     #define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE 3
198     #define SSH2_OPEN_RESOURCE_SHORTAGE 4
199    
200    
201 maya 4378 // �N���C�A���g�����T�[�o������������
202 maya 3227 enum kex_init_proposals {
203     PROPOSAL_KEX_ALGS,
204     PROPOSAL_SERVER_HOST_KEY_ALGS,
205     PROPOSAL_ENC_ALGS_CTOS,
206     PROPOSAL_ENC_ALGS_STOC,
207     PROPOSAL_MAC_ALGS_CTOS,
208     PROPOSAL_MAC_ALGS_STOC,
209     PROPOSAL_COMP_ALGS_CTOS,
210     PROPOSAL_COMP_ALGS_STOC,
211     PROPOSAL_LANG_CTOS,
212     PROPOSAL_LANG_STOC,
213     PROPOSAL_MAX
214     };
215    
216 maya 4378 #define KEX_DEFAULT_KEX ""
217     #define KEX_DEFAULT_PK_ALG ""
218     #define KEX_DEFAULT_ENCRYPT ""
219     #define KEX_DEFAULT_MAC ""
220     #define KEX_DEFAULT_COMP ""
221     #define KEX_DEFAULT_LANG ""
222 maya 3227
223     static char *myproposal[PROPOSAL_MAX] = {
224     KEX_DEFAULT_KEX,
225     KEX_DEFAULT_PK_ALG,
226     KEX_DEFAULT_ENCRYPT,
227     KEX_DEFAULT_ENCRYPT,
228     KEX_DEFAULT_MAC,
229     KEX_DEFAULT_MAC,
230     KEX_DEFAULT_COMP,
231     KEX_DEFAULT_COMP,
232     KEX_DEFAULT_LANG,
233     KEX_DEFAULT_LANG,
234     };
235    
236    
237 maya 4378 typedef enum {
238     KEY_NONE,
239     KEY_RSA1,
240     KEY_RSA,
241     KEY_DSA,
242     KEY_ECDSA256,
243     KEY_ECDSA384,
244     KEY_ECDSA521,
245     KEY_UNSPEC,
246     KEY_MAX = KEY_UNSPEC,
247     } ssh_keytype;
248     #define isECDSAkey(type) ((type) >= KEY_ECDSA256 && (type) <= KEY_ECDSA521)
249    
250     typedef struct ssh2_host_key {
251     ssh_keytype type;
252     char *name;
253     } ssh2_host_key_t;
254    
255     static ssh2_host_key_t ssh2_host_key[] = {
256 maya 4592 {KEY_RSA1, "ssh-rsa1"}, // for SSH1 only
257     {KEY_RSA, "ssh-rsa"}, // RFC4253
258     {KEY_DSA, "ssh-dss"}, // RFC4253
259     {KEY_ECDSA256, "ecdsa-sha2-nistp256"}, // RFC5656
260     {KEY_ECDSA384, "ecdsa-sha2-nistp384"}, // RFC5656
261     {KEY_ECDSA521, "ecdsa-sha2-nistp521"}, // RFC5656
262 maya 4378 {KEY_UNSPEC, "ssh-unknown"},
263     {KEY_NONE, NULL},
264     };
265    
266     /* Minimum modulus size (n) for RSA keys. */
267     #define SSH_RSA_MINIMUM_MODULUS_SIZE 768
268    
269     #define SSH_KEYGEN_DEFAULT_BITS 2048
270     #define SSH_RSA_MINIMUM_KEY_SIZE 768
271     #define SSH_DSA_MINIMUM_KEY_SIZE 1024
272    
273    
274 maya 3227 typedef struct ssh2_cipher {
275     SSHCipher cipher;
276     char *name;
277     int block_size;
278     int key_len;
279     int discard_len;
280     const EVP_CIPHER *(*func)(void);
281     } ssh2_cipher_t;
282    
283     static ssh2_cipher_t ssh2_ciphers[] = {
284 maya 4592 {SSH2_CIPHER_3DES_CBC, "3des-cbc", 8, 24, 0, EVP_des_ede3_cbc}, // RFC4253
285     {SSH2_CIPHER_AES128_CBC, "aes128-cbc", 16, 16, 0, EVP_aes_128_cbc}, // RFC4253
286     {SSH2_CIPHER_AES192_CBC, "aes192-cbc", 16, 24, 0, EVP_aes_192_cbc}, // RFC4253
287     {SSH2_CIPHER_AES256_CBC, "aes256-cbc", 16, 32, 0, EVP_aes_256_cbc}, // RFC4253
288     {SSH2_CIPHER_BLOWFISH_CBC, "blowfish-cbc", 8, 16, 0, EVP_bf_cbc}, // RFC4253
289     {SSH2_CIPHER_AES128_CTR, "aes128-ctr", 16, 16, 0, evp_aes_128_ctr}, // RFC4344
290     {SSH2_CIPHER_AES192_CTR, "aes192-ctr", 16, 24, 0, evp_aes_128_ctr}, // RFC4344
291     {SSH2_CIPHER_AES256_CTR, "aes256-ctr", 16, 32, 0, evp_aes_128_ctr}, // RFC4344
292     {SSH2_CIPHER_ARCFOUR, "arcfour", 8, 16, 0, EVP_rc4}, // RFC4253
293     {SSH2_CIPHER_ARCFOUR128, "arcfour128", 8, 16, 1536, EVP_rc4}, // RFC4345
294     {SSH2_CIPHER_ARCFOUR256, "arcfour256", 8, 32, 1536, EVP_rc4}, // RFC4345
295     {SSH2_CIPHER_CAST128_CBC, "cast128-cbc", 8, 16, 0, EVP_cast5_cbc}, // RFC4253
296     {SSH2_CIPHER_3DES_CTR, "3des-ctr", 8, 24, 0, evp_des3_ctr}, // RFC4344
297     {SSH2_CIPHER_BLOWFISH_CTR, "blowfish-ctr", 8, 16, 0, evp_bf_ctr}, // RFC4344
298     {SSH2_CIPHER_CAST128_CTR, "cast128-ctr", 8, 16, 0, evp_cast5_ctr}, // RFC4344
299     {SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc", 16, 16, 0, EVP_camellia_128_cbc}, // draft-kanno-secsh-camellia-02
300     {SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc", 16, 24, 0, EVP_camellia_192_cbc}, // draft-kanno-secsh-camellia-02
301     {SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc", 16, 32, 0, EVP_camellia_256_cbc}, // draft-kanno-secsh-camellia-02
302     {SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr", 16, 16, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02
303     {SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr", 16, 24, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02
304     {SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr", 16, 32, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02
305 doda 4433 #ifdef WITH_CAMELLIA_PRIVATE
306     {SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc@openssh.org", 16, 16, 0, EVP_camellia_128_cbc},
307     {SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc@openssh.org", 16, 24, 0, EVP_camellia_192_cbc},
308     {SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc@openssh.org", 16, 32, 0, EVP_camellia_256_cbc},
309     {SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr@openssh.org", 16, 16, 0, evp_camellia_128_ctr},
310     {SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr@openssh.org", 16, 24, 0, evp_camellia_128_ctr},
311     {SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr@openssh.org", 16, 32, 0, evp_camellia_128_ctr},
312     #endif // WITH_CAMELLIA_PRIVATE
313 maya 4301 {SSH_CIPHER_NONE, NULL, 0, 0, 0, NULL},
314 maya 3227 };
315    
316    
317 maya 4378 typedef enum {
318 yutakapon 4367 KEX_DH_NONE, /* disabled line */
319 maya 4301 KEX_DH_GRP1_SHA1,
320     KEX_DH_GRP14_SHA1,
321     KEX_DH_GEX_SHA1,
322     KEX_DH_GEX_SHA256,
323 maya 4314 KEX_ECDH_SHA2_256,
324     KEX_ECDH_SHA2_384,
325     KEX_ECDH_SHA2_521,
326 maya 4301 KEX_DH_UNKNOWN,
327 yutakapon 4367 KEX_DH_MAX = KEX_DH_UNKNOWN,
328 maya 4378 } kex_algorithm;
329 maya 4301
330     typedef struct ssh2_kex_algorithm {
331 maya 4378 kex_algorithm kextype;
332 maya 4301 char *name;
333     const EVP_MD *(*evp_md)(void);
334     } ssh2_kex_algorithm_t;
335    
336     static ssh2_kex_algorithm_t ssh2_kex_algorithms[] = {
337 maya 4592 {KEX_DH_GRP1_SHA1, "diffie-hellman-group1-sha1", EVP_sha1}, // RFC4253
338     {KEX_DH_GRP14_SHA1, "diffie-hellman-group14-sha1", EVP_sha1}, // RFC4253
339     {KEX_DH_GEX_SHA1, "diffie-hellman-group-exchange-sha1", EVP_sha1}, // RFC4419
340     {KEX_DH_GEX_SHA256, "diffie-hellman-group-exchange-sha256", EVP_sha256}, // RFC4419
341     {KEX_ECDH_SHA2_256, "ecdh-sha2-nistp256", EVP_sha256}, // RFC5656
342     {KEX_ECDH_SHA2_384, "ecdh-sha2-nistp384", EVP_sha384}, // RFC5656
343     {KEX_ECDH_SHA2_521, "ecdh-sha2-nistp521", EVP_sha512}, // RFC5656
344 maya 4378 {KEX_DH_NONE , NULL, NULL},
345 maya 4301 };
346    
347    
348 maya 4378 typedef enum {
349     HMAC_NONE, /* disabled line */
350 maya 4301 HMAC_SHA1,
351     HMAC_MD5,
352 doda 4422 HMAC_SHA1_96,
353     HMAC_MD5_96,
354 doda 4423 HMAC_RIPEMD160,
355 doda 4425 HMAC_SHA2_256,
356     HMAC_SHA2_256_96,
357     HMAC_SHA2_512,
358     HMAC_SHA2_512_96,
359 yutakapon 4367 HMAC_UNKNOWN,
360     HMAC_MAX = HMAC_UNKNOWN,
361 maya 4378 } hmac_type;
362 maya 4301
363 maya 3227 typedef struct ssh2_mac {
364 maya 4378 hmac_type type;
365 maya 3227 char *name;
366 maya 4378 const EVP_MD *(*evp_md)(void);
367 maya 3227 int truncatebits;
368     } ssh2_mac_t;
369    
370     static ssh2_mac_t ssh2_macs[] = {
371 maya 4592 {HMAC_SHA1, "hmac-sha1", EVP_sha1, 0}, // RFC4253
372     {HMAC_MD5, "hmac-md5", EVP_md5, 0}, // RFC4253
373     {HMAC_SHA1_96, "hmac-sha1-96", EVP_sha1, 96}, // RFC4253
374     {HMAC_MD5_96, "hmac-md5-96", EVP_md5, 96}, // RFC4253
375 doda 4425 {HMAC_RIPEMD160, "hmac-ripemd160@openssh.com", EVP_ripemd160, 0},
376 maya 4592 {HMAC_SHA2_256, "hmac-sha2-256", EVP_sha256, 0}, // draft-dbider-sha2-mac-for-ssh-02
377     {HMAC_SHA2_256_96, "hmac-sha2-256-96", EVP_sha256, 96}, // draft-dbider-sha2-mac-for-ssh-02
378     {HMAC_SHA2_512, "hmac-sha2-512", EVP_sha512, 0}, // draft-dbider-sha2-mac-for-ssh-02
379     {HMAC_SHA2_512_96, "hmac-sha2-512-96", EVP_sha512, 96}, // draft-dbider-sha2-mac-for-ssh-02
380 doda 4425 {HMAC_NONE, NULL, NULL, 0},
381 maya 3227 };
382    
383 maya 4301
384 maya 4378 typedef enum {
385     COMP_NONE, /* disabled line */
386     COMP_NOCOMP,
387 maya 4301 COMP_ZLIB,
388     COMP_DELAYED,
389 yutakapon 4367 COMP_UNKNOWN,
390     COMP_MAX = COMP_UNKNOWN,
391 maya 4378 } compression_type;
392 maya 3227
393 maya 4378 typedef struct ssh2_comp {
394     compression_type type;
395 maya 4301 char *name;
396 maya 4378 } ssh2_comp_t;
397 maya 3227
398 maya 4378 static ssh2_comp_t ssh2_comps[] = {
399 maya 4592 {COMP_NOCOMP, "none"}, // RFC4253
400     {COMP_ZLIB, "zlib"}, // RFC4253
401 maya 4301 {COMP_DELAYED, "zlib@openssh.com"},
402 maya 4378 {COMP_NONE, NULL},
403 maya 4301 };
404    
405    
406 maya 3227 struct Enc {
407     u_char *key;
408     u_char *iv;
409     unsigned int key_len;
410     unsigned int block_size;
411     };
412    
413     struct Mac {
414     char *name;
415     int enabled;
416     const EVP_MD *md;
417     int mac_len;
418     u_char *key;
419     int key_len;
420     };
421    
422     struct Comp {
423     int type;
424     int enabled;
425     char *name;
426     };
427    
428     typedef struct {
429     struct Enc enc;
430     struct Mac mac;
431     struct Comp comp;
432     } Newkeys;
433    
434     #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
435    
436     enum kex_modes {
437     MODE_IN,
438     MODE_OUT,
439     MODE_MAX
440     };
441    
442    
443     // �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka)
444     typedef struct Key {
445     // host key type
446 maya 4378 ssh_keytype type;
447 maya 3227 // SSH2 RSA
448     RSA *rsa;
449     // SSH2 DSA
450     DSA *dsa;
451 maya 4321 // SSH2 ECDSA
452     EC_KEY *ecdsa;
453 maya 3227 // SSH1 RSA
454     int bits;
455     unsigned char *exp;
456     unsigned char *mod;
457     } Key;
458    
459     // fingerprint������
460     enum fp_rep {
461     SSH_FP_HEX,
462     SSH_FP_BUBBLEBABBLE,
463     SSH_FP_RANDOMART
464     };
465    
466 doda 4531 enum fp_type {
467 doda 4539 SSH_FP_MD5,
468 doda 4531 SSH_FP_SHA1,
469 doda 4539 SSH_FP_SHA256
470 doda 4531 };
471    
472 maya 3227 enum scp_dir {
473 r850 3375 TOREMOTE, FROMREMOTE,
474 maya 3227 };
475    
476     /* The packet handler returns TRUE to keep the handler in place,
477     FALSE to remove the handler. */
478     typedef BOOL (* SSHPacketHandler)(PTInstVar pvar);
479    
480     typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem;
481     struct _SSHPacketHandlerItem {
482     SSHPacketHandler handler;
483     /* Circular list of handlers for given message */
484     SSHPacketHandlerItem FAR * next_for_message;
485     SSHPacketHandlerItem FAR * last_for_message;
486     /* Circular list of handlers in set */
487     SSHPacketHandlerItem FAR * next_in_set;
488     int active_for_message;
489     };
490    
491     typedef struct {
492     char FAR * hostname;
493    
494     int server_protocol_flags;
495     char FAR * server_ID;
496    
497     /* This buffer is used to hold the outgoing data, and encrypted in-place
498     here if necessary. */
499     unsigned char FAR * outbuf;
500     long outbuflen;
501     /* This buffer is used by the SSH protocol processing to store uncompressed
502     packet data for compression. User data is never streamed through here;
503     it is compressed directly from the user's buffer. */
504     unsigned char FAR * precompress_outbuf;
505     long precompress_outbuflen;
506     /* this is the length of the packet data, including the type header */
507     long outgoing_packet_len;
508    
509     /* This buffer is used by the SSH protocol processing to store decompressed
510     packet data. User data is never streamed through here; it is decompressed
511     directly to the user's buffer. */
512     unsigned char FAR * postdecompress_inbuf;
513     long postdecompress_inbuflen;
514    
515     unsigned char FAR * payload;
516     long payload_grabbed;
517     long payloadlen;
518     long payload_datastart;
519     long payload_datalen;
520    
521     uint32 receiver_sequence_number;
522     uint32 sender_sequence_number;
523    
524     z_stream compress_stream;
525     z_stream decompress_stream;
526     BOOL compressing;
527     BOOL decompressing;
528     int compression_level;
529    
530     SSHPacketHandlerItem FAR * packet_handlers[256];
531     int status_flags;
532    
533     int win_cols;
534     int win_rows;
535    
536     unsigned short tcpport;
537     } SSHState;
538    
539     #define STATUS_DONT_SEND_USER_NAME 0x01
540     #define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02
541     #define STATUS_DONT_SEND_CREDENTIALS 0x04
542     #define STATUS_HOST_OK 0x08
543     #define STATUS_INTERACTIVE 0x10
544     #define STATUS_IN_PARTIAL_ID_STRING 0x20
545    
546     void SSH_init(PTInstVar pvar);
547     void SSH_open(PTInstVar pvar);
548     void SSH_notify_disconnecting(PTInstVar pvar, char FAR * reason);
549     /* SSH_handle_server_ID returns TRUE iff a valid ID string has been
550     received. If it returns FALSE, we need to keep looking for another
551     ID string. */
552     BOOL SSH_handle_server_ID(PTInstVar pvar, char FAR * ID, int ID_len);
553     /* SSH_handle_packet requires NO PAYLOAD on entry.
554     'len' is the size of the packet: payload + padding (+ CRC for SSHv1)
555     'padding' is the size of the padding.
556     'data' points to the start of the packet data (the length field)
557     */
558     void SSH_handle_packet(PTInstVar pvar, char FAR * data, int len, int padding);
559     void SSH_notify_win_size(PTInstVar pvar, int cols, int rows);
560     void SSH_notify_user_name(PTInstVar pvar);
561     void SSH_notify_cred(PTInstVar pvar);
562     void SSH_notify_host_OK(PTInstVar pvar);
563     void SSH_send(PTInstVar pvar, unsigned char const FAR * buf, unsigned int buflen);
564     /* SSH_extract_payload returns number of bytes extracted */
565     int SSH_extract_payload(PTInstVar pvar, unsigned char FAR * dest, int len);
566     void SSH_end(PTInstVar pvar);
567    
568     void SSH_get_server_ID_info(PTInstVar pvar, char FAR * dest, int len);
569     void SSH_get_protocol_version_info(PTInstVar pvar, char FAR * dest, int len);
570     void SSH_get_compression_info(PTInstVar pvar, char FAR * dest, int len);
571    
572     /* len must be <= SSH_MAX_SEND_PACKET_SIZE */
573     void SSH_channel_send(PTInstVar pvar, int channel_num,
574     uint32 remote_channel_num,
575     unsigned char FAR * buf, int len);
576     void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num);
577     void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
578     void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num);
579     void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
580 maya 3808 void SSH_request_forwarding(PTInstVar pvar, char FAR * bind_address, int from_server_port,
581     char FAR * to_local_host, int to_local_port);
582 maya 3227 void SSH_request_X11_forwarding(PTInstVar pvar,
583     char FAR * auth_protocol, unsigned char FAR * auth_data, int auth_data_len, int screen_num);
584     void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num,
585     char FAR * to_remote_host, int to_remote_port,
586     char FAR * originator, unsigned short originator_port);
587    
588     int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile);
589     int SSH_start_scp_receive(PTInstVar pvar, char *filename);
590     int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction);
591     int SSH_sftp_transaction(PTInstVar pvar);
592    
593     /* auxiliary SSH2 interfaces for pkt.c */
594     int SSH_get_min_packet_size(PTInstVar pvar);
595     /* data is guaranteed to be at least SSH_get_min_packet_size bytes long
596     at least 5 bytes must be decrypted */
597     void SSH_predecrpyt_packet(PTInstVar pvar, char FAR * data);
598     int SSH_get_clear_MAC_size(PTInstVar pvar);
599    
600     #define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0)
601     #define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname)
602     #define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0)
603    
604     void SSH2_send_kexinit(PTInstVar pvar);
605     BOOL do_SSH2_userauth(PTInstVar pvar);
606     BOOL do_SSH2_authrequest(PTInstVar pvar);
607     void debug_print(int no, char *msg, int len);
608     int get_cipher_block_size(SSHCipher cipher);
609     int get_cipher_key_len(SSHCipher cipher);
610 maya 4378 char* get_kex_algorithm_name(kex_algorithm kextype);
611 maya 3227 const EVP_CIPHER* get_cipher_EVP_CIPHER(SSHCipher cipher);
612 maya 4378 const EVP_MD* get_kex_algorithm_EVP_MD(kex_algorithm kextype);
613     char* get_ssh2_mac_name(hmac_type type);
614     const EVP_MD* get_ssh2_mac_EVP_MD(hmac_type type);
615     int get_ssh2_mac_truncatebits(hmac_type type);
616     char* get_ssh2_comp_name(compression_type type);
617     char* get_ssh_keytype_name(ssh_keytype type);
618 maya 3227 int get_cipher_discard_len(SSHCipher cipher);
619     void ssh_heartbeat_lock_initialize(void);
620     void ssh_heartbeat_lock_finalize(void);
621     void ssh_heartbeat_lock(void);
622     void ssh_heartbeat_unlock(void);
623     void halt_ssh_heartbeat_thread(PTInstVar pvar);
624     void ssh2_channel_free(void);
625     BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar);
626 yutakapon 4152 BOOL handle_SSH2_userauth_passwd_changereq(PTInstVar pvar);
627 maya 3227 void SSH2_update_compression_myproposal(PTInstVar pvar);
628     void SSH2_update_cipher_myproposal(PTInstVar pvar);
629 yutakapon 4367 void SSH2_update_kex_myproposal(PTInstVar pvar);
630     void SSH2_update_host_key_myproposal(PTInstVar pvar);
631     void SSH2_update_hmac_myproposal(PTInstVar pvar);
632 yutakapon 4106 int SSH_notify_break_signal(PTInstVar pvar);
633 maya 3227
634 yutakapon 4926 ///
635     enum scp_state {
636     SCP_INIT, SCP_TIMESTAMP, SCP_FILEINFO, SCP_DATA, SCP_CLOSING,
637     };
638    
639     typedef struct bufchain {
640     buffer_t *msg;
641     struct bufchain *next;
642     } bufchain_t;
643    
644     typedef struct scp {
645     enum scp_dir dir; // transfer direction
646     enum scp_state state; // SCP state
647     char localfile[MAX_PATH]; // local filename
648     char localfilefull[MAX_PATH]; // local filename fullpath
649     char remotefile[MAX_PATH]; // remote filename
650     FILE *localfp; // file pointer for local file
651     struct __stat64 filestat; // file status information
652     HWND progress_window;
653     HANDLE thread;
654     unsigned int thread_id;
655     PTInstVar pvar;
656     // for receiving file
657     long long filetotalsize;
658     long long filercvsize;
659     } scp_t;
660    
661     enum sftp_state {
662     SFTP_INIT,
663     };
664    
665     typedef struct sftp {
666     enum sftp_state state;
667 yutakapon 4929 unsigned int transfer_buflen;
668     unsigned int num_requests;
669     unsigned int version;
670     unsigned int msg_id;
671     #define SFTP_EXT_POSIX_RENAME 0x00000001
672     #define SFTP_EXT_STATVFS 0x00000002
673     #define SFTP_EXT_FSTATVFS 0x00000004
674     #define SFTP_EXT_HARDLINK 0x00000008
675     unsigned int exts;
676     unsigned long long limit_kbps;
677     //struct bwlimit bwlimit_in, bwlimit_out;
678 yutakapon 4926 } sftp_t;
679    
680     typedef struct channel {
681     int used;
682     int self_id;
683     int remote_id;
684     unsigned int local_window;
685     unsigned int local_window_max;
686     unsigned int local_consumed;
687     unsigned int local_maxpacket;
688     unsigned int remote_window;
689     unsigned int remote_maxpacket;
690     enum channel_type type;
691     int local_num;
692     bufchain_t *bufchain;
693     scp_t scp;
694     buffer_t *agent_msg;
695     int agent_request_len;
696     sftp_t sftp;
697     } Channel_t;
698    
699     unsigned char FAR *begin_send_packet(PTInstVar pvar, int type, int len);
700     void finish_send_packet_special(PTInstVar pvar, int skip_compress);
701     void SSH2_send_channel_data(PTInstVar pvar, Channel_t *c, unsigned char FAR * buf, unsigned int buflen);
702    
703     #define finish_send_packet(pvar) finish_send_packet_special((pvar), 0)
704     #define get_payload_uint32(pvar, offset) get_uint32_MSBfirst((pvar)->ssh_state.payload + (offset))
705     #define get_uint32(buf) get_uint32_MSBfirst((buf))
706     #define set_uint32(buf, v) set_uint32_MSBfirst((buf), (v))
707     #define get_mpint_len(pvar, offset) ((get_ushort16_MSBfirst((pvar)->ssh_state.payload + (offset)) + 7) >> 3)
708     #define get_ushort16(buf) get_ushort16_MSBfirst((buf))
709     ///
710    
711 maya 3227 #endif

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