|
Dmitry Belyavskiy |
9fd698 |
diff --color -rup a/compat.c b/compat.c
|
|
Dmitry Belyavskiy |
9fd698 |
--- a/compat.c 2021-08-20 06:03:49.000000000 +0200
|
|
Dmitry Belyavskiy |
9fd698 |
+++ b/compat.c 2022-07-14 17:39:23.770268440 +0200
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -157,11 +157,12 @@ compat_banner(struct ssh *ssh, const cha
|
|
Dmitry Belyavskiy |
9fd698 |
debug_f("no match: %s", version);
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
+/* Always returns pointer to allocated memory, caller must free. */
|
|
Dmitry Belyavskiy |
9fd698 |
char *
|
|
Dmitry Belyavskiy |
9fd698 |
compat_cipher_proposal(struct ssh *ssh, char *cipher_prop)
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
9fd698 |
if (!(ssh->compat & SSH_BUG_BIGENDIANAES))
|
|
Dmitry Belyavskiy |
9fd698 |
- return cipher_prop;
|
|
Dmitry Belyavskiy |
9fd698 |
+ return xstrdup(cipher_prop);
|
|
Dmitry Belyavskiy |
9fd698 |
debug2_f("original cipher proposal: %s", cipher_prop);
|
|
Dmitry Belyavskiy |
9fd698 |
if ((cipher_prop = match_filter_denylist(cipher_prop, "aes*")) == NULL)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal("match_filter_denylist failed");
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -171,11 +172,12 @@ compat_cipher_proposal(struct ssh *ssh,
|
|
Dmitry Belyavskiy |
9fd698 |
return cipher_prop;
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
+/* Always returns pointer to allocated memory, caller must free. */
|
|
Dmitry Belyavskiy |
9fd698 |
char *
|
|
Dmitry Belyavskiy |
9fd698 |
compat_pkalg_proposal(struct ssh *ssh, char *pkalg_prop)
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
9fd698 |
if (!(ssh->compat & SSH_BUG_RSASIGMD5))
|
|
Dmitry Belyavskiy |
9fd698 |
- return pkalg_prop;
|
|
Dmitry Belyavskiy |
9fd698 |
+ return xstrdup(pkalg_prop);
|
|
Dmitry Belyavskiy |
9fd698 |
debug2_f("original public key proposal: %s", pkalg_prop);
|
|
Dmitry Belyavskiy |
9fd698 |
if ((pkalg_prop = match_filter_denylist(pkalg_prop, "ssh-rsa")) == NULL)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal("match_filter_denylist failed");
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -185,21 +187,26 @@ compat_pkalg_proposal(struct ssh *ssh, c
|
|
Dmitry Belyavskiy |
9fd698 |
return pkalg_prop;
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
+/* Always returns pointer to allocated memory, caller must free. */
|
|
Dmitry Belyavskiy |
9fd698 |
char *
|
|
Dmitry Belyavskiy |
9fd698 |
compat_kex_proposal(struct ssh *ssh, char *p)
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
9fd698 |
+ char *cp = NULL;
|
|
Dmitry Belyavskiy |
9fd698 |
+
|
|
Dmitry Belyavskiy |
9fd698 |
if ((ssh->compat & (SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX)) == 0)
|
|
Dmitry Belyavskiy |
9fd698 |
- return p;
|
|
Dmitry Belyavskiy |
9fd698 |
+ return xstrdup(p);
|
|
Dmitry Belyavskiy |
9fd698 |
debug2_f("original KEX proposal: %s", p);
|
|
Dmitry Belyavskiy |
9fd698 |
if ((ssh->compat & SSH_BUG_CURVE25519PAD) != 0)
|
|
Dmitry Belyavskiy |
9fd698 |
if ((p = match_filter_denylist(p,
|
|
Dmitry Belyavskiy |
9fd698 |
"curve25519-sha256@libssh.org")) == NULL)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal("match_filter_denylist failed");
|
|
Dmitry Belyavskiy |
9fd698 |
if ((ssh->compat & SSH_OLD_DHGEX) != 0) {
|
|
Dmitry Belyavskiy |
9fd698 |
+ cp = p;
|
|
Dmitry Belyavskiy |
9fd698 |
if ((p = match_filter_denylist(p,
|
|
Dmitry Belyavskiy |
9fd698 |
"diffie-hellman-group-exchange-sha256,"
|
|
Dmitry Belyavskiy |
9fd698 |
"diffie-hellman-group-exchange-sha1")) == NULL)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal("match_filter_denylist failed");
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(cp);
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
debug2_f("compat KEX proposal: %s", p);
|
|
Dmitry Belyavskiy |
9fd698 |
if (*p == '\0')
|
|
Dmitry Belyavskiy |
9fd698 |
diff --color -rup a/sshconnect2.c b/sshconnect2.c
|
|
Dmitry Belyavskiy |
9fd698 |
--- a/sshconnect2.c 2022-07-14 17:38:43.241496549 +0200
|
|
Dmitry Belyavskiy |
9fd698 |
+++ b/sshconnect2.c 2022-07-14 17:39:23.772268479 +0200
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -222,6 +222,7 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
9fd698 |
char *myproposal[PROPOSAL_MAX] = { KEX_CLIENT };
|
|
Dmitry Belyavskiy |
9fd698 |
char *s, *all_key;
|
|
Dmitry Belyavskiy |
9fd698 |
+ char *prop_kex = NULL, *prop_enc = NULL, *prop_hostkey = NULL;
|
|
Dmitry Belyavskiy |
9fd698 |
int r, use_known_hosts_order = 0;
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
#if defined(GSSAPI) && defined(WITH_OPENSSL)
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -252,10 +253,9 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
if ((s = kex_names_cat(options.kex_algorithms, "ext-info-c")) == NULL)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal_f("kex_names_cat");
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(ssh, s);
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_KEX_ALGS] = prop_kex = compat_kex_proposal(ssh, s);
|
|
Dmitry Belyavskiy |
9fd698 |
myproposal[PROPOSAL_ENC_ALGS_CTOS] =
|
|
Dmitry Belyavskiy |
9fd698 |
- compat_cipher_proposal(ssh, options.ciphers);
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_ENC_ALGS_STOC] =
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_ENC_ALGS_STOC] = prop_enc =
|
|
Dmitry Belyavskiy |
9fd698 |
compat_cipher_proposal(ssh, options.ciphers);
|
|
Dmitry Belyavskiy |
9fd698 |
myproposal[PROPOSAL_COMP_ALGS_CTOS] =
|
|
Dmitry Belyavskiy |
9fd698 |
myproposal[PROPOSAL_COMP_ALGS_STOC] =
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -264,12 +264,12 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
9fd698 |
myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
|
|
Dmitry Belyavskiy |
9fd698 |
if (use_known_hosts_order) {
|
|
Dmitry Belyavskiy |
9fd698 |
/* Query known_hosts and prefer algorithms that appear there */
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = prop_hostkey =
|
|
Dmitry Belyavskiy |
9fd698 |
compat_pkalg_proposal(ssh,
|
|
Dmitry Belyavskiy |
9fd698 |
order_hostkeyalgs(host, hostaddr, port, cinfo));
|
|
Dmitry Belyavskiy |
9fd698 |
} else {
|
|
Dmitry Belyavskiy |
9fd698 |
/* Use specified HostkeyAlgorithms exactly */
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = prop_hostkey =
|
|
Dmitry Belyavskiy |
9fd698 |
compat_pkalg_proposal(ssh, options.hostkeyalgorithms);
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -383,6 +383,10 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
9fd698 |
(r = ssh_packet_write_wait(ssh)) != 0)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal_fr(r, "send packet");
|
|
Dmitry Belyavskiy |
9fd698 |
#endif
|
|
Dmitry Belyavskiy |
9fd698 |
+ /* Free only parts of proposal that were dynamically allocated here. */
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(prop_kex);
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(prop_enc);
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(prop_hostkey);
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
/*
|
|
Dmitry Belyavskiy |
9fd698 |
diff --color -rup a/sshd.c b/sshd.c
|
|
Dmitry Belyavskiy |
9fd698 |
--- a/sshd.c 2022-07-14 17:38:43.242496568 +0200
|
|
Dmitry Belyavskiy |
9fd698 |
+++ b/sshd.c 2022-07-14 17:42:07.616388978 +0200
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -2493,14 +2493,15 @@ do_ssh2_kex(struct ssh *ssh)
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
9fd698 |
char *myproposal[PROPOSAL_MAX] = { KEX_SERVER };
|
|
Dmitry Belyavskiy |
9fd698 |
struct kex *kex;
|
|
Dmitry Belyavskiy |
9fd698 |
+ char *hostkey_types = NULL;
|
|
Dmitry Belyavskiy |
9fd698 |
+ char *prop_kex = NULL, *prop_enc = NULL, *prop_hostkey = NULL;
|
|
Dmitry Belyavskiy |
9fd698 |
int r;
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_KEX_ALGS] = compat_kex_proposal(ssh,
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_KEX_ALGS] = prop_kex = compat_kex_proposal(ssh,
|
|
Dmitry Belyavskiy |
9fd698 |
options.kex_algorithms);
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_ENC_ALGS_CTOS] = compat_cipher_proposal(ssh,
|
|
Dmitry Belyavskiy |
9fd698 |
- options.ciphers);
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_ENC_ALGS_STOC] = compat_cipher_proposal(ssh,
|
|
Dmitry Belyavskiy |
9fd698 |
- options.ciphers);
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_ENC_ALGS_CTOS] =
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_ENC_ALGS_STOC] = prop_enc =
|
|
Dmitry Belyavskiy |
9fd698 |
+ compat_cipher_proposal(ssh, options.ciphers);
|
|
Dmitry Belyavskiy |
9fd698 |
myproposal[PROPOSAL_MAC_ALGS_CTOS] =
|
|
Dmitry Belyavskiy |
9fd698 |
myproposal[PROPOSAL_MAC_ALGS_STOC] = options.macs;
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -2513,8 +2514,10 @@ do_ssh2_kex(struct ssh *ssh)
|
|
Dmitry Belyavskiy |
9fd698 |
ssh_packet_set_rekey_limits(ssh, options.rekey_limit,
|
|
Dmitry Belyavskiy |
9fd698 |
options.rekey_interval);
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
- myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = compat_pkalg_proposal(
|
|
Dmitry Belyavskiy |
9fd698 |
- ssh, list_hostkey_types());
|
|
Dmitry Belyavskiy |
9fd698 |
+ hostkey_types = list_hostkey_types();
|
|
Dmitry Belyavskiy |
9fd698 |
+ myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = prop_hostkey =
|
|
Dmitry Belyavskiy |
9fd698 |
+ compat_pkalg_proposal(ssh, hostkey_types);
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(hostkey_types);
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
#if defined(GSSAPI) && defined(WITH_OPENSSL)
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
9fd698 |
@@ -2606,6 +2609,9 @@ do_ssh2_kex(struct ssh *ssh)
|
|
Dmitry Belyavskiy |
9fd698 |
(r = ssh_packet_write_wait(ssh)) != 0)
|
|
Dmitry Belyavskiy |
9fd698 |
fatal_fr(r, "send test");
|
|
Dmitry Belyavskiy |
9fd698 |
#endif
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(prop_kex);
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(prop_enc);
|
|
Dmitry Belyavskiy |
9fd698 |
+ free(prop_hostkey);
|
|
Dmitry Belyavskiy |
9fd698 |
debug("KEX done");
|
|
Dmitry Belyavskiy |
9fd698 |
}
|
|
Dmitry Belyavskiy |
9fd698 |
|