ssh.h 41 KB

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