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 2916 - (show annotations) (download) (as text)
Sat Oct 21 13:32:37 2006 UTC (17 years, 5 months ago) by maya
Original Path: ttssh2/trunk/ttxssh/ssh.h
File MIME type: text/x-chdr
File size: 14454 byte(s)
圧縮アルゴリズムの定数を enum に変更した。

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
41 // yutaka
42 #define SSH2_USE
43
44
45 /* Some of this code has been adapted from Ian Goldberg's Pilot SSH */
46
47 typedef enum {
48 SSH_MSG_NONE, SSH_MSG_DISCONNECT, SSH_SMSG_PUBLIC_KEY, //2
49 SSH_CMSG_SESSION_KEY, SSH_CMSG_USER, SSH_CMSG_AUTH_RHOSTS, // 5
50 SSH_CMSG_AUTH_RSA, SSH_SMSG_AUTH_RSA_CHALLENGE,
51 SSH_CMSG_AUTH_RSA_RESPONSE, SSH_CMSG_AUTH_PASSWORD,
52 SSH_CMSG_REQUEST_PTY, // 10
53 SSH_CMSG_WINDOW_SIZE, SSH_CMSG_EXEC_SHELL,
54 SSH_CMSG_EXEC_CMD, SSH_SMSG_SUCCESS, SSH_SMSG_FAILURE,
55 SSH_CMSG_STDIN_DATA, SSH_SMSG_STDOUT_DATA, SSH_SMSG_STDERR_DATA,
56 SSH_CMSG_EOF, SSH_SMSG_EXITSTATUS,
57 SSH_MSG_CHANNEL_OPEN_CONFIRMATION, SSH_MSG_CHANNEL_OPEN_FAILURE,
58 SSH_MSG_CHANNEL_DATA, SSH_MSG_CHANNEL_INPUT_EOF,
59 SSH_MSG_CHANNEL_OUTPUT_CLOSED, SSH_MSG_OBSOLETED0,
60 SSH_SMSG_X11_OPEN, SSH_CMSG_PORT_FORWARD_REQUEST, SSH_MSG_PORT_OPEN,
61 SSH_CMSG_AGENT_REQUEST_FORWARDING, SSH_SMSG_AGENT_OPEN,
62 SSH_MSG_IGNORE, SSH_CMSG_EXIT_CONFIRMATION,
63 SSH_CMSG_X11_REQUEST_FORWARDING, SSH_CMSG_AUTH_RHOSTS_RSA,
64 SSH_MSG_DEBUG, SSH_CMSG_REQUEST_COMPRESSION,
65 SSH_CMSG_MAX_PACKET_SIZE, SSH_CMSG_AUTH_TIS,
66 SSH_SMSG_AUTH_TIS_CHALLENGE, SSH_CMSG_AUTH_TIS_RESPONSE,
67 SSH_CMSG_AUTH_KERBEROS, SSH_SMSG_AUTH_KERBEROS_RESPONSE
68 } SSHMessage;
69
70 typedef enum {
71 SSH_CIPHER_NONE, SSH_CIPHER_IDEA, SSH_CIPHER_DES, SSH_CIPHER_3DES,
72 SSH_CIPHER_TSS, SSH_CIPHER_RC4, SSH_CIPHER_BLOWFISH,
73 // for SSH2
74 SSH_CIPHER_3DES_CBC, SSH_CIPHER_AES128,
75 } SSHCipher;
76
77 //#define SSH_CIPHER_MAX SSH_CIPHER_BLOWFISH
78 #define SSH_CIPHER_MAX SSH_CIPHER_AES128
79
80 typedef enum {
81 SSH_AUTH_NONE, SSH_AUTH_RHOSTS, SSH_AUTH_RSA, SSH_AUTH_PASSWORD,
82 SSH_AUTH_RHOSTS_RSA, SSH_AUTH_TIS, SSH_AUTH_KERBEROS,
83 // for SSH2
84 SSH_AUTH_DSA,
85 } SSHAuthMethod;
86
87 /* we don't support Kerberos at this time */
88 //#define SSH_AUTH_MAX SSH_AUTH_TIS
89 #define SSH_AUTH_MAX SSH_AUTH_DSA
90
91 typedef enum {
92 SSH_GENERIC_AUTHENTICATION, SSH_TIS_AUTHENTICATION
93 } SSHAuthMode;
94
95 #define SSH_PROTOFLAG_SCREEN_NUMBER 1
96 #define SSH_PROTOFLAG_HOST_IN_FWD_OPEN 2
97
98 #define SSH_MAX_SEND_PACKET_SIZE 250000
99
100
101 /* SSH2 constants */
102
103 /* SSH2 messages */
104 #define SSH2_MSG_DISCONNECT 1
105 #define SSH2_MSG_IGNORE 2
106 #define SSH2_MSG_UNIMPLEMENTED 3
107 #define SSH2_MSG_DEBUG 4
108 #define SSH2_MSG_SERVICE_REQUEST 5
109 #define SSH2_MSG_SERVICE_ACCEPT 6
110
111 #define SSH2_MSG_KEXINIT 20
112 #define SSH2_MSG_NEWKEYS 21
113
114 #define SSH2_MSG_KEXDH_INIT 30
115 #define SSH2_MSG_KEXDH_REPLY 31
116
117 #define SSH2_MSG_KEX_DH_GEX_GROUP 31
118 #define SSH2_MSG_KEX_DH_GEX_INIT 32
119 #define SSH2_MSG_KEX_DH_GEX_REPLY 33
120 #define SSH2_MSG_KEX_DH_GEX_REQUEST 34
121
122 #define SSH2_MSG_USERAUTH_REQUEST 50
123 #define SSH2_MSG_USERAUTH_FAILURE 51
124 #define SSH2_MSG_USERAUTH_SUCCESS 52
125 #define SSH2_MSG_USERAUTH_BANNER 53
126
127 #define SSH2_MSG_USERAUTH_PK_OK 60
128 #define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60
129 #define SSH2_MSG_USERAUTH_INFO_REQUEST 60
130 #define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
131
132 #define SSH2_MSG_GLOBAL_REQUEST 80
133 #define SSH2_MSG_REQUEST_SUCCESS 81
134 #define SSH2_MSG_REQUEST_FAILURE 82
135 #define SSH2_MSG_CHANNEL_OPEN 90
136 #define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91
137 #define SSH2_MSG_CHANNEL_OPEN_FAILURE 92
138 #define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93
139 #define SSH2_MSG_CHANNEL_DATA 94
140 #define SSH2_MSG_CHANNEL_EXTENDED_DATA 95
141 #define SSH2_MSG_CHANNEL_EOF 96
142 #define SSH2_MSG_CHANNEL_CLOSE 97
143 #define SSH2_MSG_CHANNEL_REQUEST 98
144 #define SSH2_MSG_CHANNEL_SUCCESS 99
145 #define SSH2_MSG_CHANNEL_FAILURE 100
146
147 /* SSH2 miscellaneous constants */
148 #define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
149 #define SSH2_DISCONNECT_PROTOCOL_ERROR 2
150 #define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED 3
151 #define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4
152 #define SSH2_DISCONNECT_MAC_ERROR 5
153 #define SSH2_DISCONNECT_COMPRESSION_ERROR 6
154 #define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE 7
155 #define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
156 #define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
157 #define SSH2_DISCONNECT_CONNECTION_LOST 10
158 #define SSH2_DISCONNECT_BY_APPLICATION 11
159
160 #define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED 1
161 #define SSH2_OPEN_CONNECT_FAILED 2
162 #define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE 3
163 #define SSH2_OPEN_RESOURCE_SHORTAGE 4
164
165 // �L�[�����A���S���Y��
166 #define KEX_DH1 "diffie-hellman-group1-sha1"
167 #define KEX_DH14 "diffie-hellman-group14-sha1"
168 #define KEX_DHGEX "diffie-hellman-group-exchange-sha1"
169
170 // support of "Compression delayed" (2006.6.23 maya)
171 enum compression_algorithm {
172 COMP_NONE,
173 COMP_ZLIB,
174 COMP_DELAYED,
175 COMP_UNKNOWN
176 };
177
178 enum kex_exchange {
179 KEX_DH_GRP1_SHA1,
180 KEX_DH_GRP14_SHA1,
181 KEX_DH_GEX_SHA1,
182 KEX_MAX
183 };
184
185 enum hostkey_type {
186 KEY_RSA1,
187 KEY_RSA,
188 KEY_DSA,
189 KEY_UNSPEC,
190 };
191
192 // ���L���C���f�b�N�X�� ssh2_macs[] ���������������B
193 enum hmac_type {
194 HMAC_SHA1,
195 HMAC_MD5,
196 HMAC_UNKNOWN
197 };
198
199 #define KEX_DEFAULT_KEX "diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1"
200
201 #define KEX_DEFAULT_PK_ALG "ssh-rsa,ssh-dss"
202 #define KEX_DEFAULT_ENCRYPT \
203 "aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour," \
204 "aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se," \
205 "aes128-ctr,aes192-ctr,aes256-ctr"
206 #define KEX_DEFAULT_MAC \
207 "hmac-md5,hmac-sha1,hmac-ripemd160," \
208 "hmac-ripemd160@openssh.com," \
209 "hmac-sha1-96,hmac-md5-96"
210 // support of "Compression delayed" (2006.6.23 maya)
211 #define KEX_DEFAULT_COMP "none,zlib@openssh.com,zlib"
212 #define KEX_DEFAULT_LANG ""
213
214 /* Minimum modulus size (n) for RSA keys. */
215 #define SSH_RSA_MINIMUM_MODULUS_SIZE 768
216
217
218 enum kex_init_proposals {
219 PROPOSAL_KEX_ALGS,
220 PROPOSAL_SERVER_HOST_KEY_ALGS,
221 PROPOSAL_ENC_ALGS_CTOS,
222 PROPOSAL_ENC_ALGS_STOC,
223 PROPOSAL_MAC_ALGS_CTOS,
224 PROPOSAL_MAC_ALGS_STOC,
225 PROPOSAL_COMP_ALGS_CTOS,
226 PROPOSAL_COMP_ALGS_STOC,
227 PROPOSAL_LANG_CTOS,
228 PROPOSAL_LANG_STOC,
229 PROPOSAL_MAX
230 };
231
232 struct Enc {
233 u_char *key;
234 u_char *iv;
235 unsigned int key_len;
236 unsigned int block_size;
237 };
238
239 struct Mac {
240 char *name;
241 int enabled;
242 const EVP_MD *md;
243 int mac_len;
244 u_char *key;
245 int key_len;
246 };
247
248 struct Comp {
249 int type;
250 int enabled;
251 char *name;
252 };
253
254 typedef struct {
255 struct Enc enc;
256 struct Mac mac;
257 struct Comp comp;
258 } Newkeys;
259
260 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
261
262 enum kex_modes {
263 MODE_IN,
264 MODE_OUT,
265 MODE_MAX
266 };
267
268
269 // �z�X�g�L�[(SSH1, SSH2����)���f�[�^�\�� (2006.3.21 yutaka)
270 typedef struct Key {
271 // host key type
272 enum hostkey_type type;
273 // SSH2 RSA
274 RSA *rsa;
275 // SSH2 DSA
276 DSA *dsa;
277 // SSH1 RSA
278 int bits;
279 unsigned char *exp;
280 unsigned char *mod;
281 } Key;
282
283
284 /* The packet handler returns TRUE to keep the handler in place,
285 FALSE to remove the handler. */
286 typedef BOOL (* SSHPacketHandler)(PTInstVar pvar);
287
288 typedef struct _SSHPacketHandlerItem SSHPacketHandlerItem;
289 struct _SSHPacketHandlerItem {
290 SSHPacketHandler handler;
291 /* Circular list of handlers for given message */
292 SSHPacketHandlerItem FAR * next_for_message;
293 SSHPacketHandlerItem FAR * last_for_message;
294 /* Circular list of handlers in set */
295 SSHPacketHandlerItem FAR * next_in_set;
296 int active_for_message;
297 };
298
299 typedef struct {
300 char FAR * hostname;
301
302 int server_protocol_flags;
303 char FAR * server_ID;
304
305 /* This buffer is used to hold the outgoing data, and encrypted in-place
306 here if necessary. */
307 unsigned char FAR * outbuf;
308 long outbuflen;
309 /* This buffer is used by the SSH protocol processing to store uncompressed
310 packet data for compression. User data is never streamed through here;
311 it is compressed directly from the user's buffer. */
312 unsigned char FAR * precompress_outbuf;
313 long precompress_outbuflen;
314 /* this is the length of the packet data, including the type header */
315 long outgoing_packet_len;
316
317 /* This buffer is used by the SSH protocol processing to store decompressed
318 packet data. User data is never streamed through here; it is decompressed
319 directly to the user's buffer. */
320 unsigned char FAR * postdecompress_inbuf;
321 long postdecompress_inbuflen;
322
323 unsigned char FAR * payload;
324 long payload_grabbed;
325 long payloadlen;
326 long payload_datastart;
327 long payload_datalen;
328
329 uint32 receiver_sequence_number;
330 uint32 sender_sequence_number;
331
332 z_stream compress_stream;
333 z_stream decompress_stream;
334 BOOL compressing;
335 BOOL decompressing;
336 int compression_level;
337
338 SSHPacketHandlerItem FAR * packet_handlers[256];
339 int status_flags;
340
341 int win_cols;
342 int win_rows;
343 } SSHState;
344
345 #define STATUS_DONT_SEND_USER_NAME 0x01
346 #define STATUS_EXPECTING_COMPRESSION_RESPONSE 0x02
347 #define STATUS_DONT_SEND_CREDENTIALS 0x04
348 #define STATUS_HOST_OK 0x08
349 #define STATUS_INTERACTIVE 0x10
350 #define STATUS_IN_PARTIAL_ID_STRING 0x20
351
352 void SSH_init(PTInstVar pvar);
353 void SSH_open(PTInstVar pvar);
354 void SSH_notify_disconnecting(PTInstVar pvar, char FAR * reason);
355 /* SSH_handle_server_ID returns TRUE iff a valid ID string has been
356 received. If it returns FALSE, we need to keep looking for another
357 ID string. */
358 BOOL SSH_handle_server_ID(PTInstVar pvar, char FAR * ID, int ID_len);
359 /* SSH_handle_packet requires NO PAYLOAD on entry.
360 'len' is the size of the packet: payload + padding (+ CRC for SSHv1)
361 'padding' is the size of the padding.
362 'data' points to the start of the packet data (the length field)
363 */
364 void SSH_handle_packet(PTInstVar pvar, char FAR * data, int len, int padding);
365 void SSH_notify_win_size(PTInstVar pvar, int cols, int rows);
366 void SSH_notify_user_name(PTInstVar pvar);
367 void SSH_notify_cred(PTInstVar pvar);
368 void SSH_notify_host_OK(PTInstVar pvar);
369 void SSH_send(PTInstVar pvar, unsigned char const FAR * buf, int buflen);
370 /* SSH_extract_payload returns number of bytes extracted */
371 int SSH_extract_payload(PTInstVar pvar, unsigned char FAR * dest, int len);
372 void SSH_end(PTInstVar pvar);
373
374 void SSH_get_server_ID_info(PTInstVar pvar, char FAR * dest, int len);
375 void SSH_get_protocol_version_info(PTInstVar pvar, char FAR * dest, int len);
376 void SSH_get_compression_info(PTInstVar pvar, char FAR * dest, int len);
377
378 /* len must be <= SSH_MAX_SEND_PACKET_SIZE */
379 void SSH_channel_send(PTInstVar pvar, int channel_num,
380 uint32 remote_channel_num,
381 unsigned char FAR * buf, int len);
382 void SSH_fail_channel_open(PTInstVar pvar, uint32 remote_channel_num);
383 void SSH_confirm_channel_open(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
384 void SSH_channel_output_eof(PTInstVar pvar, uint32 remote_channel_num);
385 void SSH_channel_input_eof(PTInstVar pvar, uint32 remote_channel_num, uint32 local_channel_num);
386 void SSH_request_forwarding(PTInstVar pvar, int from_server_port,
387 char FAR * to_local_host, int to_local_port);
388 void SSH_request_X11_forwarding(PTInstVar pvar,
389 char FAR * auth_protocol, unsigned char FAR * auth_data, int auth_data_len, int screen_num);
390 void SSH_open_channel(PTInstVar pvar, uint32 local_channel_num,
391 char FAR * to_remote_host, int to_remote_port,
392 char FAR * originator, unsigned short originator_port);
393
394 /* auxiliary SSH2 interfaces for pkt.c */
395 int SSH_get_min_packet_size(PTInstVar pvar);
396 /* data is guaranteed to be at least SSH_get_min_packet_size bytes long
397 at least 5 bytes must be decrypted */
398 void SSH_predecrpyt_packet(PTInstVar pvar, char FAR * data);
399 int SSH_get_clear_MAC_size(PTInstVar pvar);
400
401 #define SSH_is_any_payload(pvar) ((pvar)->ssh_state.payload_datalen > 0)
402 #define SSH_get_host_name(pvar) ((pvar)->ssh_state.hostname)
403 #define SSH_get_compression_level(pvar) ((pvar)->ssh_state.compressing ? (pvar)->ts_SSH_CompressionLevel : 0)
404
405 void SSH2_send_kexinit(PTInstVar pvar);
406 BOOL do_SSH2_userauth(PTInstVar pvar);
407 void debug_print(int no, char *msg, int len);
408 void ssh_heartbeat_lock_initialize(void);
409 void ssh_heartbeat_lock_finalize(void);
410 void ssh_heartbeat_lock(void);
411 void ssh_heartbeat_unlock(void);
412 void halt_ssh_heartbeat_thread(PTInstVar pvar);
413 void ssh2_channel_free(void);
414 BOOL handle_SSH2_userauth_inforeq(PTInstVar pvar);
415 void SSH2_update_compression_myproposal(PTInstVar pvar);
416 void SSH2_update_cipher_myproposal(PTInstVar pvar);
417
418 enum hostkey_type get_keytype_from_name(char *name);
419 char *get_sshname_from_key(Key *key);
420 int key_to_blob(Key *key, char **blobp, int *lenp);
421 Key *key_from_blob(char *data, int blen);
422 void key_free(Key *key);
423 RSA *duplicate_RSA(RSA *src);
424 DSA *duplicate_DSA(DSA *src);
425 char *key_fingerprint(Key *key);
426
427 #endif

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