ssh.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. #ifndef WINSCP_VS
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "puttymem.h"
  5. #include "tree234.h"
  6. #include "network.h"
  7. #include "int64.h"
  8. #include "misc.h"
  9. struct ssh_channel;
  10. typedef struct ssh_tag *Ssh;
  11. extern int sshfwd_write(struct ssh_channel *c, char *, int);
  12. extern void sshfwd_write_eof(struct ssh_channel *c);
  13. extern void sshfwd_unclean_close(struct ssh_channel *c, const char *err);
  14. extern void sshfwd_unthrottle(struct ssh_channel *c, int bufsize);
  15. Conf *sshfwd_get_conf(struct ssh_channel *c);
  16. void sshfwd_x11_sharing_handover(struct ssh_channel *c,
  17. void *share_cs, void *share_chan,
  18. const char *peer_addr, int peer_port,
  19. int endian, int protomajor, int protominor,
  20. const void *initial_data, int initial_len);
  21. void sshfwd_x11_is_local(struct ssh_channel *c);
  22. extern Socket ssh_connection_sharing_init(const char *host, int port,
  23. Conf *conf, Ssh ssh, void **state);
  24. int ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
  25. void share_got_pkt_from_server(void *ctx, int type,
  26. unsigned char *pkt, int pktlen);
  27. void share_activate(void *state, const char *server_verstring);
  28. void sharestate_free(void *state);
  29. int share_ndownstreams(void *state);
  30. void ssh_connshare_log(Ssh ssh, int event, const char *logtext,
  31. const char *ds_err, const char *us_err);
  32. unsigned ssh_alloc_sharing_channel(Ssh ssh, void *sharing_ctx);
  33. void ssh_delete_sharing_channel(Ssh ssh, unsigned localid);
  34. int ssh_alloc_sharing_rportfwd(Ssh ssh, const char *shost, int sport,
  35. void *share_ctx);
  36. void ssh_sharing_queue_global_request(Ssh ssh, void *share_ctx);
  37. struct X11FakeAuth *ssh_sharing_add_x11_display(Ssh ssh, int authtype,
  38. void *share_cs,
  39. void *share_chan);
  40. void ssh_sharing_remove_x11_display(Ssh ssh, struct X11FakeAuth *auth);
  41. void ssh_send_packet_from_downstream(Ssh ssh, unsigned id, int type,
  42. const void *pkt, int pktlen,
  43. const char *additional_log_text);
  44. void ssh_sharing_downstream_connected(Ssh ssh, unsigned id,
  45. const char *peerinfo);
  46. void ssh_sharing_downstream_disconnected(Ssh ssh, unsigned id);
  47. void ssh_sharing_logf(Ssh ssh, unsigned id, const char *logfmt, ...);
  48. int ssh_agent_forwarding_permitted(Ssh ssh);
  49. void share_setup_x11_channel(void *csv, void *chanv,
  50. unsigned upstream_id, unsigned server_id,
  51. unsigned server_currwin, unsigned server_maxpkt,
  52. unsigned client_adjusted_window,
  53. const char *peer_addr, int peer_port, int endian,
  54. int protomajor, int protominor,
  55. const void *initial_data, int initial_len);
  56. /*
  57. * Useful thing.
  58. */
  59. #ifndef lenof
  60. #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
  61. #endif
  62. #define SSH_CIPHER_IDEA 1
  63. #define SSH_CIPHER_DES 2
  64. #define SSH_CIPHER_3DES 3
  65. #define SSH_CIPHER_BLOWFISH 6
  66. #ifdef MSCRYPTOAPI
  67. #define APIEXTRA 8
  68. #else
  69. #define APIEXTRA 0
  70. #endif
  71. #ifndef BIGNUM_INTERNAL
  72. typedef void *Bignum;
  73. #endif
  74. struct RSAKey {
  75. int bits;
  76. int bytes;
  77. #ifdef MSCRYPTOAPI
  78. unsigned long exponent;
  79. unsigned char *modulus;
  80. #else
  81. Bignum modulus;
  82. Bignum exponent;
  83. Bignum private_exponent;
  84. Bignum p;
  85. Bignum q;
  86. Bignum iqmp;
  87. #endif
  88. char *comment;
  89. };
  90. struct dss_key {
  91. Bignum p, q, g, y, x;
  92. };
  93. struct ec_curve;
  94. struct ec_point {
  95. const struct ec_curve *curve;
  96. Bignum x, y;
  97. Bignum z; /* Jacobian denominator */
  98. unsigned char infinity;
  99. };
  100. void ec_point_free(struct ec_point *point);
  101. /* Weierstrass form curve */
  102. struct ec_wcurve
  103. {
  104. Bignum a, b, n;
  105. struct ec_point G;
  106. };
  107. /* Montgomery form curve */
  108. struct ec_mcurve
  109. {
  110. Bignum a, b;
  111. struct ec_point G;
  112. };
  113. /* Edwards form curve */
  114. struct ec_ecurve
  115. {
  116. Bignum l, d;
  117. struct ec_point B;
  118. };
  119. struct ec_curve {
  120. enum { EC_WEIERSTRASS, EC_MONTGOMERY, EC_EDWARDS } type;
  121. /* 'name' is the identifier of the curve when it has to appear in
  122. * wire protocol encodings, as it does in e.g. the public key and
  123. * signature formats for NIST curves. Curves which do not format
  124. * their keys or signatures in this way just have name==NULL.
  125. *
  126. * 'textname' is non-NULL for all curves, and is a human-readable
  127. * identification suitable for putting in log messages. */
  128. const char *name, *textname;
  129. unsigned int fieldBits;
  130. Bignum p;
  131. union {
  132. struct ec_wcurve w;
  133. struct ec_mcurve m;
  134. struct ec_ecurve e;
  135. };
  136. };
  137. const struct ssh_signkey *ec_alg_by_oid(int len, const void *oid,
  138. const struct ec_curve **curve);
  139. const unsigned char *ec_alg_oid(const struct ssh_signkey *alg, int *oidlen);
  140. extern const int ec_nist_curve_lengths[], n_ec_nist_curve_lengths;
  141. int ec_nist_alg_and_curve_by_bits(int bits,
  142. const struct ec_curve **curve,
  143. const struct ssh_signkey **alg);
  144. int ec_ed_alg_and_curve_by_bits(int bits,
  145. const struct ec_curve **curve,
  146. const struct ssh_signkey **alg);
  147. struct ssh_signkey;
  148. struct ec_key {
  149. const struct ssh_signkey *signalg;
  150. struct ec_point publicKey;
  151. Bignum privateKey;
  152. };
  153. struct ec_point *ec_public(const Bignum privateKey, const struct ec_curve *curve);
  154. int makekey(const unsigned char *data, int len, struct RSAKey *result,
  155. const unsigned char **keystr, int order);
  156. int makeprivate(const unsigned char *data, int len, struct RSAKey *result);
  157. int rsaencrypt(unsigned char *data, int length, struct RSAKey *key);
  158. Bignum rsadecrypt(Bignum input, struct RSAKey *key);
  159. void rsasign(unsigned char *data, int length, struct RSAKey *key);
  160. void rsasanitise(struct RSAKey *key);
  161. int rsastr_len(struct RSAKey *key);
  162. void rsastr_fmt(char *str, struct RSAKey *key);
  163. void rsa_fingerprint(char *str, int len, struct RSAKey *key);
  164. int rsa_verify(struct RSAKey *key);
  165. unsigned char *rsa_public_blob(struct RSAKey *key, int *len);
  166. int rsa_public_blob_len(void *data, int maxlen);
  167. void freersakey(struct RSAKey *key);
  168. #endif // WINSCP_VS
  169. #ifndef PUTTY_UINT32_DEFINED
  170. /* This makes assumptions about the int type. */
  171. typedef unsigned int uint32;
  172. #define PUTTY_UINT32_DEFINED
  173. #endif
  174. typedef uint32 word32;
  175. #ifndef WINSCP_VS
  176. unsigned long crc32_compute(const void *s, size_t len);
  177. unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
  178. /* SSH CRC compensation attack detector */
  179. void *crcda_make_context(void);
  180. void crcda_free_context(void *handle);
  181. int detect_attack(void *handle, unsigned char *buf, uint32 len,
  182. unsigned char *IV);
  183. /*
  184. * SSH2 RSA key exchange functions
  185. */
  186. struct ssh_hash;
  187. void *ssh_rsakex_newkey(char *data, int len);
  188. void ssh_rsakex_freekey(void *key);
  189. int ssh_rsakex_klen(void *key);
  190. void ssh_rsakex_encrypt(const struct ssh_hash *h, unsigned char *in, int inlen,
  191. unsigned char *out, int outlen,
  192. void *key);
  193. /*
  194. * SSH2 ECDH key exchange functions
  195. */
  196. struct ssh_kex;
  197. const char *ssh_ecdhkex_curve_textname(const struct ssh_kex *kex);
  198. void *ssh_ecdhkex_newkey(const struct ssh_kex *kex);
  199. void ssh_ecdhkex_freekey(void *key);
  200. char *ssh_ecdhkex_getpublic(void *key, int *len);
  201. Bignum ssh_ecdhkex_getkey(void *key, char *remoteKey, int remoteKeyLen);
  202. /*
  203. * Helper function for k generation in DSA, reused in ECDSA
  204. */
  205. Bignum *dss_gen_k(const char *id_string, Bignum modulus, Bignum private_key,
  206. unsigned char *digest, int digest_len);
  207. typedef struct {
  208. uint32 h[4];
  209. } MD5_Core_State;
  210. struct MD5Context {
  211. #ifdef MSCRYPTOAPI
  212. unsigned long hHash;
  213. #else
  214. MD5_Core_State core;
  215. unsigned char block[64];
  216. int blkused;
  217. uint32 lenhi, lenlo;
  218. #endif
  219. };
  220. void MD5Init(struct MD5Context *context);
  221. void MD5Update(struct MD5Context *context, unsigned char const *buf,
  222. unsigned len);
  223. void MD5Final(unsigned char digest[16], struct MD5Context *context);
  224. void MD5Simple(void const *p, unsigned len, unsigned char output[16]);
  225. void *hmacmd5_make_context(void *);
  226. void hmacmd5_free_context(void *handle);
  227. void hmacmd5_key(void *handle, void const *key, int len);
  228. void hmacmd5_do_hmac(void *handle, unsigned char const *blk, int len,
  229. unsigned char *hmac);
  230. #ifdef MPEXT
  231. // Resolve ambiguity with OpenSSL
  232. #define SHA_Init putty_SHA_Init
  233. #define SHA_Final putty_SHA_Final
  234. #define SHA256_Init putty_SHA256_Init
  235. #define SHA256_Final putty_SHA256_Final
  236. #define SHA512_Init putty_SHA512_Init
  237. #define SHA512_Final putty_SHA512_Final
  238. #endif
  239. typedef struct {
  240. uint32 h[5];
  241. unsigned char block[64];
  242. int blkused;
  243. uint32 lenhi, lenlo;
  244. } SHA_State;
  245. void SHA_Init(SHA_State * s);
  246. void SHA_Bytes(SHA_State * s, const void *p, int len);
  247. void SHA_Final(SHA_State * s, unsigned char *output);
  248. void SHA_Simple(const void *p, int len, unsigned char *output);
  249. void hmac_sha1_simple(void *key, int keylen, void *data, int datalen,
  250. unsigned char *output);
  251. #endif // WINSCP_VS
  252. typedef struct {
  253. uint32 h[8];
  254. unsigned char block[64];
  255. int blkused;
  256. uint32 lenhi, lenlo;
  257. } SHA256_State;
  258. #ifndef WINSCP_VS
  259. void SHA256_Init(SHA256_State * s);
  260. void SHA256_Bytes(SHA256_State * s, const void *p, int len);
  261. void SHA256_Final(SHA256_State * s, unsigned char *output);
  262. void SHA256_Simple(const void *p, int len, unsigned char *output);
  263. typedef struct {
  264. uint64 h[8];
  265. unsigned char block[128];
  266. int blkused;
  267. uint32 len[4];
  268. } SHA512_State;
  269. #define SHA384_State SHA512_State
  270. void SHA512_Init(SHA512_State * s);
  271. void SHA512_Bytes(SHA512_State * s, const void *p, int len);
  272. void SHA512_Final(SHA512_State * s, unsigned char *output);
  273. void SHA512_Simple(const void *p, int len, unsigned char *output);
  274. void SHA384_Init(SHA384_State * s);
  275. #define SHA384_Bytes(s, p, len) SHA512_Bytes(s, p, len)
  276. void SHA384_Final(SHA384_State * s, unsigned char *output);
  277. void SHA384_Simple(const void *p, int len, unsigned char *output);
  278. struct ssh_mac;
  279. struct ssh_cipher {
  280. void *(*make_context)(void);
  281. void (*free_context)(void *);
  282. void (*sesskey) (void *, unsigned char *key); /* for SSH-1 */
  283. void (*encrypt) (void *, unsigned char *blk, int len);
  284. void (*decrypt) (void *, unsigned char *blk, int len);
  285. int blksize;
  286. const char *text_name;
  287. };
  288. struct ssh2_cipher {
  289. void *(*make_context)(void);
  290. void (*free_context)(void *);
  291. void (*setiv) (void *, unsigned char *key); /* for SSH-2 */
  292. void (*setkey) (void *, unsigned char *key);/* for SSH-2 */
  293. void (*encrypt) (void *, unsigned char *blk, int len);
  294. void (*decrypt) (void *, unsigned char *blk, int len);
  295. /* Ignored unless SSH_CIPHER_SEPARATE_LENGTH flag set */
  296. void (*encrypt_length) (void *, unsigned char *blk, int len, unsigned long seq);
  297. void (*decrypt_length) (void *, unsigned char *blk, int len, unsigned long seq);
  298. const char *name;
  299. int blksize;
  300. /* real_keybits is the number of bits of entropy genuinely used by
  301. * the cipher scheme; it's used for deciding how big a
  302. * Diffie-Hellman group is needed to exchange a key for the
  303. * cipher. */
  304. int real_keybits;
  305. /* padded_keybytes is the number of bytes of key data expected as
  306. * input to the setkey function; it's used for deciding how much
  307. * data needs to be generated from the post-kex generation of key
  308. * material. In a sensible cipher which uses all its key bytes for
  309. * real work, this will just be real_keybits/8, but in DES-type
  310. * ciphers which ignore one bit in each byte, it'll be slightly
  311. * different. */
  312. int padded_keybytes;
  313. unsigned int flags;
  314. #define SSH_CIPHER_IS_CBC 1
  315. #define SSH_CIPHER_SEPARATE_LENGTH 2
  316. const char *text_name;
  317. /* If set, this takes priority over other MAC. */
  318. const struct ssh_mac *required_mac;
  319. };
  320. struct ssh2_ciphers {
  321. int nciphers;
  322. const struct ssh2_cipher *const *list;
  323. };
  324. struct ssh_mac {
  325. /* Passes in the cipher context */
  326. void *(*make_context)(void *);
  327. void (*free_context)(void *);
  328. void (*setkey) (void *, unsigned char *key);
  329. /* whole-packet operations */
  330. void (*generate) (void *, unsigned char *blk, int len, unsigned long seq);
  331. int (*verify) (void *, unsigned char *blk, int len, unsigned long seq);
  332. /* partial-packet operations */
  333. void (*start) (void *);
  334. void (*bytes) (void *, unsigned char const *, int);
  335. void (*genresult) (void *, unsigned char *);
  336. int (*verresult) (void *, unsigned char const *);
  337. const char *name, *etm_name;
  338. int len, keylen;
  339. const char *text_name;
  340. };
  341. struct ssh_hash {
  342. void *(*init)(void); /* also allocates context */
  343. void *(*copy)(const void *);
  344. void (*bytes)(void *, const void *, int);
  345. void (*final)(void *, unsigned char *); /* also frees context */
  346. void (*free)(void *);
  347. int hlen; /* output length in bytes */
  348. const char *text_name;
  349. };
  350. struct ssh_kex {
  351. const char *name, *groupname;
  352. enum { KEXTYPE_DH, KEXTYPE_RSA, KEXTYPE_ECDH } main_type;
  353. const struct ssh_hash *hash;
  354. const void *extra; /* private to the kex methods */
  355. };
  356. struct ssh_kexes {
  357. int nkexes;
  358. const struct ssh_kex *const *list;
  359. };
  360. struct ssh_signkey {
  361. void *(*newkey) (const struct ssh_signkey *self,
  362. const char *data, int len);
  363. void (*freekey) (void *key);
  364. char *(*fmtkey) (void *key);
  365. unsigned char *(*public_blob) (void *key, int *len);
  366. unsigned char *(*private_blob) (void *key, int *len);
  367. void *(*createkey) (const struct ssh_signkey *self,
  368. const unsigned char *pub_blob, int pub_len,
  369. const unsigned char *priv_blob, int priv_len);
  370. void *(*openssh_createkey) (const struct ssh_signkey *self,
  371. const unsigned char **blob, int *len);
  372. int (*openssh_fmtkey) (void *key, unsigned char *blob, int len);
  373. /* OpenSSH private key blobs, as created by openssh_fmtkey and
  374. * consumed by openssh_createkey, always (at least so far...) take
  375. * the form of a number of SSH-2 strings / mpints concatenated
  376. * end-to-end. Because the new-style OpenSSH private key format
  377. * stores those blobs without a containing string wrapper, we need
  378. * to know how many strings each one consists of, so that we can
  379. * skip over the right number to find the next key in the file.
  380. * openssh_private_npieces gives that information. */
  381. int openssh_private_npieces;
  382. int (*pubkey_bits) (const struct ssh_signkey *self,
  383. const void *blob, int len);
  384. int (*verifysig) (void *key, const char *sig, int siglen,
  385. const char *data, int datalen);
  386. unsigned char *(*sign) (void *key, const char *data, int datalen,
  387. int *siglen);
  388. const char *name;
  389. const char *keytype; /* for host key cache */
  390. const void *extra; /* private to the public key methods */
  391. };
  392. struct ssh_compress {
  393. const char *name;
  394. /* For [email protected]: if non-NULL, this name will be considered once
  395. * userauth has completed successfully. */
  396. const char *delayed_name;
  397. void *(*compress_init) (void);
  398. void (*compress_cleanup) (void *);
  399. int (*compress) (void *, unsigned char *block, int len,
  400. unsigned char **outblock, int *outlen);
  401. void *(*decompress_init) (void);
  402. void (*decompress_cleanup) (void *);
  403. int (*decompress) (void *, unsigned char *block, int len,
  404. unsigned char **outblock, int *outlen);
  405. int (*disable_compression) (void *);
  406. const char *text_name;
  407. };
  408. struct ssh2_userkey {
  409. const struct ssh_signkey *alg; /* the key algorithm */
  410. void *data; /* the key data */
  411. char *comment; /* the key comment */
  412. };
  413. /* The maximum length of any hash algorithm used in kex. (bytes) */
  414. #define SSH2_KEX_MAX_HASH_LEN (64) /* SHA-512 */
  415. extern const struct ssh_cipher ssh_3des;
  416. extern const struct ssh_cipher ssh_des;
  417. extern const struct ssh_cipher ssh_blowfish_ssh1;
  418. extern const struct ssh2_ciphers ssh2_3des;
  419. extern const struct ssh2_ciphers ssh2_des;
  420. extern const struct ssh2_ciphers ssh2_aes;
  421. extern const struct ssh2_ciphers ssh2_blowfish;
  422. extern const struct ssh2_ciphers ssh2_arcfour;
  423. extern const struct ssh2_ciphers ssh2_ccp;
  424. extern const struct ssh_hash ssh_sha1;
  425. extern const struct ssh_hash ssh_sha256;
  426. extern const struct ssh_hash ssh_sha384;
  427. extern const struct ssh_hash ssh_sha512;
  428. extern const struct ssh_kexes ssh_diffiehellman_group1;
  429. extern const struct ssh_kexes ssh_diffiehellman_group14;
  430. extern const struct ssh_kexes ssh_diffiehellman_gex;
  431. extern const struct ssh_kexes ssh_rsa_kex;
  432. extern const struct ssh_kexes ssh_ecdh_kex;
  433. extern const struct ssh_signkey ssh_dss;
  434. extern const struct ssh_signkey ssh_rsa;
  435. extern const struct ssh_signkey ssh_ecdsa_ed25519;
  436. extern const struct ssh_signkey ssh_ecdsa_nistp256;
  437. extern const struct ssh_signkey ssh_ecdsa_nistp384;
  438. extern const struct ssh_signkey ssh_ecdsa_nistp521;
  439. extern const struct ssh_mac ssh_hmac_md5;
  440. extern const struct ssh_mac ssh_hmac_sha1;
  441. extern const struct ssh_mac ssh_hmac_sha1_buggy;
  442. extern const struct ssh_mac ssh_hmac_sha1_96;
  443. extern const struct ssh_mac ssh_hmac_sha1_96_buggy;
  444. extern const struct ssh_mac ssh_hmac_sha256;
  445. void *aes_make_context(void);
  446. void aes_free_context(void *handle);
  447. void aes128_key(void *handle, unsigned char *key);
  448. void aes192_key(void *handle, unsigned char *key);
  449. void aes256_key(void *handle, unsigned char *key);
  450. void aes_iv(void *handle, unsigned char *iv);
  451. void aes_ssh2_encrypt_blk(void *handle, unsigned char *blk, int len);
  452. void aes_ssh2_decrypt_blk(void *handle, unsigned char *blk, int len);
  453. void aes_ssh2_sdctr(void *handle, unsigned char *blk, int len);
  454. /*
  455. * PuTTY version number formatted as an SSH version string.
  456. */
  457. extern
  458. #ifndef MPEXT
  459. const
  460. #endif
  461. char sshver[];
  462. /*
  463. * Gross hack: pscp will try to start SFTP but fall back to scp1 if
  464. * that fails. This variable is the means by which scp.c can reach
  465. * into the SSH code and find out which one it got.
  466. */
  467. extern int ssh_fallback_cmd(void *handle);
  468. #ifndef MSCRYPTOAPI
  469. void SHATransform(word32 * digest, word32 * data);
  470. #endif
  471. int random_byte(void);
  472. void random_add_noise(void *noise, int length);
  473. void random_add_heavynoise(void *noise, int length);
  474. void logevent(void *, const char *);
  475. struct PortForwarding;
  476. /* Allocate and register a new channel for port forwarding */
  477. void *new_sock_channel(void *handle, struct PortForwarding *pf);
  478. void ssh_send_port_open(void *channel, const char *hostname, int port,
  479. const char *org);
  480. /* Exports from portfwd.c */
  481. extern char *pfd_connect(struct PortForwarding **pf, char *hostname, int port,
  482. void *c, Conf *conf, int addressfamily);
  483. extern void pfd_close(struct PortForwarding *);
  484. extern int pfd_send(struct PortForwarding *, char *data, int len);
  485. extern void pfd_send_eof(struct PortForwarding *);
  486. extern void pfd_confirm(struct PortForwarding *);
  487. extern void pfd_unthrottle(struct PortForwarding *);
  488. extern void pfd_override_throttle(struct PortForwarding *, int enable);
  489. struct PortListener;
  490. /* desthost == NULL indicates dynamic (SOCKS) port forwarding */
  491. extern char *pfl_listen(char *desthost, int destport, char *srcaddr,
  492. int port, void *backhandle, Conf *conf,
  493. struct PortListener **pl, int address_family);
  494. extern void pfl_terminate(struct PortListener *);
  495. /* Exports from x11fwd.c */
  496. enum {
  497. X11_TRANS_IPV4 = 0, X11_TRANS_IPV6 = 6, X11_TRANS_UNIX = 256
  498. };
  499. struct X11Display {
  500. /* Broken-down components of the display name itself */
  501. int unixdomain;
  502. char *hostname;
  503. int displaynum;
  504. int screennum;
  505. /* OSX sometimes replaces all the above with a full Unix-socket pathname */
  506. char *unixsocketpath;
  507. /* PuTTY networking SockAddr to connect to the display, and associated
  508. * gubbins */
  509. SockAddr addr;
  510. int port;
  511. char *realhost;
  512. /* Our local auth details for talking to the real X display. */
  513. int localauthproto;
  514. unsigned char *localauthdata;
  515. int localauthdatalen;
  516. };
  517. struct X11FakeAuth {
  518. /* Auth details we invented for a virtual display on the SSH server. */
  519. int proto;
  520. unsigned char *data;
  521. int datalen;
  522. char *protoname;
  523. char *datastring;
  524. /* The encrypted form of the first block, in XDM-AUTHORIZATION-1.
  525. * Used as part of the key when these structures are organised
  526. * into a tree. See x11_invent_fake_auth for explanation. */
  527. unsigned char *xa1_firstblock;
  528. /*
  529. * Used inside x11fwd.c to remember recently seen
  530. * XDM-AUTHORIZATION-1 strings, to avoid replay attacks.
  531. */
  532. tree234 *xdmseen;
  533. /*
  534. * What to do with an X connection matching this auth data.
  535. */
  536. struct X11Display *disp;
  537. void *share_cs, *share_chan;
  538. };
  539. void *x11_make_greeting(int endian, int protomajor, int protominor,
  540. int auth_proto, const void *auth_data, int auth_len,
  541. const char *peer_ip, int peer_port,
  542. int *outlen);
  543. int x11_authcmp(void *av, void *bv); /* for putting X11FakeAuth in a tree234 */
  544. /*
  545. * x11_setup_display() parses the display variable and fills in an
  546. * X11Display structure. Some remote auth details are invented;
  547. * the supplied authtype parameter configures the preferred
  548. * authorisation protocol to use at the remote end. The local auth
  549. * details are looked up by calling platform_get_x11_auth.
  550. */
  551. extern struct X11Display *x11_setup_display(const char *display, Conf *);
  552. void x11_free_display(struct X11Display *disp);
  553. struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
  554. void x11_free_fake_auth(struct X11FakeAuth *auth);
  555. struct X11Connection; /* opaque outside x11fwd.c */
  556. struct X11Connection *x11_init(tree234 *authtree, void *, const char *, int);
  557. extern void x11_close(struct X11Connection *);
  558. extern int x11_send(struct X11Connection *, char *, int);
  559. extern void x11_send_eof(struct X11Connection *s);
  560. extern void x11_unthrottle(struct X11Connection *s);
  561. extern void x11_override_throttle(struct X11Connection *s, int enable);
  562. char *x11_display(const char *display);
  563. /* Platform-dependent X11 functions */
  564. extern void platform_get_x11_auth(struct X11Display *display, Conf *);
  565. /* examine a mostly-filled-in X11Display and fill in localauth* */
  566. extern const int platform_uses_x11_unix_by_default;
  567. /* choose default X transport in the absence of a specified one */
  568. SockAddr platform_get_x11_unix_address(const char *path, int displaynum);
  569. /* make up a SockAddr naming the address for displaynum */
  570. char *platform_get_x_display(void);
  571. /* allocated local X display string, if any */
  572. /* Callbacks in x11.c usable _by_ platform X11 functions */
  573. /*
  574. * This function does the job of platform_get_x11_auth, provided
  575. * it is told where to find a normally formatted .Xauthority file:
  576. * it opens that file, parses it to find an auth record which
  577. * matches the display details in "display", and fills in the
  578. * localauth fields.
  579. *
  580. * It is expected that most implementations of
  581. * platform_get_x11_auth() will work by finding their system's
  582. * .Xauthority file, adjusting the display details if necessary
  583. * for local oddities like Unix-domain socket transport, and
  584. * calling this function to do the rest of the work.
  585. */
  586. void x11_get_auth_from_authfile(struct X11Display *display,
  587. const char *authfilename);
  588. int x11_identify_auth_proto(const char *proto);
  589. void *x11_dehexify(const char *hex, int *outlen);
  590. Bignum copybn(Bignum b);
  591. Bignum bn_power_2(int n);
  592. void bn_restore_invariant(Bignum b);
  593. Bignum bignum_from_long(unsigned long n);
  594. void freebn(Bignum b);
  595. Bignum modpow(Bignum base, Bignum exp, Bignum mod);
  596. Bignum modmul(Bignum a, Bignum b, Bignum mod);
  597. Bignum modsub(const Bignum a, const Bignum b, const Bignum n);
  598. void decbn(Bignum n);
  599. extern Bignum Zero, One;
  600. Bignum bignum_from_bytes(const unsigned char *data, int nbytes);
  601. Bignum bignum_from_bytes_le(const unsigned char *data, int nbytes);
  602. Bignum bignum_random_in_range(const Bignum lower, const Bignum upper);
  603. int ssh1_read_bignum(const unsigned char *data, int len, Bignum * result);
  604. int bignum_bitcount(Bignum bn);
  605. int ssh1_bignum_length(Bignum bn);
  606. int ssh2_bignum_length(Bignum bn);
  607. int bignum_byte(Bignum bn, int i);
  608. int bignum_bit(Bignum bn, int i);
  609. void bignum_set_bit(Bignum bn, int i, int value);
  610. int ssh1_write_bignum(void *data, Bignum bn);
  611. Bignum biggcd(Bignum a, Bignum b);
  612. unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
  613. Bignum bignum_add_long(Bignum number, unsigned long addend);
  614. Bignum bigadd(Bignum a, Bignum b);
  615. Bignum bigsub(Bignum a, Bignum b);
  616. Bignum bigmul(Bignum a, Bignum b);
  617. Bignum bigmuladd(Bignum a, Bignum b, Bignum addend);
  618. Bignum bigdiv(Bignum a, Bignum b);
  619. Bignum bigmod(Bignum a, Bignum b);
  620. Bignum modinv(Bignum number, Bignum modulus);
  621. Bignum bignum_bitmask(Bignum number);
  622. Bignum bignum_rshift(Bignum number, int shift);
  623. Bignum bignum_lshift(Bignum number, int shift);
  624. int bignum_cmp(Bignum a, Bignum b);
  625. char *bignum_decimal(Bignum x);
  626. Bignum bignum_from_decimal(const char *decimal);
  627. #ifdef DEBUG
  628. void diagbn(char *prefix, Bignum md);
  629. #endif
  630. int dh_is_gex(const struct ssh_kex *kex);
  631. void *dh_setup_group(const struct ssh_kex *kex);
  632. void *dh_setup_gex(Bignum pval, Bignum gval);
  633. void dh_cleanup(void *);
  634. Bignum dh_create_e(void *, int nbits);
  635. const char *dh_validate_f(void *handle, Bignum f);
  636. Bignum dh_find_K(void *, Bignum f);
  637. int loadrsakey(const Filename *filename, struct RSAKey *key,
  638. const char *passphrase, const char **errorstr);
  639. int rsakey_encrypted(const Filename *filename, char **comment);
  640. int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen,
  641. char **commentptr, const char **errorstr);
  642. int saversakey(const Filename *filename, struct RSAKey *key, char *passphrase);
  643. extern int base64_decode_atom(const char *atom, unsigned char *out);
  644. extern int base64_lines(int datalen);
  645. extern void base64_encode_atom(const unsigned char *data, int n, char *out);
  646. extern void base64_encode(FILE *fp, const unsigned char *data, int datalen,
  647. int cpl);
  648. /* ssh2_load_userkey can return this as an error */
  649. extern struct ssh2_userkey ssh2_wrong_passphrase;
  650. #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
  651. int ssh2_userkey_encrypted(const Filename *filename, char **comment);
  652. struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
  653. const char *passphrase,
  654. const char **errorstr);
  655. unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
  656. int *pub_blob_len, char **commentptr,
  657. const char **errorstr);
  658. int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
  659. char *passphrase);
  660. const struct ssh_signkey *find_pubkey_alg(const char *name);
  661. const struct ssh_signkey *find_pubkey_alg_len(int namelen, const char *name);
  662. enum {
  663. SSH_KEYTYPE_UNOPENABLE,
  664. SSH_KEYTYPE_UNKNOWN,
  665. SSH_KEYTYPE_SSH1, SSH_KEYTYPE_SSH2,
  666. /*
  667. * The OpenSSH key types deserve a little explanation. OpenSSH has
  668. * two physical formats for private key storage: an old PEM-based
  669. * one largely dictated by their use of OpenSSL and full of ASN.1,
  670. * and a new one using the same private key formats used over the
  671. * wire for talking to ssh-agent. The old format can only support
  672. * a subset of the key types, because it needs redesign for each
  673. * key type, and after a while they decided to move to the new
  674. * format so as not to have to do that.
  675. *
  676. * On input, key files are identified as either
  677. * SSH_KEYTYPE_OPENSSH_PEM or SSH_KEYTYPE_OPENSSH_NEW, describing
  678. * accurately which actual format the keys are stored in.
  679. *
  680. * On output, however, we default to following OpenSSH's own
  681. * policy of writing out PEM-style keys for maximum backwards
  682. * compatibility if the key type supports it, and otherwise
  683. * switching to the new format. So the formats you can select for
  684. * output are SSH_KEYTYPE_OPENSSH_NEW (forcing the new format for
  685. * any key type), and SSH_KEYTYPE_OPENSSH_AUTO to use the oldest
  686. * format supported by whatever key type you're writing out.
  687. *
  688. * So we have three type codes, but only two of them usable in any
  689. * given circumstance. An input key file will never be identified
  690. * as AUTO, only PEM or NEW; key export UIs should not be able to
  691. * select PEM, only AUTO or NEW.
  692. */
  693. SSH_KEYTYPE_OPENSSH_AUTO,
  694. SSH_KEYTYPE_OPENSSH_PEM,
  695. SSH_KEYTYPE_OPENSSH_NEW,
  696. SSH_KEYTYPE_SSHCOM,
  697. /*
  698. * Public-key-only formats, which we still want to be able to read
  699. * for various purposes.
  700. */
  701. SSH_KEYTYPE_SSH1_PUBLIC,
  702. SSH_KEYTYPE_SSH2_PUBLIC_RFC4716,
  703. SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH
  704. };
  705. char *ssh1_pubkey_str(struct RSAKey *ssh1key);
  706. void ssh1_write_pubkey(FILE *fp, struct RSAKey *ssh1key);
  707. char *ssh2_pubkey_openssh_str(struct ssh2_userkey *key);
  708. void ssh2_write_pubkey(FILE *fp, const char *comment,
  709. const void *v_pub_blob, int pub_len,
  710. int keytype);
  711. char *ssh2_fingerprint_blob(const void *blob, int bloblen);
  712. char *ssh2_fingerprint(const struct ssh_signkey *alg, void *data);
  713. int key_type(const Filename *filename);
  714. const char *key_type_to_str(int type);
  715. #ifdef MPEXT
  716. unsigned char *openssh_loadpub_line(char * line, char **algorithm,
  717. int *pub_blob_len, char **commentptr,
  718. const char **errorstr);
  719. #endif
  720. int import_possible(int type);
  721. int import_target_type(int type);
  722. int import_encrypted(const Filename *filename, int type, char **comment);
  723. int import_ssh1(const Filename *filename, int type,
  724. struct RSAKey *key, char *passphrase, const char **errmsg_p);
  725. struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
  726. char *passphrase, const char **errmsg_p);
  727. int export_ssh1(const Filename *filename, int type,
  728. struct RSAKey *key, char *passphrase);
  729. int export_ssh2(const Filename *filename, int type,
  730. struct ssh2_userkey *key, char *passphrase);
  731. void des3_decrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
  732. void des3_encrypt_pubkey(unsigned char *key, unsigned char *blk, int len);
  733. void des3_decrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
  734. unsigned char *blk, int len);
  735. void des3_encrypt_pubkey_ossh(unsigned char *key, unsigned char *iv,
  736. unsigned char *blk, int len);
  737. void aes256_encrypt_pubkey(unsigned char *key, unsigned char *blk,
  738. int len);
  739. void aes256_decrypt_pubkey(unsigned char *key, unsigned char *blk,
  740. int len);
  741. void des_encrypt_xdmauth(const unsigned char *key,
  742. unsigned char *blk, int len);
  743. void des_decrypt_xdmauth(const unsigned char *key,
  744. unsigned char *blk, int len);
  745. void openssh_bcrypt(const char *passphrase,
  746. const unsigned char *salt, int saltbytes,
  747. int rounds, unsigned char *out, int outbytes);
  748. /*
  749. * For progress updates in the key generation utility.
  750. */
  751. #define PROGFN_INITIALISE 1
  752. #define PROGFN_LIN_PHASE 2
  753. #define PROGFN_EXP_PHASE 3
  754. #define PROGFN_PHASE_EXTENT 4
  755. #define PROGFN_READY 5
  756. #define PROGFN_PROGRESS 6
  757. typedef void (*progfn_t) (void *param, int action, int phase, int progress);
  758. int rsa_generate(struct RSAKey *key, int bits, progfn_t pfn,
  759. void *pfnparam);
  760. int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
  761. void *pfnparam);
  762. int ec_generate(struct ec_key *key, int bits, progfn_t pfn,
  763. void *pfnparam);
  764. int ec_edgenerate(struct ec_key *key, int bits, progfn_t pfn,
  765. void *pfnparam);
  766. Bignum primegen(int bits, int modulus, int residue, Bignum factor,
  767. int phase, progfn_t pfn, void *pfnparam, unsigned firstbits);
  768. void invent_firstbits(unsigned *one, unsigned *two);
  769. /*
  770. * zlib compression.
  771. */
  772. void *zlib_compress_init(void);
  773. void zlib_compress_cleanup(void *);
  774. void *zlib_decompress_init(void);
  775. void zlib_decompress_cleanup(void *);
  776. int zlib_compress_block(void *, unsigned char *block, int len,
  777. unsigned char **outblock, int *outlen);
  778. int zlib_decompress_block(void *, unsigned char *block, int len,
  779. unsigned char **outblock, int *outlen);
  780. /*
  781. * Connection-sharing API provided by platforms. This function must
  782. * either:
  783. * - return SHARE_NONE and do nothing
  784. * - return SHARE_DOWNSTREAM and set *sock to a Socket connected to
  785. * downplug
  786. * - return SHARE_UPSTREAM and set *sock to a Socket connected to
  787. * upplug.
  788. */
  789. enum { SHARE_NONE, SHARE_DOWNSTREAM, SHARE_UPSTREAM };
  790. int platform_ssh_share(const char *name, Conf *conf,
  791. Plug downplug, Plug upplug, Socket *sock,
  792. char **logtext, char **ds_err, char **us_err,
  793. int can_upstream, int can_downstream);
  794. void platform_ssh_share_cleanup(const char *name);
  795. /*
  796. * SSH-1 message type codes.
  797. */
  798. #define SSH1_MSG_DISCONNECT 1 /* 0x1 */
  799. #define SSH1_SMSG_PUBLIC_KEY 2 /* 0x2 */
  800. #define SSH1_CMSG_SESSION_KEY 3 /* 0x3 */
  801. #define SSH1_CMSG_USER 4 /* 0x4 */
  802. #define SSH1_CMSG_AUTH_RSA 6 /* 0x6 */
  803. #define SSH1_SMSG_AUTH_RSA_CHALLENGE 7 /* 0x7 */
  804. #define SSH1_CMSG_AUTH_RSA_RESPONSE 8 /* 0x8 */
  805. #define SSH1_CMSG_AUTH_PASSWORD 9 /* 0x9 */
  806. #define SSH1_CMSG_REQUEST_PTY 10 /* 0xa */
  807. #define SSH1_CMSG_WINDOW_SIZE 11 /* 0xb */
  808. #define SSH1_CMSG_EXEC_SHELL 12 /* 0xc */
  809. #define SSH1_CMSG_EXEC_CMD 13 /* 0xd */
  810. #define SSH1_SMSG_SUCCESS 14 /* 0xe */
  811. #define SSH1_SMSG_FAILURE 15 /* 0xf */
  812. #define SSH1_CMSG_STDIN_DATA 16 /* 0x10 */
  813. #define SSH1_SMSG_STDOUT_DATA 17 /* 0x11 */
  814. #define SSH1_SMSG_STDERR_DATA 18 /* 0x12 */
  815. #define SSH1_CMSG_EOF 19 /* 0x13 */
  816. #define SSH1_SMSG_EXIT_STATUS 20 /* 0x14 */
  817. #define SSH1_MSG_CHANNEL_OPEN_CONFIRMATION 21 /* 0x15 */
  818. #define SSH1_MSG_CHANNEL_OPEN_FAILURE 22 /* 0x16 */
  819. #define SSH1_MSG_CHANNEL_DATA 23 /* 0x17 */
  820. #define SSH1_MSG_CHANNEL_CLOSE 24 /* 0x18 */
  821. #define SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION 25 /* 0x19 */
  822. #define SSH1_SMSG_X11_OPEN 27 /* 0x1b */
  823. #define SSH1_CMSG_PORT_FORWARD_REQUEST 28 /* 0x1c */
  824. #define SSH1_MSG_PORT_OPEN 29 /* 0x1d */
  825. #define SSH1_CMSG_AGENT_REQUEST_FORWARDING 30 /* 0x1e */
  826. #define SSH1_SMSG_AGENT_OPEN 31 /* 0x1f */
  827. #define SSH1_MSG_IGNORE 32 /* 0x20 */
  828. #define SSH1_CMSG_EXIT_CONFIRMATION 33 /* 0x21 */
  829. #define SSH1_CMSG_X11_REQUEST_FORWARDING 34 /* 0x22 */
  830. #define SSH1_CMSG_AUTH_RHOSTS_RSA 35 /* 0x23 */
  831. #define SSH1_MSG_DEBUG 36 /* 0x24 */
  832. #define SSH1_CMSG_REQUEST_COMPRESSION 37 /* 0x25 */
  833. #define SSH1_CMSG_AUTH_TIS 39 /* 0x27 */
  834. #define SSH1_SMSG_AUTH_TIS_CHALLENGE 40 /* 0x28 */
  835. #define SSH1_CMSG_AUTH_TIS_RESPONSE 41 /* 0x29 */
  836. #define SSH1_CMSG_AUTH_CCARD 70 /* 0x46 */
  837. #define SSH1_SMSG_AUTH_CCARD_CHALLENGE 71 /* 0x47 */
  838. #define SSH1_CMSG_AUTH_CCARD_RESPONSE 72 /* 0x48 */
  839. #define SSH1_AUTH_RHOSTS 1 /* 0x1 */
  840. #define SSH1_AUTH_RSA 2 /* 0x2 */
  841. #define SSH1_AUTH_PASSWORD 3 /* 0x3 */
  842. #define SSH1_AUTH_RHOSTS_RSA 4 /* 0x4 */
  843. #define SSH1_AUTH_TIS 5 /* 0x5 */
  844. #define SSH1_AUTH_CCARD 16 /* 0x10 */
  845. #define SSH1_PROTOFLAG_SCREEN_NUMBER 1 /* 0x1 */
  846. /* Mask for protoflags we will echo back to server if seen */
  847. #define SSH1_PROTOFLAGS_SUPPORTED 0 /* 0x1 */
  848. /*
  849. * SSH-2 message type codes.
  850. */
  851. #define SSH2_MSG_DISCONNECT 1 /* 0x1 */
  852. #define SSH2_MSG_IGNORE 2 /* 0x2 */
  853. #define SSH2_MSG_UNIMPLEMENTED 3 /* 0x3 */
  854. #define SSH2_MSG_DEBUG 4 /* 0x4 */
  855. #define SSH2_MSG_SERVICE_REQUEST 5 /* 0x5 */
  856. #define SSH2_MSG_SERVICE_ACCEPT 6 /* 0x6 */
  857. #define SSH2_MSG_KEXINIT 20 /* 0x14 */
  858. #define SSH2_MSG_NEWKEYS 21 /* 0x15 */
  859. #define SSH2_MSG_KEXDH_INIT 30 /* 0x1e */
  860. #define SSH2_MSG_KEXDH_REPLY 31 /* 0x1f */
  861. #define SSH2_MSG_KEX_DH_GEX_REQUEST_OLD 30 /* 0x1e */
  862. #define SSH2_MSG_KEX_DH_GEX_REQUEST 34 /* 0x22 */
  863. #define SSH2_MSG_KEX_DH_GEX_GROUP 31 /* 0x1f */
  864. #define SSH2_MSG_KEX_DH_GEX_INIT 32 /* 0x20 */
  865. #define SSH2_MSG_KEX_DH_GEX_REPLY 33 /* 0x21 */
  866. #define SSH2_MSG_KEXRSA_PUBKEY 30 /* 0x1e */
  867. #define SSH2_MSG_KEXRSA_SECRET 31 /* 0x1f */
  868. #define SSH2_MSG_KEXRSA_DONE 32 /* 0x20 */
  869. #define SSH2_MSG_KEX_ECDH_INIT 30 /* 0x1e */
  870. #define SSH2_MSG_KEX_ECDH_REPLY 31 /* 0x1f */
  871. #define SSH2_MSG_KEX_ECMQV_INIT 30 /* 0x1e */
  872. #define SSH2_MSG_KEX_ECMQV_REPLY 31 /* 0x1f */
  873. #define SSH2_MSG_USERAUTH_REQUEST 50 /* 0x32 */
  874. #define SSH2_MSG_USERAUTH_FAILURE 51 /* 0x33 */
  875. #define SSH2_MSG_USERAUTH_SUCCESS 52 /* 0x34 */
  876. #define SSH2_MSG_USERAUTH_BANNER 53 /* 0x35 */
  877. #define SSH2_MSG_USERAUTH_PK_OK 60 /* 0x3c */
  878. #define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60 /* 0x3c */
  879. #define SSH2_MSG_USERAUTH_INFO_REQUEST 60 /* 0x3c */
  880. #define SSH2_MSG_USERAUTH_INFO_RESPONSE 61 /* 0x3d */
  881. #define SSH2_MSG_GLOBAL_REQUEST 80 /* 0x50 */
  882. #define SSH2_MSG_REQUEST_SUCCESS 81 /* 0x51 */
  883. #define SSH2_MSG_REQUEST_FAILURE 82 /* 0x52 */
  884. #define SSH2_MSG_CHANNEL_OPEN 90 /* 0x5a */
  885. #define SSH2_MSG_CHANNEL_OPEN_CONFIRMATION 91 /* 0x5b */
  886. #define SSH2_MSG_CHANNEL_OPEN_FAILURE 92 /* 0x5c */
  887. #define SSH2_MSG_CHANNEL_WINDOW_ADJUST 93 /* 0x5d */
  888. #define SSH2_MSG_CHANNEL_DATA 94 /* 0x5e */
  889. #define SSH2_MSG_CHANNEL_EXTENDED_DATA 95 /* 0x5f */
  890. #define SSH2_MSG_CHANNEL_EOF 96 /* 0x60 */
  891. #define SSH2_MSG_CHANNEL_CLOSE 97 /* 0x61 */
  892. #define SSH2_MSG_CHANNEL_REQUEST 98 /* 0x62 */
  893. #define SSH2_MSG_CHANNEL_SUCCESS 99 /* 0x63 */
  894. #define SSH2_MSG_CHANNEL_FAILURE 100 /* 0x64 */
  895. #define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE 60
  896. #define SSH2_MSG_USERAUTH_GSSAPI_TOKEN 61
  897. #define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
  898. #define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
  899. #define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65
  900. #define SSH2_MSG_USERAUTH_GSSAPI_MIC 66
  901. /*
  902. * SSH-1 agent messages.
  903. */
  904. #define SSH1_AGENTC_REQUEST_RSA_IDENTITIES 1
  905. #define SSH1_AGENT_RSA_IDENTITIES_ANSWER 2
  906. #define SSH1_AGENTC_RSA_CHALLENGE 3
  907. #define SSH1_AGENT_RSA_RESPONSE 4
  908. #define SSH1_AGENTC_ADD_RSA_IDENTITY 7
  909. #define SSH1_AGENTC_REMOVE_RSA_IDENTITY 8
  910. #define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
  911. /*
  912. * Messages common to SSH-1 and OpenSSH's SSH-2.
  913. */
  914. #define SSH_AGENT_FAILURE 5
  915. #define SSH_AGENT_SUCCESS 6
  916. /*
  917. * OpenSSH's SSH-2 agent messages.
  918. */
  919. #define SSH2_AGENTC_REQUEST_IDENTITIES 11
  920. #define SSH2_AGENT_IDENTITIES_ANSWER 12
  921. #define SSH2_AGENTC_SIGN_REQUEST 13
  922. #define SSH2_AGENT_SIGN_RESPONSE 14
  923. #define SSH2_AGENTC_ADD_IDENTITY 17
  924. #define SSH2_AGENTC_REMOVE_IDENTITY 18
  925. #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
  926. /*
  927. * Assorted other SSH-related enumerations.
  928. */
  929. #define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 /* 0x1 */
  930. #define SSH2_DISCONNECT_PROTOCOL_ERROR 2 /* 0x2 */
  931. #define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED 3 /* 0x3 */
  932. #define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4 /* 0x4 */
  933. #define SSH2_DISCONNECT_MAC_ERROR 5 /* 0x5 */
  934. #define SSH2_DISCONNECT_COMPRESSION_ERROR 6 /* 0x6 */
  935. #define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE 7 /* 0x7 */
  936. #define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 /* 0x8 */
  937. #define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 /* 0x9 */
  938. #define SSH2_DISCONNECT_CONNECTION_LOST 10 /* 0xa */
  939. #define SSH2_DISCONNECT_BY_APPLICATION 11 /* 0xb */
  940. #define SSH2_DISCONNECT_TOO_MANY_CONNECTIONS 12 /* 0xc */
  941. #define SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER 13 /* 0xd */
  942. #define SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14 /* 0xe */
  943. #define SSH2_DISCONNECT_ILLEGAL_USER_NAME 15 /* 0xf */
  944. #define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED 1 /* 0x1 */
  945. #define SSH2_OPEN_CONNECT_FAILED 2 /* 0x2 */
  946. #define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE 3 /* 0x3 */
  947. #define SSH2_OPEN_RESOURCE_SHORTAGE 4 /* 0x4 */
  948. #define SSH2_EXTENDED_DATA_STDERR 1 /* 0x1 */
  949. /*
  950. * Need this to warn about support for the original SSH-2 keyfile
  951. * format.
  952. */
  953. void old_keyfile_warning(void);
  954. #endif // WINSCP_VS