sshverstring.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /*
  2. * Code to handle the initial SSH version string exchange.
  3. */
  4. #include <assert.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include "putty.h"
  8. #include "ssh.h"
  9. #include "sshbpp.h"
  10. #include "sshcr.h"
  11. #define PREFIX_MAXLEN 64
  12. struct ssh_verstring_state {
  13. int crState;
  14. Conf *conf;
  15. ptrlen prefix_wanted;
  16. char *our_protoversion;
  17. struct ssh_version_receiver *receiver;
  18. int send_early;
  19. int found_prefix;
  20. int major_protoversion;
  21. int remote_bugs;
  22. char prefix[PREFIX_MAXLEN];
  23. char *vstring;
  24. int vslen, vstrsize;
  25. char *protoversion;
  26. const char *softwareversion;
  27. char *our_vstring;
  28. int i;
  29. BinaryPacketProtocol bpp;
  30. };
  31. static void ssh_verstring_free(BinaryPacketProtocol *bpp);
  32. static void ssh_verstring_handle_input(BinaryPacketProtocol *bpp);
  33. static void ssh_verstring_handle_output(BinaryPacketProtocol *bpp);
  34. static PktOut *ssh_verstring_new_pktout(int type);
  35. static void ssh_verstring_queue_disconnect(BinaryPacketProtocol *bpp,
  36. const char *msg, int category);
  37. static const struct BinaryPacketProtocolVtable ssh_verstring_vtable = {
  38. ssh_verstring_free,
  39. ssh_verstring_handle_input,
  40. ssh_verstring_handle_output,
  41. ssh_verstring_new_pktout,
  42. ssh_verstring_queue_disconnect,
  43. };
  44. static void ssh_detect_bugs(struct ssh_verstring_state *s);
  45. static int ssh_version_includes_v1(const char *ver);
  46. static int ssh_version_includes_v2(const char *ver);
  47. BinaryPacketProtocol *ssh_verstring_new(
  48. Conf *conf, Frontend *frontend, int bare_connection_mode,
  49. const char *protoversion, struct ssh_version_receiver *rcv)
  50. {
  51. struct ssh_verstring_state *s = snew(struct ssh_verstring_state);
  52. memset(s, 0, sizeof(struct ssh_verstring_state));
  53. if (!bare_connection_mode) {
  54. s->prefix_wanted = PTRLEN_LITERAL("SSH-");
  55. } else {
  56. /*
  57. * Ordinary SSH begins with the banner "SSH-x.y-...". Here,
  58. * we're going to be speaking just the ssh-connection
  59. * subprotocol, extracted and given a trivial binary packet
  60. * protocol, so we need a new banner.
  61. *
  62. * The new banner is like the ordinary SSH banner, but
  63. * replaces the prefix 'SSH-' at the start with a new name. In
  64. * proper SSH style (though of course this part of the proper
  65. * SSH protocol _isn't_ subject to this kind of
  66. * DNS-domain-based extension), we define the new name in our
  67. * extension space.
  68. */
  69. s->prefix_wanted = PTRLEN_LITERAL(
  70. "[email protected]");
  71. }
  72. assert(s->prefix_wanted.len <= PREFIX_MAXLEN);
  73. s->conf = conf_copy(conf);
  74. s->bpp.frontend = frontend;
  75. s->bpp.frontend = frontend;
  76. s->our_protoversion = dupstr(protoversion);
  77. s->receiver = rcv;
  78. /*
  79. * We send our version string early if we can. But if it includes
  80. * SSH-1, we can't, because we have to take the other end into
  81. * account too (see below).
  82. */
  83. s->send_early = !ssh_version_includes_v1(protoversion);
  84. s->bpp.vt = &ssh_verstring_vtable;
  85. ssh_bpp_common_setup(&s->bpp);
  86. return &s->bpp;
  87. }
  88. void ssh_verstring_free(BinaryPacketProtocol *bpp)
  89. {
  90. struct ssh_verstring_state *s =
  91. container_of(bpp, struct ssh_verstring_state, bpp);
  92. conf_free(s->conf);
  93. sfree(s->vstring);
  94. sfree(s->protoversion);
  95. sfree(s->our_vstring);
  96. sfree(s->our_protoversion);
  97. sfree(s);
  98. }
  99. static int ssh_versioncmp(const char *a, const char *b)
  100. {
  101. char *ae, *be;
  102. unsigned long av, bv;
  103. av = strtoul(a, &ae, 10);
  104. bv = strtoul(b, &be, 10);
  105. if (av != bv)
  106. return (av < bv ? -1 : +1);
  107. if (*ae == '.')
  108. ae++;
  109. if (*be == '.')
  110. be++;
  111. av = strtoul(ae, &ae, 10);
  112. bv = strtoul(be, &be, 10);
  113. if (av != bv)
  114. return (av < bv ? -1 : +1);
  115. return 0;
  116. }
  117. static int ssh_version_includes_v1(const char *ver)
  118. {
  119. return ssh_versioncmp(ver, "2.0") < 0;
  120. }
  121. static int ssh_version_includes_v2(const char *ver)
  122. {
  123. return ssh_versioncmp(ver, "1.99") >= 0;
  124. }
  125. #define bpp_logevent(printf_args) \
  126. logevent_and_free(s->bpp.frontend, dupprintf printf_args)
  127. static void ssh_verstring_send(struct ssh_verstring_state *s)
  128. {
  129. char *p;
  130. int sv_pos;
  131. /*
  132. * Construct our outgoing version string.
  133. */
  134. s->our_vstring = dupprintf(
  135. "%.*s%s-%s",
  136. (int)s->prefix_wanted.len, (const char *)s->prefix_wanted.ptr,
  137. s->our_protoversion, sshver);
  138. sv_pos = s->prefix_wanted.len + strlen(s->our_protoversion) + 1;
  139. /* Convert minus signs and spaces in the software version string
  140. * into underscores. */
  141. for (p = s->our_vstring + sv_pos; *p; p++) {
  142. if (*p == '-' || *p == ' ')
  143. *p = '_';
  144. }
  145. #ifdef FUZZING
  146. /*
  147. * Replace the first character of the string with an "I" if we're
  148. * compiling this code for fuzzing - i.e. the protocol prefix
  149. * becomes "ISH-" instead of "SSH-".
  150. *
  151. * This is irrelevant to any real client software (the only thing
  152. * reading the output of PuTTY built for fuzzing is the fuzzer,
  153. * which can adapt to whatever it sees anyway). But it's a safety
  154. * precaution making it difficult to accidentally run such a
  155. * version of PuTTY (which would be hugely insecure) against a
  156. * live peer implementation.
  157. *
  158. * (So the replacement prefix "ISH" notionally stands for
  159. * 'Insecure Shell', of course.)
  160. */
  161. s->our_vstring[0] = 'I';
  162. #endif
  163. /*
  164. * Now send that version string, plus trailing \r\n or just \n
  165. * (the latter in SSH-1 mode).
  166. */
  167. bufchain_add(s->bpp.out_raw, s->our_vstring, strlen(s->our_vstring));
  168. if (ssh_version_includes_v2(s->our_protoversion))
  169. bufchain_add(s->bpp.out_raw, "\015", 1);
  170. bufchain_add(s->bpp.out_raw, "\012", 1);
  171. bpp_logevent(("We claim version: %s", s->our_vstring));
  172. }
  173. #define BPP_WAITFOR(minlen) do \
  174. { \
  175. crMaybeWaitUntilV( \
  176. s->bpp.input_eof || \
  177. bufchain_size(s->bpp.in_raw) >= (minlen)); \
  178. if (s->bpp.input_eof) \
  179. goto eof; \
  180. } while (0)
  181. void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
  182. {
  183. struct ssh_verstring_state *s =
  184. container_of(bpp, struct ssh_verstring_state, bpp);
  185. crBegin(s->crState);
  186. /*
  187. * If we're sending our version string up front before seeing the
  188. * other side's, then do it now.
  189. */
  190. if (s->send_early)
  191. ssh_verstring_send(s);
  192. /*
  193. * Search for a line beginning with the protocol name prefix in
  194. * the input.
  195. */
  196. s->i = 0;
  197. while (1) {
  198. /*
  199. * Every time round this loop, we're at the start of a new
  200. * line, so look for the prefix.
  201. */
  202. BPP_WAITFOR(s->prefix_wanted.len);
  203. bufchain_fetch(s->bpp.in_raw, s->prefix, s->prefix_wanted.len);
  204. if (!memcmp(s->prefix, s->prefix_wanted.ptr, s->prefix_wanted.len)) {
  205. bufchain_consume(s->bpp.in_raw, s->prefix_wanted.len);
  206. break;
  207. }
  208. /*
  209. * If we didn't find it, consume data until we see a newline.
  210. */
  211. while (1) {
  212. int len;
  213. void *data;
  214. char *nl;
  215. /* Wait to receive at least 1 byte, but then consume more
  216. * than that if it's there. */
  217. BPP_WAITFOR(1);
  218. bufchain_prefix(s->bpp.in_raw, &data, &len);
  219. if ((nl = memchr(data, '\012', len)) != NULL) {
  220. bufchain_consume(s->bpp.in_raw, nl - (char *)data + 1);
  221. break;
  222. } else {
  223. bufchain_consume(s->bpp.in_raw, len);
  224. }
  225. }
  226. }
  227. s->found_prefix = TRUE;
  228. /*
  229. * Start a buffer to store the full greeting line.
  230. */
  231. s->vstrsize = s->prefix_wanted.len + 16;
  232. s->vstring = snewn(s->vstrsize, char);
  233. memcpy(s->vstring, s->prefix_wanted.ptr, s->prefix_wanted.len);
  234. s->vslen = s->prefix_wanted.len;
  235. /*
  236. * Now read the rest of the greeting line.
  237. */
  238. s->i = 0;
  239. do {
  240. int len;
  241. void *data;
  242. char *nl;
  243. crMaybeWaitUntilV(bufchain_size(s->bpp.in_raw) > 0);
  244. bufchain_prefix(s->bpp.in_raw, &data, &len);
  245. if ((nl = memchr(data, '\012', len)) != NULL) {
  246. len = nl - (char *)data + 1;
  247. }
  248. if (s->vslen + len >= s->vstrsize - 1) {
  249. s->vstrsize = (s->vslen + len) * 5 / 4 + 32;
  250. s->vstring = sresize(s->vstring, s->vstrsize, char);
  251. }
  252. memcpy(s->vstring + s->vslen, data, len);
  253. s->vslen += len;
  254. bufchain_consume(s->bpp.in_raw, len);
  255. } while (s->vstring[s->vslen-1] != '\012');
  256. /*
  257. * Trim \r and \n from the version string, and replace them with
  258. * a NUL terminator.
  259. */
  260. while (s->vslen > 0 &&
  261. (s->vstring[s->vslen-1] == '\r' ||
  262. s->vstring[s->vslen-1] == '\n'))
  263. s->vslen--;
  264. s->vstring[s->vslen] = '\0';
  265. bpp_logevent(("Remote version: %s", s->vstring));
  266. /*
  267. * Pick out the protocol version and software version. The former
  268. * goes in a separately allocated string, so that s->vstring
  269. * remains intact for later use in key exchange; the latter is the
  270. * tail of s->vstring, so it doesn't need to be allocated.
  271. */
  272. {
  273. const char *pv_start = s->vstring + s->prefix_wanted.len;
  274. int pv_len = strcspn(pv_start, "-");
  275. s->protoversion = dupprintf("%.*s", pv_len, pv_start);
  276. s->softwareversion = pv_start + pv_len;
  277. if (*s->softwareversion) {
  278. assert(*s->softwareversion == '-');
  279. s->softwareversion++;
  280. }
  281. }
  282. ssh_detect_bugs(s);
  283. /*
  284. * Figure out what actual SSH protocol version we're speaking.
  285. */
  286. if (ssh_version_includes_v2(s->our_protoversion) &&
  287. ssh_version_includes_v2(s->protoversion)) {
  288. /*
  289. * We're doing SSH-2.
  290. */
  291. s->major_protoversion = 2;
  292. } else if (ssh_version_includes_v1(s->our_protoversion) &&
  293. ssh_version_includes_v1(s->protoversion)) {
  294. /*
  295. * We're doing SSH-1.
  296. */
  297. s->major_protoversion = 1;
  298. /*
  299. * There are multiple minor versions of SSH-1, and the
  300. * protocol does not specify that the minimum of client
  301. * and server versions is used. So we must adjust our
  302. * outgoing protocol version to be no higher than that of
  303. * the other side.
  304. */
  305. if (!s->send_early &&
  306. ssh_versioncmp(s->our_protoversion, s->protoversion) > 0) {
  307. sfree(s->our_protoversion);
  308. s->our_protoversion = dupstr(s->protoversion);
  309. }
  310. } else {
  311. /*
  312. * Unable to agree on a major protocol version at all.
  313. */
  314. if (!ssh_version_includes_v2(s->our_protoversion)) {
  315. ssh_sw_abort(s->bpp.ssh,
  316. "SSH protocol version 1 required by our "
  317. "configuration but not provided by remote");
  318. } else {
  319. ssh_sw_abort(s->bpp.ssh,
  320. "SSH protocol version 2 required by our "
  321. "configuration but remote only provides "
  322. "(old, insecure) SSH-1");
  323. }
  324. crStopV;
  325. }
  326. bpp_logevent(("Using SSH protocol version %d", s->major_protoversion));
  327. if (!s->send_early) {
  328. /*
  329. * If we didn't send our version string early, construct and
  330. * send it now, because now we know what it is.
  331. */
  332. ssh_verstring_send(s);
  333. }
  334. /*
  335. * And we're done. Notify our receiver that we now know our
  336. * protocol version. This will cause it to disconnect us from the
  337. * input stream and ultimately free us, because our job is now
  338. * done.
  339. */
  340. s->receiver->got_ssh_version(s->receiver, s->major_protoversion);
  341. return;
  342. eof:
  343. ssh_remote_error(s->bpp.ssh,
  344. "Server unexpectedly closed network connection");
  345. return; /* avoid touching s now it's been freed */
  346. crFinishV;
  347. }
  348. static PktOut *ssh_verstring_new_pktout(int type)
  349. {
  350. assert(0 && "Should never try to send packets during SSH version "
  351. "string exchange");
  352. return NULL;
  353. }
  354. static void ssh_verstring_handle_output(BinaryPacketProtocol *bpp)
  355. {
  356. assert(0 && "Should never try to send packets during SSH version "
  357. "string exchange");
  358. }
  359. /*
  360. * Examine the remote side's version string, and compare it against a
  361. * list of known buggy implementations.
  362. */
  363. static void ssh_detect_bugs(struct ssh_verstring_state *s)
  364. {
  365. const char *imp = s->softwareversion;
  366. s->remote_bugs = 0;
  367. /*
  368. * General notes on server version strings:
  369. * - Not all servers reporting "Cisco-1.25" have all the bugs listed
  370. * here -- in particular, we've heard of one that's perfectly happy
  371. * with SSH1_MSG_IGNOREs -- but this string never seems to change,
  372. * so we can't distinguish them.
  373. */
  374. if (conf_get_int(s->conf, CONF_sshbug_ignore1) == FORCE_ON ||
  375. (conf_get_int(s->conf, CONF_sshbug_ignore1) == AUTO &&
  376. (!strcmp(imp, "1.2.18") || !strcmp(imp, "1.2.19") ||
  377. !strcmp(imp, "1.2.20") || !strcmp(imp, "1.2.21") ||
  378. !strcmp(imp, "1.2.22") || !strcmp(imp, "Cisco-1.25") ||
  379. !strcmp(imp, "OSU_1.4alpha3") || !strcmp(imp, "OSU_1.5alpha4")))) {
  380. /*
  381. * These versions don't support SSH1_MSG_IGNORE, so we have
  382. * to use a different defence against password length
  383. * sniffing.
  384. */
  385. s->remote_bugs |= BUG_CHOKES_ON_SSH1_IGNORE;
  386. bpp_logevent(("We believe remote version has SSH-1 ignore bug"));
  387. }
  388. if (conf_get_int(s->conf, CONF_sshbug_plainpw1) == FORCE_ON ||
  389. (conf_get_int(s->conf, CONF_sshbug_plainpw1) == AUTO &&
  390. (!strcmp(imp, "Cisco-1.25") || !strcmp(imp, "OSU_1.4alpha3")))) {
  391. /*
  392. * These versions need a plain password sent; they can't
  393. * handle having a null and a random length of data after
  394. * the password.
  395. */
  396. s->remote_bugs |= BUG_NEEDS_SSH1_PLAIN_PASSWORD;
  397. bpp_logevent(("We believe remote version needs a "
  398. "plain SSH-1 password"));
  399. }
  400. if (conf_get_int(s->conf, CONF_sshbug_rsa1) == FORCE_ON ||
  401. (conf_get_int(s->conf, CONF_sshbug_rsa1) == AUTO &&
  402. (!strcmp(imp, "Cisco-1.25")))) {
  403. /*
  404. * These versions apparently have no clue whatever about
  405. * RSA authentication and will panic and die if they see
  406. * an AUTH_RSA message.
  407. */
  408. s->remote_bugs |= BUG_CHOKES_ON_RSA;
  409. bpp_logevent(("We believe remote version can't handle SSH-1 "
  410. "RSA authentication"));
  411. }
  412. if (conf_get_int(s->conf, CONF_sshbug_hmac2) == FORCE_ON ||
  413. (conf_get_int(s->conf, CONF_sshbug_hmac2) == AUTO &&
  414. !wc_match("* VShell", imp) &&
  415. (wc_match("2.1.0*", imp) || wc_match("2.0.*", imp) ||
  416. wc_match("2.2.0*", imp) || wc_match("2.3.0*", imp) ||
  417. wc_match("2.1 *", imp)))) {
  418. /*
  419. * These versions have the HMAC bug.
  420. */
  421. s->remote_bugs |= BUG_SSH2_HMAC;
  422. bpp_logevent(("We believe remote version has SSH-2 HMAC bug"));
  423. }
  424. if (conf_get_int(s->conf, CONF_sshbug_derivekey2) == FORCE_ON ||
  425. (conf_get_int(s->conf, CONF_sshbug_derivekey2) == AUTO &&
  426. !wc_match("* VShell", imp) &&
  427. (wc_match("2.0.0*", imp) || wc_match("2.0.10*", imp) ))) {
  428. /*
  429. * These versions have the key-derivation bug (failing to
  430. * include the literal shared secret in the hashes that
  431. * generate the keys).
  432. */
  433. s->remote_bugs |= BUG_SSH2_DERIVEKEY;
  434. bpp_logevent(("We believe remote version has SSH-2 "
  435. "key-derivation bug"));
  436. }
  437. if (conf_get_int(s->conf, CONF_sshbug_rsapad2) == FORCE_ON ||
  438. (conf_get_int(s->conf, CONF_sshbug_rsapad2) == AUTO &&
  439. (wc_match("OpenSSH_2.[5-9]*", imp) ||
  440. wc_match("OpenSSH_3.[0-2]*", imp) ||
  441. wc_match("mod_sftp/0.[0-8]*", imp) ||
  442. wc_match("mod_sftp/0.9.[0-8]", imp)))) {
  443. /*
  444. * These versions have the SSH-2 RSA padding bug.
  445. */
  446. s->remote_bugs |= BUG_SSH2_RSA_PADDING;
  447. bpp_logevent(("We believe remote version has SSH-2 RSA padding bug"));
  448. }
  449. if (conf_get_int(s->conf, CONF_sshbug_pksessid2) == FORCE_ON ||
  450. (conf_get_int(s->conf, CONF_sshbug_pksessid2) == AUTO &&
  451. wc_match("OpenSSH_2.[0-2]*", imp))) {
  452. /*
  453. * These versions have the SSH-2 session-ID bug in
  454. * public-key authentication.
  455. */
  456. s->remote_bugs |= BUG_SSH2_PK_SESSIONID;
  457. bpp_logevent(("We believe remote version has SSH-2 "
  458. "public-key-session-ID bug"));
  459. }
  460. if (conf_get_int(s->conf, CONF_sshbug_rekey2) == FORCE_ON ||
  461. (conf_get_int(s->conf, CONF_sshbug_rekey2) == AUTO &&
  462. (wc_match("DigiSSH_2.0", imp) ||
  463. wc_match("OpenSSH_2.[0-4]*", imp) ||
  464. wc_match("OpenSSH_2.5.[0-3]*", imp) ||
  465. wc_match("Sun_SSH_1.0", imp) ||
  466. wc_match("Sun_SSH_1.0.1", imp) ||
  467. /* All versions <= 1.2.6 (they changed their format in 1.2.7) */
  468. wc_match("WeOnlyDo-*", imp)))) {
  469. /*
  470. * These versions have the SSH-2 rekey bug.
  471. */
  472. s->remote_bugs |= BUG_SSH2_REKEY;
  473. bpp_logevent(("We believe remote version has SSH-2 rekey bug"));
  474. }
  475. if (conf_get_int(s->conf, CONF_sshbug_maxpkt2) == FORCE_ON ||
  476. (conf_get_int(s->conf, CONF_sshbug_maxpkt2) == AUTO &&
  477. (wc_match("1.36_sshlib GlobalSCAPE", imp) ||
  478. wc_match("1.36 sshlib: GlobalScape", imp)))) {
  479. /*
  480. * This version ignores our makpkt and needs to be throttled.
  481. */
  482. s->remote_bugs |= BUG_SSH2_MAXPKT;
  483. bpp_logevent(("We believe remote version ignores SSH-2 "
  484. "maximum packet size"));
  485. }
  486. if (conf_get_int(s->conf, CONF_sshbug_ignore2) == FORCE_ON) {
  487. /*
  488. * Servers that don't support SSH2_MSG_IGNORE. Currently,
  489. * none detected automatically.
  490. */
  491. s->remote_bugs |= BUG_CHOKES_ON_SSH2_IGNORE;
  492. bpp_logevent(("We believe remote version has SSH-2 ignore bug"));
  493. }
  494. if (conf_get_int(s->conf, CONF_sshbug_oldgex2) == FORCE_ON ||
  495. (conf_get_int(s->conf, CONF_sshbug_oldgex2) == AUTO &&
  496. (wc_match("OpenSSH_2.[235]*", imp)))) {
  497. /*
  498. * These versions only support the original (pre-RFC4419)
  499. * SSH-2 GEX request, and disconnect with a protocol error if
  500. * we use the newer version.
  501. */
  502. s->remote_bugs |= BUG_SSH2_OLDGEX;
  503. bpp_logevent(("We believe remote version has outdated SSH-2 GEX"));
  504. }
  505. if (conf_get_int(s->conf, CONF_sshbug_winadj) == FORCE_ON) {
  506. /*
  507. * Servers that don't support our winadj request for one
  508. * reason or another. Currently, none detected automatically.
  509. */
  510. s->remote_bugs |= BUG_CHOKES_ON_WINADJ;
  511. bpp_logevent(("We believe remote version has winadj bug"));
  512. }
  513. if (conf_get_int(s->conf, CONF_sshbug_chanreq) == FORCE_ON ||
  514. (conf_get_int(s->conf, CONF_sshbug_chanreq) == AUTO &&
  515. (wc_match("OpenSSH_[2-5].*", imp) ||
  516. wc_match("OpenSSH_6.[0-6]*", imp) ||
  517. wc_match("dropbear_0.[2-4][0-9]*", imp) ||
  518. wc_match("dropbear_0.5[01]*", imp)))) {
  519. /*
  520. * These versions have the SSH-2 channel request bug.
  521. * OpenSSH 6.7 and above do not:
  522. * https://bugzilla.mindrot.org/show_bug.cgi?id=1818
  523. * dropbear_0.52 and above do not:
  524. * https://secure.ucc.asn.au/hg/dropbear/rev/cd02449b709c
  525. */
  526. s->remote_bugs |= BUG_SENDS_LATE_REQUEST_REPLY;
  527. bpp_logevent(("We believe remote version has SSH-2 "
  528. "channel request bug"));
  529. }
  530. }
  531. const char *ssh_verstring_get_remote(BinaryPacketProtocol *bpp)
  532. {
  533. struct ssh_verstring_state *s =
  534. container_of(bpp, struct ssh_verstring_state, bpp);
  535. return s->vstring;
  536. }
  537. const char *ssh_verstring_get_local(BinaryPacketProtocol *bpp)
  538. {
  539. struct ssh_verstring_state *s =
  540. container_of(bpp, struct ssh_verstring_state, bpp);
  541. return s->our_vstring;
  542. }
  543. int ssh_verstring_get_bugs(BinaryPacketProtocol *bpp)
  544. {
  545. struct ssh_verstring_state *s =
  546. container_of(bpp, struct ssh_verstring_state, bpp);
  547. return s->remote_bugs;
  548. }
  549. static void ssh_verstring_queue_disconnect(BinaryPacketProtocol *bpp,
  550. const char *msg, int category)
  551. {
  552. /* No way to send disconnect messages at this stage of the protocol! */
  553. }