ssh.h 42 KB

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