Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5545 - (show annotations) (download) (as text)
Mon Mar 17 16:06:58 2014 UTC (10 years ago) by yutakapon
Original Path: trunk/ttssh2/ttxssh/ssh.h
File MIME type: text/x-chdr
File size: 26554 byte(s)
チケット #33263
Curve25519楕円曲線DH(Diffe Hellman)アルゴリズムを使った鍵交換をサポートした。

svn+ssh://svn.sourceforge.jp/svnroot/ttssh2/branches/ssh_ed25519
ブランチからマージ。

現時点でサポートしている機能は下記の通り。

 ・Key Generatorで ED25519 鍵の作成
 ・Key Generatorで RSA/DSA/ECDSA 秘密鍵ファイルに bcrypt KDF を選択可能。
 ・ED25519 による公開鍵認証ログイン
 ・RSA(bcrypt KDF) による公開鍵認証ログイン
 ・DSA(bcrypt KDF) による公開鍵認証ログイン
 ・ECDSA(bcrypt KDF) による公開鍵認証ログイン
 ・Host Keyに ssh-ed25519 のサポート

1 /*
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 #include "config.h"
42 #include <sys/types.h>
43 #include <sys/stat.h>
44
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 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 extern const EVP_CIPHER *evp_camellia_128_ctr(void);
57
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 SSH2_CIPHER_3DES_CTR, SSH2_CIPHER_BLOWFISH_CTR, SSH2_CIPHER_CAST128_CTR,
94 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 } 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 SSH_AUTH_MAX = SSH_AUTH_PAGEANT,
104 } 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 #define SSH2_MSG_KEX_ECDH_INIT 30
155 #define SSH2_MSG_KEX_ECDH_REPLY 31
156
157 #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 // �N���C�A���g�����T�[�o������������
202 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 #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
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 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_ED25519,
246 KEY_UNSPEC,
247 KEY_MAX = KEY_UNSPEC,
248 } ssh_keytype;
249 #define isFixedLengthKey(type) ((type) >= KEY_DSA && (type) <= KEY_ED25519)
250
251 typedef struct ssh2_host_key {
252 ssh_keytype type;
253 char *name;
254 } ssh2_host_key_t;
255
256 static ssh2_host_key_t ssh2_host_key[] = {
257 {KEY_RSA1, "ssh-rsa1"}, // for SSH1 only
258 {KEY_RSA, "ssh-rsa"}, // RFC4253
259 {KEY_DSA, "ssh-dss"}, // RFC4253
260 {KEY_ECDSA256, "ecdsa-sha2-nistp256"}, // RFC5656
261 {KEY_ECDSA384, "ecdsa-sha2-nistp384"}, // RFC5656
262 {KEY_ECDSA521, "ecdsa-sha2-nistp521"}, // RFC5656
263 {KEY_ED25519, "ssh-ed25519"},
264 {KEY_UNSPEC, "ssh-unknown"},
265 {KEY_NONE, NULL},
266 };
267
268 /* Minimum modulus size (n) for RSA keys. */
269 #define SSH_RSA_MINIMUM_MODULUS_SIZE 768
270
271 #define SSH_KEYGEN_DEFAULT_BITS 2048
272 #define SSH_RSA_MINIMUM_KEY_SIZE 768
273 #define SSH_DSA_MINIMUM_KEY_SIZE 1024
274
275
276 typedef struct ssh2_cipher {
277 SSHCipher cipher;
278 char *name;
279 int block_size;
280 int key_len;
281 int discard_len;
282 const EVP_CIPHER *(*func)(void);
283 } ssh2_cipher_t;
284
285 static ssh2_cipher_t ssh2_ciphers[] = {
286 {SSH2_CIPHER_3DES_CBC, "3des-cbc", 8, 24, 0, EVP_des_ede3_cbc}, // RFC4253
287 {SSH2_CIPHER_AES128_CBC, "aes128-cbc", 16, 16, 0, EVP_aes_128_cbc}, // RFC4253
288 {SSH2_CIPHER_AES192_CBC, "aes192-cbc", 16, 24, 0, EVP_aes_192_cbc}, // RFC4253
289 {SSH2_CIPHER_AES256_CBC, "aes256-cbc", 16, 32, 0, EVP_aes_256_cbc}, // RFC4253
290 {SSH2_CIPHER_BLOWFISH_CBC, "blowfish-cbc", 8, 16, 0, EVP_bf_cbc}, // RFC4253
291 {SSH2_CIPHER_AES128_CTR, "aes128-ctr", 16, 16, 0, evp_aes_128_ctr}, // RFC4344
292 {SSH2_CIPHER_AES192_CTR, "aes192-ctr", 16, 24, 0, evp_aes_128_ctr}, // RFC4344
293 {SSH2_CIPHER_AES256_CTR, "aes256-ctr", 16, 32, 0, evp_aes_128_ctr}, // RFC4344
294 {SSH2_CIPHER_ARCFOUR, "arcfour", 8, 16, 0, EVP_rc4}, // RFC4253
295 {SSH2_CIPHER_ARCFOUR128, "arcfour128", 8, 16, 1536, EVP_rc4}, // RFC4345
296 {SSH2_CIPHER_ARCFOUR256, "arcfour256", 8, 32, 1536, EVP_rc4}, // RFC4345
297 {SSH2_CIPHER_CAST128_CBC, "cast128-cbc", 8, 16, 0, EVP_cast5_cbc}, // RFC4253
298 {SSH2_CIPHER_3DES_CTR, "3des-ctr", 8, 24, 0, evp_des3_ctr}, // RFC4344
299 {SSH2_CIPHER_BLOWFISH_CTR, "blowfish-ctr", 8, 16, 0, evp_bf_ctr}, // RFC4344
300 {SSH2_CIPHER_CAST128_CTR, "cast128-ctr", 8, 16, 0, evp_cast5_ctr}, // RFC4344
301 {SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc", 16, 16, 0, EVP_camellia_128_cbc}, // draft-kanno-secsh-camellia-02
302 {SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc", 16, 24, 0, EVP_camellia_192_cbc}, // draft-kanno-secsh-camellia-02
303 {SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc", 16, 32, 0, EVP_camellia_256_cbc}, // draft-kanno-secsh-camellia-02
304 {SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr", 16, 16, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02
305 {SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr", 16, 24, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02
306 {SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr", 16, 32, 0, evp_camellia_128_ctr}, // draft-kanno-secsh-camellia-02
307 #ifdef WITH_CAMELLIA_PRIVATE
308 {SSH2_CIPHER_CAMELLIA128_CBC, "camellia128-cbc@openssh.org", 16, 16, 0, EVP_camellia_128_cbc},
309 {SSH2_CIPHER_CAMELLIA192_CBC, "camellia192-cbc@openssh.org", 16, 24, 0, EVP_camellia_192_cbc},
310 {SSH2_CIPHER_CAMELLIA256_CBC, "camellia256-cbc@openssh.org", 16, 32, 0, EVP_camellia_256_cbc},
311 {SSH2_CIPHER_CAMELLIA128_CTR, "camellia128-ctr@openssh.org", 16, 16, 0, evp_camellia_128_ctr},
312 {SSH2_CIPHER_CAMELLIA192_CTR, "camellia192-ctr@openssh.org", 16, 24, 0, evp_camellia_128_ctr},
313 {SSH2_CIPHER_CAMELLIA256_CTR, "camellia256-ctr@openssh.org", 16, 32, 0, evp_camellia_128_ctr},
314 #endif // WITH_CAMELLIA_PRIVATE
315 {SSH_CIPHER_NONE, NULL, 0, 0, 0, NULL},
316 };
317
318
319 typedef enum {
320 KEX_DH_NONE, /* disabled line */
321 KEX_DH_GRP1_SHA1,
322 KEX_DH_GRP14_SHA1,
323 KEX_DH_GEX_SHA1,
324 KEX_DH_GEX_SHA256,
325 KEX_ECDH_SHA2_256,
326 KEX_ECDH_SHA2_384,
327 KEX_ECDH_SHA2_521,
328 KEX_DH_UNKNOWN,
329 KEX_DH_MAX = KEX_DH_UNKNOWN,
330 } kex_algorithm;
331
332 typedef struct ssh2_kex_algorithm {
333 kex_algorithm kextype;
334 char *name;
335 const EVP_MD *(*evp_md)(void);
336 } ssh2_kex_algorithm_t;
337
338 static ssh2_kex_algorithm_t ssh2_kex_algorithms[] = {
339 {KEX_DH_GRP1_SHA1, "diffie-hellman-group1-sha1", EVP_sha1}, // RFC4253
340 {KEX_DH_GRP14_SHA1, "diffie-hellman-group14-sha1", EVP_sha1}, // RFC4253
341 {KEX_DH_GEX_SHA1, "diffie-hellman-group-exchange-sha1", EVP_sha1}, // RFC4419
342 {KEX_DH_GEX_SHA256, "diffie-hellman-group-exchange-sha256", EVP_sha256}, // RFC4419
343 {KEX_ECDH_SHA2_256, "ecdh-sha2-nistp256", EVP_sha256}, // RFC5656
344 {KEX_ECDH_SHA2_384, "ecdh-sha2-nistp384", EVP_sha384}, // RFC5656
345 {KEX_ECDH_SHA2_521, "ecdh-sha2-nistp521", EVP_sha512}, // RFC5656
346 {KEX_DH_NONE , NULL, NULL},
347 };
348
349
350 typedef enum {
351 HMAC_NONE, /* disabled line */
352 HMAC_SHA1,
353 HMAC_MD5,
354 HMAC_SHA1_96,
355 HMAC_MD5_96,
356 HMAC_RIPEMD160,
357 HMAC_SHA2_256,
358 HMAC_SHA2_256_96,
359 HMAC_SHA2_512,
360 HMAC_SHA2_512_96,
361 HMAC_UNKNOWN,
362 HMAC_MAX = HMAC_UNKNOWN,
363 } hmac_type;
364
365 typedef struct ssh2_mac {
366 hmac_type type;
367 char *name;
368 const EVP_MD *(*evp_md)(void);
369 int truncatebits;
370 } ssh2_mac_t;
371
372 static ssh2_mac_t ssh2_macs[] = {
373 {HMAC_SHA1, "hmac-sha1", EVP_sha1, 0}, // RFC4253
374 {HMAC_MD5, "hmac-md5", EVP_md5, 0}, // RFC4253
375 {HMAC_SHA1_96, "hmac-sha1-96", EVP_sha1, 96}, // RFC4253
376 {HMAC_MD5_96, "hmac-md5-96", EVP_md5, 96}, // RFC4253
377 {HMAC_RIPEMD160, "hmac-ripemd160@openssh.com", EVP_ripemd160, 0},
378 {HMAC_SHA2_256, "hmac-sha2-256", EVP_sha256, 0}, // RFC6668
379 // {HMAC_SHA2_256_96, "hmac-sha2-256-96", EVP_sha256, 96}, // draft-dbider-sha2-mac-for-ssh-05, deleted at 06
380 {HMAC_SHA2_512, "hmac-sha2-512", EVP_sha512, 0}, // RFC6668
381 // {HMAC_SHA2_512_96, "hmac-sha2-512-96", EVP_sha512, 96}, // draft-dbider-sha2-mac-for-ssh-05, deleted at 06
382 {HMAC_NONE, NULL, NULL, 0},
383 };
384
385
386 typedef enum {
387 COMP_NONE, /* disabled line */
388 COMP_NOCOMP,
389 COMP_ZLIB,
390 COMP_DELAYED,
391 COMP_UNKNOWN,
392 COMP_MAX = COMP_UNKNOWN,
393 } compression_type;
394
395 typedef struct ssh2_comp {
396 compression_type type;
397 char *name;
398 } ssh2_comp_t;
399
400 static ssh2_comp_t ssh2_comps[] = {
401 {COMP_NOCOMP, "none"}, // RFC4253
402 {COMP_ZLIB, "zlib"}, // RFC4253
403 {COMP_DELAYED, "zlib@openssh.com"},
404 {COMP_NONE, NULL},
405 };
406
407
408 struct Enc {
409 u_char *key;
410 u_char *iv;
411 unsigned int key_len;
412 unsigned int block_size;
413 };
414
415 struct Mac {
416 char *name;
417 int enabled;
418 const EVP_MD *md;
419 int mac_len;
420 u_char *key;
421 int key_len;
422 };
423
424 struct Comp {
425 int type;
426 int enabled;
427 char *name;
428 };
429
430 typedef struct {
431 struct Enc enc;
432 struct Mac mac;
433 struct Comp comp;
434 } Newkeys;
435
436 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
437
438 enum kex_modes {
439 MODE_IN,
440 MODE_OUT,
441 MODE_MAX
442 };
443
444
445 // �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka)
446 typedef struct Key {
447 // host key type
448 ssh_keytype type;
449 // SSH2 RSA
450 RSA *rsa;
451 // SSH2 DSA
452 DSA *dsa;
453 // SSH2 ECDSA
454 EC_KEY *ecdsa;
455 // SSH1 RSA
456 int bits;
457 unsigned char *exp;
458 unsigned char *mod;
459 // SSH2 ED25519
460 unsigned char *ed25519_sk;
461 unsigned char *ed25519_pk;
462 int bcrypt_kdf;
463 } Key;
464
465 // fingerprint������
466 enum fp_rep {
467 SSH_FP_HEX,
468 SSH_FP_BUBBLEBABBLE,
469 SSH_FP_RANDOMART
470 };
471
472 enum fp_type {
473 SSH_FP_MD5,
474 SSH_FP_SHA1,
475 SSH_FP_SHA256
476 };
477
478 enum scp_dir {
479 TOREMOTE, FROMREMOTE,
480 };
481
482 /* The packet handler returns TRUE to keep the handler in place,
483 FALSE to remove the handler. */
484 typedef BOOL (* SSHPacketHandler)(PTInstVar pvar);
485
486 typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem;
487 struct _SSHPacketHandlerItem {
488 SSHPacketHandler handler;
489 /* Circular list of handlers for given message */
490 SSHPacketHandlerItem FAR * next_for_message;
491 SSHPacketHandlerItem FAR * last_for_message;
492 /* Circular list of handlers in set */
493 SSHPacketHandlerItem FAR * next_in_set;
494 int active_for_message;
495 };
496
497 typedef struct {
498 char FAR * hostname;
499
500 int server_protocol_flags;
501 char FAR * server_ID;
502
503 /* This buffer is used to hold the outgoing data, and encrypted in-place
504 here if necessary. */
505 unsigned char FAR * outbuf;
506 long outbuflen;
507 /* This buffer is used by the SSH protocol processing to store uncompressed
508 packet data for compression. User data is never streamed through here;
509 it is compressed directly from the user's buffer. */
510 unsigned char FAR * precompress_outbuf;
511 long precompress_outbuflen;
512 /* this is the length of the packet data, including the type header */
513 long outgoing_packet_len;
514
515 /* This buffer is used by the SSH protocol processing to store decompressed
516 packet data. User data is never streamed through here; it is decompressed
517 directly to the user's buffer. */
518 unsigned char FAR * postdecompress_inbuf;
519 long postdecompress_inbuflen;
520
521 unsigned char FAR * payload;
522 long payload_grabbed;
523 long payloadlen;
524 long payload_datastart;
525 long payload_datalen;
526
527 uint32 receiver_sequence_number;
528 uint32 sender_sequence_number;
529
530 z_stream compress_stream;
531 z_stream decompress_stream;
532 BOOL compressing;
533 BOOL decompressing;
534 int compression_level;
535
536 SSHPacketHandlerItem FAR * packet_handlers[256];
537 int status_flags;
538
539 int win_cols;
540 int win_rows;
541
542 unsigned short tcpport;
543 } SSHState;
544
545 #define STATUS_DONT_SEND_USER_NAME 0x01
546 #define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02
547 #define STATUS_DONT_SEND_CREDENTIALS 0x04
548 #define STATUS_HOST_OK 0x08
549 #define STATUS_INTERACTIVE 0x10
550 #define STATUS_IN_PARTIAL_ID_STRING 0x20
551
552 void SSH_init(PTInstVar pvar);
553 void SSH_open(PTInstVar pvar);
554 void SSH_notify_disconnecting(PTInstVar pvar, char FAR * reason);
555 /* SSH_handle_server_ID returns TRUE iff a valid ID string has been
556 received. If it returns FALSE, we need to keep looking for another
557 ID string. */
558 BOOL SSH_handle_server_ID(PTInstVar pvar, char FAR * ID, int ID_len);
559 /* SSH_handle_packet requires NO PAYLOAD on entry.
560 'len' is the size of the packet: payload + padding (+ CRC for SSHv1)
561 'padding' is the size of the padding.
562 'data' points to the start of the packet data (the length field)
563 */
564 void SSH_handle_packet(PTInstVar pvar, char FAR * data, int len, int padding);
565 void SSH_notify_win_size(PTInstVar pvar, int cols, int rows);
566 void SSH_notify_user_name(PTInstVar pvar);
567 void SSH_notify_cred(PTInstVar pvar);
568 void SSH_notify_host_OK(PTInstVar pvar);
569 void SSH_send(PTInstVar pvar, unsigned char const FAR * buf, unsigned int buflen);
570 /* SSH_extract_payload returns number of bytes extracted */
571 int SSH_extract_payload(PTInstVar pvar, unsigned char FAR * dest, int len);
572 void SSH_end(PTInstVar pvar);
573
574 void SSH_get_server_ID_info(PTInstVar pvar, char FAR * dest, int len);
575 void SSH_get_protocol_version_info(PTInstVar pvar, char FAR * dest, int len);
576 void SSH_get_compression_info(PTInstVar pvar, char FAR * dest, int len);
577
578 /* len must be <= SSH_MAX_SEND_PACKET_SIZE */
579 void SSH_channel_send(PTInstVar pvar, int channel_num,
580 uint32 remote_channel_num,
581 unsigned char FAR * buf, int len, int retry);
582 void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num);
583 void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
584 void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num);
585 void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
586 void SSH_request_forwarding(PTInstVar pvar, char FAR * bind_address, int from_server_port,
587 char FAR * to_local_host, int to_local_port);
588 void SSH_cancel_request_forwarding(PTInstVar pvar, char FAR * bind_address, int from_server_port, int reply);
589 void SSH_request_X11_forwarding(PTInstVar pvar,
590 char FAR * auth_protocol, unsigned char FAR * auth_data, int auth_data_len, int screen_num);
591 void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num,
592 char FAR * to_remote_host, int to_remote_port,
593 char FAR * originator, unsigned short originator_port);
594
595 int SSH_start_scp(PTInstVar pvar, char *sendfile, char *dstfile);
596 int SSH_start_scp_receive(PTInstVar pvar, char *filename);
597 int SSH_scp_transaction(PTInstVar pvar, char *sendfile, char *dstfile, enum scp_dir direction);
598 int SSH_sftp_transaction(PTInstVar pvar);
599
600 /* auxiliary SSH2 interfaces for pkt.c */
601 int SSH_get_min_packet_size(PTInstVar pvar);
602 /* data is guaranteed to be at least SSH_get_min_packet_size bytes long
603 at least 5 bytes must be decrypted */
604 void SSH_predecrpyt_packet(PTInstVar pvar, char FAR * data);
605 int SSH_get_clear_MAC_size(PTInstVar pvar);
606
607 #define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0)
608 #define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname)
609 #define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0)
610
611 void SSH2_send_kexinit(PTInstVar pvar);
612 BOOL do_SSH2_userauth(PTInstVar pvar);
613 BOOL do_SSH2_authrequest(PTInstVar pvar);
614 void debug_print(int no, char *msg, int len);
615 int get_cipher_block_size(SSHCipher cipher);
616 int get_cipher_key_len(SSHCipher cipher);
617 SSHCipher get_cipher_by_name(char *name);
618 char* get_kex_algorithm_name(kex_algorithm kextype);
619 const EVP_CIPHER* get_cipher_EVP_CIPHER(SSHCipher cipher);
620 const EVP_MD* get_kex_algorithm_EVP_MD(kex_algorithm kextype);
621 char* get_ssh2_mac_name(hmac_type type);
622 const EVP_MD* get_ssh2_mac_EVP_MD(hmac_type type);
623 int get_ssh2_mac_truncatebits(hmac_type type);
624 char* get_ssh2_comp_name(compression_type type);
625 char* get_ssh_keytype_name(ssh_keytype type);
626 int get_cipher_discard_len(SSHCipher cipher);
627 void ssh_heartbeat_lock_initialize(void);
628 void ssh_heartbeat_lock_finalize(void);
629 void ssh_heartbeat_lock(void);
630 void ssh_heartbeat_unlock(void);
631 void halt_ssh_heartbeat_thread(PTInstVar pvar);
632 void ssh2_channel_free(void);
633 BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar);
634 BOOL handle_SSH2_userauth_passwd_changereq(PTInstVar pvar);
635 void SSH2_update_compression_myproposal(PTInstVar pvar);
636 void SSH2_update_cipher_myproposal(PTInstVar pvar);
637 void SSH2_update_kex_myproposal(PTInstVar pvar);
638 void SSH2_update_host_key_myproposal(PTInstVar pvar);
639 void SSH2_update_hmac_myproposal(PTInstVar pvar);
640 int SSH_notify_break_signal(PTInstVar pvar);
641
642 ///
643 enum scp_state {
644 SCP_INIT, SCP_TIMESTAMP, SCP_FILEINFO, SCP_DATA, SCP_CLOSING,
645 };
646
647 typedef struct bufchain {
648 buffer_t *msg;
649 struct bufchain *next;
650 } bufchain_t;
651
652 typedef struct scp {
653 enum scp_dir dir; // transfer direction
654 enum scp_state state; // SCP state
655 char localfile[MAX_PATH]; // local filename
656 char localfilefull[MAX_PATH]; // local filename fullpath
657 char remotefile[MAX_PATH]; // remote filename
658 FILE *localfp; // file pointer for local file
659 struct __stat64 filestat; // file status information
660 HWND progress_window;
661 HANDLE thread;
662 unsigned int thread_id;
663 PTInstVar pvar;
664 // for receiving file
665 long long filetotalsize;
666 long long filercvsize;
667 } scp_t;
668
669 enum sftp_state {
670 SFTP_INIT, SFTP_CONNECTED, SFTP_REALPATH,
671 };
672
673 typedef struct sftp {
674 enum sftp_state state;
675 HWND console_window;
676 unsigned int transfer_buflen;
677 unsigned int num_requests;
678 unsigned int version;
679 unsigned int msg_id;
680 #define SFTP_EXT_POSIX_RENAME 0x00000001
681 #define SFTP_EXT_STATVFS 0x00000002
682 #define SFTP_EXT_FSTATVFS 0x00000004
683 #define SFTP_EXT_HARDLINK 0x00000008
684 unsigned int exts;
685 unsigned long long limit_kbps;
686 //struct bwlimit bwlimit_in, bwlimit_out;
687 char path[1024];
688 } sftp_t;
689
690 typedef struct channel {
691 int used;
692 int self_id;
693 int remote_id;
694 unsigned int local_window;
695 unsigned int local_window_max;
696 unsigned int local_consumed;
697 unsigned int local_maxpacket;
698 unsigned int remote_window;
699 unsigned int remote_maxpacket;
700 enum channel_type type;
701 int local_num;
702 bufchain_t *bufchain;
703 scp_t scp;
704 buffer_t *agent_msg;
705 int agent_request_len;
706 sftp_t sftp;
707 #define SSH_CHANNEL_STATE_CLOSE_SENT 0x00000001
708 unsigned int state;
709 } Channel_t;
710
711 unsigned char FAR *begin_send_packet(PTInstVar pvar, int type, int len);
712 void finish_send_packet_special(PTInstVar pvar, int skip_compress);
713 void SSH2_send_channel_data(PTInstVar pvar, Channel_t *c, unsigned char FAR * buf, unsigned int buflen, int retry);
714
715 #define finish_send_packet(pvar) finish_send_packet_special((pvar), 0)
716 #define get_payload_uint32(pvar, offset) get_uint32_MSBfirst((pvar)->ssh_state.payload + (offset))
717 #define get_uint32(buf) get_uint32_MSBfirst((buf))
718 #define set_uint32(buf, v) set_uint32_MSBfirst((buf), (v))
719 #define get_mpint_len(pvar, offset) ((get_ushort16_MSBfirst((pvar)->ssh_state.payload + (offset)) + 7) >> 3)
720 #define get_ushort16(buf) get_ushort16_MSBfirst((buf))
721 ///
722
723 #endif

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