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