summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hostfile.c14
-rw-r--r--hostfile.h3
-rw-r--r--sshconnect2.c20
3 files changed, 31 insertions, 6 deletions
diff --git a/hostfile.c b/hostfile.c
index a4a355972..a91dbbd94 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.c,v 1.79 2020/03/06 18:25:12 markus Exp $ */ 1/* $OpenBSD: hostfile.c,v 1.80 2020/05/13 09:52:41 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -406,6 +406,18 @@ lookup_key_in_hostkeys_by_type(struct hostkeys *hostkeys, int keytype,
406 found) == HOST_FOUND); 406 found) == HOST_FOUND);
407} 407}
408 408
409int
410lookup_marker_in_hostkeys(struct hostkeys *hostkeys, int want_marker)
411{
412 u_int i;
413
414 for (i = 0; i < hostkeys->num_entries; i++) {
415 if (hostkeys->entries[i].marker == (HostkeyMarker)want_marker)
416 return 1;
417 }
418 return 0;
419}
420
409static int 421static int
410write_host_entry(FILE *f, const char *host, const char *ip, 422write_host_entry(FILE *f, const char *host, const char *ip,
411 const struct sshkey *key, int store_hash) 423 const struct sshkey *key, int store_hash)
diff --git a/hostfile.h b/hostfile.h
index bd2104373..49fcbb7e8 100644
--- a/hostfile.h
+++ b/hostfile.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.h,v 1.24 2015/02/16 22:08:57 djm Exp $ */ 1/* $OpenBSD: hostfile.h,v 1.25 2020/05/13 09:52:41 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -39,6 +39,7 @@ HostStatus check_key_in_hostkeys(struct hostkeys *, struct sshkey *,
39 const struct hostkey_entry **); 39 const struct hostkey_entry **);
40int lookup_key_in_hostkeys_by_type(struct hostkeys *, int, 40int lookup_key_in_hostkeys_by_type(struct hostkeys *, int,
41 const struct hostkey_entry **); 41 const struct hostkey_entry **);
42int lookup_marker_in_hostkeys(struct hostkeys *, int);
42 43
43int hostfile_read_key(char **, u_int *, struct sshkey *); 44int hostfile_read_key(char **, u_int *, struct sshkey *);
44int add_host_to_hostfile(const char *, const char *, 45int add_host_to_hostfile(const char *, const char *,
diff --git a/sshconnect2.c b/sshconnect2.c
index 1a6545edf..08b4f8550 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect2.c,v 1.321 2020/04/17 03:38:47 djm Exp $ */ 1/* $OpenBSD: sshconnect2.c,v 1.322 2020/05/13 09:52:41 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Damien Miller. All rights reserved. 4 * Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -135,11 +135,23 @@ order_hostkeyalgs(char *host, struct sockaddr *hostaddr, u_short port)
135 while ((alg = strsep(&avail, ",")) && *alg != '\0') { 135 while ((alg = strsep(&avail, ",")) && *alg != '\0') {
136 if ((ktype = sshkey_type_from_name(alg)) == KEY_UNSPEC) 136 if ((ktype = sshkey_type_from_name(alg)) == KEY_UNSPEC)
137 fatal("%s: unknown alg %s", __func__, alg); 137 fatal("%s: unknown alg %s", __func__, alg);
138 /*
139 * If we have a @cert-authority marker in known_hosts then
140 * prefer all certificate algorithms.
141 */
142 if (sshkey_type_is_cert(ktype) &&
143 lookup_marker_in_hostkeys(hostkeys, MRK_CA)) {
144 ALG_APPEND(first, alg);
145 continue;
146 }
147 /* If the key appears in known_hosts then prefer it */
138 if (lookup_key_in_hostkeys_by_type(hostkeys, 148 if (lookup_key_in_hostkeys_by_type(hostkeys,
139 sshkey_type_plain(ktype), NULL)) 149 sshkey_type_plain(ktype), NULL)) {
140 ALG_APPEND(first, alg); 150 ALG_APPEND(first, alg);
141 else 151 continue;
142 ALG_APPEND(last, alg); 152 }
153 /* Otherwise, put it last */
154 ALG_APPEND(last, alg);
143 } 155 }
144#undef ALG_APPEND 156#undef ALG_APPEND
145 xasprintf(&ret, "%s%s%s", first, 157 xasprintf(&ret, "%s%s%s", first,