ssh1login.c 47 KB

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