|
Dmitry Belyavskiy |
f561c6 |
diff -up openssh-9.3p1/regress/hostkey-agent.sh.xxx openssh-9.3p1/regress/hostkey-agent.sh
|
|
Dmitry Belyavskiy |
f561c6 |
--- openssh-9.3p1/regress/hostkey-agent.sh.xxx 2023-05-29 18:15:56.311236887 +0200
|
|
Dmitry Belyavskiy |
f561c6 |
+++ openssh-9.3p1/regress/hostkey-agent.sh 2023-05-29 18:16:07.598503551 +0200
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -17,8 +17,21 @@ trace "make CA key"
|
|
Dmitry Belyavskiy |
03150f |
|
|
Dmitry Belyavskiy |
03150f |
${SSHKEYGEN} -qt ed25519 -f $OBJ/agent-ca -N '' || fatal "ssh-keygen CA"
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
+PUBKEY_ACCEPTED_ALGOS=`$SSH -G "example.com" | \
|
|
Dmitry Belyavskiy |
9fd698 |
+ grep -i "PubkeyAcceptedAlgorithms" | cut -d ' ' -f2- | tr "," "|"`
|
|
Dmitry Belyavskiy |
9fd698 |
+SSH_ACCEPTED_KEYTYPES=`echo "$SSH_KEYTYPES" | egrep "$PUBKEY_ACCEPTED_ALGOS"`
|
|
Dmitry Belyavskiy |
f561c6 |
+echo $PUBKEY_ACCEPTED_ALGOS | grep "rsa"
|
|
Dmitry Belyavskiy |
f561c6 |
+r=$?
|
|
Dmitry Belyavskiy |
f561c6 |
+if [ $r == 0 ]; then
|
|
Dmitry Belyavskiy |
f561c6 |
+echo $SSH_ACCEPTED_KEYTYPES | grep "rsa"
|
|
Dmitry Belyavskiy |
f561c6 |
+r=$?
|
|
Dmitry Belyavskiy |
f561c6 |
+if [ $r -ne 0 ]; then
|
|
Dmitry Belyavskiy |
f561c6 |
+SSH_ACCEPTED_KEYTYPES="$SSH_ACCEPTED_KEYTYPES ssh-rsa"
|
|
Dmitry Belyavskiy |
f561c6 |
+fi
|
|
Dmitry Belyavskiy |
f561c6 |
+fi
|
|
Dmitry Belyavskiy |
9fd698 |
+
|
|
Dmitry Belyavskiy |
9fd698 |
trace "load hostkeys"
|
|
Dmitry Belyavskiy |
9fd698 |
-for k in $SSH_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
9fd698 |
+for k in $SSH_ACCEPTED_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
${SSHKEYGEN} -qt $k -f $OBJ/agent-key.$k -N '' || fatal "ssh-keygen $k"
|
|
Dmitry Belyavskiy |
f561c6 |
${SSHKEYGEN} -s $OBJ/agent-ca -qh -n localhost-with-alias \
|
|
Dmitry Belyavskiy |
f561c6 |
-I localhost-with-alias $OBJ/agent-key.$k.pub || \
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -32,12 +48,16 @@ rm $OBJ/agent-ca # Don't need CA private
|
|
Dmitry Belyavskiy |
03150f |
|
|
Dmitry Belyavskiy |
9fd698 |
unset SSH_AUTH_SOCK
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
03150f |
-for k in $SSH_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
03150f |
+for k in $SSH_ACCEPTED_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
verbose "key type $k"
|
|
Dmitry Belyavskiy |
f561c6 |
+ hka=$k
|
|
Dmitry Belyavskiy |
f561c6 |
+ if [ $k = "ssh-rsa" ]; then
|
|
Dmitry Belyavskiy |
f561c6 |
+ hka="rsa-sha2-512"
|
|
Dmitry Belyavskiy |
f561c6 |
+ fi
|
|
Dmitry Belyavskiy |
f561c6 |
cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
- echo "HostKeyAlgorithms $k" >> $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
+ echo "HostKeyAlgorithms $hka" >> $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
echo "Hostkey $OBJ/agent-key.${k}" >> $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
- opts="-oHostKeyAlgorithms=$k -F $OBJ/ssh_proxy"
|
|
Dmitry Belyavskiy |
f561c6 |
+ opts="-oHostKeyAlgorithms=$hka -F $OBJ/ssh_proxy"
|
|
Dmitry Belyavskiy |
f561c6 |
( printf 'localhost-with-alias,127.0.0.1,::1 ' ;
|
|
Dmitry Belyavskiy |
f561c6 |
cat $OBJ/agent-key.$k.pub) > $OBJ/known_hosts
|
|
Dmitry Belyavskiy |
f561c6 |
SSH_CONNECTION=`${SSH} $opts host 'echo $SSH_CONNECTION'`
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -50,15 +70,16 @@ for k in $SSH_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
done
|
|
Dmitry Belyavskiy |
f561c6 |
|
|
Dmitry Belyavskiy |
f561c6 |
SSH_CERTTYPES=`ssh -Q key-sig | grep 'cert-v01@openssh.com'`
|
|
Dmitry Belyavskiy |
f561c6 |
+SSH_ACCEPTED_CERTTYPES=`echo "$SSH_CERTTYPES" | egrep "$PUBKEY_ACCEPTED_ALGOS"`
|
|
Dmitry Belyavskiy |
f561c6 |
|
|
Dmitry Belyavskiy |
f561c6 |
# Prepare sshd_proxy for certificates.
|
|
Dmitry Belyavskiy |
f561c6 |
cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
HOSTKEYALGS=""
|
|
Dmitry Belyavskiy |
f561c6 |
-for k in $SSH_CERTTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
+for k in $SSH_ACCEPTED_CERTTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
test -z "$HOSTKEYALGS" || HOSTKEYALGS="${HOSTKEYALGS},"
|
|
Dmitry Belyavskiy |
f561c6 |
HOSTKEYALGS="${HOSTKEYALGS}${k}"
|
|
Dmitry Belyavskiy |
f561c6 |
done
|
|
Dmitry Belyavskiy |
f561c6 |
-for k in $SSH_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
+for k in $SSH_ACCEPTED_KEYTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
echo "Hostkey $OBJ/agent-key.${k}.pub" >> $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
echo "HostCertificate $OBJ/agent-key.${k}-cert.pub" >> $OBJ/sshd_proxy
|
|
Dmitry Belyavskiy |
f561c6 |
test -f $OBJ/agent-key.${k}.pub || fatal "no $k key"
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -70,7 +93,7 @@ echo "HostKeyAlgorithms $HOSTKEYALGS" >>
|
|
Dmitry Belyavskiy |
f561c6 |
( printf '@cert-authority localhost-with-alias ' ;
|
|
Dmitry Belyavskiy |
f561c6 |
cat $OBJ/agent-ca.pub) > $OBJ/known_hosts
|
|
Dmitry Belyavskiy |
f561c6 |
|
|
Dmitry Belyavskiy |
f561c6 |
-for k in $SSH_CERTTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
+for k in $SSH_ACCEPTED_CERTTYPES ; do
|
|
Dmitry Belyavskiy |
f561c6 |
verbose "cert type $k"
|
|
Dmitry Belyavskiy |
f561c6 |
opts="-oHostKeyAlgorithms=$k -F $OBJ/ssh_proxy"
|
|
Dmitry Belyavskiy |
f561c6 |
SSH_CONNECTION=`${SSH} $opts host 'echo $SSH_CONNECTION'`
|
|
Dmitry Belyavskiy |
f561c6 |
diff -up openssh-9.3p1/sshconnect2.c.xxx openssh-9.3p1/sshconnect2.c
|
|
Dmitry Belyavskiy |
f561c6 |
--- openssh-9.3p1/sshconnect2.c.xxx 2023-04-26 17:37:35.100827792 +0200
|
|
Dmitry Belyavskiy |
f561c6 |
+++ openssh-9.3p1/sshconnect2.c 2023-04-26 17:50:31.860748877 +0200
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -221,7 +221,7 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
f561c6 |
const struct ssh_conn_info *cinfo)
|
|
Dmitry Belyavskiy |
9fd698 |
{
|
|
Dmitry Belyavskiy |
f561c6 |
char *myproposal[PROPOSAL_MAX];
|
|
Dmitry Belyavskiy |
f561c6 |
- char *s, *all_key, *hkalgs = NULL;
|
|
Dmitry Belyavskiy |
f561c6 |
+ char *s, *all_key, *hkalgs = NULL, *filtered_algs = NULL;
|
|
Dmitry Belyavskiy |
9fd698 |
int r, use_known_hosts_order = 0;
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
f561c6 |
#if defined(GSSAPI) && defined(WITH_OPENSSL)
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -260,9 +260,21 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
f561c6 |
if (use_known_hosts_order)
|
|
Dmitry Belyavskiy |
f561c6 |
hkalgs = order_hostkeyalgs(host, hostaddr, port, cinfo);
|
|
Dmitry Belyavskiy |
f561c6 |
|
|
Dmitry Belyavskiy |
f561c6 |
+ filtered_algs = hkalgs ? match_filter_allowlist(hkalgs, options.pubkey_accepted_algos)
|
|
Dmitry Belyavskiy |
f561c6 |
+ : match_filter_allowlist(options.hostkeyalgorithms,
|
|
Dmitry Belyavskiy |
f561c6 |
+ options.pubkey_accepted_algos);
|
|
Dmitry Belyavskiy |
f561c6 |
+ if (filtered_algs == NULL) {
|
|
Dmitry Belyavskiy |
f561c6 |
+ if (hkalgs)
|
|
Dmitry Belyavskiy |
f561c6 |
+ fatal_f("No match between algorithms for %s (host %s) and pubkey accepted algorithms %s",
|
|
Dmitry Belyavskiy |
f561c6 |
+ hkalgs, host, options.pubkey_accepted_algos);
|
|
Dmitry Belyavskiy |
f561c6 |
+ else
|
|
Dmitry Belyavskiy |
f561c6 |
+ fatal_f("No match between host key algorithms %s and pubkey accepted algorithms %s",
|
|
Dmitry Belyavskiy |
f561c6 |
+ options.hostkeyalgorithms, options.pubkey_accepted_algos);
|
|
Dmitry Belyavskiy |
f561c6 |
+ }
|
|
Dmitry Belyavskiy |
f561c6 |
+
|
|
Dmitry Belyavskiy |
f561c6 |
kex_proposal_populate_entries(ssh, myproposal, s, options.ciphers,
|
|
Dmitry Belyavskiy |
f561c6 |
options.macs, compression_alg_list(options.compression),
|
|
Dmitry Belyavskiy |
f561c6 |
- hkalgs ? hkalgs : options.hostkeyalgorithms);
|
|
Dmitry Belyavskiy |
f561c6 |
+ filtered_algs);
|
|
Dmitry Belyavskiy |
9fd698 |
|
|
Dmitry Belyavskiy |
9fd698 |
#if defined(GSSAPI) && defined(WITH_OPENSSL)
|
|
Dmitry Belyavskiy |
9fd698 |
if (options.gss_keyex) {
|
|
Dmitry Belyavskiy |
f561c6 |
@@ -303,6 +315,7 @@ ssh_kex2(struct ssh *ssh, char *host, st
|
|
Dmitry Belyavskiy |
f561c6 |
#endif
|
|
Dmitry Belyavskiy |
f561c6 |
|
|
Dmitry Belyavskiy |
f561c6 |
free(hkalgs);
|
|
Dmitry Belyavskiy |
f561c6 |
+ free(filtered_algs);
|
|
Dmitry Belyavskiy |
f561c6 |
|
|
Dmitry Belyavskiy |
f561c6 |
/* start key exchange */
|
|
Dmitry Belyavskiy |
f561c6 |
if ((r = kex_setup(ssh, myproposal)) != 0)
|