ssh1login.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. /*
  2. * Packet protocol layer for the SSH-1 login phase (combining what
  3. * SSH-2 would think of as key exchange and user authentication).
  4. */
  5. #include <assert.h>
  6. #include "putty.h"
  7. #include "ssh.h"
  8. #include "sshbpp.h"
  9. #include "sshppl.h"
  10. #include "sshcr.h"
  11. struct ssh1_login_state {
  12. int crState;
  13. PacketProtocolLayer *successor_layer;
  14. Conf *conf;
  15. char *savedhost;
  16. int savedport;
  17. int try_agent_auth;
  18. int remote_protoflags;
  19. int local_protoflags;
  20. unsigned char session_key[32];
  21. char *username;
  22. agent_pending_query *auth_agent_query;
  23. int len;
  24. unsigned char *rsabuf;
  25. unsigned long supported_ciphers_mask, supported_auths_mask;
  26. int tried_publickey, tried_agent;
  27. int tis_auth_refused, ccard_auth_refused;
  28. unsigned char cookie[8];
  29. unsigned char session_id[16];
  30. int cipher_type;
  31. strbuf *publickey_blob;
  32. char *publickey_comment;
  33. int privatekey_available, privatekey_encrypted;
  34. prompts_t *cur_prompt;
  35. int userpass_ret;
  36. char c;
  37. int pwpkt_type;
  38. void *agent_response_to_free;
  39. ptrlen agent_response;
  40. BinarySource asrc[1]; /* response from SSH agent */
  41. int keyi, nkeys;
  42. int authed;
  43. struct RSAKey key;
  44. Bignum challenge;
  45. ptrlen comment;
  46. int dlgret;
  47. Filename *keyfile;
  48. struct RSAKey servkey, hostkey;
  49. int want_user_input;
  50. PacketProtocolLayer ppl;
  51. };
  52. static void ssh1_login_free(PacketProtocolLayer *);
  53. static void ssh1_login_process_queue(PacketProtocolLayer *);
  54. static void ssh1_login_dialog_callback(void *, int);
  55. static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
  56. SessionSpecialCode code, int arg);
  57. static int ssh1_login_want_user_input(PacketProtocolLayer *ppl);
  58. static void ssh1_login_got_user_input(PacketProtocolLayer *ppl);
  59. static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
  60. static const struct PacketProtocolLayerVtable ssh1_login_vtable = {
  61. ssh1_login_free,
  62. ssh1_login_process_queue,
  63. ssh1_common_get_specials,
  64. ssh1_login_special_cmd,
  65. ssh1_login_want_user_input,
  66. ssh1_login_got_user_input,
  67. ssh1_login_reconfigure,
  68. NULL /* no layer names in SSH-1 */,
  69. };
  70. static void ssh1_login_agent_query(struct ssh1_login_state *s, strbuf *req);
  71. static void ssh1_login_agent_callback(void *loginv, void *reply, int replylen);
  72. PacketProtocolLayer *ssh1_login_new(
  73. Conf *conf, const char *host, int port,
  74. PacketProtocolLayer *successor_layer)
  75. {
  76. struct ssh1_login_state *s = snew(struct ssh1_login_state);
  77. memset(s, 0, sizeof(*s));
  78. s->ppl.vt = &ssh1_login_vtable;
  79. s->conf = conf_copy(conf);
  80. s->savedhost = dupstr(host);
  81. s->savedport = port;
  82. s->successor_layer = successor_layer;
  83. return &s->ppl;
  84. }
  85. static void ssh1_login_free(PacketProtocolLayer *ppl)
  86. {
  87. struct ssh1_login_state *s =
  88. container_of(ppl, struct ssh1_login_state, ppl);
  89. if (s->successor_layer)
  90. ssh_ppl_free(s->successor_layer);
  91. conf_free(s->conf);
  92. sfree(s->savedhost);
  93. sfree(s->rsabuf);
  94. sfree(s->username);
  95. if (s->publickey_blob)
  96. strbuf_free(s->publickey_blob);
  97. sfree(s->publickey_comment);
  98. if (s->cur_prompt)
  99. free_prompts(s->cur_prompt);
  100. sfree(s->agent_response_to_free);
  101. if (s->auth_agent_query)
  102. agent_cancel_query(s->auth_agent_query);
  103. sfree(s);
  104. }
  105. static int ssh1_login_filter_queue(struct ssh1_login_state *s)
  106. {
  107. return ssh1_common_filter_queue(&s->ppl);
  108. }
  109. static PktIn *ssh1_login_pop(struct ssh1_login_state *s)
  110. {
  111. if (ssh1_login_filter_queue(s))
  112. return NULL;
  113. return pq_pop(s->ppl.in_pq);
  114. }
  115. static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
  116. {
  117. struct ssh1_login_state *s =
  118. container_of(ppl, struct ssh1_login_state, ppl);
  119. PktIn *pktin;
  120. PktOut *pkt;
  121. int i;
  122. /* Filter centrally handled messages off the front of the queue on
  123. * every entry to this coroutine, no matter where we're resuming
  124. * from, even if we're _not_ looping on pq_pop. That way we can
  125. * still proactively handle those messages even if we're waiting
  126. * for a user response. */
  127. if (ssh1_login_filter_queue(s))
  128. return;
  129. crBegin(s->crState);
  130. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  131. if (pktin->type != SSH1_SMSG_PUBLIC_KEY) {
  132. ssh_proto_error(s->ppl.ssh, "Public key packet not received");
  133. return;
  134. }
  135. ppl_logevent(("Received public keys"));
  136. {
  137. ptrlen pl = get_data(pktin, 8);
  138. memcpy(s->cookie, pl.ptr, pl.len);
  139. }
  140. get_rsa_ssh1_pub(pktin, &s->servkey, RSA_SSH1_EXPONENT_FIRST);
  141. get_rsa_ssh1_pub(pktin, &s->hostkey, RSA_SSH1_EXPONENT_FIRST);
  142. s->hostkey.comment = NULL; /* avoid confusing rsa_ssh1_fingerprint */
  143. /*
  144. * Log the host key fingerprint.
  145. */
  146. if (!get_err(pktin)) {
  147. char *fingerprint = rsa_ssh1_fingerprint(&s->hostkey);
  148. ppl_logevent(("Host key fingerprint is:"));
  149. ppl_logevent((" %s", fingerprint));
  150. sfree(fingerprint);
  151. }
  152. s->remote_protoflags = get_uint32(pktin);
  153. s->supported_ciphers_mask = get_uint32(pktin);
  154. s->supported_auths_mask = get_uint32(pktin);
  155. if (get_err(pktin)) {
  156. ssh_proto_error(s->ppl.ssh, "Bad SSH-1 public key packet");
  157. return;
  158. }
  159. if ((s->ppl.remote_bugs & BUG_CHOKES_ON_RSA))
  160. s->supported_auths_mask &= ~(1 << SSH1_AUTH_RSA);
  161. s->local_protoflags =
  162. s->remote_protoflags & SSH1_PROTOFLAGS_SUPPORTED;
  163. s->local_protoflags |= SSH1_PROTOFLAG_SCREEN_NUMBER;
  164. ssh1_compute_session_id(s->session_id, s->cookie,
  165. &s->hostkey, &s->servkey);
  166. for (i = 0; i < 32; i++)
  167. s->session_key[i] = random_byte();
  168. /*
  169. * Verify that the `bits' and `bytes' parameters match.
  170. */
  171. if (s->hostkey.bits > s->hostkey.bytes * 8 ||
  172. s->servkey.bits > s->servkey.bytes * 8) {
  173. ssh_proto_error(s->ppl.ssh, "SSH-1 public keys were badly formatted");
  174. return;
  175. }
  176. s->len = (s->hostkey.bytes > s->servkey.bytes ?
  177. s->hostkey.bytes : s->servkey.bytes);
  178. s->rsabuf = snewn(s->len, unsigned char);
  179. /*
  180. * Verify the host key.
  181. */
  182. {
  183. /*
  184. * First format the key into a string.
  185. */
  186. int len = rsastr_len(&s->hostkey);
  187. char *fingerprint;
  188. char *keystr = snewn(len, char);
  189. rsastr_fmt(keystr, &s->hostkey);
  190. fingerprint = rsa_ssh1_fingerprint(&s->hostkey);
  191. /* First check against manually configured host keys. */
  192. s->dlgret = verify_ssh_manual_host_key(s->conf, fingerprint, NULL);
  193. sfree(fingerprint);
  194. if (s->dlgret == 0) { /* did not match */
  195. sfree(keystr);
  196. ssh_proto_error(s->ppl.ssh, "Host key did not appear in manually "
  197. "configured list");
  198. return;
  199. } else if (s->dlgret < 0) { /* none configured; use standard handling */
  200. s->dlgret = seat_verify_ssh_host_key(
  201. s->ppl.seat, s->savedhost, s->savedport,
  202. "rsa", keystr, fingerprint, ssh1_login_dialog_callback, s);
  203. sfree(keystr);
  204. #ifdef FUZZING
  205. s->dlgret = 1;
  206. #endif
  207. crMaybeWaitUntilV(s->dlgret >= 0);
  208. if (s->dlgret == 0) {
  209. ssh_user_close(s->ppl.ssh,
  210. "User aborted at host key verification");
  211. return;
  212. }
  213. } else {
  214. sfree(keystr);
  215. }
  216. }
  217. for (i = 0; i < 32; i++) {
  218. s->rsabuf[i] = s->session_key[i];
  219. if (i < 16)
  220. s->rsabuf[i] ^= s->session_id[i];
  221. }
  222. {
  223. struct RSAKey *smaller = (s->hostkey.bytes > s->servkey.bytes ?
  224. &s->servkey : &s->hostkey);
  225. struct RSAKey *larger = (s->hostkey.bytes > s->servkey.bytes ?
  226. &s->hostkey : &s->servkey);
  227. if (!rsa_ssh1_encrypt(s->rsabuf, 32, smaller) ||
  228. !rsa_ssh1_encrypt(s->rsabuf, smaller->bytes, larger)) {
  229. ssh_proto_error(s->ppl.ssh, "SSH-1 public key encryptions failed "
  230. "due to bad formatting");
  231. return;
  232. }
  233. }
  234. ppl_logevent(("Encrypted session key"));
  235. {
  236. int cipher_chosen = 0, warn = 0;
  237. const char *cipher_string = NULL;
  238. int i;
  239. for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) {
  240. int next_cipher = conf_get_int_int(
  241. s->conf, CONF_ssh_cipherlist, i);
  242. if (next_cipher == CIPHER_WARN) {
  243. /* If/when we choose a cipher, warn about it */
  244. warn = 1;
  245. } else if (next_cipher == CIPHER_AES) {
  246. /* XXX Probably don't need to mention this. */
  247. ppl_logevent(("AES not supported in SSH-1, skipping"));
  248. } else {
  249. switch (next_cipher) {
  250. case CIPHER_3DES: s->cipher_type = SSH_CIPHER_3DES;
  251. cipher_string = "3DES"; break;
  252. case CIPHER_BLOWFISH: s->cipher_type = SSH_CIPHER_BLOWFISH;
  253. cipher_string = "Blowfish"; break;
  254. case CIPHER_DES: s->cipher_type = SSH_CIPHER_DES;
  255. cipher_string = "single-DES"; break;
  256. }
  257. if (s->supported_ciphers_mask & (1 << s->cipher_type))
  258. cipher_chosen = 1;
  259. }
  260. }
  261. if (!cipher_chosen) {
  262. if ((s->supported_ciphers_mask & (1 << SSH_CIPHER_3DES)) == 0) {
  263. ssh_proto_error(s->ppl.ssh, "Server violates SSH-1 protocol "
  264. "by not supporting 3DES encryption");
  265. } else {
  266. /* shouldn't happen */
  267. ssh_sw_abort(s->ppl.ssh, "No supported ciphers found");
  268. }
  269. return;
  270. }
  271. /* Warn about chosen cipher if necessary. */
  272. if (warn) {
  273. s->dlgret = seat_confirm_weak_crypto_primitive(
  274. s->ppl.seat, "cipher", cipher_string,
  275. ssh1_login_dialog_callback, s);
  276. crMaybeWaitUntilV(s->dlgret >= 0);
  277. if (s->dlgret == 0) {
  278. ssh_user_close(s->ppl.ssh, "User aborted at cipher warning");
  279. return;
  280. }
  281. }
  282. }
  283. switch (s->cipher_type) {
  284. case SSH_CIPHER_3DES:
  285. ppl_logevent(("Using 3DES encryption"));
  286. break;
  287. case SSH_CIPHER_DES:
  288. ppl_logevent(("Using single-DES encryption"));
  289. break;
  290. case SSH_CIPHER_BLOWFISH:
  291. ppl_logevent(("Using Blowfish encryption"));
  292. break;
  293. }
  294. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_SESSION_KEY);
  295. put_byte(pkt, s->cipher_type);
  296. put_data(pkt, s->cookie, 8);
  297. put_uint16(pkt, s->len * 8);
  298. put_data(pkt, s->rsabuf, s->len);
  299. put_uint32(pkt, s->local_protoflags);
  300. pq_push(s->ppl.out_pq, pkt);
  301. ppl_logevent(("Trying to enable encryption..."));
  302. sfree(s->rsabuf);
  303. s->rsabuf = NULL;
  304. /*
  305. * Force the BPP to synchronously marshal all packets up to and
  306. * including the SESSION_KEY into wire format, before we turn on
  307. * crypto.
  308. */
  309. ssh_bpp_handle_output(s->ppl.bpp);
  310. {
  311. const struct ssh1_cipheralg *cipher =
  312. (s->cipher_type == SSH_CIPHER_BLOWFISH ? &ssh1_blowfish :
  313. s->cipher_type == SSH_CIPHER_DES ? &ssh1_des : &ssh1_3des);
  314. ssh1_bpp_new_cipher(s->ppl.bpp, cipher, s->session_key);
  315. }
  316. if (s->servkey.modulus) {
  317. sfree(s->servkey.modulus);
  318. s->servkey.modulus = NULL;
  319. }
  320. if (s->servkey.exponent) {
  321. sfree(s->servkey.exponent);
  322. s->servkey.exponent = NULL;
  323. }
  324. if (s->hostkey.modulus) {
  325. sfree(s->hostkey.modulus);
  326. s->hostkey.modulus = NULL;
  327. }
  328. if (s->hostkey.exponent) {
  329. sfree(s->hostkey.exponent);
  330. s->hostkey.exponent = NULL;
  331. }
  332. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  333. if (pktin->type != SSH1_SMSG_SUCCESS) {
  334. ssh_proto_error(s->ppl.ssh, "Encryption not successfully enabled");
  335. return;
  336. }
  337. ppl_logevent(("Successfully started encryption"));
  338. if ((s->username = get_remote_username(s->conf)) == NULL) {
  339. s->cur_prompt = new_prompts();
  340. s->cur_prompt->to_server = TRUE;
  341. s->cur_prompt->name = dupstr("SSH login name");
  342. add_prompt(s->cur_prompt, dupstr("login as: "), TRUE);
  343. s->userpass_ret = seat_get_userpass_input(
  344. s->ppl.seat, s->cur_prompt, NULL);
  345. while (1) {
  346. while (s->userpass_ret < 0 &&
  347. bufchain_size(s->ppl.user_input) > 0)
  348. s->userpass_ret = seat_get_userpass_input(
  349. s->ppl.seat, s->cur_prompt, s->ppl.user_input);
  350. if (s->userpass_ret >= 0)
  351. break;
  352. s->want_user_input = TRUE;
  353. crReturnV;
  354. s->want_user_input = FALSE;
  355. }
  356. if (!s->userpass_ret) {
  357. /*
  358. * Failed to get a username. Terminate.
  359. */
  360. ssh_user_close(s->ppl.ssh, "No username provided");
  361. return;
  362. }
  363. s->username = dupstr(s->cur_prompt->prompts[0]->result);
  364. free_prompts(s->cur_prompt);
  365. s->cur_prompt = NULL;
  366. }
  367. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_USER);
  368. put_stringz(pkt, s->username);
  369. pq_push(s->ppl.out_pq, pkt);
  370. ppl_logevent(("Sent username \"%s\"", s->username));
  371. if ((flags & FLAG_VERBOSE) || (flags & FLAG_INTERACTIVE))
  372. ppl_printf(("Sent username \"%s\"\r\n", s->username));
  373. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  374. if (!(s->supported_auths_mask & (1 << SSH1_AUTH_RSA))) {
  375. /* We must not attempt PK auth. Pretend we've already tried it. */
  376. s->tried_publickey = s->tried_agent = TRUE;
  377. } else {
  378. s->tried_publickey = s->tried_agent = FALSE;
  379. }
  380. s->tis_auth_refused = s->ccard_auth_refused = FALSE;
  381. /*
  382. * Load the public half of any configured keyfile for later use.
  383. */
  384. s->keyfile = conf_get_filename(s->conf, CONF_keyfile);
  385. if (!filename_is_null(s->keyfile)) {
  386. int keytype;
  387. ppl_logevent(("Reading key file \"%.150s\"",
  388. filename_to_str(s->keyfile)));
  389. keytype = key_type(s->keyfile);
  390. if (keytype == SSH_KEYTYPE_SSH1 ||
  391. keytype == SSH_KEYTYPE_SSH1_PUBLIC) {
  392. const char *error;
  393. s->publickey_blob = strbuf_new();
  394. if (rsa_ssh1_loadpub(s->keyfile,
  395. BinarySink_UPCAST(s->publickey_blob),
  396. &s->publickey_comment, &error)) {
  397. s->privatekey_available = (keytype == SSH_KEYTYPE_SSH1);
  398. if (!s->privatekey_available)
  399. ppl_logevent(("Key file contains public key only"));
  400. s->privatekey_encrypted = rsa_ssh1_encrypted(s->keyfile, NULL);
  401. } else {
  402. ppl_logevent(("Unable to load key (%s)", error));
  403. ppl_printf(("Unable to load key file \"%s\" (%s)\r\n",
  404. filename_to_str(s->keyfile), error));
  405. strbuf_free(s->publickey_blob);
  406. s->publickey_blob = NULL;
  407. }
  408. } else {
  409. ppl_logevent(("Unable to use this key file (%s)",
  410. key_type_to_str(keytype)));
  411. ppl_printf(("Unable to use key file \"%s\" (%s)\r\n",
  412. filename_to_str(s->keyfile),
  413. key_type_to_str(keytype)));
  414. }
  415. }
  416. /* Check whether we're configured to try Pageant, and also whether
  417. * it's available. */
  418. s->try_agent_auth = (conf_get_int(s->conf, CONF_tryagent) &&
  419. agent_exists());
  420. while (pktin->type == SSH1_SMSG_FAILURE) {
  421. s->pwpkt_type = SSH1_CMSG_AUTH_PASSWORD;
  422. if (s->try_agent_auth && !s->tried_agent) {
  423. /*
  424. * Attempt RSA authentication using Pageant.
  425. */
  426. s->authed = FALSE;
  427. s->tried_agent = 1;
  428. ppl_logevent(("Pageant is running. Requesting keys."));
  429. /* Request the keys held by the agent. */
  430. {
  431. strbuf *request = strbuf_new_for_agent_query();
  432. put_byte(request, SSH1_AGENTC_REQUEST_RSA_IDENTITIES);
  433. ssh1_login_agent_query(s, request);
  434. strbuf_free(request);
  435. crMaybeWaitUntilV(!s->auth_agent_query);
  436. }
  437. BinarySource_BARE_INIT(
  438. s->asrc, s->agent_response.ptr, s->agent_response.len);
  439. get_uint32(s->asrc); /* skip length field */
  440. if (get_byte(s->asrc) == SSH1_AGENT_RSA_IDENTITIES_ANSWER) {
  441. s->nkeys = toint(get_uint32(s->asrc));
  442. if (s->nkeys < 0) {
  443. ppl_logevent(("Pageant reported negative key count %d",
  444. s->nkeys));
  445. s->nkeys = 0;
  446. }
  447. ppl_logevent(("Pageant has %d SSH-1 keys", s->nkeys));
  448. for (s->keyi = 0; s->keyi < s->nkeys; s->keyi++) {
  449. size_t start, end;
  450. start = s->asrc->pos;
  451. get_rsa_ssh1_pub(s->asrc, &s->key,
  452. RSA_SSH1_EXPONENT_FIRST);
  453. end = s->asrc->pos;
  454. s->comment = get_string(s->asrc);
  455. if (get_err(s->asrc)) {
  456. ppl_logevent(("Pageant key list packet was truncated"));
  457. break;
  458. }
  459. if (s->publickey_blob) {
  460. ptrlen keystr = make_ptrlen(
  461. (const char *)s->asrc->data + start, end - start);
  462. if (keystr.len == s->publickey_blob->len &&
  463. !memcmp(keystr.ptr, s->publickey_blob->s,
  464. s->publickey_blob->len)) {
  465. ppl_logevent(("Pageant key #%d matches "
  466. "configured key file", s->keyi));
  467. s->tried_publickey = 1;
  468. } else
  469. /* Skip non-configured key */
  470. continue;
  471. }
  472. ppl_logevent(("Trying Pageant key #%d", s->keyi));
  473. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_AUTH_RSA);
  474. put_mp_ssh1(pkt, s->key.modulus);
  475. pq_push(s->ppl.out_pq, pkt);
  476. crMaybeWaitUntilV((pktin = ssh1_login_pop(s))
  477. != NULL);
  478. if (pktin->type != SSH1_SMSG_AUTH_RSA_CHALLENGE) {
  479. ppl_logevent(("Key refused"));
  480. continue;
  481. }
  482. ppl_logevent(("Received RSA challenge"));
  483. s->challenge = get_mp_ssh1(pktin);
  484. if (get_err(pktin)) {
  485. freebn(s->challenge);
  486. ssh_proto_error(s->ppl.ssh, "Server's RSA challenge "
  487. "was badly formatted");
  488. return;
  489. }
  490. {
  491. strbuf *agentreq;
  492. const char *ret;
  493. agentreq = strbuf_new_for_agent_query();
  494. put_byte(agentreq, SSH1_AGENTC_RSA_CHALLENGE);
  495. put_uint32(agentreq, bignum_bitcount(s->key.modulus));
  496. put_mp_ssh1(agentreq, s->key.exponent);
  497. put_mp_ssh1(agentreq, s->key.modulus);
  498. put_mp_ssh1(agentreq, s->challenge);
  499. put_data(agentreq, s->session_id, 16);
  500. put_uint32(agentreq, 1); /* response format */
  501. ssh1_login_agent_query(s, agentreq);
  502. strbuf_free(agentreq);
  503. crMaybeWaitUntilV(!s->auth_agent_query);
  504. ret = s->agent_response.ptr;
  505. if (ret) {
  506. if (s->agent_response.len >= 5+16 &&
  507. ret[4] == SSH1_AGENT_RSA_RESPONSE) {
  508. ppl_logevent(("Sending Pageant's response"));
  509. pkt = ssh_bpp_new_pktout(
  510. s->ppl.bpp, SSH1_CMSG_AUTH_RSA_RESPONSE);
  511. put_data(pkt, ret + 5, 16);
  512. pq_push(s->ppl.out_pq, pkt);
  513. sfree((char *)ret);
  514. crMaybeWaitUntilV(
  515. (pktin = ssh1_login_pop(s))
  516. != NULL);
  517. if (pktin->type == SSH1_SMSG_SUCCESS) {
  518. ppl_logevent(("Pageant's response "
  519. "accepted"));
  520. if (flags & FLAG_VERBOSE) {
  521. ppl_printf(("Authenticated using RSA "
  522. "key \"%.*s\" from "
  523. "agent\r\n", PTRLEN_PRINTF(
  524. s->comment)));
  525. }
  526. s->authed = TRUE;
  527. } else
  528. ppl_logevent(("Pageant's response not "
  529. "accepted"));
  530. } else {
  531. ppl_logevent(("Pageant failed to answer "
  532. "challenge"));
  533. sfree((char *)ret);
  534. }
  535. } else {
  536. ppl_logevent(("No reply received from Pageant"));
  537. }
  538. }
  539. freebn(s->key.exponent);
  540. freebn(s->key.modulus);
  541. freebn(s->challenge);
  542. if (s->authed)
  543. break;
  544. }
  545. sfree(s->agent_response_to_free);
  546. s->agent_response_to_free = NULL;
  547. if (s->publickey_blob && !s->tried_publickey)
  548. ppl_logevent(("Configured key file not in Pageant"));
  549. } else {
  550. ppl_logevent(("Failed to get reply from Pageant"));
  551. }
  552. if (s->authed)
  553. break;
  554. }
  555. if (s->publickey_blob && s->privatekey_available &&
  556. !s->tried_publickey) {
  557. /*
  558. * Try public key authentication with the specified
  559. * key file.
  560. */
  561. int got_passphrase; /* need not be kept over crReturn */
  562. if (flags & FLAG_VERBOSE)
  563. ppl_printf(("Trying public key authentication.\r\n"));
  564. ppl_logevent(("Trying public key \"%s\"",
  565. filename_to_str(s->keyfile)));
  566. s->tried_publickey = 1;
  567. got_passphrase = FALSE;
  568. while (!got_passphrase) {
  569. /*
  570. * Get a passphrase, if necessary.
  571. */
  572. int retd;
  573. char *passphrase = NULL; /* only written after crReturn */
  574. const char *error;
  575. if (!s->privatekey_encrypted) {
  576. if (flags & FLAG_VERBOSE)
  577. ppl_printf(("No passphrase required.\r\n"));
  578. passphrase = NULL;
  579. } else {
  580. s->cur_prompt = new_prompts(s->ppl.seat);
  581. s->cur_prompt->to_server = FALSE;
  582. s->cur_prompt->name = dupstr("SSH key passphrase");
  583. add_prompt(s->cur_prompt,
  584. dupprintf("Passphrase for key \"%.100s\": ",
  585. s->publickey_comment), FALSE);
  586. s->userpass_ret = seat_get_userpass_input(
  587. s->ppl.seat, s->cur_prompt, NULL);
  588. while (1) {
  589. while (s->userpass_ret < 0 &&
  590. bufchain_size(s->ppl.user_input) > 0)
  591. s->userpass_ret = seat_get_userpass_input(
  592. s->ppl.seat, s->cur_prompt, s->ppl.user_input);
  593. if (s->userpass_ret >= 0)
  594. break;
  595. s->want_user_input = TRUE;
  596. crReturnV;
  597. s->want_user_input = FALSE;
  598. }
  599. if (!s->userpass_ret) {
  600. /* Failed to get a passphrase. Terminate. */
  601. ssh_user_close(s->ppl.ssh,
  602. "User aborted at passphrase prompt");
  603. return;
  604. }
  605. passphrase = dupstr(s->cur_prompt->prompts[0]->result);
  606. free_prompts(s->cur_prompt);
  607. s->cur_prompt = NULL;
  608. }
  609. /*
  610. * Try decrypting key with passphrase.
  611. */
  612. retd = rsa_ssh1_loadkey(
  613. s->keyfile, &s->key, passphrase, &error);
  614. if (passphrase) {
  615. smemclr(passphrase, strlen(passphrase));
  616. sfree(passphrase);
  617. }
  618. if (retd == 1) {
  619. /* Correct passphrase. */
  620. got_passphrase = TRUE;
  621. } else if (retd == 0) {
  622. ppl_printf(("Couldn't load private key from %s (%s).\r\n",
  623. filename_to_str(s->keyfile), error));
  624. got_passphrase = FALSE;
  625. break; /* go and try something else */
  626. } else if (retd == -1) {
  627. ppl_printf(("Wrong passphrase.\r\n"));
  628. got_passphrase = FALSE;
  629. /* and try again */
  630. } else {
  631. assert(0 && "unexpected return from rsa_ssh1_loadkey()");
  632. got_passphrase = FALSE; /* placate optimisers */
  633. }
  634. }
  635. if (got_passphrase) {
  636. /*
  637. * Send a public key attempt.
  638. */
  639. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_AUTH_RSA);
  640. put_mp_ssh1(pkt, s->key.modulus);
  641. pq_push(s->ppl.out_pq, pkt);
  642. crMaybeWaitUntilV((pktin = ssh1_login_pop(s))
  643. != NULL);
  644. if (pktin->type == SSH1_SMSG_FAILURE) {
  645. ppl_printf(("Server refused our public key.\r\n"));
  646. continue; /* go and try something else */
  647. }
  648. if (pktin->type != SSH1_SMSG_AUTH_RSA_CHALLENGE) {
  649. ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
  650. " in response to offer of public key, "
  651. "type %d (%s)", pktin->type,
  652. ssh1_pkt_type(pktin->type));
  653. return;
  654. }
  655. {
  656. int i;
  657. unsigned char buffer[32];
  658. Bignum challenge, response;
  659. challenge = get_mp_ssh1(pktin);
  660. if (get_err(pktin)) {
  661. freebn(challenge);
  662. ssh_proto_error(s->ppl.ssh, "Server's RSA challenge "
  663. "was badly formatted");
  664. return;
  665. }
  666. response = rsa_ssh1_decrypt(challenge, &s->key);
  667. freebn(s->key.private_exponent);/* burn the evidence */
  668. for (i = 0; i < 32; i++) {
  669. buffer[i] = bignum_byte(response, 31 - i);
  670. }
  671. {
  672. struct MD5Context md5c;
  673. MD5Init(&md5c);
  674. put_data(&md5c, buffer, 32);
  675. put_data(&md5c, s->session_id, 16);
  676. MD5Final(buffer, &md5c);
  677. }
  678. pkt = ssh_bpp_new_pktout(
  679. s->ppl.bpp, SSH1_CMSG_AUTH_RSA_RESPONSE);
  680. put_data(pkt, buffer, 16);
  681. pq_push(s->ppl.out_pq, pkt);
  682. freebn(challenge);
  683. freebn(response);
  684. }
  685. crMaybeWaitUntilV((pktin = ssh1_login_pop(s))
  686. != NULL);
  687. if (pktin->type == SSH1_SMSG_FAILURE) {
  688. if (flags & FLAG_VERBOSE)
  689. ppl_printf(("Failed to authenticate with"
  690. " our public key.\r\n"));
  691. continue; /* go and try something else */
  692. } else if (pktin->type != SSH1_SMSG_SUCCESS) {
  693. ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
  694. " in response to RSA authentication, "
  695. "type %d (%s)", pktin->type,
  696. ssh1_pkt_type(pktin->type));
  697. return;
  698. }
  699. break; /* we're through! */
  700. }
  701. }
  702. /*
  703. * Otherwise, try various forms of password-like authentication.
  704. */
  705. s->cur_prompt = new_prompts(s->ppl.seat);
  706. if (conf_get_int(s->conf, CONF_try_tis_auth) &&
  707. (s->supported_auths_mask & (1 << SSH1_AUTH_TIS)) &&
  708. !s->tis_auth_refused) {
  709. s->pwpkt_type = SSH1_CMSG_AUTH_TIS_RESPONSE;
  710. ppl_logevent(("Requested TIS authentication"));
  711. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_AUTH_TIS);
  712. pq_push(s->ppl.out_pq, pkt);
  713. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  714. if (pktin->type == SSH1_SMSG_FAILURE) {
  715. ppl_logevent(("TIS authentication declined"));
  716. if (flags & FLAG_INTERACTIVE)
  717. ppl_printf(("TIS authentication refused.\r\n"));
  718. s->tis_auth_refused = 1;
  719. continue;
  720. } else if (pktin->type == SSH1_SMSG_AUTH_TIS_CHALLENGE) {
  721. ptrlen challenge;
  722. char *instr_suf, *prompt;
  723. challenge = get_string(pktin);
  724. if (get_err(pktin)) {
  725. ssh_proto_error(s->ppl.ssh, "TIS challenge packet was "
  726. "badly formed");
  727. return;
  728. }
  729. ppl_logevent(("Received TIS challenge"));
  730. s->cur_prompt->to_server = TRUE;
  731. s->cur_prompt->name = dupstr("SSH TIS authentication");
  732. /* Prompt heuristic comes from OpenSSH */
  733. if (memchr(challenge.ptr, '\n', challenge.len)) {
  734. instr_suf = dupstr("");
  735. prompt = mkstr(challenge);
  736. } else {
  737. instr_suf = mkstr(challenge);
  738. prompt = dupstr("Response: ");
  739. }
  740. s->cur_prompt->instruction =
  741. dupprintf("Using TIS authentication.%s%s",
  742. (*instr_suf) ? "\n" : "",
  743. instr_suf);
  744. s->cur_prompt->instr_reqd = TRUE;
  745. add_prompt(s->cur_prompt, prompt, FALSE);
  746. sfree(instr_suf);
  747. } else {
  748. ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
  749. " in response to TIS authentication, "
  750. "type %d (%s)", pktin->type,
  751. ssh1_pkt_type(pktin->type));
  752. return;
  753. }
  754. }
  755. if (conf_get_int(s->conf, CONF_try_tis_auth) &&
  756. (s->supported_auths_mask & (1 << SSH1_AUTH_CCARD)) &&
  757. !s->ccard_auth_refused) {
  758. s->pwpkt_type = SSH1_CMSG_AUTH_CCARD_RESPONSE;
  759. ppl_logevent(("Requested CryptoCard authentication"));
  760. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_AUTH_CCARD);
  761. pq_push(s->ppl.out_pq, pkt);
  762. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  763. if (pktin->type == SSH1_SMSG_FAILURE) {
  764. ppl_logevent(("CryptoCard authentication declined"));
  765. ppl_printf(("CryptoCard authentication refused.\r\n"));
  766. s->ccard_auth_refused = 1;
  767. continue;
  768. } else if (pktin->type == SSH1_SMSG_AUTH_CCARD_CHALLENGE) {
  769. ptrlen challenge;
  770. char *instr_suf, *prompt;
  771. challenge = get_string(pktin);
  772. if (get_err(pktin)) {
  773. ssh_proto_error(s->ppl.ssh, "CryptoCard challenge packet "
  774. "was badly formed");
  775. return;
  776. }
  777. ppl_logevent(("Received CryptoCard challenge"));
  778. s->cur_prompt->to_server = TRUE;
  779. s->cur_prompt->name = dupstr("SSH CryptoCard authentication");
  780. s->cur_prompt->name_reqd = FALSE;
  781. /* Prompt heuristic comes from OpenSSH */
  782. if (memchr(challenge.ptr, '\n', challenge.len)) {
  783. instr_suf = dupstr("");
  784. prompt = mkstr(challenge);
  785. } else {
  786. instr_suf = mkstr(challenge);
  787. prompt = dupstr("Response: ");
  788. }
  789. s->cur_prompt->instruction =
  790. dupprintf("Using CryptoCard authentication.%s%s",
  791. (*instr_suf) ? "\n" : "",
  792. instr_suf);
  793. s->cur_prompt->instr_reqd = TRUE;
  794. add_prompt(s->cur_prompt, prompt, FALSE);
  795. sfree(instr_suf);
  796. } else {
  797. ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
  798. " in response to TIS authentication, "
  799. "type %d (%s)", pktin->type,
  800. ssh1_pkt_type(pktin->type));
  801. return;
  802. }
  803. }
  804. if (s->pwpkt_type == SSH1_CMSG_AUTH_PASSWORD) {
  805. if ((s->supported_auths_mask & (1 << SSH1_AUTH_PASSWORD)) == 0) {
  806. ssh_sw_abort(s->ppl.ssh, "No supported authentication methods "
  807. "available");
  808. return;
  809. }
  810. s->cur_prompt->to_server = TRUE;
  811. s->cur_prompt->name = dupstr("SSH password");
  812. add_prompt(s->cur_prompt, dupprintf("%s@%s's password: ",
  813. s->username, s->savedhost),
  814. FALSE);
  815. }
  816. /*
  817. * Show password prompt, having first obtained it via a TIS
  818. * or CryptoCard exchange if we're doing TIS or CryptoCard
  819. * authentication.
  820. */
  821. s->userpass_ret = seat_get_userpass_input(
  822. s->ppl.seat, s->cur_prompt, NULL);
  823. while (1) {
  824. while (s->userpass_ret < 0 &&
  825. bufchain_size(s->ppl.user_input) > 0)
  826. s->userpass_ret = seat_get_userpass_input(
  827. s->ppl.seat, s->cur_prompt, s->ppl.user_input);
  828. if (s->userpass_ret >= 0)
  829. break;
  830. s->want_user_input = TRUE;
  831. crReturnV;
  832. s->want_user_input = FALSE;
  833. }
  834. if (!s->userpass_ret) {
  835. /*
  836. * Failed to get a password (for example
  837. * because one was supplied on the command line
  838. * which has already failed to work). Terminate.
  839. */
  840. ssh_user_close(s->ppl.ssh, "User aborted at password prompt");
  841. return;
  842. }
  843. if (s->pwpkt_type == SSH1_CMSG_AUTH_PASSWORD) {
  844. /*
  845. * Defence against traffic analysis: we send a
  846. * whole bunch of packets containing strings of
  847. * different lengths. One of these strings is the
  848. * password, in a SSH1_CMSG_AUTH_PASSWORD packet.
  849. * The others are all random data in
  850. * SSH1_MSG_IGNORE packets. This way a passive
  851. * listener can't tell which is the password, and
  852. * hence can't deduce the password length.
  853. *
  854. * Anybody with a password length greater than 16
  855. * bytes is going to have enough entropy in their
  856. * password that a listener won't find it _that_
  857. * much help to know how long it is. So what we'll
  858. * do is:
  859. *
  860. * - if password length < 16, we send 15 packets
  861. * containing string lengths 1 through 15
  862. *
  863. * - otherwise, we let N be the nearest multiple
  864. * of 8 below the password length, and send 8
  865. * packets containing string lengths N through
  866. * N+7. This won't obscure the order of
  867. * magnitude of the password length, but it will
  868. * introduce a bit of extra uncertainty.
  869. *
  870. * A few servers can't deal with SSH1_MSG_IGNORE, at
  871. * least in this context. For these servers, we need
  872. * an alternative defence. We make use of the fact
  873. * that the password is interpreted as a C string:
  874. * so we can append a NUL, then some random data.
  875. *
  876. * A few servers can deal with neither SSH1_MSG_IGNORE
  877. * here _nor_ a padded password string.
  878. * For these servers we are left with no defences
  879. * against password length sniffing.
  880. */
  881. if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH1_IGNORE) &&
  882. !(s->ppl.remote_bugs & BUG_NEEDS_SSH1_PLAIN_PASSWORD)) {
  883. /*
  884. * The server can deal with SSH1_MSG_IGNORE, so
  885. * we can use the primary defence.
  886. */
  887. int bottom, top, pwlen, i;
  888. pwlen = strlen(s->cur_prompt->prompts[0]->result);
  889. if (pwlen < 16) {
  890. bottom = 0; /* zero length passwords are OK! :-) */
  891. top = 15;
  892. } else {
  893. bottom = pwlen & ~7;
  894. top = bottom + 7;
  895. }
  896. assert(pwlen >= bottom && pwlen <= top);
  897. for (i = bottom; i <= top; i++) {
  898. if (i == pwlen) {
  899. pkt = ssh_bpp_new_pktout(s->ppl.bpp, s->pwpkt_type);
  900. put_stringz(pkt, s->cur_prompt->prompts[0]->result);
  901. pq_push(s->ppl.out_pq, pkt);
  902. } else {
  903. int j;
  904. strbuf *random_data = strbuf_new();
  905. for (j = 0; j < i; j++)
  906. put_byte(random_data, random_byte());
  907. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_IGNORE);
  908. put_stringsb(pkt, random_data);
  909. pq_push(s->ppl.out_pq, pkt);
  910. }
  911. }
  912. ppl_logevent(("Sending password with camouflage packets"));
  913. }
  914. else if (!(s->ppl.remote_bugs & BUG_NEEDS_SSH1_PLAIN_PASSWORD)) {
  915. /*
  916. * The server can't deal with SSH1_MSG_IGNORE
  917. * but can deal with padded passwords, so we
  918. * can use the secondary defence.
  919. */
  920. strbuf *padded_pw = strbuf_new();
  921. ppl_logevent(("Sending length-padded password"));
  922. pkt = ssh_bpp_new_pktout(s->ppl.bpp, s->pwpkt_type);
  923. put_asciz(padded_pw, s->cur_prompt->prompts[0]->result);
  924. do {
  925. put_byte(padded_pw, random_byte());
  926. } while (padded_pw->len % 64 != 0);
  927. put_stringsb(pkt, padded_pw);
  928. pq_push(s->ppl.out_pq, pkt);
  929. } else {
  930. /*
  931. * The server is believed unable to cope with
  932. * any of our password camouflage methods.
  933. */
  934. ppl_logevent(("Sending unpadded password"));
  935. pkt = ssh_bpp_new_pktout(s->ppl.bpp, s->pwpkt_type);
  936. put_stringz(pkt, s->cur_prompt->prompts[0]->result);
  937. pq_push(s->ppl.out_pq, pkt);
  938. }
  939. } else {
  940. pkt = ssh_bpp_new_pktout(s->ppl.bpp, s->pwpkt_type);
  941. put_stringz(pkt, s->cur_prompt->prompts[0]->result);
  942. pq_push(s->ppl.out_pq, pkt);
  943. }
  944. ppl_logevent(("Sent password"));
  945. free_prompts(s->cur_prompt);
  946. s->cur_prompt = NULL;
  947. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  948. if (pktin->type == SSH1_SMSG_FAILURE) {
  949. if (flags & FLAG_VERBOSE)
  950. ppl_printf(("Access denied\r\n"));
  951. ppl_logevent(("Authentication refused"));
  952. } else if (pktin->type != SSH1_SMSG_SUCCESS) {
  953. ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
  954. " in response to password authentication, type %d "
  955. "(%s)", pktin->type, ssh1_pkt_type(pktin->type));
  956. return;
  957. }
  958. }
  959. ppl_logevent(("Authentication successful"));
  960. if (conf_get_int(s->conf, CONF_compression)) {
  961. ppl_logevent(("Requesting compression"));
  962. pkt = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_CMSG_REQUEST_COMPRESSION);
  963. put_uint32(pkt, 6); /* gzip compression level */
  964. pq_push(s->ppl.out_pq, pkt);
  965. crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL);
  966. if (pktin->type == SSH1_SMSG_SUCCESS) {
  967. /*
  968. * We don't have to actually do anything here: the SSH-1
  969. * BPP will take care of automatically starting the
  970. * compression, by recognising our outgoing request packet
  971. * and the success response. (Horrible, but it's the
  972. * easiest way to avoid race conditions if other packets
  973. * cross in transit.)
  974. */
  975. } else if (pktin->type == SSH1_SMSG_FAILURE) {
  976. ppl_logevent(("Server refused to enable compression"));
  977. ppl_printf(("Server refused to compress\r\n"));
  978. } else {
  979. ssh_proto_error(s->ppl.ssh, "Received unexpected packet"
  980. " in response to compression request, type %d "
  981. "(%s)", pktin->type, ssh1_pkt_type(pktin->type));
  982. return;
  983. }
  984. }
  985. ssh1_connection_set_local_protoflags(
  986. s->successor_layer, s->local_protoflags);
  987. {
  988. PacketProtocolLayer *successor = s->successor_layer;
  989. s->successor_layer = NULL; /* avoid freeing it ourself */
  990. ssh_ppl_replace(&s->ppl, successor);
  991. return; /* we've just freed s, so avoid even touching s->crState */
  992. }
  993. crFinishV;
  994. }
  995. static void ssh1_login_dialog_callback(void *loginv, int ret)
  996. {
  997. struct ssh1_login_state *s = (struct ssh1_login_state *)loginv;
  998. s->dlgret = ret;
  999. ssh_ppl_process_queue(&s->ppl);
  1000. }
  1001. static void ssh1_login_agent_query(struct ssh1_login_state *s, strbuf *req)
  1002. {
  1003. void *response;
  1004. int response_len;
  1005. sfree(s->agent_response_to_free);
  1006. s->agent_response_to_free = NULL;
  1007. s->auth_agent_query = agent_query(req, &response, &response_len,
  1008. ssh1_login_agent_callback, s);
  1009. if (!s->auth_agent_query)
  1010. ssh1_login_agent_callback(s, response, response_len);
  1011. }
  1012. static void ssh1_login_agent_callback(void *loginv, void *reply, int replylen)
  1013. {
  1014. struct ssh1_login_state *s = (struct ssh1_login_state *)loginv;
  1015. s->auth_agent_query = NULL;
  1016. s->agent_response_to_free = reply;
  1017. s->agent_response = make_ptrlen(reply, replylen);
  1018. queue_idempotent_callback(&s->ppl.ic_process_queue);
  1019. }
  1020. static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
  1021. SessionSpecialCode code, int arg)
  1022. {
  1023. struct ssh1_login_state *s =
  1024. container_of(ppl, struct ssh1_login_state, ppl);
  1025. PktOut *pktout;
  1026. if (code == SS_PING || code == SS_NOP) {
  1027. if (!(s->ppl.remote_bugs & BUG_CHOKES_ON_SSH1_IGNORE)) {
  1028. pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH1_MSG_IGNORE);
  1029. put_stringz(pktout, "");
  1030. pq_push(s->ppl.out_pq, pktout);
  1031. }
  1032. }
  1033. }
  1034. static int ssh1_login_want_user_input(PacketProtocolLayer *ppl)
  1035. {
  1036. struct ssh1_login_state *s =
  1037. container_of(ppl, struct ssh1_login_state, ppl);
  1038. return s->want_user_input;
  1039. }
  1040. static void ssh1_login_got_user_input(PacketProtocolLayer *ppl)
  1041. {
  1042. struct ssh1_login_state *s =
  1043. container_of(ppl, struct ssh1_login_state, ppl);
  1044. if (s->want_user_input)
  1045. queue_idempotent_callback(&s->ppl.ic_process_queue);
  1046. }
  1047. static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
  1048. {
  1049. struct ssh1_login_state *s =
  1050. container_of(ppl, struct ssh1_login_state, ppl);
  1051. ssh_ppl_reconfigure(s->successor_layer, conf);
  1052. }