ssh.h 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define WINSCP_SSH
  4. #include "puttymem.h"
  5. #include "tree234.h"
  6. #ifndef WINSCP_VS
  7. #include "network.h"
  8. #endif
  9. #include "misc.h"
  10. #ifndef WINSCP_VS
  11. struct ssh_channel;
  12. /*
  13. * Buffer management constants. There are several of these for
  14. * various different purposes:
  15. *
  16. * - SSH1_BUFFER_LIMIT is the amount of backlog that must build up
  17. * on a local data stream before we throttle the whole SSH
  18. * connection (in SSH-1 only). Throttling the whole connection is
  19. * pretty drastic so we set this high in the hope it won't
  20. * happen very often.
  21. *
  22. * - SSH_MAX_BACKLOG is the amount of backlog that must build up
  23. * on the SSH connection itself before we defensively throttle
  24. * _all_ local data streams. This is pretty drastic too (though
  25. * thankfully unlikely in SSH-2 since the window mechanism should
  26. * ensure that the server never has any need to throttle its end
  27. * of the connection), so we set this high as well.
  28. *
  29. * - OUR_V2_WINSIZE is the default window size we present on SSH-2
  30. * channels.
  31. *
  32. * - OUR_V2_BIGWIN is the window size we advertise for the only
  33. * channel in a simple connection. It must be <= INT_MAX.
  34. *
  35. * - OUR_V2_MAXPKT is the official "maximum packet size" we send
  36. * to the remote side. This actually has nothing to do with the
  37. * size of the _packet_, but is instead a limit on the amount
  38. * of data we're willing to receive in a single SSH2 channel
  39. * data message.
  40. *
  41. * - OUR_V2_PACKETLIMIT is actually the maximum size of SSH
  42. * _packet_ we're prepared to cope with. It must be a multiple
  43. * of the cipher block size, and must be at least 35000.
  44. */
  45. #define SSH1_BUFFER_LIMIT 32768
  46. #define SSH_MAX_BACKLOG 32768
  47. #define OUR_V2_WINSIZE 16384
  48. #define OUR_V2_BIGWIN 0x7fffffff
  49. #define OUR_V2_MAXPKT 0x4000UL
  50. #define OUR_V2_PACKETLIMIT 0x9000UL
  51. typedef struct PacketQueueNode PacketQueueNode;
  52. struct PacketQueueNode {
  53. PacketQueueNode *next, *prev;
  54. size_t formal_size; /* contribution to PacketQueueBase's total_size */
  55. bool on_free_queue; /* is this packet scheduled for freeing? */
  56. };
  57. typedef struct PktIn {
  58. int type;
  59. unsigned long sequence; /* SSH-2 incoming sequence number */
  60. PacketQueueNode qnode; /* for linking this packet on to a queue */
  61. BinarySource_IMPLEMENTATION;
  62. } PktIn;
  63. typedef struct PktOut {
  64. size_t prefix; /* bytes up to and including type field */
  65. size_t length; /* total bytes, including prefix */
  66. int type;
  67. size_t minlen; /* SSH-2: ensure wire length is at least this */
  68. unsigned char *data; /* allocated storage */
  69. size_t maxlen; /* amount of storage allocated for `data' */
  70. /* Extra metadata used in SSH packet logging mode, allowing us to
  71. * log in the packet header line that the packet came from a
  72. * connection-sharing downstream and what if anything unusual was
  73. * done to it. The additional_log_text field is expected to be a
  74. * static string - it will not be freed. */
  75. unsigned downstream_id;
  76. const char *additional_log_text;
  77. PacketQueueNode qnode; /* for linking this packet on to a queue */
  78. BinarySink_IMPLEMENTATION;
  79. } PktOut;
  80. typedef struct PacketQueueBase {
  81. PacketQueueNode end;
  82. size_t total_size; /* sum of all formal_size fields on the queue */
  83. struct IdempotentCallback *ic;
  84. Seat * seat; // WINSCP
  85. } PacketQueueBase;
  86. typedef struct PktInQueue {
  87. PacketQueueBase pqb;
  88. PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop);
  89. } PktInQueue;
  90. typedef struct PktOutQueue {
  91. PacketQueueBase pqb;
  92. PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop);
  93. } PktOutQueue;
  94. void pq_base_push(PacketQueueBase *pqb, PacketQueueNode *node);
  95. void pq_base_push_front(PacketQueueBase *pqb, PacketQueueNode *node);
  96. void pq_base_concatenate(PacketQueueBase *dest,
  97. PacketQueueBase *q1, PacketQueueBase *q2);
  98. void pq_in_init(PktInQueue *pq, Seat * seat); // WINSCP
  99. void pq_out_init(PktOutQueue *pq, Seat * seat); // WINSCP
  100. void pq_in_clear(PktInQueue *pq);
  101. void pq_out_clear(PktOutQueue *pq);
  102. #define pq_push(pq, pkt) \
  103. TYPECHECK((pq)->after(&(pq)->pqb, NULL, false) == pkt, \
  104. pq_base_push(&(pq)->pqb, &(pkt)->qnode))
  105. #define pq_push_front(pq, pkt) \
  106. TYPECHECK((pq)->after(&(pq)->pqb, NULL, false) == pkt, \
  107. pq_base_push_front(&(pq)->pqb, &(pkt)->qnode))
  108. #define pq_peek(pq) ((pq)->after(&(pq)->pqb, &(pq)->pqb.end, false))
  109. #define pq_pop(pq) ((pq)->after(&(pq)->pqb, &(pq)->pqb.end, true))
  110. #define pq_concatenate(dst, q1, q2) \
  111. TYPECHECK((q1)->after(&(q1)->pqb, NULL, false) == \
  112. (dst)->after(&(dst)->pqb, NULL, false) && \
  113. (q2)->after(&(q2)->pqb, NULL, false) == \
  114. (dst)->after(&(dst)->pqb, NULL, false), \
  115. pq_base_concatenate(&(dst)->pqb, &(q1)->pqb, &(q2)->pqb))
  116. #define pq_first(pq) pq_peek(pq)
  117. #define pq_next(pq, pkt) ((pq)->after(&(pq)->pqb, &(pkt)->qnode, false))
  118. /*
  119. * Packet type contexts, so that ssh2_pkt_type can correctly decode
  120. * the ambiguous type numbers back into the correct type strings.
  121. */
  122. typedef enum {
  123. SSH2_PKTCTX_NOKEX,
  124. SSH2_PKTCTX_DHGROUP,
  125. SSH2_PKTCTX_DHGEX,
  126. SSH2_PKTCTX_ECDHKEX,
  127. SSH2_PKTCTX_GSSKEX,
  128. SSH2_PKTCTX_RSAKEX
  129. } Pkt_KCtx;
  130. typedef enum {
  131. SSH2_PKTCTX_NOAUTH,
  132. SSH2_PKTCTX_PUBLICKEY,
  133. SSH2_PKTCTX_PASSWORD,
  134. SSH2_PKTCTX_GSSAPI,
  135. SSH2_PKTCTX_KBDINTER
  136. } Pkt_ACtx;
  137. typedef struct PacketLogSettings {
  138. bool omit_passwords, omit_data;
  139. Pkt_KCtx kctx;
  140. Pkt_ACtx actx;
  141. } PacketLogSettings;
  142. #define MAX_BLANKS 4 /* no packet needs more censored sections than this */
  143. int ssh1_censor_packet(
  144. const PacketLogSettings *pls, int type, bool sender_is_client,
  145. ptrlen pkt, logblank_t *blanks);
  146. int ssh2_censor_packet(
  147. const PacketLogSettings *pls, int type, bool sender_is_client,
  148. ptrlen pkt, logblank_t *blanks);
  149. PktOut *ssh_new_packet(void);
  150. void ssh_free_pktout(PktOut *pkt);
  151. Socket *ssh_connection_sharing_init(
  152. const char *host, int port, Conf *conf, LogContext *logctx,
  153. Plug *sshplug, ssh_sharing_state **state);
  154. void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate,
  155. ConnectionLayer *cl);
  156. bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
  157. void share_got_pkt_from_server(ssh_sharing_connstate *ctx, int type,
  158. const void *pkt, int pktlen);
  159. void share_activate(ssh_sharing_state *sharestate,
  160. const char *server_verstring);
  161. void sharestate_free(ssh_sharing_state *state);
  162. int share_ndownstreams(ssh_sharing_state *state);
  163. void ssh_connshare_log(Ssh *ssh, int event, const char *logtext,
  164. const char *ds_err, const char *us_err);
  165. void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan,
  166. unsigned upstream_id, unsigned server_id,
  167. unsigned server_currwin, unsigned server_maxpkt,
  168. unsigned client_adjusted_window,
  169. const char *peer_addr, int peer_port, int endian,
  170. int protomajor, int protominor,
  171. const void *initial_data, int initial_len);
  172. /* Per-application overrides for what roles we can take in connection
  173. * sharing, regardless of user configuration (e.g. pscp will never be
  174. * an upstream) */
  175. extern const bool share_can_be_downstream;
  176. extern const bool share_can_be_upstream;
  177. struct X11Display;
  178. struct X11FakeAuth;
  179. /* Structure definition centralised here because the SSH-1 and SSH-2
  180. * connection layers both use it. But the client module (portfwd.c)
  181. * should not try to look inside here. */
  182. struct ssh_rportfwd {
  183. unsigned sport, dport;
  184. char *shost, *dhost;
  185. int addressfamily;
  186. char *log_description; /* name of remote listening port, for logging */
  187. ssh_sharing_connstate *share_ctx;
  188. PortFwdRecord *pfr;
  189. };
  190. void free_rportfwd(struct ssh_rportfwd *rpf);
  191. typedef struct ConnectionLayerVtable ConnectionLayerVtable;
  192. struct ConnectionLayerVtable {
  193. /* Allocate and free remote-to-local port forwardings, called by
  194. * PortFwdManager or by connection sharing */
  195. struct ssh_rportfwd *(*rportfwd_alloc)(
  196. ConnectionLayer *cl,
  197. const char *shost, int sport, const char *dhost, int dport,
  198. int addressfamily, const char *log_description, PortFwdRecord *pfr,
  199. ssh_sharing_connstate *share_ctx);
  200. void (*rportfwd_remove)(ConnectionLayer *cl, struct ssh_rportfwd *rpf);
  201. /* Open a local-to-remote port forwarding channel, called by
  202. * PortFwdManager */
  203. SshChannel *(*lportfwd_open)(
  204. ConnectionLayer *cl, const char *hostname, int port,
  205. const char *description, const SocketPeerInfo *peerinfo,
  206. Channel *chan);
  207. /* Initiate opening of a 'session'-type channel */
  208. SshChannel *(*session_open)(ConnectionLayer *cl, Channel *chan);
  209. /* Open outgoing channels for X and agent forwarding. (Used in the
  210. * SSH server.) */
  211. SshChannel *(*serverside_x11_open)(ConnectionLayer *cl, Channel *chan,
  212. const SocketPeerInfo *pi);
  213. SshChannel *(*serverside_agent_open)(ConnectionLayer *cl, Channel *chan);
  214. /* Add an X11 display for ordinary X forwarding */
  215. struct X11FakeAuth *(*add_x11_display)(
  216. ConnectionLayer *cl, int authtype, struct X11Display *x11disp);
  217. /* Add and remove X11 displays for connection sharing downstreams */
  218. struct X11FakeAuth *(*add_sharing_x11_display)(
  219. ConnectionLayer *cl, int authtype, ssh_sharing_connstate *share_cs,
  220. share_channel *share_chan);
  221. void (*remove_sharing_x11_display)(
  222. ConnectionLayer *cl, struct X11FakeAuth *auth);
  223. /* Pass through an outgoing SSH packet from a downstream */
  224. void (*send_packet_from_downstream)(
  225. ConnectionLayer *cl, unsigned id, int type,
  226. const void *pkt, int pktlen, const char *additional_log_text);
  227. /* Allocate/free an upstream channel number associated with a
  228. * sharing downstream */
  229. unsigned (*alloc_sharing_channel)(ConnectionLayer *cl,
  230. ssh_sharing_connstate *connstate);
  231. void (*delete_sharing_channel)(ConnectionLayer *cl, unsigned localid);
  232. /* Indicate that a downstream has sent a global request with the
  233. * want-reply flag, so that when a reply arrives it will be passed
  234. * back to that downstrean */
  235. void (*sharing_queue_global_request)(
  236. ConnectionLayer *cl, ssh_sharing_connstate *connstate);
  237. /* Indicate that the last downstream has disconnected */
  238. void (*sharing_no_more_downstreams)(ConnectionLayer *cl);
  239. /* Query whether the connection layer is doing agent forwarding */
  240. bool (*agent_forwarding_permitted)(ConnectionLayer *cl);
  241. /* Set the size of the main terminal window (if any) */
  242. void (*terminal_size)(ConnectionLayer *cl, int width, int height);
  243. /* Indicate that the backlog on standard output has cleared */
  244. void (*stdout_unthrottle)(ConnectionLayer *cl, size_t bufsize);
  245. /* Query the size of the backlog on standard _input_ */
  246. size_t (*stdin_backlog)(ConnectionLayer *cl);
  247. /* Tell the connection layer that the SSH connection itself has
  248. * backed up, so it should tell all currently open channels to
  249. * cease reading from their local input sources if they can. (Or
  250. * tell it that that state of affairs has gone away again.) */
  251. void (*throttle_all_channels)(ConnectionLayer *cl, bool throttled);
  252. /* Ask the connection layer about its current preference for
  253. * line-discipline options. */
  254. bool (*ldisc_option)(ConnectionLayer *cl, int option);
  255. /* Communicate _to_ the connection layer (from the main session
  256. * channel) what its preference for line-discipline options is. */
  257. void (*set_ldisc_option)(ConnectionLayer *cl, int option, bool value);
  258. /* Communicate to the connection layer whether X forwarding was
  259. * successfully enabled (for purposes of knowing whether to accept
  260. * subsequent channel-opens). */
  261. void (*enable_x_fwd)(ConnectionLayer *cl);
  262. /* Communicate / query whether the main session channel currently
  263. * wants user input. The set function is called by mainchan; the
  264. * query function is called by the top-level ssh.c. */
  265. void (*set_wants_user_input)(ConnectionLayer *cl, bool wanted);
  266. bool (*get_wants_user_input)(ConnectionLayer *cl);
  267. /* Notify the connection layer that more data has been added to
  268. * the user input queue. */
  269. void (*got_user_input)(ConnectionLayer *cl);
  270. };
  271. struct ConnectionLayer {
  272. LogContext *logctx;
  273. const struct ConnectionLayerVtable *vt;
  274. };
  275. static inline struct ssh_rportfwd *ssh_rportfwd_alloc(
  276. ConnectionLayer *cl, const char *sh, int sp, const char *dh, int dp,
  277. int af, const char *log, PortFwdRecord *pfr, ssh_sharing_connstate *cs)
  278. { return cl->vt->rportfwd_alloc(cl, sh, sp, dh, dp, af, log, pfr, cs); }
  279. static inline void ssh_rportfwd_remove(
  280. ConnectionLayer *cl, struct ssh_rportfwd *rpf)
  281. { cl->vt->rportfwd_remove(cl, rpf); }
  282. static inline SshChannel *ssh_lportfwd_open(
  283. ConnectionLayer *cl, const char *host, int port,
  284. const char *desc, const SocketPeerInfo *pi, Channel *chan)
  285. { return cl->vt->lportfwd_open(cl, host, port, desc, pi, chan); }
  286. static inline SshChannel *ssh_session_open(ConnectionLayer *cl, Channel *chan)
  287. { return cl->vt->session_open(cl, chan); }
  288. static inline SshChannel *ssh_serverside_x11_open(
  289. ConnectionLayer *cl, Channel *chan, const SocketPeerInfo *pi)
  290. { return cl->vt->serverside_x11_open(cl, chan, pi); }
  291. static inline SshChannel *ssh_serverside_agent_open(
  292. ConnectionLayer *cl, Channel *chan)
  293. { return cl->vt->serverside_agent_open(cl, chan); }
  294. static inline struct X11FakeAuth *ssh_add_x11_display(
  295. ConnectionLayer *cl, int authtype, struct X11Display *x11disp)
  296. { return cl->vt->add_x11_display(cl, authtype, x11disp); }
  297. static inline struct X11FakeAuth *ssh_add_sharing_x11_display(
  298. ConnectionLayer *cl, int authtype, ssh_sharing_connstate *share_cs,
  299. share_channel *share_chan)
  300. { return cl->vt->add_sharing_x11_display(cl, authtype, share_cs, share_chan); }
  301. static inline void ssh_remove_sharing_x11_display(
  302. ConnectionLayer *cl, struct X11FakeAuth *auth)
  303. { cl->vt->remove_sharing_x11_display(cl, auth); }
  304. static inline void ssh_send_packet_from_downstream(
  305. ConnectionLayer *cl, unsigned id, int type,
  306. const void *pkt, int len, const char *log)
  307. { cl->vt->send_packet_from_downstream(cl, id, type, pkt, len, log); }
  308. static inline unsigned ssh_alloc_sharing_channel(
  309. ConnectionLayer *cl, ssh_sharing_connstate *connstate)
  310. { return cl->vt->alloc_sharing_channel(cl, connstate); }
  311. static inline void ssh_delete_sharing_channel(
  312. ConnectionLayer *cl, unsigned localid)
  313. { cl->vt->delete_sharing_channel(cl, localid); }
  314. static inline void ssh_sharing_queue_global_request(
  315. ConnectionLayer *cl, ssh_sharing_connstate *connstate)
  316. { cl->vt->sharing_queue_global_request(cl, connstate); }
  317. static inline void ssh_sharing_no_more_downstreams(ConnectionLayer *cl)
  318. { cl->vt->sharing_no_more_downstreams(cl); }
  319. static inline bool ssh_agent_forwarding_permitted(ConnectionLayer *cl)
  320. { return cl->vt->agent_forwarding_permitted(cl); }
  321. static inline void ssh_terminal_size(ConnectionLayer *cl, int w, int h)
  322. { cl->vt->terminal_size(cl, w, h); }
  323. static inline void ssh_stdout_unthrottle(ConnectionLayer *cl, size_t bufsize)
  324. { cl->vt->stdout_unthrottle(cl, bufsize); }
  325. static inline size_t ssh_stdin_backlog(ConnectionLayer *cl)
  326. { return cl->vt->stdin_backlog(cl); }
  327. static inline void ssh_throttle_all_channels(ConnectionLayer *cl, bool thr)
  328. { cl->vt->throttle_all_channels(cl, thr); }
  329. static inline bool ssh_ldisc_option(ConnectionLayer *cl, int option)
  330. { return cl->vt->ldisc_option(cl, option); }
  331. static inline void ssh_set_ldisc_option(ConnectionLayer *cl, int opt, bool val)
  332. { cl->vt->set_ldisc_option(cl, opt, val); }
  333. static inline void ssh_enable_x_fwd(ConnectionLayer *cl)
  334. { cl->vt->enable_x_fwd(cl); }
  335. static inline void ssh_set_wants_user_input(ConnectionLayer *cl, bool wanted)
  336. { cl->vt->set_wants_user_input(cl, wanted); }
  337. static inline bool ssh_get_wants_user_input(ConnectionLayer *cl)
  338. { return cl->vt->get_wants_user_input(cl); }
  339. static inline void ssh_got_user_input(ConnectionLayer *cl)
  340. { cl->vt->got_user_input(cl); }
  341. /* Exports from portfwd.c */
  342. PortFwdManager *portfwdmgr_new(ConnectionLayer *cl);
  343. void portfwdmgr_free(PortFwdManager *mgr);
  344. void portfwdmgr_config(PortFwdManager *mgr, Conf *conf);
  345. void portfwdmgr_close(PortFwdManager *mgr, PortFwdRecord *pfr);
  346. void portfwdmgr_close_all(PortFwdManager *mgr);
  347. char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
  348. char *hostname, int port, SshChannel *c,
  349. int addressfamily);
  350. bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
  351. const char *keyhost, int keyport, Conf *conf);
  352. bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port);
  353. Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug, bool start_ready);
  354. void portfwd_raw_free(Channel *pfchan);
  355. void portfwd_raw_setup(Channel *pfchan, Socket *s, SshChannel *sc);
  356. Socket *platform_make_agent_socket(Plug *plug, const char *dirprefix,
  357. char **error, char **name);
  358. LogContext *ssh_get_logctx(Ssh *ssh);
  359. /* Communications back to ssh.c from connection layers */
  360. void ssh_throttle_conn(Ssh *ssh, int adjust);
  361. void ssh_got_exitcode(Ssh *ssh, int status);
  362. void ssh_ldisc_update(Ssh *ssh);
  363. void ssh_check_sendok(Ssh *ssh);
  364. void ssh_got_fallback_cmd(Ssh *ssh);
  365. bool ssh_is_bare(Ssh *ssh);
  366. /* Communications back to ssh.c from the BPP */
  367. void ssh_conn_processed_data(Ssh *ssh);
  368. void ssh_sendbuffer_changed(Ssh *ssh);
  369. void ssh_check_frozen(Ssh *ssh);
  370. /* Functions to abort the connection, for various reasons. */
  371. void ssh_remote_error(Ssh *ssh, const char *fmt, ...) PRINTF_LIKE(2, 3);
  372. void ssh_remote_eof(Ssh *ssh, const char *fmt, ...) PRINTF_LIKE(2, 3);
  373. void ssh_proto_error(Ssh *ssh, const char *fmt, ...) PRINTF_LIKE(2, 3);
  374. void ssh_sw_abort(Ssh *ssh, const char *fmt, ...) PRINTF_LIKE(2, 3);
  375. void ssh_sw_abort_deferred(Ssh *ssh, const char *fmt, ...) PRINTF_LIKE(2, 3);
  376. void ssh_user_close(Ssh *ssh, const char *fmt, ...) PRINTF_LIKE(2, 3);
  377. void ssh_spr_close(Ssh *ssh, SeatPromptResult spr, const char *context);
  378. /* Bit positions in the SSH-1 cipher protocol word */
  379. #define SSH1_CIPHER_IDEA 1
  380. #define SSH1_CIPHER_DES 2
  381. #define SSH1_CIPHER_3DES 3
  382. #define SSH1_CIPHER_BLOWFISH 6
  383. /* The subset of those that we support, with names for selecting them
  384. * on Uppity's command line */
  385. #define SSH1_SUPPORTED_CIPHER_LIST(X) \
  386. X(SSH1_CIPHER_3DES, "3des") \
  387. X(SSH1_CIPHER_BLOWFISH, "blowfish") \
  388. X(SSH1_CIPHER_DES, "des") \
  389. /* end of list */
  390. #define SSH1_CIPHER_LIST_MAKE_MASK(bitpos, name) | (1U << bitpos)
  391. #define SSH1_SUPPORTED_CIPHER_MASK \
  392. (0 SSH1_SUPPORTED_CIPHER_LIST(SSH1_CIPHER_LIST_MAKE_MASK))
  393. struct ssh_key {
  394. const ssh_keyalg *vt;
  395. };
  396. struct RSAKey {
  397. int bits;
  398. int bytes;
  399. mp_int *modulus;
  400. mp_int *exponent;
  401. mp_int *private_exponent;
  402. mp_int *p;
  403. mp_int *q;
  404. mp_int *iqmp;
  405. char *comment;
  406. ssh_key sshk;
  407. };
  408. struct dsa_key {
  409. mp_int *p, *q, *g, *y, *x;
  410. ssh_key sshk;
  411. };
  412. struct ec_curve;
  413. /* Weierstrass form curve */
  414. struct ec_wcurve
  415. {
  416. WeierstrassCurve *wc;
  417. WeierstrassPoint *G;
  418. mp_int *G_order;
  419. };
  420. /* Montgomery form curve */
  421. struct ec_mcurve
  422. {
  423. MontgomeryCurve *mc;
  424. MontgomeryPoint *G;
  425. unsigned log2_cofactor;
  426. };
  427. /* Edwards form curve */
  428. struct ec_ecurve
  429. {
  430. EdwardsCurve *ec;
  431. EdwardsPoint *G;
  432. mp_int *G_order;
  433. unsigned log2_cofactor;
  434. };
  435. typedef enum EllipticCurveType {
  436. EC_WEIERSTRASS, EC_MONTGOMERY, EC_EDWARDS
  437. } EllipticCurveType;
  438. struct ec_curve {
  439. EllipticCurveType type;
  440. /* 'name' is the identifier of the curve when it has to appear in
  441. * wire protocol encodings, as it does in e.g. the public key and
  442. * signature formats for NIST curves. Curves which do not format
  443. * their keys or signatures in this way just have name==NULL.
  444. *
  445. * 'textname' is non-NULL for all curves, and is a human-readable
  446. * identification suitable for putting in log messages. */
  447. const char *name, *textname;
  448. size_t fieldBits, fieldBytes;
  449. mp_int *p;
  450. union {
  451. struct ec_wcurve w;
  452. struct ec_mcurve m;
  453. struct ec_ecurve e;
  454. };
  455. };
  456. const ssh_keyalg *ec_alg_by_oid(int len, const void *oid,
  457. const struct ec_curve **curve);
  458. const unsigned char *ec_alg_oid(const ssh_keyalg *alg, int *oidlen);
  459. extern const int ec_nist_curve_lengths[], n_ec_nist_curve_lengths;
  460. extern const int ec_ed_curve_lengths[], n_ec_ed_curve_lengths;
  461. bool ec_nist_alg_and_curve_by_bits(int bits,
  462. const struct ec_curve **curve,
  463. const ssh_keyalg **alg);
  464. bool ec_ed_alg_and_curve_by_bits(int bits,
  465. const struct ec_curve **curve,
  466. const ssh_keyalg **alg);
  467. struct ecdsa_key {
  468. const struct ec_curve *curve;
  469. WeierstrassPoint *publicKey;
  470. mp_int *privateKey;
  471. ssh_key sshk;
  472. };
  473. struct eddsa_key {
  474. const struct ec_curve *curve;
  475. EdwardsPoint *publicKey;
  476. mp_int *privateKey;
  477. ssh_key sshk;
  478. };
  479. WeierstrassPoint *ecdsa_public(mp_int *private_key, const ssh_keyalg *alg);
  480. EdwardsPoint *eddsa_public(mp_int *private_key, const ssh_keyalg *alg);
  481. typedef struct key_components {
  482. size_t ncomponents, componentsize;
  483. struct {
  484. char *name;
  485. bool is_mp_int;
  486. union {
  487. char *text;
  488. mp_int *mp;
  489. };
  490. } *components;
  491. } key_components;
  492. key_components *key_components_new(void);
  493. void key_components_add_text(key_components *kc,
  494. const char *name, const char *value);
  495. void key_components_add_mp(key_components *kc,
  496. const char *name, mp_int *value);
  497. void key_components_free(key_components *kc);
  498. /*
  499. * SSH-1 never quite decided which order to store the two components
  500. * of an RSA key. During connection setup, the server sends its host
  501. * and server keys with the exponent first; private key files store
  502. * the modulus first. The agent protocol is even more confusing,
  503. * because the client specifies a key to the server in one order and
  504. * the server lists the keys it knows about in the other order!
  505. */
  506. typedef enum { RSA_SSH1_EXPONENT_FIRST, RSA_SSH1_MODULUS_FIRST } RsaSsh1Order;
  507. void BinarySource_get_rsa_ssh1_pub(
  508. BinarySource *src, RSAKey *result, RsaSsh1Order order);
  509. void BinarySource_get_rsa_ssh1_priv(
  510. BinarySource *src, RSAKey *rsa);
  511. RSAKey *BinarySource_get_rsa_ssh1_priv_agent(BinarySource *src);
  512. bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key);
  513. mp_int *rsa_ssh1_decrypt(mp_int *input, RSAKey *key);
  514. bool rsa_ssh1_decrypt_pkcs1(mp_int *input, RSAKey *key, strbuf *outbuf);
  515. char *rsastr_fmt(RSAKey *key);
  516. char *rsa_ssh1_fingerprint(RSAKey *key);
  517. char **rsa_ssh1_fake_all_fingerprints(RSAKey *key);
  518. bool rsa_verify(RSAKey *key);
  519. void rsa_ssh1_public_blob(BinarySink *bs, RSAKey *key, RsaSsh1Order order);
  520. int rsa_ssh1_public_blob_len(ptrlen data);
  521. void rsa_ssh1_private_blob_agent(BinarySink *bs, RSAKey *key);
  522. void freersapriv(RSAKey *key);
  523. void freersakey(RSAKey *key);
  524. key_components *rsa_components(RSAKey *key);
  525. #endif // WINSCP_VS
  526. #ifndef WINSCP_VS
  527. uint32_t crc32_rfc1662(ptrlen data);
  528. uint32_t crc32_ssh1(ptrlen data);
  529. uint32_t crc32_update(uint32_t crc_input, ptrlen data);
  530. /* SSH CRC compensation attack detector */
  531. struct crcda_ctx;
  532. struct crcda_ctx *crcda_make_context(void);
  533. void crcda_free_context(struct crcda_ctx *ctx);
  534. bool detect_attack(struct crcda_ctx *ctx,
  535. const unsigned char *buf, uint32_t len,
  536. const unsigned char *IV);
  537. /*
  538. * SSH2 RSA key exchange functions
  539. */
  540. struct ssh_rsa_kex_extra {
  541. int minklen;
  542. };
  543. RSAKey *ssh_rsakex_newkey(ptrlen data);
  544. void ssh_rsakex_freekey(RSAKey *key);
  545. int ssh_rsakex_klen(RSAKey *key);
  546. strbuf *ssh_rsakex_encrypt(
  547. RSAKey *key, const ssh_hashalg *h, ptrlen plaintext);
  548. mp_int *ssh_rsakex_decrypt(
  549. RSAKey *key, const ssh_hashalg *h, ptrlen ciphertext);
  550. /*
  551. * SSH2 ECDH key exchange functions
  552. */
  553. const char *ssh_ecdhkex_curve_textname(const ssh_kex *kex);
  554. ecdh_key *ssh_ecdhkex_newkey(const ssh_kex *kex);
  555. void ssh_ecdhkex_freekey(ecdh_key *key);
  556. void ssh_ecdhkex_getpublic(ecdh_key *key, BinarySink *bs);
  557. mp_int *ssh_ecdhkex_getkey(ecdh_key *key, ptrlen remoteKey);
  558. /*
  559. * Helper function for k generation in DSA, reused in ECDSA
  560. */
  561. mp_int *dsa_gen_k(const char *id_string,
  562. mp_int *modulus, mp_int *private_key,
  563. unsigned char *digest, int digest_len);
  564. #endif
  565. struct ssh_cipher {
  566. const ssh_cipheralg *vt;
  567. };
  568. #ifndef WINSCP_VS
  569. #ifdef MPEXT
  570. // Resolve ambiguity with OpenSSL
  571. #define SHA_Init putty_SHA_Init
  572. #define SHA_Final putty_SHA_Final
  573. #define SHA256_Init putty_SHA256_Init
  574. #define SHA256_Final putty_SHA256_Final
  575. #define SHA512_Init putty_SHA512_Init
  576. #define SHA512_Final putty_SHA512_Final
  577. #endif
  578. #endif // WINSCP_VS
  579. struct ssh_cipheralg {
  580. ssh_cipher *(*new)(const ssh_cipheralg *alg);
  581. void (*free)(ssh_cipher *);
  582. void (*setiv)(ssh_cipher *, const void *iv);
  583. void (*setkey)(ssh_cipher *, const void *key);
  584. void (*encrypt)(ssh_cipher *, void *blk, int len);
  585. void (*decrypt)(ssh_cipher *, void *blk, int len);
  586. /* Ignored unless SSH_CIPHER_SEPARATE_LENGTH flag set */
  587. void (*encrypt_length)(ssh_cipher *, void *blk, int len,
  588. unsigned long seq);
  589. void (*decrypt_length)(ssh_cipher *, void *blk, int len,
  590. unsigned long seq);
  591. const char *ssh2_id;
  592. int blksize;
  593. /* real_keybits is the number of bits of entropy genuinely used by
  594. * the cipher scheme; it's used for deciding how big a
  595. * Diffie-Hellman group is needed to exchange a key for the
  596. * cipher. */
  597. int real_keybits;
  598. /* padded_keybytes is the number of bytes of key data expected as
  599. * input to the setkey function; it's used for deciding how much
  600. * data needs to be generated from the post-kex generation of key
  601. * material. In a sensible cipher which uses all its key bytes for
  602. * real work, this will just be real_keybits/8, but in DES-type
  603. * ciphers which ignore one bit in each byte, it'll be slightly
  604. * different. */
  605. int padded_keybytes;
  606. unsigned int flags;
  607. #define SSH_CIPHER_IS_CBC 1
  608. #define SSH_CIPHER_SEPARATE_LENGTH 2
  609. const char *text_name;
  610. /* If set, this takes priority over other MAC. */
  611. const ssh2_macalg *required_mac;
  612. /* Pointer to any extra data used by a particular implementation. */
  613. const void *extra;
  614. };
  615. #ifndef WINSCP_VS
  616. static inline ssh_cipher *ssh_cipher_new(const ssh_cipheralg *alg)
  617. { return alg->new(alg); }
  618. static inline void ssh_cipher_free(ssh_cipher *c)
  619. { c->vt->free(c); }
  620. static inline void ssh_cipher_setiv(ssh_cipher *c, const void *iv)
  621. { c->vt->setiv(c, iv); }
  622. static inline void ssh_cipher_setkey(ssh_cipher *c, const void *key)
  623. { c->vt->setkey(c, key); }
  624. static inline void ssh_cipher_encrypt(ssh_cipher *c, void *blk, int len)
  625. { c->vt->encrypt(c, blk, len); }
  626. static inline void ssh_cipher_decrypt(ssh_cipher *c, void *blk, int len)
  627. { c->vt->decrypt(c, blk, len); }
  628. static inline void ssh_cipher_encrypt_length(
  629. ssh_cipher *c, void *blk, int len, unsigned long seq)
  630. { c->vt->encrypt_length(c, blk, len, seq); }
  631. static inline void ssh_cipher_decrypt_length(
  632. ssh_cipher *c, void *blk, int len, unsigned long seq)
  633. { c->vt->decrypt_length(c, blk, len, seq); }
  634. static inline const struct ssh_cipheralg *ssh_cipher_alg(ssh_cipher *c)
  635. { return c->vt; }
  636. struct ssh2_ciphers {
  637. int nciphers;
  638. const ssh_cipheralg *const *list;
  639. };
  640. struct ssh2_mac {
  641. const ssh2_macalg *vt;
  642. BinarySink_DELEGATE_IMPLEMENTATION;
  643. };
  644. struct ssh2_macalg {
  645. /* Passes in the cipher context */
  646. ssh2_mac *(*new)(const ssh2_macalg *alg, ssh_cipher *cipher);
  647. void (*free)(ssh2_mac *);
  648. void (*setkey)(ssh2_mac *, ptrlen key);
  649. void (*start)(ssh2_mac *);
  650. void (*genresult)(ssh2_mac *, unsigned char *);
  651. const char *(*text_name)(ssh2_mac *);
  652. const char *name, *etm_name;
  653. int len, keylen;
  654. /* Pointer to any extra data used by a particular implementation. */
  655. const void *extra;
  656. };
  657. static inline ssh2_mac *ssh2_mac_new(
  658. const ssh2_macalg *alg, ssh_cipher *cipher)
  659. { return alg->new(alg, cipher); }
  660. static inline void ssh2_mac_free(ssh2_mac *m)
  661. { m->vt->free(m); }
  662. static inline void ssh2_mac_setkey(ssh2_mac *m, ptrlen key)
  663. { m->vt->setkey(m, key); }
  664. static inline void ssh2_mac_start(ssh2_mac *m)
  665. { m->vt->start(m); }
  666. static inline void ssh2_mac_genresult(ssh2_mac *m, unsigned char *out)
  667. { m->vt->genresult(m, out); }
  668. static inline const char *ssh2_mac_text_name(ssh2_mac *m)
  669. { return m->vt->text_name(m); }
  670. static inline const ssh2_macalg *ssh2_mac_alg(ssh2_mac *m)
  671. { return m->vt; }
  672. /* Centralised 'methods' for ssh2_mac, defined in mac.c. These run
  673. * the MAC in a specifically SSH-2 style, i.e. taking account of a
  674. * packet sequence number as well as the data to be authenticated. */
  675. bool ssh2_mac_verresult(ssh2_mac *, const void *);
  676. void ssh2_mac_generate(ssh2_mac *, void *, int, unsigned long seq);
  677. bool ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq);
  678. /* Use a MAC in its raw form, outside SSH-2 context, to MAC a given
  679. * string with a given key in the most obvious way. */
  680. void mac_simple(const ssh2_macalg *alg, ptrlen key, ptrlen data, void *output);
  681. #endif // !WINSCP_VS
  682. struct ssh_hash {
  683. const ssh_hashalg *vt;
  684. BinarySink_DELEGATE_IMPLEMENTATION;
  685. };
  686. struct ssh_hashalg {
  687. ssh_hash *(*new)(const ssh_hashalg *alg);
  688. void (*reset)(ssh_hash *);
  689. void (*copyfrom)(ssh_hash *dest, ssh_hash *src);
  690. void (*digest)(ssh_hash *, unsigned char *);
  691. void (*free)(ssh_hash *);
  692. size_t hlen; /* output length in bytes */
  693. size_t blocklen; /* length of the hash's input block, or 0 for N/A */
  694. const char *text_basename; /* the semantic name of the hash */
  695. const char *annotation; /* extra info, e.g. which of multiple impls */
  696. const char *text_name; /* both combined, e.g. "SHA-n (unaccelerated)" */
  697. const void *extra; /* private to the hash implementation */
  698. };
  699. static inline ssh_hash *ssh_hash_new(const ssh_hashalg *alg)
  700. { ssh_hash *h = alg->new(alg); if (h) h->vt->reset(h); return h; }
  701. static inline ssh_hash *ssh_hash_copy(ssh_hash *orig)
  702. { ssh_hash *h = orig->vt->new(orig->vt); h->vt->copyfrom(h, orig); return h; }
  703. static inline void ssh_hash_digest(ssh_hash *h, unsigned char *out)
  704. { h->vt->digest(h, out); }
  705. static inline void ssh_hash_free(ssh_hash *h)
  706. { h->vt->free(h); }
  707. static inline const ssh_hashalg *ssh_hash_alg(ssh_hash *h)
  708. { return h->vt; }
  709. /* The reset and copyfrom vtable methods return void. But for call-site
  710. * convenience, these wrappers return their input pointer. */
  711. static inline ssh_hash *ssh_hash_reset(ssh_hash *h)
  712. { h->vt->reset(h); return h; }
  713. static inline ssh_hash *ssh_hash_copyfrom(ssh_hash *dest, ssh_hash *src)
  714. { dest->vt->copyfrom(dest, src); return dest; }
  715. /* ssh_hash_final emits the digest _and_ frees the ssh_hash */
  716. static inline void ssh_hash_final(ssh_hash *h, unsigned char *out)
  717. { h->vt->digest(h, out); h->vt->free(h); }
  718. /* ssh_hash_digest_nondestructive generates a finalised hash from the
  719. * given object without changing its state, so you can continue
  720. * appending data to get a hash of an extended string. */
  721. static inline void ssh_hash_digest_nondestructive(ssh_hash *h,
  722. unsigned char *out)
  723. { ssh_hash_final(ssh_hash_copy(h), out); }
  724. /* Handy macros for defining all those text-name fields at once */
  725. #define HASHALG_NAMES_BARE(base) \
  726. /*.text_basename =*/ base, /*.annotation =*/ NULL, /*.text_name =*/ base
  727. #define HASHALG_NAMES_ANNOTATED(base, ann) \
  728. /*.text_basename =*/ base, /*.annotation =*/ ann, /*.text_name =*/ base " (" ann ")"
  729. #ifndef WINSCP_VS
  730. void hash_simple(const ssh_hashalg *alg, ptrlen data, void *output);
  731. struct ssh_kex {
  732. const char *name, *groupname;
  733. enum { KEXTYPE_DH, KEXTYPE_RSA, KEXTYPE_ECDH, KEXTYPE_GSS } main_type;
  734. const ssh_hashalg *hash;
  735. const void *extra; /* private to the kex methods */
  736. };
  737. struct ssh_kexes {
  738. int nkexes;
  739. const ssh_kex *const *list;
  740. };
  741. /* Indices of the negotiation strings in the KEXINIT packet */
  742. enum kexlist {
  743. KEXLIST_KEX, KEXLIST_HOSTKEY, KEXLIST_CSCIPHER, KEXLIST_SCCIPHER,
  744. KEXLIST_CSMAC, KEXLIST_SCMAC, KEXLIST_CSCOMP, KEXLIST_SCCOMP,
  745. NKEXLIST
  746. };
  747. #pragma option push -w-mnc // WINSCP
  748. struct ssh_keyalg {
  749. /* Constructors that create an ssh_key */
  750. ssh_key *(*new_pub) (const ssh_keyalg *self, ptrlen pub);
  751. ssh_key *(*new_priv) (const ssh_keyalg *self, ptrlen pub, ptrlen priv);
  752. ssh_key *(*new_priv_openssh) (const ssh_keyalg *self, BinarySource *);
  753. /* Methods that operate on an existing ssh_key */
  754. void (*freekey) (ssh_key *key);
  755. char *(*invalid) (ssh_key *key, unsigned flags);
  756. void (*sign) (ssh_key *key, ptrlen data, unsigned flags, BinarySink *);
  757. bool (*verify) (ssh_key *key, ptrlen sig, ptrlen data);
  758. void (*public_blob)(ssh_key *key, BinarySink *);
  759. void (*private_blob)(ssh_key *key, BinarySink *);
  760. void (*openssh_blob) (ssh_key *key, BinarySink *);
  761. char *(*cache_str) (ssh_key *key);
  762. key_components *(*components) (ssh_key *key);
  763. /* 'Class methods' that don't deal with an ssh_key at all */
  764. int (*pubkey_bits) (const ssh_keyalg *self, ptrlen blob);
  765. /* Constant data fields giving information about the key type */
  766. const char *ssh_id; /* string identifier in the SSH protocol */
  767. const char *cache_id; /* identifier used in PuTTY's host key cache */
  768. const void *extra; /* private to the public key methods */
  769. const unsigned supported_flags; /* signature-type flags we understand */
  770. };
  771. #pragma option pop // WINSCP
  772. static inline ssh_key *ssh_key_new_pub(const ssh_keyalg *self, ptrlen pub)
  773. { return self->new_pub(self, pub); }
  774. static inline ssh_key *ssh_key_new_priv(
  775. const ssh_keyalg *self, ptrlen pub, ptrlen priv)
  776. { return self->new_priv(self, pub, priv); }
  777. static inline ssh_key *ssh_key_new_priv_openssh(
  778. const ssh_keyalg *self, BinarySource *src)
  779. { return self->new_priv_openssh(self, src); }
  780. static inline void ssh_key_free(ssh_key *key)
  781. { key->vt->freekey(key); }
  782. static inline char *ssh_key_invalid(ssh_key *key, unsigned flags)
  783. { return key->vt->invalid(key, flags); }
  784. static inline void ssh_key_sign(
  785. ssh_key *key, ptrlen data, unsigned flags, BinarySink *bs)
  786. { key->vt->sign(key, data, flags, bs); }
  787. static inline bool ssh_key_verify(ssh_key *key, ptrlen sig, ptrlen data)
  788. { return key->vt->verify(key, sig, data); }
  789. static inline void ssh_key_public_blob(ssh_key *key, BinarySink *bs)
  790. { key->vt->public_blob(key, bs); }
  791. static inline void ssh_key_private_blob(ssh_key *key, BinarySink *bs)
  792. { key->vt->private_blob(key, bs); }
  793. static inline void ssh_key_openssh_blob(ssh_key *key, BinarySink *bs)
  794. { key->vt->openssh_blob(key, bs); }
  795. static inline char *ssh_key_cache_str(ssh_key *key)
  796. { return key->vt->cache_str(key); }
  797. static inline key_components *ssh_key_components(ssh_key *key)
  798. { return key->vt->components(key); }
  799. static inline int ssh_key_public_bits(const ssh_keyalg *self, ptrlen blob)
  800. { return self->pubkey_bits(self, blob); }
  801. static inline const ssh_keyalg *ssh_key_alg(ssh_key *key)
  802. { return key->vt; }
  803. static inline const char *ssh_key_ssh_id(ssh_key *key)
  804. { return key->vt->ssh_id; }
  805. static inline const char *ssh_key_cache_id(ssh_key *key)
  806. { return key->vt->cache_id; }
  807. /*
  808. * Enumeration of signature flags from draft-miller-ssh-agent-02
  809. */
  810. #define SSH_AGENT_RSA_SHA2_256 2
  811. #define SSH_AGENT_RSA_SHA2_512 4
  812. struct ssh_compressor {
  813. const ssh_compression_alg *vt;
  814. };
  815. struct ssh_decompressor {
  816. const ssh_compression_alg *vt;
  817. };
  818. struct ssh_compression_alg {
  819. const char *name;
  820. /* For [email protected]: if non-NULL, this name will be considered once
  821. * userauth has completed successfully. */
  822. const char *delayed_name;
  823. ssh_compressor *(*compress_new)(void);
  824. void (*compress_free)(ssh_compressor *);
  825. void (*compress)(ssh_compressor *, const unsigned char *block, int len,
  826. unsigned char **outblock, int *outlen,
  827. int minlen);
  828. ssh_decompressor *(*decompress_new)(void);
  829. void (*decompress_free)(ssh_decompressor *);
  830. bool (*decompress)(ssh_decompressor *, const unsigned char *block, int len,
  831. unsigned char **outblock, int *outlen);
  832. const char *text_name;
  833. };
  834. static inline ssh_compressor *ssh_compressor_new(
  835. const ssh_compression_alg *alg)
  836. { return alg->compress_new(); }
  837. static inline ssh_decompressor *ssh_decompressor_new(
  838. const ssh_compression_alg *alg)
  839. { return alg->decompress_new(); }
  840. static inline void ssh_compressor_free(ssh_compressor *c)
  841. { c->vt->compress_free(c); }
  842. static inline void ssh_decompressor_free(ssh_decompressor *d)
  843. { d->vt->decompress_free(d); }
  844. static inline void ssh_compressor_compress(
  845. ssh_compressor *c, const unsigned char *block, int len,
  846. unsigned char **outblock, int *outlen, int minlen)
  847. { c->vt->compress(c, block, len, outblock, outlen, minlen); }
  848. static inline bool ssh_decompressor_decompress(
  849. ssh_decompressor *d, const unsigned char *block, int len,
  850. unsigned char **outblock, int *outlen)
  851. { return d->vt->decompress(d, block, len, outblock, outlen); }
  852. static inline const ssh_compression_alg *ssh_compressor_alg(
  853. ssh_compressor *c)
  854. { return c->vt; }
  855. static inline const ssh_compression_alg *ssh_decompressor_alg(
  856. ssh_decompressor *d)
  857. { return d->vt; }
  858. struct ssh2_userkey {
  859. ssh_key *key; /* the key itself */
  860. char *comment; /* the key comment */
  861. };
  862. /* Argon2 password hashing function */
  863. typedef enum { Argon2d = 0, Argon2i = 1, Argon2id = 2 } Argon2Flavour;
  864. void argon2(Argon2Flavour, uint32_t mem, uint32_t passes,
  865. uint32_t parallel, uint32_t taglen,
  866. ptrlen P, ptrlen S, ptrlen K, ptrlen X, strbuf *out);
  867. void argon2_choose_passes(
  868. Argon2Flavour, uint32_t mem, uint32_t milliseconds, uint32_t *passes,
  869. uint32_t parallel, uint32_t taglen, ptrlen P, ptrlen S, ptrlen K, ptrlen X,
  870. strbuf *out);
  871. /* The H' hash defined in Argon2, exposed just for testcrypt */
  872. strbuf *argon2_long_hash(unsigned length, ptrlen data);
  873. /* The maximum length of any hash algorithm. (bytes) */
  874. #define MAX_HASH_LEN (114) /* longest is SHAKE256 with 114-byte output */
  875. extern const ssh_cipheralg ssh_3des_ssh1;
  876. extern const ssh_cipheralg ssh_blowfish_ssh1;
  877. extern const ssh_cipheralg ssh_3des_ssh2_ctr;
  878. extern const ssh_cipheralg ssh_3des_ssh2;
  879. extern const ssh_cipheralg ssh_des;
  880. extern const ssh_cipheralg ssh_des_sshcom_ssh2;
  881. extern const ssh_cipheralg ssh_aes256_sdctr;
  882. extern const ssh_cipheralg ssh_aes256_sdctr_ni;
  883. extern const ssh_cipheralg ssh_aes256_sdctr_neon;
  884. extern const ssh_cipheralg ssh_aes256_sdctr_sw;
  885. extern const ssh_cipheralg ssh_aes256_cbc;
  886. extern const ssh_cipheralg ssh_aes256_cbc_ni;
  887. extern const ssh_cipheralg ssh_aes256_cbc_neon;
  888. extern const ssh_cipheralg ssh_aes256_cbc_sw;
  889. extern const ssh_cipheralg ssh_aes192_sdctr;
  890. extern const ssh_cipheralg ssh_aes192_sdctr_ni;
  891. extern const ssh_cipheralg ssh_aes192_sdctr_neon;
  892. extern const ssh_cipheralg ssh_aes192_sdctr_sw;
  893. extern const ssh_cipheralg ssh_aes192_cbc;
  894. extern const ssh_cipheralg ssh_aes192_cbc_ni;
  895. extern const ssh_cipheralg ssh_aes192_cbc_neon;
  896. extern const ssh_cipheralg ssh_aes192_cbc_sw;
  897. extern const ssh_cipheralg ssh_aes128_sdctr;
  898. extern const ssh_cipheralg ssh_aes128_sdctr_ni;
  899. extern const ssh_cipheralg ssh_aes128_sdctr_neon;
  900. extern const ssh_cipheralg ssh_aes128_sdctr_sw;
  901. extern const ssh_cipheralg ssh_aes128_cbc;
  902. extern const ssh_cipheralg ssh_aes128_cbc_ni;
  903. extern const ssh_cipheralg ssh_aes128_cbc_neon;
  904. extern const ssh_cipheralg ssh_aes128_cbc_sw;
  905. extern const ssh_cipheralg ssh_blowfish_ssh2_ctr;
  906. extern const ssh_cipheralg ssh_blowfish_ssh2;
  907. extern const ssh_cipheralg ssh_arcfour256_ssh2;
  908. extern const ssh_cipheralg ssh_arcfour128_ssh2;
  909. extern const ssh_cipheralg ssh2_chacha20_poly1305;
  910. extern const ssh2_ciphers ssh2_3des;
  911. extern const ssh2_ciphers ssh2_des;
  912. extern const ssh2_ciphers ssh2_aes;
  913. extern const ssh2_ciphers ssh2_blowfish;
  914. extern const ssh2_ciphers ssh2_arcfour;
  915. extern const ssh2_ciphers ssh2_ccp;
  916. extern const ssh_hashalg ssh_md5;
  917. extern const ssh_hashalg ssh_sha1;
  918. extern const ssh_hashalg ssh_sha1_ni;
  919. extern const ssh_hashalg ssh_sha1_neon;
  920. extern const ssh_hashalg ssh_sha1_sw;
  921. extern const ssh_hashalg ssh_sha256;
  922. extern const ssh_hashalg ssh_sha256_ni;
  923. extern const ssh_hashalg ssh_sha256_neon;
  924. extern const ssh_hashalg ssh_sha256_sw;
  925. extern const ssh_hashalg ssh_sha384;
  926. extern const ssh_hashalg ssh_sha384_neon;
  927. extern const ssh_hashalg ssh_sha384_sw;
  928. extern const ssh_hashalg ssh_sha512;
  929. extern const ssh_hashalg ssh_sha512_neon;
  930. extern const ssh_hashalg ssh_sha512_sw;
  931. extern const ssh_hashalg ssh_sha3_224;
  932. extern const ssh_hashalg ssh_sha3_256;
  933. extern const ssh_hashalg ssh_sha3_384;
  934. extern const ssh_hashalg ssh_sha3_512;
  935. extern const ssh_hashalg ssh_shake256_114bytes;
  936. extern const ssh_hashalg ssh_blake2b;
  937. extern const ssh_kexes ssh_diffiehellman_group1;
  938. extern const ssh_kexes ssh_diffiehellman_group14;
  939. extern const ssh_kexes ssh_diffiehellman_gex;
  940. extern const ssh_kex ssh_diffiehellman_group1_sha1;
  941. extern const ssh_kex ssh_diffiehellman_group14_sha256;
  942. extern const ssh_kex ssh_diffiehellman_group14_sha1;
  943. extern const ssh_kexes ssh_gssk5_sha1_kex;
  944. extern const ssh_kexes ssh_rsa_kex;
  945. extern const ssh_kex ssh_ec_kex_curve25519;
  946. extern const ssh_kex ssh_ec_kex_curve448;
  947. extern const ssh_kex ssh_ec_kex_nistp256;
  948. extern const ssh_kex ssh_ec_kex_nistp384;
  949. extern const ssh_kex ssh_ec_kex_nistp521;
  950. extern const ssh_kexes ssh_ecdh_kex;
  951. extern const ssh_keyalg ssh_dsa;
  952. extern const ssh_keyalg ssh_rsa;
  953. extern const ssh_keyalg ssh_rsa_sha256;
  954. extern const ssh_keyalg ssh_rsa_sha512;
  955. extern const ssh_keyalg ssh_ecdsa_ed25519;
  956. extern const ssh_keyalg ssh_ecdsa_ed448;
  957. extern const ssh_keyalg ssh_ecdsa_nistp256;
  958. extern const ssh_keyalg ssh_ecdsa_nistp384;
  959. extern const ssh_keyalg ssh_ecdsa_nistp521;
  960. extern const ssh2_macalg ssh_hmac_md5;
  961. extern const ssh2_macalg ssh_hmac_sha1;
  962. extern const ssh2_macalg ssh_hmac_sha1_buggy;
  963. extern const ssh2_macalg ssh_hmac_sha1_96;
  964. extern const ssh2_macalg ssh_hmac_sha1_96_buggy;
  965. extern const ssh2_macalg ssh_hmac_sha256;
  966. extern const ssh2_macalg ssh2_poly1305;
  967. extern const ssh_compression_alg ssh_zlib;
  968. /* Special constructor: BLAKE2b can be instantiated with any hash
  969. * length up to 128 bytes */
  970. ssh_hash *blake2b_new_general(unsigned hashlen);
  971. /*
  972. * On some systems, you have to detect hardware crypto acceleration by
  973. * asking the local OS API rather than OS-agnostically asking the CPU
  974. * itself. If so, then this function should be implemented in each
  975. * platform subdirectory.
  976. */
  977. bool platform_aes_neon_available(void);
  978. bool platform_sha256_neon_available(void);
  979. bool platform_sha1_neon_available(void);
  980. bool platform_sha512_neon_available(void);
  981. /*
  982. * PuTTY version number formatted as an SSH version string.
  983. */
  984. extern
  985. #ifndef MPEXT
  986. const
  987. #endif
  988. char sshver[];
  989. /*
  990. * Gross hack: pscp will try to start SFTP but fall back to scp1 if
  991. * that fails. This variable is the means by which pscp.c can reach
  992. * into the SSH code and find out which one it got.
  993. */
  994. extern bool ssh_fallback_cmd(Backend *backend);
  995. /*
  996. * The PRNG type, defined in prng.c. Visible data fields are
  997. * 'savesize', which suggests how many random bytes you should request
  998. * from a particular PRNG instance to write to putty.rnd, and a
  999. * BinarySink implementation which you can use to write seed data in
  1000. * between calling prng_seed_{begin,finish}.
  1001. */
  1002. struct prng {
  1003. size_t savesize;
  1004. BinarySink_IMPLEMENTATION;
  1005. /* (also there's a surrounding implementation struct in prng.c) */
  1006. };
  1007. prng *prng_new(const ssh_hashalg *hashalg);
  1008. void prng_free(prng *p);
  1009. void prng_seed_begin(prng *p);
  1010. void prng_seed_finish(prng *p);
  1011. void prng_read(prng *p, void *vout, size_t size);
  1012. void prng_add_entropy(prng *p, unsigned source_id, ptrlen data);
  1013. size_t prng_seed_bits(prng *p);
  1014. /* This function must be implemented by the platform, and returns a
  1015. * timer in milliseconds that the PRNG can use to know whether it's
  1016. * been reseeded too recently to do it again.
  1017. *
  1018. * The PRNG system has its own special timing function not because its
  1019. * timing needs are unusual in the real applications, but simply so
  1020. * that testcrypt can mock it to keep the tests deterministic. */
  1021. uint64_t prng_reseed_time_ms(void);
  1022. void random_read(void *out, size_t size);
  1023. /* Exports from x11fwd.c */
  1024. enum {
  1025. X11_TRANS_IPV4 = 0, X11_TRANS_IPV6 = 6, X11_TRANS_UNIX = 256
  1026. };
  1027. struct X11Display {
  1028. /* Broken-down components of the display name itself */
  1029. bool unixdomain;
  1030. char *hostname;
  1031. int displaynum;
  1032. int screennum;
  1033. /* OSX sometimes replaces all the above with a full Unix-socket pathname */
  1034. char *unixsocketpath;
  1035. /* PuTTY networking SockAddr to connect to the display, and associated
  1036. * gubbins */
  1037. SockAddr *addr;
  1038. int port;
  1039. char *realhost;
  1040. /* Our local auth details for talking to the real X display. */
  1041. int localauthproto;
  1042. unsigned char *localauthdata;
  1043. int localauthdatalen;
  1044. };
  1045. struct X11FakeAuth {
  1046. /* Auth details we invented for a virtual display on the SSH server. */
  1047. int proto;
  1048. unsigned char *data;
  1049. int datalen;
  1050. char *protoname;
  1051. char *datastring;
  1052. /* The encrypted form of the first block, in XDM-AUTHORIZATION-1.
  1053. * Used as part of the key when these structures are organised
  1054. * into a tree. See x11_invent_fake_auth for explanation. */
  1055. unsigned char *xa1_firstblock;
  1056. /*
  1057. * Used inside x11fwd.c to remember recently seen
  1058. * XDM-AUTHORIZATION-1 strings, to avoid replay attacks.
  1059. */
  1060. tree234 *xdmseen;
  1061. /*
  1062. * What to do with an X connection matching this auth data.
  1063. */
  1064. struct X11Display *disp;
  1065. ssh_sharing_connstate *share_cs;
  1066. share_channel *share_chan;
  1067. };
  1068. int x11_authcmp(void *av, void *bv); /* for putting X11FakeAuth in a tree234 */
  1069. /*
  1070. * x11_setup_display() parses the display variable and fills in an
  1071. * X11Display structure. Some remote auth details are invented;
  1072. * the supplied authtype parameter configures the preferred
  1073. * authorisation protocol to use at the remote end. The local auth
  1074. * details are looked up by calling platform_get_x11_auth.
  1075. *
  1076. * If the returned pointer is NULL, then *error_msg will contain a
  1077. * dynamically allocated error message string.
  1078. */
  1079. extern struct X11Display *x11_setup_display(const char *display, Conf *,
  1080. char **error_msg);
  1081. void x11_free_display(struct X11Display *disp);
  1082. struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
  1083. void x11_free_fake_auth(struct X11FakeAuth *auth);
  1084. Channel *x11_new_channel(tree234 *authtree, SshChannel *c,
  1085. const char *peeraddr, int peerport,
  1086. bool connection_sharing_possible);
  1087. char *x11_display(const char *display);
  1088. /* Platform-dependent X11 functions */
  1089. extern void platform_get_x11_auth(struct X11Display *display, Conf *);
  1090. /* examine a mostly-filled-in X11Display and fill in localauth* */
  1091. extern const bool platform_uses_x11_unix_by_default;
  1092. /* choose default X transport in the absence of a specified one */
  1093. SockAddr *platform_get_x11_unix_address(const char *path, int displaynum);
  1094. /* make up a SockAddr naming the address for displaynum */
  1095. char *platform_get_x_display(void);
  1096. /* allocated local X display string, if any */
  1097. /* X11-related helper functions in utils */
  1098. /*
  1099. * This function does the job of platform_get_x11_auth, provided
  1100. * it is told where to find a normally formatted .Xauthority file:
  1101. * it opens that file, parses it to find an auth record which
  1102. * matches the display details in "display", and fills in the
  1103. * localauth fields.
  1104. *
  1105. * It is expected that most implementations of
  1106. * platform_get_x11_auth() will work by finding their system's
  1107. * .Xauthority file, adjusting the display details if necessary
  1108. * for local oddities like Unix-domain socket transport, and
  1109. * calling this function to do the rest of the work.
  1110. */
  1111. void x11_get_auth_from_authfile(struct X11Display *display,
  1112. const char *authfilename);
  1113. void x11_format_auth_for_authfile(
  1114. BinarySink *bs, SockAddr *addr, int display_no,
  1115. ptrlen authproto, ptrlen authdata);
  1116. void *x11_make_greeting(int endian, int protomajor, int protominor,
  1117. int auth_proto, const void *auth_data, int auth_len,
  1118. const char *peer_ip, int peer_port,
  1119. int *outlen);
  1120. int x11_identify_auth_proto(ptrlen protoname);
  1121. void *x11_dehexify(ptrlen hex, int *outlen);
  1122. bool x11_parse_ip(const char *addr_string, unsigned long *ip);
  1123. Channel *agentf_new(SshChannel *c, Plug *plug); // WINSCP
  1124. bool dh_is_gex(const ssh_kex *kex);
  1125. dh_ctx *dh_setup_group(const ssh_kex *kex);
  1126. dh_ctx *dh_setup_gex(mp_int *pval, mp_int *gval);
  1127. int dh_modulus_bit_size(const dh_ctx *ctx);
  1128. void dh_cleanup(dh_ctx *);
  1129. mp_int *dh_create_e(dh_ctx *);
  1130. const char *dh_validate_f(dh_ctx *, mp_int *f);
  1131. mp_int *dh_find_K(dh_ctx *, mp_int *f);
  1132. static inline bool is_base64_char(char c)
  1133. {
  1134. return ((c >= '0' && c <= '9') ||
  1135. (c >= 'a' && c <= 'z') ||
  1136. (c >= 'A' && c <= 'Z') ||
  1137. c == '+' || c == '/' || c == '=');
  1138. }
  1139. extern int base64_decode_atom(const char *atom, unsigned char *out);
  1140. extern int base64_lines(int datalen);
  1141. extern void base64_encode_atom(const unsigned char *data, int n, char *out);
  1142. extern void base64_encode(FILE *fp, const unsigned char *data, int datalen,
  1143. int cpl);
  1144. /* ppk_load_* can return this as an error */
  1145. extern ssh2_userkey ssh2_wrong_passphrase;
  1146. #define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
  1147. bool ppk_encrypted_s(BinarySource *src, char **comment);
  1148. bool ppk_encrypted_f(const Filename *filename, char **comment);
  1149. bool rsa1_encrypted_s(BinarySource *src, char **comment);
  1150. bool rsa1_encrypted_f(const Filename *filename, char **comment);
  1151. ssh2_userkey *ppk_load_s(BinarySource *src, const char *passphrase,
  1152. const char **errorstr);
  1153. ssh2_userkey *ppk_load_f(const Filename *filename, const char *passphrase,
  1154. const char **errorstr);
  1155. int rsa1_load_s(BinarySource *src, RSAKey *key,
  1156. const char *passphrase, const char **errorstr);
  1157. int rsa1_load_f(const Filename *filename, RSAKey *key,
  1158. const char *passphrase, const char **errorstr);
  1159. typedef struct ppk_save_parameters {
  1160. unsigned fmt_version; /* currently 2 or 3 */
  1161. /*
  1162. * Parameters for fmt_version == 3
  1163. */
  1164. Argon2Flavour argon2_flavour;
  1165. uint32_t argon2_mem; /* in Kbyte */
  1166. bool argon2_passes_auto;
  1167. union {
  1168. uint32_t argon2_passes; /* if auto == false */
  1169. uint32_t argon2_milliseconds; /* if auto == true */
  1170. };
  1171. uint32_t argon2_parallelism;
  1172. /* The ability to choose a specific salt is only intended for the
  1173. * use of the automated test of PuTTYgen. It's a (mild) security
  1174. * risk to do it with any passphrase you actually care about,
  1175. * because it invalidates the entire point of having a salt in the
  1176. * first place. */
  1177. const uint8_t *salt;
  1178. size_t saltlen;
  1179. } ppk_save_parameters;
  1180. extern const ppk_save_parameters ppk_save_default_parameters;
  1181. strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
  1182. const ppk_save_parameters *params);
  1183. bool ppk_save_f(const Filename *filename, ssh2_userkey *key,
  1184. const char *passphrase, const ppk_save_parameters *params);
  1185. strbuf *rsa1_save_sb(RSAKey *key, const char *passphrase);
  1186. bool rsa1_save_f(const Filename *filename, RSAKey *key,
  1187. const char *passphrase);
  1188. bool ppk_loadpub_s(BinarySource *src, char **algorithm, BinarySink *bs,
  1189. char **commentptr, const char **errorstr);
  1190. bool ppk_loadpub_f(const Filename *filename, char **algorithm, BinarySink *bs,
  1191. char **commentptr, const char **errorstr);
  1192. int rsa1_loadpub_s(BinarySource *src, BinarySink *bs,
  1193. char **commentptr, const char **errorstr);
  1194. int rsa1_loadpub_f(const Filename *filename, BinarySink *bs,
  1195. char **commentptr, const char **errorstr);
  1196. extern const ssh_keyalg *const all_keyalgs[];
  1197. extern const size_t n_keyalgs;
  1198. const ssh_keyalg *find_pubkey_alg(const char *name);
  1199. const ssh_keyalg *find_pubkey_alg_len(ptrlen name);
  1200. /* Convenient wrappers on the LoadedFile mechanism suitable for key files */
  1201. LoadedFile *lf_load_keyfile(const Filename *filename, const char **errptr);
  1202. LoadedFile *lf_load_keyfile_fp(FILE *fp, const char **errptr);
  1203. enum {
  1204. SSH_KEYTYPE_UNOPENABLE,
  1205. SSH_KEYTYPE_UNKNOWN,
  1206. SSH_KEYTYPE_SSH1, SSH_KEYTYPE_SSH2,
  1207. /*
  1208. * The OpenSSH key types deserve a little explanation. OpenSSH has
  1209. * two physical formats for private key storage: an old PEM-based
  1210. * one largely dictated by their use of OpenSSL and full of ASN.1,
  1211. * and a new one using the same private key formats used over the
  1212. * wire for talking to ssh-agent. The old format can only support
  1213. * a subset of the key types, because it needs redesign for each
  1214. * key type, and after a while they decided to move to the new
  1215. * format so as not to have to do that.
  1216. *
  1217. * On input, key files are identified as either
  1218. * SSH_KEYTYPE_OPENSSH_PEM or SSH_KEYTYPE_OPENSSH_NEW, describing
  1219. * accurately which actual format the keys are stored in.
  1220. *
  1221. * On output, however, we default to following OpenSSH's own
  1222. * policy of writing out PEM-style keys for maximum backwards
  1223. * compatibility if the key type supports it, and otherwise
  1224. * switching to the new format. So the formats you can select for
  1225. * output are SSH_KEYTYPE_OPENSSH_NEW (forcing the new format for
  1226. * any key type), and SSH_KEYTYPE_OPENSSH_AUTO to use the oldest
  1227. * format supported by whatever key type you're writing out.
  1228. *
  1229. * So we have three type codes, but only two of them usable in any
  1230. * given circumstance. An input key file will never be identified
  1231. * as AUTO, only PEM or NEW; key export UIs should not be able to
  1232. * select PEM, only AUTO or NEW.
  1233. */
  1234. SSH_KEYTYPE_OPENSSH_AUTO,
  1235. SSH_KEYTYPE_OPENSSH_PEM,
  1236. SSH_KEYTYPE_OPENSSH_NEW,
  1237. SSH_KEYTYPE_SSHCOM,
  1238. /*
  1239. * Public-key-only formats, which we still want to be able to read
  1240. * for various purposes.
  1241. */
  1242. SSH_KEYTYPE_SSH1_PUBLIC,
  1243. SSH_KEYTYPE_SSH2_PUBLIC_RFC4716,
  1244. SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH
  1245. };
  1246. typedef enum {
  1247. SSH_FPTYPE_MD5,
  1248. SSH_FPTYPE_SHA256,
  1249. } FingerprintType;
  1250. #define SSH_FPTYPE_DEFAULT SSH_FPTYPE_SHA256
  1251. #define SSH_N_FPTYPES (SSH_FPTYPE_SHA256 + 1)
  1252. FingerprintType ssh2_pick_fingerprint(char **fingerprints,
  1253. FingerprintType preferred_type);
  1254. FingerprintType ssh2_pick_default_fingerprint(char **fingerprints);
  1255. char *ssh1_pubkey_str(RSAKey *ssh1key);
  1256. void ssh1_write_pubkey(FILE *fp, RSAKey *ssh1key);
  1257. char *ssh2_pubkey_openssh_str(ssh2_userkey *key);
  1258. void ssh2_write_pubkey(FILE *fp, const char *comment,
  1259. const void *v_pub_blob, int pub_len,
  1260. int keytype);
  1261. char *ssh2_fingerprint_blob(ptrlen, FingerprintType);
  1262. char *ssh2_fingerprint(ssh_key *key, FingerprintType);
  1263. char **ssh2_all_fingerprints_for_blob(ptrlen);
  1264. char **ssh2_all_fingerprints(ssh_key *key);
  1265. void ssh2_free_all_fingerprints(char **);
  1266. int key_type(const Filename *filename);
  1267. int key_type_s(BinarySource *src);
  1268. const char *key_type_to_str(int type);
  1269. bool openssh_loadpub(BinarySource *src, char **algorithm, // WINSCP
  1270. BinarySink *bs,
  1271. char **commentptr, const char **errorstr);
  1272. bool import_possible(int type);
  1273. int import_target_type(int type);
  1274. bool import_encrypted(const Filename *filename, int type, char **comment);
  1275. bool import_encrypted_s(const Filename *filename, BinarySource *src,
  1276. int type, char **comment);
  1277. int import_ssh1(const Filename *filename, int type,
  1278. RSAKey *key, char *passphrase, const char **errmsg_p);
  1279. int import_ssh1_s(BinarySource *src, int type,
  1280. RSAKey *key, char *passphrase, const char **errmsg_p);
  1281. ssh2_userkey *import_ssh2(const Filename *filename, int type,
  1282. char *passphrase, const char **errmsg_p);
  1283. ssh2_userkey *import_ssh2_s(BinarySource *src, int type,
  1284. char *passphrase, const char **errmsg_p);
  1285. bool export_ssh1(const Filename *filename, int type,
  1286. RSAKey *key, char *passphrase);
  1287. bool export_ssh2(const Filename *filename, int type,
  1288. ssh2_userkey *key, char *passphrase);
  1289. void des3_decrypt_pubkey(const void *key, void *blk, int len);
  1290. void des3_encrypt_pubkey(const void *key, void *blk, int len);
  1291. void des3_decrypt_pubkey_ossh(const void *key, const void *iv,
  1292. void *blk, int len);
  1293. void des3_encrypt_pubkey_ossh(const void *key, const void *iv,
  1294. void *blk, int len);
  1295. void aes256_encrypt_pubkey(const void *key, const void *iv,
  1296. void *blk, int len);
  1297. void aes256_decrypt_pubkey(const void *key, const void *iv,
  1298. void *blk, int len);
  1299. void des_encrypt_xdmauth(const void *key, void *blk, int len);
  1300. void des_decrypt_xdmauth(const void *key, void *blk, int len);
  1301. void openssh_bcrypt(ptrlen passphrase, ptrlen salt,
  1302. int rounds, unsigned char *out, int outbytes);
  1303. /*
  1304. * Connection-sharing API provided by platforms. This function must
  1305. * either:
  1306. * - return SHARE_NONE and do nothing
  1307. * - return SHARE_DOWNSTREAM and set *sock to a Socket connected to
  1308. * downplug
  1309. * - return SHARE_UPSTREAM and set *sock to a Socket connected to
  1310. * upplug.
  1311. */
  1312. enum { SHARE_NONE, SHARE_DOWNSTREAM, SHARE_UPSTREAM };
  1313. int platform_ssh_share(const char *name, Conf *conf,
  1314. Plug *downplug, Plug *upplug, Socket **sock,
  1315. char **logtext, char **ds_err, char **us_err,
  1316. bool can_upstream, bool can_downstream);
  1317. void platform_ssh_share_cleanup(const char *name);
  1318. /*
  1319. * List macro defining the SSH-1 message type codes.
  1320. */
  1321. #define SSH1_MESSAGE_TYPES(X, y) \
  1322. X(y, SSH1_MSG_DISCONNECT, 1) \
  1323. X(y, SSH1_SMSG_PUBLIC_KEY, 2) \
  1324. X(y, SSH1_CMSG_SESSION_KEY, 3) \
  1325. X(y, SSH1_CMSG_USER, 4) \
  1326. X(y, SSH1_CMSG_AUTH_RSA, 6) \
  1327. X(y, SSH1_SMSG_AUTH_RSA_CHALLENGE, 7) \
  1328. X(y, SSH1_CMSG_AUTH_RSA_RESPONSE, 8) \
  1329. X(y, SSH1_CMSG_AUTH_PASSWORD, 9) \
  1330. X(y, SSH1_CMSG_REQUEST_PTY, 10) \
  1331. X(y, SSH1_CMSG_WINDOW_SIZE, 11) \
  1332. X(y, SSH1_CMSG_EXEC_SHELL, 12) \
  1333. X(y, SSH1_CMSG_EXEC_CMD, 13) \
  1334. X(y, SSH1_SMSG_SUCCESS, 14) \
  1335. X(y, SSH1_SMSG_FAILURE, 15) \
  1336. X(y, SSH1_CMSG_STDIN_DATA, 16) \
  1337. X(y, SSH1_SMSG_STDOUT_DATA, 17) \
  1338. X(y, SSH1_SMSG_STDERR_DATA, 18) \
  1339. X(y, SSH1_CMSG_EOF, 19) \
  1340. X(y, SSH1_SMSG_EXIT_STATUS, 20) \
  1341. X(y, SSH1_MSG_CHANNEL_OPEN_CONFIRMATION, 21) \
  1342. X(y, SSH1_MSG_CHANNEL_OPEN_FAILURE, 22) \
  1343. X(y, SSH1_MSG_CHANNEL_DATA, 23) \
  1344. X(y, SSH1_MSG_CHANNEL_CLOSE, 24) \
  1345. X(y, SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION, 25) \
  1346. X(y, SSH1_SMSG_X11_OPEN, 27) \
  1347. X(y, SSH1_CMSG_PORT_FORWARD_REQUEST, 28) \
  1348. X(y, SSH1_MSG_PORT_OPEN, 29) \
  1349. X(y, SSH1_CMSG_AGENT_REQUEST_FORWARDING, 30) \
  1350. X(y, SSH1_SMSG_AGENT_OPEN, 31) \
  1351. X(y, SSH1_MSG_IGNORE, 32) \
  1352. X(y, SSH1_CMSG_EXIT_CONFIRMATION, 33) \
  1353. X(y, SSH1_CMSG_X11_REQUEST_FORWARDING, 34) \
  1354. X(y, SSH1_CMSG_AUTH_RHOSTS_RSA, 35) \
  1355. X(y, SSH1_MSG_DEBUG, 36) \
  1356. X(y, SSH1_CMSG_REQUEST_COMPRESSION, 37) \
  1357. X(y, SSH1_CMSG_AUTH_TIS, 39) \
  1358. X(y, SSH1_SMSG_AUTH_TIS_CHALLENGE, 40) \
  1359. X(y, SSH1_CMSG_AUTH_TIS_RESPONSE, 41) \
  1360. X(y, SSH1_CMSG_AUTH_CCARD, 70) \
  1361. X(y, SSH1_SMSG_AUTH_CCARD_CHALLENGE, 71) \
  1362. X(y, SSH1_CMSG_AUTH_CCARD_RESPONSE, 72) \
  1363. /* end of list */
  1364. #define SSH1_AUTH_RHOSTS 1 /* 0x1 */
  1365. #define SSH1_AUTH_RSA 2 /* 0x2 */
  1366. #define SSH1_AUTH_PASSWORD 3 /* 0x3 */
  1367. #define SSH1_AUTH_RHOSTS_RSA 4 /* 0x4 */
  1368. #define SSH1_AUTH_TIS 5 /* 0x5 */
  1369. #define SSH1_AUTH_CCARD 16 /* 0x10 */
  1370. #define SSH1_PROTOFLAG_SCREEN_NUMBER 1 /* 0x1 */
  1371. /* Mask for protoflags we will echo back to server if seen */
  1372. #define SSH1_PROTOFLAGS_SUPPORTED 0 /* 0x1 */
  1373. /*
  1374. * List macro defining SSH-2 message type codes. Some of these depend
  1375. * on particular contexts (i.e. a previously negotiated kex or auth
  1376. * method)
  1377. */
  1378. #define SSH2_MESSAGE_TYPES(X, K, A, y) \
  1379. X(y, SSH2_MSG_DISCONNECT, 1) \
  1380. X(y, SSH2_MSG_IGNORE, 2) \
  1381. X(y, SSH2_MSG_UNIMPLEMENTED, 3) \
  1382. X(y, SSH2_MSG_DEBUG, 4) \
  1383. X(y, SSH2_MSG_SERVICE_REQUEST, 5) \
  1384. X(y, SSH2_MSG_SERVICE_ACCEPT, 6) \
  1385. X(y, SSH2_MSG_EXT_INFO, 7) \
  1386. X(y, SSH2_MSG_KEXINIT, 20) \
  1387. X(y, SSH2_MSG_NEWKEYS, 21) \
  1388. K(y, SSH2_MSG_KEXDH_INIT, 30, SSH2_PKTCTX_DHGROUP) \
  1389. K(y, SSH2_MSG_KEXDH_REPLY, 31, SSH2_PKTCTX_DHGROUP) \
  1390. K(y, SSH2_MSG_KEX_DH_GEX_REQUEST_OLD, 30, SSH2_PKTCTX_DHGEX) \
  1391. K(y, SSH2_MSG_KEX_DH_GEX_REQUEST, 34, SSH2_PKTCTX_DHGEX) \
  1392. K(y, SSH2_MSG_KEX_DH_GEX_GROUP, 31, SSH2_PKTCTX_DHGEX) \
  1393. K(y, SSH2_MSG_KEX_DH_GEX_INIT, 32, SSH2_PKTCTX_DHGEX) \
  1394. K(y, SSH2_MSG_KEX_DH_GEX_REPLY, 33, SSH2_PKTCTX_DHGEX) \
  1395. K(y, SSH2_MSG_KEXGSS_INIT, 30, SSH2_PKTCTX_GSSKEX) \
  1396. K(y, SSH2_MSG_KEXGSS_CONTINUE, 31, SSH2_PKTCTX_GSSKEX) \
  1397. K(y, SSH2_MSG_KEXGSS_COMPLETE, 32, SSH2_PKTCTX_GSSKEX) \
  1398. K(y, SSH2_MSG_KEXGSS_HOSTKEY, 33, SSH2_PKTCTX_GSSKEX) \
  1399. K(y, SSH2_MSG_KEXGSS_ERROR, 34, SSH2_PKTCTX_GSSKEX) \
  1400. K(y, SSH2_MSG_KEXGSS_GROUPREQ, 40, SSH2_PKTCTX_GSSKEX) \
  1401. K(y, SSH2_MSG_KEXGSS_GROUP, 41, SSH2_PKTCTX_GSSKEX) \
  1402. K(y, SSH2_MSG_KEXRSA_PUBKEY, 30, SSH2_PKTCTX_RSAKEX) \
  1403. K(y, SSH2_MSG_KEXRSA_SECRET, 31, SSH2_PKTCTX_RSAKEX) \
  1404. K(y, SSH2_MSG_KEXRSA_DONE, 32, SSH2_PKTCTX_RSAKEX) \
  1405. K(y, SSH2_MSG_KEX_ECDH_INIT, 30, SSH2_PKTCTX_ECDHKEX) \
  1406. K(y, SSH2_MSG_KEX_ECDH_REPLY, 31, SSH2_PKTCTX_ECDHKEX) \
  1407. X(y, SSH2_MSG_USERAUTH_REQUEST, 50) \
  1408. X(y, SSH2_MSG_USERAUTH_FAILURE, 51) \
  1409. X(y, SSH2_MSG_USERAUTH_SUCCESS, 52) \
  1410. X(y, SSH2_MSG_USERAUTH_BANNER, 53) \
  1411. A(y, SSH2_MSG_USERAUTH_PK_OK, 60, SSH2_PKTCTX_PUBLICKEY) \
  1412. A(y, SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ, 60, SSH2_PKTCTX_PASSWORD) \
  1413. A(y, SSH2_MSG_USERAUTH_INFO_REQUEST, 60, SSH2_PKTCTX_KBDINTER) \
  1414. A(y, SSH2_MSG_USERAUTH_INFO_RESPONSE, 61, SSH2_PKTCTX_KBDINTER) \
  1415. A(y, SSH2_MSG_USERAUTH_GSSAPI_RESPONSE, 60, SSH2_PKTCTX_GSSAPI) \
  1416. A(y, SSH2_MSG_USERAUTH_GSSAPI_TOKEN, 61, SSH2_PKTCTX_GSSAPI) \
  1417. A(y, SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, 63, SSH2_PKTCTX_GSSAPI) \
  1418. A(y, SSH2_MSG_USERAUTH_GSSAPI_ERROR, 64, SSH2_PKTCTX_GSSAPI) \
  1419. A(y, SSH2_MSG_USERAUTH_GSSAPI_ERRTOK, 65, SSH2_PKTCTX_GSSAPI) \
  1420. A(y, SSH2_MSG_USERAUTH_GSSAPI_MIC, 66, SSH2_PKTCTX_GSSAPI) \
  1421. X(y, SSH2_MSG_GLOBAL_REQUEST, 80) \
  1422. X(y, SSH2_MSG_REQUEST_SUCCESS, 81) \
  1423. X(y, SSH2_MSG_REQUEST_FAILURE, 82) \
  1424. X(y, SSH2_MSG_CHANNEL_OPEN, 90) \
  1425. X(y, SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, 91) \
  1426. X(y, SSH2_MSG_CHANNEL_OPEN_FAILURE, 92) \
  1427. X(y, SSH2_MSG_CHANNEL_WINDOW_ADJUST, 93) \
  1428. X(y, SSH2_MSG_CHANNEL_DATA, 94) \
  1429. X(y, SSH2_MSG_CHANNEL_EXTENDED_DATA, 95) \
  1430. X(y, SSH2_MSG_CHANNEL_EOF, 96) \
  1431. X(y, SSH2_MSG_CHANNEL_CLOSE, 97) \
  1432. X(y, SSH2_MSG_CHANNEL_REQUEST, 98) \
  1433. X(y, SSH2_MSG_CHANNEL_SUCCESS, 99) \
  1434. X(y, SSH2_MSG_CHANNEL_FAILURE, 100) \
  1435. /* end of list */
  1436. #define DEF_ENUM_UNIVERSAL(y, name, value) name = value,
  1437. #define DEF_ENUM_CONTEXTUAL(y, name, value, context) name = value,
  1438. enum {
  1439. SSH1_MESSAGE_TYPES(DEF_ENUM_UNIVERSAL, y)
  1440. SSH2_MESSAGE_TYPES(DEF_ENUM_UNIVERSAL,
  1441. DEF_ENUM_CONTEXTUAL, DEF_ENUM_CONTEXTUAL, y)
  1442. /* Virtual packet type, for packets too short to even have a type */
  1443. SSH_MSG_NO_TYPE_CODE = 256
  1444. };
  1445. #undef DEF_ENUM_UNIVERSAL
  1446. #undef DEF_ENUM_CONTEXTUAL
  1447. /*
  1448. * SSH-1 agent messages.
  1449. */
  1450. #define SSH1_AGENTC_REQUEST_RSA_IDENTITIES 1
  1451. #define SSH1_AGENT_RSA_IDENTITIES_ANSWER 2
  1452. #define SSH1_AGENTC_RSA_CHALLENGE 3
  1453. #define SSH1_AGENT_RSA_RESPONSE 4
  1454. #define SSH1_AGENTC_ADD_RSA_IDENTITY 7
  1455. #define SSH1_AGENTC_REMOVE_RSA_IDENTITY 8
  1456. #define SSH1_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 /* openssh private? */
  1457. /*
  1458. * Messages common to SSH-1 and OpenSSH's SSH-2.
  1459. */
  1460. #define SSH_AGENT_FAILURE 5
  1461. #define SSH_AGENT_SUCCESS 6
  1462. /*
  1463. * OpenSSH's SSH-2 agent messages.
  1464. */
  1465. #define SSH2_AGENTC_REQUEST_IDENTITIES 11
  1466. #define SSH2_AGENT_IDENTITIES_ANSWER 12
  1467. #define SSH2_AGENTC_SIGN_REQUEST 13
  1468. #define SSH2_AGENT_SIGN_RESPONSE 14
  1469. #define SSH2_AGENTC_ADD_IDENTITY 17
  1470. #define SSH2_AGENTC_REMOVE_IDENTITY 18
  1471. #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19
  1472. #define SSH2_AGENTC_EXTENSION 27
  1473. #define SSH_AGENT_EXTENSION_FAILURE 28
  1474. /*
  1475. * Assorted other SSH-related enumerations.
  1476. */
  1477. #define SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1 /* 0x1 */
  1478. #define SSH2_DISCONNECT_PROTOCOL_ERROR 2 /* 0x2 */
  1479. #define SSH2_DISCONNECT_KEY_EXCHANGE_FAILED 3 /* 0x3 */
  1480. #define SSH2_DISCONNECT_HOST_AUTHENTICATION_FAILED 4 /* 0x4 */
  1481. #define SSH2_DISCONNECT_MAC_ERROR 5 /* 0x5 */
  1482. #define SSH2_DISCONNECT_COMPRESSION_ERROR 6 /* 0x6 */
  1483. #define SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE 7 /* 0x7 */
  1484. #define SSH2_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8 /* 0x8 */
  1485. #define SSH2_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9 /* 0x9 */
  1486. #define SSH2_DISCONNECT_CONNECTION_LOST 10 /* 0xa */
  1487. #define SSH2_DISCONNECT_BY_APPLICATION 11 /* 0xb */
  1488. #define SSH2_DISCONNECT_TOO_MANY_CONNECTIONS 12 /* 0xc */
  1489. #define SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER 13 /* 0xd */
  1490. #define SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14 /* 0xe */
  1491. #define SSH2_DISCONNECT_ILLEGAL_USER_NAME 15 /* 0xf */
  1492. #define SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED 1 /* 0x1 */
  1493. #define SSH2_OPEN_CONNECT_FAILED 2 /* 0x2 */
  1494. #define SSH2_OPEN_UNKNOWN_CHANNEL_TYPE 3 /* 0x3 */
  1495. #define SSH2_OPEN_RESOURCE_SHORTAGE 4 /* 0x4 */
  1496. #define SSH2_EXTENDED_DATA_STDERR 1 /* 0x1 */
  1497. enum {
  1498. /* TTY modes with opcodes defined consistently in the SSH specs. */
  1499. #define TTYMODE_CHAR(name, val, index) SSH_TTYMODE_##name = val,
  1500. #define TTYMODE_FLAG(name, val, field, mask) SSH_TTYMODE_##name = val,
  1501. #include "ssh/ttymode-list.h"
  1502. #undef TTYMODE_CHAR
  1503. #undef TTYMODE_FLAG
  1504. /* Modes encoded differently between SSH-1 and SSH-2, for which we
  1505. * make up our own dummy opcodes to avoid confusion. */
  1506. TTYMODE_dummy = 255,
  1507. TTYMODE_ISPEED, TTYMODE_OSPEED,
  1508. /* Limiting value that we can use as an array bound below */
  1509. TTYMODE_LIMIT,
  1510. /* The real opcodes for terminal speeds. */
  1511. TTYMODE_ISPEED_SSH1 = 192,
  1512. TTYMODE_OSPEED_SSH1 = 193,
  1513. TTYMODE_ISPEED_SSH2 = 128,
  1514. TTYMODE_OSPEED_SSH2 = 129,
  1515. /* And the opcode that ends a list. */
  1516. TTYMODE_END_OF_LIST = 0
  1517. };
  1518. struct ssh_ttymodes {
  1519. /* A boolean per mode, indicating whether it's set. */
  1520. bool have_mode[TTYMODE_LIMIT];
  1521. /* The actual value for each mode. */
  1522. unsigned mode_val[TTYMODE_LIMIT];
  1523. };
  1524. struct ssh_ttymodes get_ttymodes_from_conf(Seat *seat, Conf *conf);
  1525. struct ssh_ttymodes read_ttymodes_from_packet(
  1526. BinarySource *bs, int ssh_version);
  1527. void write_ttymodes_to_packet(BinarySink *bs, int ssh_version,
  1528. struct ssh_ttymodes modes);
  1529. const char *ssh1_pkt_type(int type);
  1530. const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type);
  1531. bool ssh2_pkt_type_code_valid(unsigned type);
  1532. /*
  1533. * Need this to warn about support for the original SSH-2 keyfile
  1534. * format.
  1535. */
  1536. void old_keyfile_warning(void);
  1537. /*
  1538. * Flags indicating implementation bugs that we know how to mitigate
  1539. * if we think the other end has them.
  1540. */
  1541. #define SSH_IMPL_BUG_LIST(X) \
  1542. X(BUG_CHOKES_ON_SSH1_IGNORE) \
  1543. X(BUG_SSH2_HMAC) \
  1544. X(BUG_NEEDS_SSH1_PLAIN_PASSWORD) \
  1545. X(BUG_CHOKES_ON_RSA) \
  1546. X(BUG_SSH2_RSA_PADDING) \
  1547. X(BUG_SSH2_DERIVEKEY) \
  1548. X(BUG_SSH2_REKEY) \
  1549. X(BUG_SSH2_PK_SESSIONID) \
  1550. X(BUG_SSH2_MAXPKT) \
  1551. X(BUG_CHOKES_ON_SSH2_IGNORE) \
  1552. X(BUG_CHOKES_ON_WINADJ) \
  1553. X(BUG_SENDS_LATE_REQUEST_REPLY) \
  1554. X(BUG_SSH2_OLDGEX) \
  1555. /* end of list */
  1556. #define TMP_DECLARE_LOG2_ENUM(thing) log2_##thing,
  1557. enum { SSH_IMPL_BUG_LIST(TMP_DECLARE_LOG2_ENUM) };
  1558. #undef TMP_DECLARE_LOG2_ENUM
  1559. #define TMP_DECLARE_REAL_ENUM(thing) thing = 1 << log2_##thing,
  1560. enum { SSH_IMPL_BUG_LIST(TMP_DECLARE_REAL_ENUM) };
  1561. #undef TMP_DECLARE_REAL_ENUM
  1562. /* Shared system for allocating local SSH channel ids. Expects to be
  1563. * passed a tree full of structs that have a field called 'localid' of
  1564. * type unsigned, and will check that! */
  1565. unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset);
  1566. #define alloc_channel_id(tree, type) \
  1567. TYPECHECK(&((type *)0)->localid == (unsigned *)0, \
  1568. alloc_channel_id_general(tree, offsetof(type, localid)))
  1569. void add_to_commasep(strbuf *buf, const char *data);
  1570. bool get_commasep_word(ptrlen *list, ptrlen *word);
  1571. SeatPromptResult verify_ssh_host_key(
  1572. InteractionReadySeat iseat, Conf *conf, const char *host, int port,
  1573. ssh_key *key, const char *keytype, char *keystr, const char *keydisp,
  1574. char **fingerprints, void (*callback)(void *ctx, SeatPromptResult result),
  1575. void *ctx);
  1576. typedef struct ssh_transient_hostkey_cache ssh_transient_hostkey_cache;
  1577. ssh_transient_hostkey_cache *ssh_transient_hostkey_cache_new(void);
  1578. void ssh_transient_hostkey_cache_free(ssh_transient_hostkey_cache *thc);
  1579. void ssh_transient_hostkey_cache_add(
  1580. ssh_transient_hostkey_cache *thc, ssh_key *key);
  1581. bool ssh_transient_hostkey_cache_verify(
  1582. ssh_transient_hostkey_cache *thc, ssh_key *key);
  1583. bool ssh_transient_hostkey_cache_has(
  1584. ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg);
  1585. bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc);
  1586. #endif // WINSCP_VS