]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - ssh.h
Refactor ssh.c's APIs to x11fwd.c and portfwd.c.
[PuTTY.git] / ssh.h
1 #include <stdio.h>
2 #include <string.h>
3
4 #include "puttymem.h"
5 #include "tree234.h"
6 #include "network.h"
7 #include "int64.h"
8 #include "misc.h"
9
10 struct ssh_channel;
11
12 extern int sshfwd_write(struct ssh_channel *c, char *, int);
13 extern void sshfwd_write_eof(struct ssh_channel *c);
14 extern void sshfwd_unclean_close(struct ssh_channel *c, const char *err);
15 extern void sshfwd_unthrottle(struct ssh_channel *c, int bufsize);
16
17 /*
18  * Useful thing.
19  */
20 #ifndef lenof
21 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
22 #endif
23
24 #define SSH_CIPHER_IDEA         1
25 #define SSH_CIPHER_DES          2
26 #define SSH_CIPHER_3DES         3
27 #define SSH_CIPHER_BLOWFISH     6
28
29 #ifdef MSCRYPTOAPI
30 #define APIEXTRA 8
31 #else
32 #define APIEXTRA 0
33 #endif
34
35 #ifndef BIGNUM_INTERNAL
36 typedef void *Bignum;
37 #endif
38
39 struct RSAKey {
40     int bits;
41     int bytes;
42 #ifdef MSCRYPTOAPI
43     unsigned long exponent;
44     unsigned char *modulus;
45 #else
46     Bignum modulus;
47     Bignum exponent;
48     Bignum private_exponent;
49     Bignum p;
50     Bignum q;
51     Bignum iqmp;
52 #endif
53     char *comment;
54 };
55
56 struct dss_key {
57     Bignum p, q, g, y, x;
58 };
59
60 int makekey(unsigned char *data, int len, struct RSAKey *result,
61             unsigned char **keystr, int order);
62 int makeprivate(unsigned char *data, int len, struct RSAKey *result);
63 int rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
64 Bignum rsadecrypt(Bignum input, struct RSAKey *key);
65 void rsasign(unsigned char *data, int length, struct RSAKey *key);
66 void rsasanitise(struct RSAKey *key);
67 int rsastr_len(struct RSAKey *key);
68 void rsastr_fmt(char *str, struct RSAKey *key);
69 void rsa_fingerprint(char *str, int len, struct RSAKey *key);
70 int rsa_verify(struct RSAKey *key);
71 unsigned char *rsa_public_blob(struct RSAKey *key, int *len);
72 int rsa_public_blob_len(void *data, int maxlen);
73 void freersakey(struct RSAKey *key);
74
75 #ifndef PUTTY_UINT32_DEFINED
76 /* This makes assumptions about the int type. */
77 typedef unsigned int uint32;
78 #define PUTTY_UINT32_DEFINED
79 #endif
80 typedef uint32 word32;
81
82 unsigned long crc32_compute(const void *s, size_t len);
83 unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
84
85 /* SSH CRC compensation attack detector */
86 void *crcda_make_context(void);
87 void crcda_free_context(void *handle);
88 int detect_attack(void *handle, unsigned char *buf, uint32 len,
89                   unsigned char *IV);
90
91 /*
92  * SSH2 RSA key exchange functions
93  */
94 struct ssh_hash;
95 void *ssh_rsakex_newkey(char *data, int len);
96 void ssh_rsakex_freekey(void *key);
97 int ssh_rsakex_klen(void *key);
98 void ssh_rsakex_encrypt(const struct ssh_hash *h, unsigned char *in, int inlen,
99                         unsigned char *out, int outlen,
100                         void *key);
101
102 typedef struct {
103     uint32 h[4];
104 } MD5_Core_State;
105
106 struct MD5Context {
107 #ifdef MSCRYPTOAPI
108     unsigned long hHash;
109 #else
110     MD5_Core_State core;
111     unsigned char block[64];
112     int blkused;
113     uint32 lenhi, lenlo;
114 #endif
115 };
116
117 void MD5Init(struct MD5Context *context);
118 void MD5Update(struct MD5Context *context, unsigned char const *buf,
119                unsigned len);
120 void MD5Final(unsigned char digest[16], struct MD5Context *context);
121 void MD5Simple(void const *p, unsigned len, unsigned char output[16]);
122
123 void *hmacmd5_make_context(void);
124 void hmacmd5_free_context(void *handle);
125 void hmacmd5_key(void *handle, void const *key, int len);
126 void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len,
127                      unsigned char *hmac);
128
129 typedef struct {
130     uint32 h[5];
131     unsigned char block[64];
132     int blkused;
133     uint32 lenhi, lenlo;
134 } SHA_State;
135 void SHA_Init(SHA_State * s);
136 void SHA_Bytes(SHA_State * s, const void *p, int len);
137 void SHA_Final(SHA_State * s, unsigned char *output);
138 void SHA_Simple(const void *p, int len, unsigned char *output);
139
140 void hmac_sha1_simple(void *key, int keylen, void *data, int datalen,
141                       unsigned char *output);
142 typedef struct {
143     uint32 h[8];
144     unsigned char block[64];
145     int blkused;
146     uint32 lenhi, lenlo;
147 } SHA256_State;
148 void SHA256_Init(SHA256_State * s);
149 void SHA256_Bytes(SHA256_State * s, const void *p, int len);
150 void SHA256_Final(SHA256_State * s, unsigned char *output);
151 void SHA256_Simple(const void *p, int len, unsigned char *output);
152
153 typedef struct {
154     uint64 h[8];
155     unsigned char block[128];
156     int blkused;
157     uint32 len[4];
158 } SHA512_State;
159 void SHA512_Init(SHA512_State * s);
160 void SHA512_Bytes(SHA512_State * s, const void *p, int len);
161 void SHA512_Final(SHA512_State * s, unsigned char *output);
162 void SHA512_Simple(const void *p, int len, unsigned char *output);
163
164 struct ssh_cipher {
165     void *(*make_context)(void);
166     void (*free_context)(void *);
167     void (*sesskey) (void *, unsigned char *key);       /* for SSH-1 */
168     void (*encrypt) (void *, unsigned char *blk, int len);
169     void (*decrypt) (void *, unsigned char *blk, int len);
170     int blksize;
171     char *text_name;
172 };
173
174 struct ssh2_cipher {
175     void *(*make_context)(void);
176     void (*free_context)(void *);
177     void (*setiv) (void *, unsigned char *key); /* for SSH-2 */
178     void (*setkey) (void *, unsigned char *key);/* for SSH-2 */
179     void (*encrypt) (void *, unsigned char *blk, int len);
180     void (*decrypt) (void *, unsigned char *blk, int len);
181     char *name;
182     int blksize;
183     int keylen;
184     unsigned int flags;
185 #define SSH_CIPHER_IS_CBC       1
186     char *text_name;
187 };
188
189 struct ssh2_ciphers {
190     int nciphers;
191     const struct ssh2_cipher *const *list;
192 };
193
194 struct ssh_mac {
195     void *(*make_context)(void);
196     void (*free_context)(void *);
197     void (*setkey) (void *, unsigned char *key);
198     /* whole-packet operations */
199     void (*generate) (void *, unsigned char *blk, int len, unsigned long seq);
200     int (*verify) (void *, unsigned char *blk, int len, unsigned long seq);
201     /* partial-packet operations */
202     void (*start) (void *);
203     void (*bytes) (void *, unsigned char const *, int);
204     void (*genresult) (void *, unsigned char *);
205     int (*verresult) (void *, unsigned char const *);
206     char *name;
207     int len;
208     char *text_name;
209 };
210
211 struct ssh_hash {
212     void *(*init)(void); /* also allocates context */
213     void (*bytes)(void *, void *, int);
214     void (*final)(void *, unsigned char *); /* also frees context */
215     int hlen; /* output length in bytes */
216     char *text_name;
217 };   
218
219 struct ssh_kex {
220     char *name, *groupname;
221     enum { KEXTYPE_DH, KEXTYPE_RSA } main_type;
222     /* For DH */
223     const unsigned char *pdata, *gdata; /* NULL means group exchange */
224     int plen, glen;
225     const struct ssh_hash *hash;
226 };
227
228 struct ssh_kexes {
229     int nkexes;
230     const struct ssh_kex *const *list;
231 };
232
233 struct ssh_signkey {
234     void *(*newkey) (char *data, int len);
235     void (*freekey) (void *key);
236     char *(*fmtkey) (void *key);
237     unsigned char *(*public_blob) (void *key, int *len);
238     unsigned char *(*private_blob) (void *key, int *len);
239     void *(*createkey) (unsigned char *pub_blob, int pub_len,
240                         unsigned char *priv_blob, int priv_len);
241     void *(*openssh_createkey) (unsigned char **blob, int *len);
242     int (*openssh_fmtkey) (void *key, unsigned char *blob, int len);
243     int (*pubkey_bits) (void *blob, int len);
244     char *(*fingerprint) (void *key);
245     int (*verifysig) (void *key, char *sig, int siglen,
246                       char *data, int datalen);
247     unsigned char *(*sign) (void *key, char *data, int datalen,
248                             int *siglen);
249     char *name;
250     char *keytype;                     /* for host key cache */
251 };
252
253 struct ssh_compress {
254     char *name;
255     /* For zlib@openssh.com: if non-NULL, this name will be considered once
256      * userauth has completed successfully. */
257     char *delayed_name;
258     void *(*compress_init) (void);
259     void (*compress_cleanup) (void *);
260     int (*compress) (void *, unsigned char *block, int len,
261                      unsigned char **outblock, int *outlen);
262     void *(*decompress_init) (void);
263     void (*decompress_cleanup) (void *);
264     int (*decompress) (void *, unsigned char *block, int len,
265                        unsigned char **outblock, int *outlen);
266     int (*disable_compression) (void *);
267     char *text_name;
268 };
269
270 struct ssh2_userkey {
271     const struct ssh_signkey *alg;     /* the key algorithm */
272     void *data;                        /* the key data */
273     char *comment;                     /* the key comment */
274 };
275
276 /* The maximum length of any hash algorithm used in kex. (bytes) */
277 #define SSH2_KEX_MAX_HASH_LEN (32) /* SHA-256 */
278
279 extern const struct ssh_cipher ssh_3des;
280 extern const struct ssh_cipher ssh_des;
281 extern const struct ssh_cipher ssh_blowfish_ssh1;
282 extern const struct ssh2_ciphers ssh2_3des;
283 extern const struct ssh2_ciphers ssh2_des;
284 extern const struct ssh2_ciphers ssh2_aes;
285 extern const struct ssh2_ciphers ssh2_blowfish;
286 extern const struct ssh2_ciphers ssh2_arcfour;
287 extern const struct ssh_hash ssh_sha1;
288 extern const struct ssh_hash ssh_sha256;
289 extern const struct ssh_kexes ssh_diffiehellman_group1;
290 extern const struct ssh_kexes ssh_diffiehellman_group14;
291 extern const struct ssh_kexes ssh_diffiehellman_gex;
292 extern const struct ssh_kexes ssh_rsa_kex;
293 extern const struct ssh_signkey ssh_dss;
294 extern const struct ssh_signkey ssh_rsa;
295 extern const struct ssh_mac ssh_hmac_md5;
296 extern const struct ssh_mac ssh_hmac_sha1;
297 extern const struct ssh_mac ssh_hmac_sha1_buggy;
298 extern const struct ssh_mac ssh_hmac_sha1_96;
299 extern const struct ssh_mac ssh_hmac_sha1_96_buggy;
300 extern const struct ssh_mac ssh_hmac_sha256;
301
302 void *aes_make_context(void);
303 void aes_free_context(void *handle);
304 void aes128_key(void *handle, unsigned char *key);
305 void aes192_key(void *handle, unsigned char *key);
306 void aes256_key(void *handle, unsigned char *key);
307 void aes_iv(void *handle, unsigned char *iv);
308 void aes_ssh2_encrypt_blk(void *handle, unsigned char *blk, int len);
309 void aes_ssh2_decrypt_blk(void *handle, unsigned char *blk, int len);
310
311 /*
312  * PuTTY version number formatted as an SSH version string. 
313  */
314 extern char sshver[];
315
316 /*
317  * Gross hack: pscp will try to start SFTP but fall back to scp1 if
318  * that fails. This variable is the means by which scp.c can reach
319  * into the SSH code and find out which one it got.
320  */
321 extern int ssh_fallback_cmd(void *handle);
322
323 #ifndef MSCRYPTOAPI
324 void SHATransform(word32 * digest, word32 * data);
325 #endif
326
327 int random_byte(void);
328 void random_add_noise(void *noise, int length);
329 void random_add_heavynoise(void *noise, int length);
330
331 void logevent(void *, const char *);
332
333 struct PortForwarding;
334
335 /* Allocate and register a new channel for port forwarding */
336 void *new_sock_channel(void *handle, struct PortForwarding *pf);
337 void ssh_send_port_open(void *channel, char *hostname, int port, char *org);
338
339 /* Exports from portfwd.c */
340 extern char *pfd_connect(struct PortForwarding **pf, char *hostname, int port,
341                          void *c, Conf *conf, int addressfamily);
342 extern void pfd_close(struct PortForwarding *);
343 extern int pfd_send(struct PortForwarding *, char *data, int len);
344 extern void pfd_send_eof(struct PortForwarding *);
345 extern void pfd_confirm(struct PortForwarding *);
346 extern void pfd_unthrottle(struct PortForwarding *);
347 extern void pfd_override_throttle(struct PortForwarding *, int enable);
348 struct PortListener;
349 /* desthost == NULL indicates dynamic (SOCKS) port forwarding */
350 extern char *pfl_listen(char *desthost, int destport, char *srcaddr,
351                         int port, void *backhandle, Conf *conf,
352                         struct PortListener **pl, int address_family);
353 extern void pfl_terminate(struct PortListener *);
354
355 /* Exports from x11fwd.c */
356 enum {
357     X11_TRANS_IPV4 = 0, X11_TRANS_IPV6 = 6, X11_TRANS_UNIX = 256
358 };
359 struct X11Display {
360     /* Broken-down components of the display name itself */
361     int unixdomain;
362     char *hostname;
363     int displaynum;
364     int screennum;
365     /* OSX sometimes replaces all the above with a full Unix-socket pathname */
366     char *unixsocketpath;
367
368     /* PuTTY networking SockAddr to connect to the display, and associated
369      * gubbins */
370     SockAddr addr;
371     int port;
372     char *realhost;
373
374     /* Auth details we invented for the virtual display on the SSH server. */
375     int remoteauthproto;
376     unsigned char *remoteauthdata;
377     int remoteauthdatalen;
378     char *remoteauthprotoname;
379     char *remoteauthdatastring;
380
381     /* Our local auth details for talking to the real X display. */
382     int localauthproto;
383     unsigned char *localauthdata;
384     int localauthdatalen;
385
386     /*
387      * Used inside x11fwd.c to remember recently seen
388      * XDM-AUTHORIZATION-1 strings, to avoid replay attacks.
389      */
390     tree234 *xdmseen;
391 };
392 /*
393  * x11_setup_display() parses the display variable and fills in an
394  * X11Display structure. Some remote auth details are invented;
395  * the supplied authtype parameter configures the preferred
396  * authorisation protocol to use at the remote end. The local auth
397  * details are looked up by calling platform_get_x11_auth.
398  */
399 extern struct X11Display *x11_setup_display(char *display, int authtype,
400                                             Conf *);
401 void x11_free_display(struct X11Display *disp);
402 struct X11Connection;                  /* opaque outside x11fwd.c */
403 extern char *x11_init(struct X11Connection **, struct X11Display *,
404                       void *, const char *, int, Conf *);
405 extern void x11_close(struct X11Connection *);
406 extern int x11_send(struct X11Connection *, char *, int);
407 extern void x11_send_eof(struct X11Connection *s);
408 extern void x11_unthrottle(struct X11Connection *s);
409 extern void x11_override_throttle(struct X11Connection *s, int enable);
410 char *x11_display(const char *display);
411 /* Platform-dependent X11 functions */
412 extern void platform_get_x11_auth(struct X11Display *display, Conf *);
413     /* examine a mostly-filled-in X11Display and fill in localauth* */
414 extern const int platform_uses_x11_unix_by_default;
415     /* choose default X transport in the absence of a specified one */
416 SockAddr platform_get_x11_unix_address(const char *path, int displaynum);
417     /* make up a SockAddr naming the address for displaynum */
418 char *platform_get_x_display(void);
419     /* allocated local X display string, if any */
420 /* Callbacks in x11.c usable _by_ platform X11 functions */
421 /*
422  * This function does the job of platform_get_x11_auth, provided
423  * it is told where to find a normally formatted .Xauthority file:
424  * it opens that file, parses it to find an auth record which
425  * matches the display details in "display", and fills in the
426  * localauth fields.
427  *
428  * It is expected that most implementations of
429  * platform_get_x11_auth() will work by finding their system's
430  * .Xauthority file, adjusting the display details if necessary
431  * for local oddities like Unix-domain socket transport, and
432  * calling this function to do the rest of the work.
433  */
434 void x11_get_auth_from_authfile(struct X11Display *display,
435                                 const char *authfilename);
436
437 Bignum copybn(Bignum b);
438 Bignum bn_power_2(int n);
439 void bn_restore_invariant(Bignum b);
440 Bignum bignum_from_long(unsigned long n);
441 void freebn(Bignum b);
442 Bignum modpow(Bignum base, Bignum exp, Bignum mod);
443 Bignum modmul(Bignum a, Bignum b, Bignum mod);
444 void decbn(Bignum n);
445 extern Bignum Zero, One;
446 Bignum bignum_from_bytes(const unsigned char *data, int nbytes);
447 int ssh1_read_bignum(const unsigned char *data, int len, Bignum * result);
448 int bignum_bitcount(Bignum bn);
449 int ssh1_bignum_length(Bignum bn);
450 int ssh2_bignum_length(Bignum bn);
451 int bignum_byte(Bignum bn, int i);
452 int bignum_bit(Bignum bn, int i);
453 void bignum_set_bit(Bignum bn, int i, int value);
454 int ssh1_write_bignum(void *data, Bignum bn);
455 Bignum biggcd(Bignum a, Bignum b);
456 unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
457 Bignum bignum_add_long(Bignum number, unsigned long addend);
458 Bignum bigadd(Bignum a, Bignum b);
459 Bignum bigsub(Bignum a, Bignum b);
460 Bignum bigmul(Bignum a, Bignum b);
461 Bignum bigmuladd(Bignum a, Bignum b, Bignum addend);
462 Bignum bigdiv(Bignum a, Bignum b);
463 Bignum bigmod(Bignum a, Bignum b);
464 Bignum modinv(Bignum number, Bignum modulus);
465 Bignum bignum_bitmask(Bignum number);
466 Bignum bignum_rshift(Bignum number, int shift);
467 int bignum_cmp(Bignum a, Bignum b);
468 char *bignum_decimal(Bignum x);
469
470 #ifdef DEBUG
471 void diagbn(char *prefix, Bignum md);
472 #endif
473
474 void *dh_setup_group(const struct ssh_kex *kex);
475 void *dh_setup_gex(Bignum pval, Bignum gval);
476 void dh_cleanup(void *);
477 Bignum dh_create_e(void *, int nbits);
478 Bignum dh_find_K(void *, Bignum f);
479
480 int loadrsakey(const Filename *filename, struct RSAKey *key,
481                char *passphrase, const char **errorstr);
482 int rsakey_encrypted(const Filename *filename, char **comment);
483 int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen,
484                    char **commentptr, const char **errorstr);
485
486 int saversakey(const Filename *filename, struct RSAKey *key, char *passphrase);
487
488 extern int base64_decode_atom(char *atom, unsigned char *out);
489 extern int base64_lines(int datalen);
490 extern void base64_encode_atom(unsigned char *data, int n, char *out);
491 extern void base64_encode(FILE *fp, unsigned char *data, int datalen, int cpl);
492
493 /* ssh2_load_userkey can return this as an error */
494 extern struct ssh2_userkey ssh2_wrong_passphrase;
495 #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
496
497 int ssh2_userkey_encrypted(const Filename *filename, char **comment);
498 struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
499                                        char *passphrase, const char **errorstr);
500 unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
501                                     int *pub_blob_len, char **commentptr,
502                                     const char **errorstr);
503 int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
504                       char *passphrase);
505 const struct ssh_signkey *find_pubkey_alg(const char *name);
506
507 enum {
508     SSH_KEYTYPE_UNOPENABLE,
509     SSH_KEYTYPE_UNKNOWN,
510     SSH_KEYTYPE_SSH1, SSH_KEYTYPE_SSH2,
511     SSH_KEYTYPE_OPENSSH, SSH_KEYTYPE_SSHCOM
512 };
513 int key_type(const Filename *filename);
514 char *key_type_to_str(int type);
515
516 int import_possible(int type);
517 int import_target_type(int type);
518 int import_encrypted(const Filename *filename, int type, char **comment);
519 int import_ssh1(const Filename *filename, int type,
520                 struct RSAKey *key, char *passphrase, const char **errmsg_p);
521 struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
522                                  char *passphrase, const char **errmsg_p);
523 int export_ssh1(const Filename *filename, int type,
524                 struct RSAKey *key, char *passphrase);
525 int export_ssh2(const Filename *filename, int type,
526                 struct ssh2_userkey *key, char *passphrase);
527
528 void des3_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
529 void des3_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
530 void des3_decrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
531                               unsigned char *blk, int len);
532 void des3_encrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
533                               unsigned char *blk, int len);
534 void aes256_encrypt_pubkey(unsigned char *key, unsigned char *blk,
535                            int len);
536 void aes256_decrypt_pubkey(unsigned char *key, unsigned char *blk,
537                            int len);
538
539 void des_encrypt_xdmauth(unsigned char *key, unsigned char *blk, int len);
540 void des_decrypt_xdmauth(unsigned char *key, unsigned char *blk, int len);
541
542 /*
543  * For progress updates in the key generation utility.
544  */
545 #define PROGFN_INITIALISE 1
546 #define PROGFN_LIN_PHASE 2
547 #define PROGFN_EXP_PHASE 3
548 #define PROGFN_PHASE_EXTENT 4
549 #define PROGFN_READY 5
550 #define PROGFN_PROGRESS 6
551 typedef void (*progfn_t) (void *param, int action, int phase, int progress);
552
553 int rsa_generate(struct RSAKey *key, int bits, progfn_t pfn,
554                  void *pfnparam);
555 int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
556                  void *pfnparam);
557 Bignum primegen(int bits, int modulus, int residue, Bignum factor,
558                 int phase, progfn_t pfn, void *pfnparam, unsigned firstbits);
559 void invent_firstbits(unsigned *one, unsigned *two);
560
561
562 /*
563  * zlib compression.
564  */
565 void *zlib_compress_init(void);
566 void zlib_compress_cleanup(void *);
567 void *zlib_decompress_init(void);
568 void zlib_decompress_cleanup(void *);
569 int zlib_compress_block(void *, unsigned char *block, int len,
570                         unsigned char **outblock, int *outlen);
571 int zlib_decompress_block(void *, unsigned char *block, int len,
572                           unsigned char **outblock, int *outlen);
573
574 /*
575  * SSH-1 message type codes.
576  */
577 #define SSH1_MSG_DISCONNECT                       1     /* 0x1 */
578 #define SSH1_SMSG_PUBLIC_KEY                      2     /* 0x2 */
579 #define SSH1_CMSG_SESSION_KEY                     3     /* 0x3 */
580 #define SSH1_CMSG_USER                            4     /* 0x4 */
581 #define SSH1_CMSG_AUTH_RSA                        6     /* 0x6 */
582 #define SSH1_SMSG_AUTH_RSA_CHALLENGE              7     /* 0x7 */
583 #define SSH1_CMSG_AUTH_RSA_RESPONSE               8     /* 0x8 */
584 #define SSH1_CMSG_AUTH_PASSWORD                   9     /* 0x9 */
585 #define SSH1_CMSG_REQUEST_PTY                     10    /* 0xa */
586 #define SSH1_CMSG_WINDOW_SIZE                     11    /* 0xb */
587 #define SSH1_CMSG_EXEC_SHELL                      12    /* 0xc */
588 #define SSH1_CMSG_EXEC_CMD                        13    /* 0xd */
589 #define SSH1_SMSG_SUCCESS                         14    /* 0xe */
590 #define SSH1_SMSG_FAILURE                         15    /* 0xf */
591 #define SSH1_CMSG_STDIN_DATA                      16    /* 0x10 */
592 #define SSH1_SMSG_STDOUT_DATA                     17    /* 0x11 */
593 #define SSH1_SMSG_STDERR_DATA                     18    /* 0x12 */
594 #define SSH1_CMSG_EOF                             19    /* 0x13 */
595 #define SSH1_SMSG_EXIT_STATUS                     20    /* 0x14 */
596 #define SSH1_MSG_CHANNEL_OPEN_CONFIRMATION        21    /* 0x15 */
597 #define SSH1_MSG_CHANNEL_OPEN_FAILURE             22    /* 0x16 */
598 #define SSH1_MSG_CHANNEL_DATA                     23    /* 0x17 */
599 #define SSH1_MSG_CHANNEL_CLOSE                    24    /* 0x18 */
600 #define SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION       25    /* 0x19 */
601 #define SSH1_SMSG_X11_OPEN                        27    /* 0x1b */
602 #define SSH1_CMSG_PORT_FORWARD_REQUEST            28    /* 0x1c */
603 #define SSH1_MSG_PORT_OPEN                        29    /* 0x1d */
604 #define SSH1_CMSG_AGENT_REQUEST_FORWARDING        30    /* 0x1e */
605 #define SSH1_SMSG_AGENT_OPEN                      31    /* 0x1f */
606 #define SSH1_MSG_IGNORE                           32    /* 0x20 */
607 #define SSH1_CMSG_EXIT_CONFIRMATION               33    /* 0x21 */
608 #define SSH1_CMSG_X11_REQUEST_FORWARDING          34    /* 0x22 */
609 #define SSH1_CMSG_AUTH_RHOSTS_RSA                 35    /* 0x23 */
610 #define SSH1_MSG_DEBUG                            36    /* 0x24 */
611 #define SSH1_CMSG_REQUEST_COMPRESSION             37    /* 0x25 */
612 #define SSH1_CMSG_AUTH_TIS                        39    /* 0x27 */
613 #define SSH1_SMSG_AUTH_TIS_CHALLENGE              40    /* 0x28 */
614 #define SSH1_CMSG_AUTH_TIS_RESPONSE               41    /* 0x29 */
615 #define SSH1_CMSG_AUTH_CCARD                      70    /* 0x46 */
616 #define SSH1_SMSG_AUTH_CCARD_CHALLENGE            71    /* 0x47 */
617 #define SSH1_CMSG_AUTH_CCARD_RESPONSE             72    /* 0x48 */
618
619 #define SSH1_AUTH_RHOSTS                          1     /* 0x1 */
620 #define SSH1_AUTH_RSA                             2     /* 0x2 */
621 #define SSH1_AUTH_PASSWORD                        3     /* 0x3 */
622 #define SSH1_AUTH_RHOSTS_RSA                      4     /* 0x4 */
623 #define SSH1_AUTH_TIS                             5     /* 0x5 */
624 #define SSH1_AUTH_CCARD                           16    /* 0x10 */
625
626 #define SSH1_PROTOFLAG_SCREEN_NUMBER              1     /* 0x1 */
627 /* Mask for protoflags we will echo back to server if seen */
628 #define SSH1_PROTOFLAGS_SUPPORTED                 0     /* 0x1 */
629
630 /*
631  * SSH-2 message type codes.
632  */
633 #define SSH2_MSG_DISCONNECT                       1     /* 0x1 */
634 #define SSH2_MSG_IGNORE                           2     /* 0x2 */
635 #define SSH2_MSG_UNIMPLEMENTED                    3     /* 0x3 */
636 #define SSH2_MSG_DEBUG                            4     /* 0x4 */
637 #define SSH2_MSG_SERVICE_REQUEST                  5     /* 0x5 */
638 #define SSH2_MSG_SERVICE_ACCEPT                   6     /* 0x6 */
639 #define SSH2_MSG_KEXINIT                          20    /* 0x14 */
640 #define SSH2_MSG_NEWKEYS                          21    /* 0x15 */
641 #define SSH2_MSG_KEXDH_INIT                       30    /* 0x1e */
642 #define SSH2_MSG_KEXDH_REPLY                      31    /* 0x1f */
643 #define SSH2_MSG_KEX_DH_GEX_REQUEST               30    /* 0x1e */
644 #define SSH2_MSG_KEX_DH_GEX_GROUP                 31    /* 0x1f */
645 #define SSH2_MSG_KEX_DH_GEX_INIT                  32    /* 0x20 */
646 #define SSH2_MSG_KEX_DH_GEX_REPLY                 33    /* 0x21 */
647 #define SSH2_MSG_KEXRSA_PUBKEY                    30    /* 0x1e */
648 #define SSH2_MSG_KEXRSA_SECRET                    31    /* 0x1f */
649 #define SSH2_MSG_KEXRSA_DONE                      32    /* 0x20 */
650 #define SSH2_MSG_USERAUTH_REQUEST                 50    /* 0x32 */
651 #define SSH2_MSG_USERAUTH_FAILURE                 51    /* 0x33 */
652 #define SSH2_MSG_USERAUTH_SUCCESS                 52    /* 0x34 */
653 #define SSH2_MSG_USERAUTH_BANNER                  53    /* 0x35 */
654 #define SSH2_MSG_USERAUTH_PK_OK                   60    /* 0x3c */
655 #define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ        60    /* 0x3c */
656 #define SSH2_MSG_USERAUTH_INFO_REQUEST            60    /* 0x3c */
657 #define SSH2_MSG_USERAUTH_INFO_RESPONSE           61    /* 0x3d */
658 #define SSH2_MSG_GLOBAL_REQUEST                   80    /* 0x50 */
659 #define SSH2_MSG_REQUEST_SUCCESS                  81    /* 0x51 */
660 #define SSH2_MSG_REQUEST_FAILURE                  82    /* 0x52 */
661 #define SSH2_MSG_CHANNEL_OPEN                     90    /* 0x5a */
662 #define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION        91    /* 0x5b */
663 #define SSH2_MSG_CHANNEL_OPEN_FAILURE             92    /* 0x5c */
664 #define SSH2_MSG_CHANNEL_WINDOW_ADJUST            93    /* 0x5d */
665 #define SSH2_MSG_CHANNEL_DATA                     94    /* 0x5e */
666 #define SSH2_MSG_CHANNEL_EXTENDED_DATA            95    /* 0x5f */
667 #define SSH2_MSG_CHANNEL_EOF                      96    /* 0x60 */
668 #define SSH2_MSG_CHANNEL_CLOSE                    97    /* 0x61 */
669 #define SSH2_MSG_CHANNEL_REQUEST                  98    /* 0x62 */
670 #define SSH2_MSG_CHANNEL_SUCCESS                  99    /* 0x63 */
671 #define SSH2_MSG_CHANNEL_FAILURE                  100   /* 0x64 */
672 #define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE               60
673 #define SSH2_MSG_USERAUTH_GSSAPI_TOKEN                  61
674 #define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE      63
675 #define SSH2_MSG_USERAUTH_GSSAPI_ERROR                  64
676 #define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK                 65
677 #define SSH2_MSG_USERAUTH_GSSAPI_MIC                    66
678
679 /*
680  * SSH-1 agent messages.
681  */
682 #define SSH1_AGENTC_REQUEST_RSA_IDENTITIES    1
683 #define SSH1_AGENT_RSA_IDENTITIES_ANSWER      2
684 #define SSH1_AGENTC_RSA_CHALLENGE             3
685 #define SSH1_AGENT_RSA_RESPONSE               4
686 #define SSH1_AGENTC_ADD_RSA_IDENTITY          7
687 #define SSH1_AGENTC_REMOVE_RSA_IDENTITY       8
688 #define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
689
690 /*
691  * Messages common to SSH-1 and OpenSSH's SSH-2.
692  */
693 #define SSH_AGENT_FAILURE                    5
694 #define SSH_AGENT_SUCCESS                    6
695
696 /*
697  * OpenSSH's SSH-2 agent messages.
698  */
699 #define SSH2_AGENTC_REQUEST_IDENTITIES          11
700 #define SSH2_AGENT_IDENTITIES_ANSWER            12
701 #define SSH2_AGENTC_SIGN_REQUEST                13
702 #define SSH2_AGENT_SIGN_RESPONSE                14
703 #define SSH2_AGENTC_ADD_IDENTITY                17
704 #define SSH2_AGENTC_REMOVE_IDENTITY             18
705 #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES       19
706
707 /*
708  * Assorted other SSH-related enumerations.
709  */
710 #define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1   /* 0x1 */
711 #define SSH2_DISCONNECT_PROTOCOL_ERROR            2     /* 0x2 */
712 #define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED       3     /* 0x3 */
713 #define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4    /* 0x4 */
714 #define SSH2_DISCONNECT_MAC_ERROR                 5     /* 0x5 */
715 #define SSH2_DISCONNECT_COMPRESSION_ERROR         6     /* 0x6 */
716 #define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE     7     /* 0x7 */
717 #define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8        /* 0x8 */
718 #define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE   9     /* 0x9 */
719 #define SSH2_DISCONNECT_CONNECTION_LOST           10    /* 0xa */
720 #define SSH2_DISCONNECT_BY_APPLICATION            11    /* 0xb */
721 #define SSH2_DISCONNECT_TOO_MANY_CONNECTIONS      12    /* 0xc */
722 #define SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER    13    /* 0xd */
723 #define SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14       /* 0xe */
724 #define SSH2_DISCONNECT_ILLEGAL_USER_NAME         15    /* 0xf */
725
726 #define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED     1     /* 0x1 */
727 #define SSH2_OPEN_CONNECT_FAILED                  2     /* 0x2 */
728 #define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE            3     /* 0x3 */
729 #define SSH2_OPEN_RESOURCE_SHORTAGE               4     /* 0x4 */
730
731 #define SSH2_EXTENDED_DATA_STDERR                 1     /* 0x1 */
732
733 /*
734  * Need this to warn about support for the original SSH-2 keyfile
735  * format.
736  */
737 void old_keyfile_warning(void);