11 typedef struct ssh_tag *Ssh;
13 extern int sshfwd_write(struct ssh_channel *c, char *, int);
14 extern void sshfwd_write_eof(struct ssh_channel *c);
15 extern void sshfwd_unclean_close(struct ssh_channel *c, const char *err);
16 extern void sshfwd_unthrottle(struct ssh_channel *c, int bufsize);
17 Conf *sshfwd_get_conf(struct ssh_channel *c);
18 void sshfwd_x11_sharing_handover(struct ssh_channel *c,
19 void *share_cs, void *share_chan,
20 const char *peer_addr, int peer_port,
21 int endian, int protomajor, int protominor,
22 const void *initial_data, int initial_len);
23 void sshfwd_x11_is_local(struct ssh_channel *c);
25 extern Socket ssh_connection_sharing_init(const char *host, int port,
26 Conf *conf, Ssh ssh, void **state);
27 void share_got_pkt_from_server(void *ctx, int type,
28 unsigned char *pkt, int pktlen);
29 void share_activate(void *state, const char *server_verstring);
30 void sharestate_free(void *state);
31 int share_ndownstreams(void *state);
33 void ssh_connshare_log(Ssh ssh, int event, const char *logtext,
34 const char *ds_err, const char *us_err);
35 unsigned ssh_alloc_sharing_channel(Ssh ssh, void *sharing_ctx);
36 void ssh_delete_sharing_channel(Ssh ssh, unsigned localid);
37 int ssh_alloc_sharing_rportfwd(Ssh ssh, const char *shost, int sport,
39 void ssh_sharing_queue_global_request(Ssh ssh, void *share_ctx);
40 struct X11FakeAuth *ssh_sharing_add_x11_display(Ssh ssh, int authtype,
43 void ssh_sharing_remove_x11_display(Ssh ssh, struct X11FakeAuth *auth);
44 void ssh_send_packet_from_downstream(Ssh ssh, unsigned id, int type,
45 const void *pkt, int pktlen,
46 const char *additional_log_text);
47 void ssh_sharing_downstream_connected(Ssh ssh, unsigned id);
48 void ssh_sharing_downstream_disconnected(Ssh ssh, unsigned id);
49 void ssh_sharing_logf(Ssh ssh, unsigned id, const char *logfmt, ...);
50 int ssh_agent_forwarding_permitted(Ssh ssh);
51 void share_setup_x11_channel(void *csv, void *chanv,
52 unsigned upstream_id, unsigned server_id,
53 unsigned server_currwin, unsigned server_maxpkt,
54 unsigned client_adjusted_window,
55 const char *peer_addr, int peer_port, int endian,
56 int protomajor, int protominor,
57 const void *initial_data, int initial_len);
63 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
66 #define SSH_CIPHER_IDEA 1
67 #define SSH_CIPHER_DES 2
68 #define SSH_CIPHER_3DES 3
69 #define SSH_CIPHER_BLOWFISH 6
77 #ifndef BIGNUM_INTERNAL
85 unsigned long exponent;
86 unsigned char *modulus;
90 Bignum private_exponent;
105 const struct ec_curve *curve;
107 Bignum z; /* Jacobian denominator */
108 unsigned char infinity;
111 void ec_point_free(struct ec_point *point);
114 unsigned int fieldBits;
119 extern unsigned char nistp256_oid[];
120 extern unsigned char nistp384_oid[];
121 extern unsigned char nistp521_oid[];
122 extern int nistp256_oid_len;
123 extern int nistp384_oid_len;
124 extern int nistp521_oid_len;
125 struct ec_curve *ec_p256(void);
126 struct ec_curve *ec_p384(void);
127 struct ec_curve *ec_p521(void);
130 struct ec_point publicKey;
134 int makekey(unsigned char *data, int len, struct RSAKey *result,
135 unsigned char **keystr, int order);
136 int makeprivate(unsigned char *data, int len, struct RSAKey *result);
137 int rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
138 Bignum rsadecrypt(Bignum input, struct RSAKey *key);
139 void rsasign(unsigned char *data, int length, struct RSAKey *key);
140 void rsasanitise(struct RSAKey *key);
141 int rsastr_len(struct RSAKey *key);
142 void rsastr_fmt(char *str, struct RSAKey *key);
143 void rsa_fingerprint(char *str, int len, struct RSAKey *key);
144 int rsa_verify(struct RSAKey *key);
145 unsigned char *rsa_public_blob(struct RSAKey *key, int *len);
146 int rsa_public_blob_len(void *data, int maxlen);
147 void freersakey(struct RSAKey *key);
149 #ifndef PUTTY_UINT32_DEFINED
150 /* This makes assumptions about the int type. */
151 typedef unsigned int uint32;
152 #define PUTTY_UINT32_DEFINED
154 typedef uint32 word32;
156 unsigned long crc32_compute(const void *s, size_t len);
157 unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
159 /* SSH CRC compensation attack detector */
160 void *crcda_make_context(void);
161 void crcda_free_context(void *handle);
162 int detect_attack(void *handle, unsigned char *buf, uint32 len,
166 * SSH2 RSA key exchange functions
169 void *ssh_rsakex_newkey(char *data, int len);
170 void ssh_rsakex_freekey(void *key);
171 int ssh_rsakex_klen(void *key);
172 void ssh_rsakex_encrypt(const struct ssh_hash *h, unsigned char *in, int inlen,
173 unsigned char *out, int outlen,
177 * SSH2 ECDH key exchange functions
179 void *ssh_ecdhkex_newkey(struct ec_curve *curve);
180 void ssh_ecdhkex_freekey(void *key);
181 char *ssh_ecdhkex_getpublic(void *key, int *len);
182 Bignum ssh_ecdhkex_getkey(void *key, char *remoteKey, int remoteKeyLen);
185 * Helper function for k generation in DSA, reused in ECDSA
187 Bignum *dss_gen_k(const char *id_string, Bignum modulus, Bignum private_key,
188 unsigned char *digest, int digest_len);
199 unsigned char block[64];
205 void MD5Init(struct MD5Context *context);
206 void MD5Update(struct MD5Context *context, unsigned char const *buf,
208 void MD5Final(unsigned char digest[16], struct MD5Context *context);
209 void MD5Simple(void const *p, unsigned len, unsigned char output[16]);
211 void *hmacmd5_make_context(void);
212 void hmacmd5_free_context(void *handle);
213 void hmacmd5_key(void *handle, void const *key, int len);
214 void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len,
215 unsigned char *hmac);
219 unsigned char block[64];
223 void SHA_Init(SHA_State * s);
224 void SHA_Bytes(SHA_State * s, const void *p, int len);
225 void SHA_Final(SHA_State * s, unsigned char *output);
226 void SHA_Simple(const void *p, int len, unsigned char *output);
228 void hmac_sha1_simple(void *key, int keylen, void *data, int datalen,
229 unsigned char *output);
232 unsigned char block[64];
236 void SHA256_Init(SHA256_State * s);
237 void SHA256_Bytes(SHA256_State * s, const void *p, int len);
238 void SHA256_Final(SHA256_State * s, unsigned char *output);
239 void SHA256_Simple(const void *p, int len, unsigned char *output);
243 unsigned char block[128];
247 #define SHA384_State SHA512_State
248 void SHA512_Init(SHA512_State * s);
249 void SHA512_Bytes(SHA512_State * s, const void *p, int len);
250 void SHA512_Final(SHA512_State * s, unsigned char *output);
251 void SHA512_Simple(const void *p, int len, unsigned char *output);
252 void SHA384_Init(SHA384_State * s);
253 #define SHA384_Bytes(s, p, len) SHA512_Bytes(s, p, len)
254 void SHA384_Final(SHA384_State * s, unsigned char *output);
255 void SHA384_Simple(const void *p, int len, unsigned char *output);
258 void *(*make_context)(void);
259 void (*free_context)(void *);
260 void (*sesskey) (void *, unsigned char *key); /* for SSH-1 */
261 void (*encrypt) (void *, unsigned char *blk, int len);
262 void (*decrypt) (void *, unsigned char *blk, int len);
268 void *(*make_context)(void);
269 void (*free_context)(void *);
270 void (*setiv) (void *, unsigned char *key); /* for SSH-2 */
271 void (*setkey) (void *, unsigned char *key);/* for SSH-2 */
272 void (*encrypt) (void *, unsigned char *blk, int len);
273 void (*decrypt) (void *, unsigned char *blk, int len);
278 #define SSH_CIPHER_IS_CBC 1
282 struct ssh2_ciphers {
284 const struct ssh2_cipher *const *list;
288 void *(*make_context)(void);
289 void (*free_context)(void *);
290 void (*setkey) (void *, unsigned char *key);
291 /* whole-packet operations */
292 void (*generate) (void *, unsigned char *blk, int len, unsigned long seq);
293 int (*verify) (void *, unsigned char *blk, int len, unsigned long seq);
294 /* partial-packet operations */
295 void (*start) (void *);
296 void (*bytes) (void *, unsigned char const *, int);
297 void (*genresult) (void *, unsigned char *);
298 int (*verresult) (void *, unsigned char const *);
305 void *(*init)(void); /* also allocates context */
306 void (*bytes)(void *, void *, int);
307 void (*final)(void *, unsigned char *); /* also frees context */
308 int hlen; /* output length in bytes */
313 char *name, *groupname;
314 enum { KEXTYPE_DH, KEXTYPE_RSA, KEXTYPE_ECDH } main_type;
316 const unsigned char *pdata, *gdata; /* NULL means group exchange */
318 const struct ssh_hash *hash;
323 const struct ssh_kex *const *list;
327 void *(*newkey) (char *data, int len);
328 void (*freekey) (void *key);
329 char *(*fmtkey) (void *key);
330 unsigned char *(*public_blob) (void *key, int *len);
331 unsigned char *(*private_blob) (void *key, int *len);
332 void *(*createkey) (unsigned char *pub_blob, int pub_len,
333 unsigned char *priv_blob, int priv_len);
334 void *(*openssh_createkey) (unsigned char **blob, int *len);
335 int (*openssh_fmtkey) (void *key, unsigned char *blob, int len);
336 int (*pubkey_bits) (void *blob, int len);
337 char *(*fingerprint) (void *key);
338 int (*verifysig) (void *key, char *sig, int siglen,
339 char *data, int datalen);
340 unsigned char *(*sign) (void *key, char *data, int datalen,
343 char *keytype; /* for host key cache */
346 struct ssh_compress {
348 /* For zlib@openssh.com: if non-NULL, this name will be considered once
349 * userauth has completed successfully. */
351 void *(*compress_init) (void);
352 void (*compress_cleanup) (void *);
353 int (*compress) (void *, unsigned char *block, int len,
354 unsigned char **outblock, int *outlen);
355 void *(*decompress_init) (void);
356 void (*decompress_cleanup) (void *);
357 int (*decompress) (void *, unsigned char *block, int len,
358 unsigned char **outblock, int *outlen);
359 int (*disable_compression) (void *);
363 struct ssh2_userkey {
364 const struct ssh_signkey *alg; /* the key algorithm */
365 void *data; /* the key data */
366 char *comment; /* the key comment */
369 /* The maximum length of any hash algorithm used in kex. (bytes) */
370 #define SSH2_KEX_MAX_HASH_LEN (64) /* SHA-512 */
372 extern const struct ssh_cipher ssh_3des;
373 extern const struct ssh_cipher ssh_des;
374 extern const struct ssh_cipher ssh_blowfish_ssh1;
375 extern const struct ssh2_ciphers ssh2_3des;
376 extern const struct ssh2_ciphers ssh2_des;
377 extern const struct ssh2_ciphers ssh2_aes;
378 extern const struct ssh2_ciphers ssh2_blowfish;
379 extern const struct ssh2_ciphers ssh2_arcfour;
380 extern const struct ssh_hash ssh_sha1;
381 extern const struct ssh_hash ssh_sha256;
382 extern const struct ssh_hash ssh_sha384;
383 extern const struct ssh_hash ssh_sha512;
384 extern const struct ssh_kexes ssh_diffiehellman_group1;
385 extern const struct ssh_kexes ssh_diffiehellman_group14;
386 extern const struct ssh_kexes ssh_diffiehellman_gex;
387 extern const struct ssh_kexes ssh_rsa_kex;
388 extern const struct ssh_kexes ssh_ecdh_kex;
389 extern const struct ssh_signkey ssh_dss;
390 extern const struct ssh_signkey ssh_rsa;
391 extern const struct ssh_signkey ssh_ecdsa_nistp256;
392 extern const struct ssh_signkey ssh_ecdsa_nistp384;
393 extern const struct ssh_signkey ssh_ecdsa_nistp521;
394 extern const struct ssh_mac ssh_hmac_md5;
395 extern const struct ssh_mac ssh_hmac_sha1;
396 extern const struct ssh_mac ssh_hmac_sha1_buggy;
397 extern const struct ssh_mac ssh_hmac_sha1_96;
398 extern const struct ssh_mac ssh_hmac_sha1_96_buggy;
399 extern const struct ssh_mac ssh_hmac_sha256;
401 void *aes_make_context(void);
402 void aes_free_context(void *handle);
403 void aes128_key(void *handle, unsigned char *key);
404 void aes192_key(void *handle, unsigned char *key);
405 void aes256_key(void *handle, unsigned char *key);
406 void aes_iv(void *handle, unsigned char *iv);
407 void aes_ssh2_encrypt_blk(void *handle, unsigned char *blk, int len);
408 void aes_ssh2_decrypt_blk(void *handle, unsigned char *blk, int len);
411 * PuTTY version number formatted as an SSH version string.
413 extern char sshver[];
416 * Gross hack: pscp will try to start SFTP but fall back to scp1 if
417 * that fails. This variable is the means by which scp.c can reach
418 * into the SSH code and find out which one it got.
420 extern int ssh_fallback_cmd(void *handle);
423 void SHATransform(word32 * digest, word32 * data);
426 int random_byte(void);
427 void random_add_noise(void *noise, int length);
428 void random_add_heavynoise(void *noise, int length);
430 void logevent(void *, const char *);
432 struct PortForwarding;
434 /* Allocate and register a new channel for port forwarding */
435 void *new_sock_channel(void *handle, struct PortForwarding *pf);
436 void ssh_send_port_open(void *channel, char *hostname, int port, char *org);
438 /* Exports from portfwd.c */
439 extern char *pfd_connect(struct PortForwarding **pf, char *hostname, int port,
440 void *c, Conf *conf, int addressfamily);
441 extern void pfd_close(struct PortForwarding *);
442 extern int pfd_send(struct PortForwarding *, char *data, int len);
443 extern void pfd_send_eof(struct PortForwarding *);
444 extern void pfd_confirm(struct PortForwarding *);
445 extern void pfd_unthrottle(struct PortForwarding *);
446 extern void pfd_override_throttle(struct PortForwarding *, int enable);
448 /* desthost == NULL indicates dynamic (SOCKS) port forwarding */
449 extern char *pfl_listen(char *desthost, int destport, char *srcaddr,
450 int port, void *backhandle, Conf *conf,
451 struct PortListener **pl, int address_family);
452 extern void pfl_terminate(struct PortListener *);
454 /* Exports from x11fwd.c */
456 X11_TRANS_IPV4 = 0, X11_TRANS_IPV6 = 6, X11_TRANS_UNIX = 256
459 /* Broken-down components of the display name itself */
464 /* OSX sometimes replaces all the above with a full Unix-socket pathname */
465 char *unixsocketpath;
467 /* PuTTY networking SockAddr to connect to the display, and associated
473 /* Our local auth details for talking to the real X display. */
475 unsigned char *localauthdata;
476 int localauthdatalen;
479 /* Auth details we invented for a virtual display on the SSH server. */
486 /* The encrypted form of the first block, in XDM-AUTHORIZATION-1.
487 * Used as part of the key when these structures are organised
488 * into a tree. See x11_invent_fake_auth for explanation. */
489 unsigned char *xa1_firstblock;
492 * Used inside x11fwd.c to remember recently seen
493 * XDM-AUTHORIZATION-1 strings, to avoid replay attacks.
498 * What to do with an X connection matching this auth data.
500 struct X11Display *disp;
501 void *share_cs, *share_chan;
503 void *x11_make_greeting(int endian, int protomajor, int protominor,
504 int auth_proto, const void *auth_data, int auth_len,
505 const char *peer_ip, int peer_port,
507 int x11_authcmp(void *av, void *bv); /* for putting X11FakeAuth in a tree234 */
509 * x11_setup_display() parses the display variable and fills in an
510 * X11Display structure. Some remote auth details are invented;
511 * the supplied authtype parameter configures the preferred
512 * authorisation protocol to use at the remote end. The local auth
513 * details are looked up by calling platform_get_x11_auth.
515 extern struct X11Display *x11_setup_display(char *display, Conf *);
516 void x11_free_display(struct X11Display *disp);
517 struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
518 void x11_free_fake_auth(struct X11FakeAuth *auth);
519 struct X11Connection; /* opaque outside x11fwd.c */
520 struct X11Connection *x11_init(tree234 *authtree, void *, const char *, int);
521 extern void x11_close(struct X11Connection *);
522 extern int x11_send(struct X11Connection *, char *, int);
523 extern void x11_send_eof(struct X11Connection *s);
524 extern void x11_unthrottle(struct X11Connection *s);
525 extern void x11_override_throttle(struct X11Connection *s, int enable);
526 char *x11_display(const char *display);
527 /* Platform-dependent X11 functions */
528 extern void platform_get_x11_auth(struct X11Display *display, Conf *);
529 /* examine a mostly-filled-in X11Display and fill in localauth* */
530 extern const int platform_uses_x11_unix_by_default;
531 /* choose default X transport in the absence of a specified one */
532 SockAddr platform_get_x11_unix_address(const char *path, int displaynum);
533 /* make up a SockAddr naming the address for displaynum */
534 char *platform_get_x_display(void);
535 /* allocated local X display string, if any */
536 /* Callbacks in x11.c usable _by_ platform X11 functions */
538 * This function does the job of platform_get_x11_auth, provided
539 * it is told where to find a normally formatted .Xauthority file:
540 * it opens that file, parses it to find an auth record which
541 * matches the display details in "display", and fills in the
544 * It is expected that most implementations of
545 * platform_get_x11_auth() will work by finding their system's
546 * .Xauthority file, adjusting the display details if necessary
547 * for local oddities like Unix-domain socket transport, and
548 * calling this function to do the rest of the work.
550 void x11_get_auth_from_authfile(struct X11Display *display,
551 const char *authfilename);
552 int x11_identify_auth_proto(const char *proto);
553 void *x11_dehexify(const char *hex, int *outlen);
555 Bignum copybn(Bignum b);
556 Bignum bn_power_2(int n);
557 void bn_restore_invariant(Bignum b);
558 Bignum bignum_from_long(unsigned long n);
559 void freebn(Bignum b);
560 Bignum modpow(Bignum base, Bignum exp, Bignum mod);
561 Bignum modmul(Bignum a, Bignum b, Bignum mod);
562 Bignum modsub(const Bignum a, const Bignum b, const Bignum n);
563 void decbn(Bignum n);
564 extern Bignum Zero, One;
565 Bignum bignum_from_bytes(const unsigned char *data, int nbytes);
566 Bignum bignum_random_in_range(const Bignum lower, const Bignum upper);
567 int ssh1_read_bignum(const unsigned char *data, int len, Bignum * result);
568 int bignum_bitcount(Bignum bn);
569 int ssh1_bignum_length(Bignum bn);
570 int ssh2_bignum_length(Bignum bn);
571 int bignum_byte(Bignum bn, int i);
572 int bignum_bit(Bignum bn, int i);
573 void bignum_set_bit(Bignum bn, int i, int value);
574 int ssh1_write_bignum(void *data, Bignum bn);
575 Bignum biggcd(Bignum a, Bignum b);
576 unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
577 Bignum bignum_add_long(Bignum number, unsigned long addend);
578 Bignum bigadd(Bignum a, Bignum b);
579 Bignum bigsub(Bignum a, Bignum b);
580 Bignum bigmul(Bignum a, Bignum b);
581 Bignum bigmuladd(Bignum a, Bignum b, Bignum addend);
582 Bignum bigdiv(Bignum a, Bignum b);
583 Bignum bigmod(Bignum a, Bignum b);
584 Bignum modinv(Bignum number, Bignum modulus);
585 Bignum bignum_bitmask(Bignum number);
586 Bignum bignum_rshift(Bignum number, int shift);
587 Bignum bignum_lshift(Bignum number, int shift);
588 int bignum_cmp(Bignum a, Bignum b);
589 char *bignum_decimal(Bignum x);
592 void diagbn(char *prefix, Bignum md);
595 void *dh_setup_group(const struct ssh_kex *kex);
596 void *dh_setup_gex(Bignum pval, Bignum gval);
597 void dh_cleanup(void *);
598 Bignum dh_create_e(void *, int nbits);
599 const char *dh_validate_f(void *handle, Bignum f);
600 Bignum dh_find_K(void *, Bignum f);
602 int loadrsakey(const Filename *filename, struct RSAKey *key,
603 char *passphrase, const char **errorstr);
604 int rsakey_encrypted(const Filename *filename, char **comment);
605 int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen,
606 char **commentptr, const char **errorstr);
608 int saversakey(const Filename *filename, struct RSAKey *key, char *passphrase);
610 extern int base64_decode_atom(char *atom, unsigned char *out);
611 extern int base64_lines(int datalen);
612 extern void base64_encode_atom(unsigned char *data, int n, char *out);
613 extern void base64_encode(FILE *fp, unsigned char *data, int datalen, int cpl);
615 /* ssh2_load_userkey can return this as an error */
616 extern struct ssh2_userkey ssh2_wrong_passphrase;
617 #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
619 int ssh2_userkey_encrypted(const Filename *filename, char **comment);
620 struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
621 char *passphrase, const char **errorstr);
622 unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
623 int *pub_blob_len, char **commentptr,
624 const char **errorstr);
625 int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
627 const struct ssh_signkey *find_pubkey_alg(const char *name);
630 SSH_KEYTYPE_UNOPENABLE,
632 SSH_KEYTYPE_SSH1, SSH_KEYTYPE_SSH2,
633 SSH_KEYTYPE_OPENSSH, SSH_KEYTYPE_SSHCOM
635 int key_type(const Filename *filename);
636 char *key_type_to_str(int type);
638 int import_possible(int type);
639 int import_target_type(int type);
640 int import_encrypted(const Filename *filename, int type, char **comment);
641 int import_ssh1(const Filename *filename, int type,
642 struct RSAKey *key, char *passphrase, const char **errmsg_p);
643 struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
644 char *passphrase, const char **errmsg_p);
645 int export_ssh1(const Filename *filename, int type,
646 struct RSAKey *key, char *passphrase);
647 int export_ssh2(const Filename *filename, int type,
648 struct ssh2_userkey *key, char *passphrase);
650 void des3_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
651 void des3_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
652 void des3_decrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
653 unsigned char *blk, int len);
654 void des3_encrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
655 unsigned char *blk, int len);
656 void aes256_encrypt_pubkey(unsigned char *key, unsigned char *blk,
658 void aes256_decrypt_pubkey(unsigned char *key, unsigned char *blk,
661 void des_encrypt_xdmauth(const unsigned char *key,
662 unsigned char *blk, int len);
663 void des_decrypt_xdmauth(const unsigned char *key,
664 unsigned char *blk, int len);
667 * For progress updates in the key generation utility.
669 #define PROGFN_INITIALISE 1
670 #define PROGFN_LIN_PHASE 2
671 #define PROGFN_EXP_PHASE 3
672 #define PROGFN_PHASE_EXTENT 4
673 #define PROGFN_READY 5
674 #define PROGFN_PROGRESS 6
675 typedef void (*progfn_t) (void *param, int action, int phase, int progress);
677 int rsa_generate(struct RSAKey *key, int bits, progfn_t pfn,
679 int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
681 int ec_generate(struct ec_key *key, int bits, progfn_t pfn,
683 Bignum primegen(int bits, int modulus, int residue, Bignum factor,
684 int phase, progfn_t pfn, void *pfnparam, unsigned firstbits);
685 void invent_firstbits(unsigned *one, unsigned *two);
691 void *zlib_compress_init(void);
692 void zlib_compress_cleanup(void *);
693 void *zlib_decompress_init(void);
694 void zlib_decompress_cleanup(void *);
695 int zlib_compress_block(void *, unsigned char *block, int len,
696 unsigned char **outblock, int *outlen);
697 int zlib_decompress_block(void *, unsigned char *block, int len,
698 unsigned char **outblock, int *outlen);
701 * Connection-sharing API provided by platforms. This function must
703 * - return SHARE_NONE and do nothing
704 * - return SHARE_DOWNSTREAM and set *sock to a Socket connected to
706 * - return SHARE_UPSTREAM and set *sock to a Socket connected to
709 enum { SHARE_NONE, SHARE_DOWNSTREAM, SHARE_UPSTREAM };
710 int platform_ssh_share(const char *name, Conf *conf,
711 Plug downplug, Plug upplug, Socket *sock,
712 char **logtext, char **ds_err, char **us_err,
713 int can_upstream, int can_downstream);
714 void platform_ssh_share_cleanup(const char *name);
717 * SSH-1 message type codes.
719 #define SSH1_MSG_DISCONNECT 1 /* 0x1 */
720 #define SSH1_SMSG_PUBLIC_KEY 2 /* 0x2 */
721 #define SSH1_CMSG_SESSION_KEY 3 /* 0x3 */
722 #define SSH1_CMSG_USER 4 /* 0x4 */
723 #define SSH1_CMSG_AUTH_RSA 6 /* 0x6 */
724 #define SSH1_SMSG_AUTH_RSA_CHALLENGE 7 /* 0x7 */
725 #define SSH1_CMSG_AUTH_RSA_RESPONSE 8 /* 0x8 */
726 #define SSH1_CMSG_AUTH_PASSWORD 9 /* 0x9 */
727 #define SSH1_CMSG_REQUEST_PTY 10 /* 0xa */
728 #define SSH1_CMSG_WINDOW_SIZE 11 /* 0xb */
729 #define SSH1_CMSG_EXEC_SHELL 12 /* 0xc */
730 #define SSH1_CMSG_EXEC_CMD 13 /* 0xd */
731 #define SSH1_SMSG_SUCCESS 14 /* 0xe */
732 #define SSH1_SMSG_FAILURE 15 /* 0xf */
733 #define SSH1_CMSG_STDIN_DATA 16 /* 0x10 */
734 #define SSH1_SMSG_STDOUT_DATA 17 /* 0x11 */
735 #define SSH1_SMSG_STDERR_DATA 18 /* 0x12 */
736 #define SSH1_CMSG_EOF 19 /* 0x13 */
737 #define SSH1_SMSG_EXIT_STATUS 20 /* 0x14 */
738 #define SSH1_MSG_CHANNEL_OPEN_CONFIRMATION 21 /* 0x15 */
739 #define SSH1_MSG_CHANNEL_OPEN_FAILURE 22 /* 0x16 */
740 #define SSH1_MSG_CHANNEL_DATA 23 /* 0x17 */
741 #define SSH1_MSG_CHANNEL_CLOSE 24 /* 0x18 */
742 #define SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION 25 /* 0x19 */
743 #define SSH1_SMSG_X11_OPEN 27 /* 0x1b */
744 #define SSH1_CMSG_PORT_FORWARD_REQUEST 28 /* 0x1c */
745 #define SSH1_MSG_PORT_OPEN 29 /* 0x1d */
746 #define SSH1_CMSG_AGENT_REQUEST_FORWARDING 30 /* 0x1e */
747 #define SSH1_SMSG_AGENT_OPEN 31 /* 0x1f */
748 #define SSH1_MSG_IGNORE 32 /* 0x20 */
749 #define SSH1_CMSG_EXIT_CONFIRMATION 33 /* 0x21 */
750 #define SSH1_CMSG_X11_REQUEST_FORWARDING 34 /* 0x22 */
751 #define SSH1_CMSG_AUTH_RHOSTS_RSA 35 /* 0x23 */
752 #define SSH1_MSG_DEBUG 36 /* 0x24 */
753 #define SSH1_CMSG_REQUEST_COMPRESSION 37 /* 0x25 */
754 #define SSH1_CMSG_AUTH_TIS 39 /* 0x27 */
755 #define SSH1_SMSG_AUTH_TIS_CHALLENGE 40 /* 0x28 */
756 #define SSH1_CMSG_AUTH_TIS_RESPONSE 41 /* 0x29 */
757 #define SSH1_CMSG_AUTH_CCARD 70 /* 0x46 */
758 #define SSH1_SMSG_AUTH_CCARD_CHALLENGE 71 /* 0x47 */
759 #define SSH1_CMSG_AUTH_CCARD_RESPONSE 72 /* 0x48 */
761 #define SSH1_AUTH_RHOSTS 1 /* 0x1 */
762 #define SSH1_AUTH_RSA 2 /* 0x2 */
763 #define SSH1_AUTH_PASSWORD 3 /* 0x3 */
764 #define SSH1_AUTH_RHOSTS_RSA 4 /* 0x4 */
765 #define SSH1_AUTH_TIS 5 /* 0x5 */
766 #define SSH1_AUTH_CCARD 16 /* 0x10 */
768 #define SSH1_PROTOFLAG_SCREEN_NUMBER 1 /* 0x1 */
769 /* Mask for protoflags we will echo back to server if seen */
770 #define SSH1_PROTOFLAGS_SUPPORTED 0 /* 0x1 */
773 * SSH-2 message type codes.
775 #define SSH2_MSG_DISCONNECT 1 /* 0x1 */
776 #define SSH2_MSG_IGNORE 2 /* 0x2 */
777 #define SSH2_MSG_UNIMPLEMENTED 3 /* 0x3 */
778 #define SSH2_MSG_DEBUG 4 /* 0x4 */
779 #define SSH2_MSG_SERVICE_REQUEST 5 /* 0x5 */
780 #define SSH2_MSG_SERVICE_ACCEPT 6 /* 0x6 */
781 #define SSH2_MSG_KEXINIT 20 /* 0x14 */
782 #define SSH2_MSG_NEWKEYS 21 /* 0x15 */
783 #define SSH2_MSG_KEXDH_INIT 30 /* 0x1e */
784 #define SSH2_MSG_KEXDH_REPLY 31 /* 0x1f */
785 #define SSH2_MSG_KEX_DH_GEX_REQUEST 30 /* 0x1e */
786 #define SSH2_MSG_KEX_DH_GEX_GROUP 31 /* 0x1f */
787 #define SSH2_MSG_KEX_DH_GEX_INIT 32 /* 0x20 */
788 #define SSH2_MSG_KEX_DH_GEX_REPLY 33 /* 0x21 */
789 #define SSH2_MSG_KEXRSA_PUBKEY 30 /* 0x1e */
790 #define SSH2_MSG_KEXRSA_SECRET 31 /* 0x1f */
791 #define SSH2_MSG_KEXRSA_DONE 32 /* 0x20 */
792 #define SSH2_MSG_KEX_ECDH_INIT 30 /* 0x1e */
793 #define SSH2_MSG_KEX_ECDH_REPLY 31 /* 0x1f */
794 #define SSH2_MSG_KEX_ECMQV_INIT 30 /* 0x1e */
795 #define SSH2_MSG_KEX_ECMQV_REPLY 31 /* 0x1f */
796 #define SSH2_MSG_USERAUTH_REQUEST 50 /* 0x32 */
797 #define SSH2_MSG_USERAUTH_FAILURE 51 /* 0x33 */
798 #define SSH2_MSG_USERAUTH_SUCCESS 52 /* 0x34 */
799 #define SSH2_MSG_USERAUTH_BANNER 53 /* 0x35 */
800 #define SSH2_MSG_USERAUTH_PK_OK 60 /* 0x3c */
801 #define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60 /* 0x3c */
802 #define SSH2_MSG_USERAUTH_INFO_REQUEST 60 /* 0x3c */
803 #define SSH2_MSG_USERAUTH_INFO_RESPONSE 61 /* 0x3d */
804 #define SSH2_MSG_GLOBAL_REQUEST 80 /* 0x50 */
805 #define SSH2_MSG_REQUEST_SUCCESS 81 /* 0x51 */
806 #define SSH2_MSG_REQUEST_FAILURE 82 /* 0x52 */
807 #define SSH2_MSG_CHANNEL_OPEN 90 /* 0x5a */
808 #define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91 /* 0x5b */
809 #define SSH2_MSG_CHANNEL_OPEN_FAILURE 92 /* 0x5c */
810 #define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93 /* 0x5d */
811 #define SSH2_MSG_CHANNEL_DATA 94 /* 0x5e */
812 #define SSH2_MSG_CHANNEL_EXTENDED_DATA 95 /* 0x5f */
813 #define SSH2_MSG_CHANNEL_EOF 96 /* 0x60 */
814 #define SSH2_MSG_CHANNEL_CLOSE 97 /* 0x61 */
815 #define SSH2_MSG_CHANNEL_REQUEST 98 /* 0x62 */
816 #define SSH2_MSG_CHANNEL_SUCCESS 99 /* 0x63 */
817 #define SSH2_MSG_CHANNEL_FAILURE 100 /* 0x64 */
818 #define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE 60
819 #define SSH2_MSG_USERAUTH_GSSAPI_TOKEN 61
820 #define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
821 #define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
822 #define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65
823 #define SSH2_MSG_USERAUTH_GSSAPI_MIC 66
826 * SSH-1 agent messages.
828 #define SSH1_AGENTC_REQUEST_RSA_IDENTITIES 1
829 #define SSH1_AGENT_RSA_IDENTITIES_ANSWER 2
830 #define SSH1_AGENTC_RSA_CHALLENGE 3
831 #define SSH1_AGENT_RSA_RESPONSE 4
832 #define SSH1_AGENTC_ADD_RSA_IDENTITY 7
833 #define SSH1_AGENTC_REMOVE_RSA_IDENTITY 8
834 #define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
837 * Messages common to SSH-1 and OpenSSH's SSH-2.
839 #define SSH_AGENT_FAILURE 5
840 #define SSH_AGENT_SUCCESS 6
843 * OpenSSH's SSH-2 agent messages.
845 #define SSH2_AGENTC_REQUEST_IDENTITIES 11
846 #define SSH2_AGENT_IDENTITIES_ANSWER 12
847 #define SSH2_AGENTC_SIGN_REQUEST 13
848 #define SSH2_AGENT_SIGN_RESPONSE 14
849 #define SSH2_AGENTC_ADD_IDENTITY 17
850 #define SSH2_AGENTC_REMOVE_IDENTITY 18
851 #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
854 * Assorted other SSH-related enumerations.
856 #define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 /* 0x1 */
857 #define SSH2_DISCONNECT_PROTOCOL_ERROR 2 /* 0x2 */
858 #define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED 3 /* 0x3 */
859 #define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4 /* 0x4 */
860 #define SSH2_DISCONNECT_MAC_ERROR 5 /* 0x5 */
861 #define SSH2_DISCONNECT_COMPRESSION_ERROR 6 /* 0x6 */
862 #define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE 7 /* 0x7 */
863 #define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 /* 0x8 */
864 #define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 /* 0x9 */
865 #define SSH2_DISCONNECT_CONNECTION_LOST 10 /* 0xa */
866 #define SSH2_DISCONNECT_BY_APPLICATION 11 /* 0xb */
867 #define SSH2_DISCONNECT_TOO_MANY_CONNECTIONS 12 /* 0xc */
868 #define SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER 13 /* 0xd */
869 #define SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14 /* 0xe */
870 #define SSH2_DISCONNECT_ILLEGAL_USER_NAME 15 /* 0xf */
872 #define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED 1 /* 0x1 */
873 #define SSH2_OPEN_CONNECT_FAILED 2 /* 0x2 */
874 #define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE 3 /* 0x3 */
875 #define SSH2_OPEN_RESOURCE_SHORTAGE 4 /* 0x4 */
877 #define SSH2_EXTENDED_DATA_STDERR 1 /* 0x1 */
880 * Need this to warn about support for the original SSH-2 keyfile
883 void old_keyfile_warning(void);