1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Factor out the check for ext-info-* keyword.

I'm about to want to use the same code to check for something else.
It's only a handful of lines, but even so.

Also, since the string constants are mentioned several times, this
seems like a good moment to lift them out into reusable static const
ptrlens.
This commit is contained in:
Simon Tatham 2023-11-18 08:50:58 +00:00
parent 9e09915157
commit f2e7086902

View File

@ -27,6 +27,9 @@ const static ssh2_macalg *const buggymacs[] = {
&ssh_hmac_sha1_buggy, &ssh_hmac_sha1_96_buggy, &ssh_hmac_md5
};
const static ptrlen ext_info_c = PTRLEN_DECL_LITERAL("ext-info-c");
const static ptrlen ext_info_s = PTRLEN_DECL_LITERAL("ext-info-s");
static ssh_compressor *ssh_comp_none_init(void)
{
return NULL;
@ -938,9 +941,9 @@ static void ssh2_write_kexinit_lists(
}
if (i == KEXLIST_KEX && first_time) {
if (our_hostkeys) /* we're the server */
add_to_commasep(list, "ext-info-s");
add_to_commasep_pl(list, ext_info_s);
else /* we're the client */
add_to_commasep(list, "ext-info-c");
add_to_commasep_pl(list, ext_info_c);
}
put_stringsb(pktout, list);
}
@ -955,6 +958,14 @@ struct server_hostkeys {
size_t n, size;
};
static bool kexinit_keyword_found(ptrlen list, ptrlen keyword)
{
for (ptrlen word; get_commasep_word(&list, &word) ;)
if (ptrlen_eq_ptrlen(word, keyword))
return true;
return false;
}
static bool ssh2_scan_kexinits(
ptrlen client_kexinit, ptrlen server_kexinit, bool we_are_server,
struct kexinit_algorithm_list kexlists[NKEXLIST],
@ -1165,16 +1176,10 @@ static bool ssh2_scan_kexinits(
/*
* Check whether the other side advertised support for EXT_INFO.
*/
{
ptrlen extinfo_advert =
(we_are_server ? PTRLEN_LITERAL("ext-info-c") :
PTRLEN_LITERAL("ext-info-s"));
ptrlen list = (we_are_server ? clists[KEXLIST_KEX] :
slists[KEXLIST_KEX]);
for (ptrlen word; get_commasep_word(&list, &word) ;)
if (ptrlen_eq_ptrlen(word, extinfo_advert))
*can_send_ext_info = true;
}
if (kexinit_keyword_found(
we_are_server ? clists[KEXLIST_KEX] : slists[KEXLIST_KEX],
we_are_server ? ext_info_c : ext_info_s))
*can_send_ext_info = true;
if (server_hostkeys) {
/*