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 2800 - (hide annotations) (download) (as text)
Sat Mar 12 15:07:34 2005 UTC (19 years, 1 month ago) by yutakakn
Original Path: ttssh2/trunk/ttxssh/ssh.h
File MIME type: text/x-chdr
File size: 13460 byte(s)
SSH2 keyboard-interactive認証をTISダイアログに実装した。

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

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