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