summaryrefslogtreecommitdiff
path: root/hostfile.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-08-01 01:21:56 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-08-01 01:21:56 +0000
commit3ed6640532ea53bc37182262141c9e917a448025 (patch)
tree88ad1d4bbb9cd865c154f24ad12feafd7e302ccd /hostfile.c
parent18d2b5d399a6ee97c65a058c14054fd2da2b891a (diff)
- markus@cvs.openbsd.org 2002/07/24 16:11:18
[hostfile.c hostfile.h sshconnect.c] print out all known keys for a host if we get a unknown host key, see discussion at http://marc.theaimsgroup.com/?t=101069210100016&r=1&w=4 the ssharp mitm tool attacks users in a similar way, so i'd like to pointed out again: A MITM attack is always possible if the ssh client prints: The authenticity of host 'bla' can't be established. (protocol version 2 with pubkey authentication allows you to detect MITM attacks)
Diffstat (limited to 'hostfile.c')
-rw-r--r--hostfile.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/hostfile.c b/hostfile.c
index cefff8d62..dcee03448 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -36,7 +36,7 @@
36 */ 36 */
37 37
38#include "includes.h" 38#include "includes.h"
39RCSID("$OpenBSD: hostfile.c,v 1.29 2001/12/18 10:04:21 jakob Exp $"); 39RCSID("$OpenBSD: hostfile.c,v 1.30 2002/07/24 16:11:18 markus Exp $");
40 40
41#include "packet.h" 41#include "packet.h"
42#include "match.h" 42#include "match.h"
@@ -91,11 +91,14 @@ hostfile_check_key(int bits, Key *key, const char *host, const char *filename, i
91 * in the list of our known hosts. Returns HOST_OK if the host is known and 91 * in the list of our known hosts. Returns HOST_OK if the host is known and
92 * has the specified key, HOST_NEW if the host is not known, and HOST_CHANGED 92 * has the specified key, HOST_NEW if the host is not known, and HOST_CHANGED
93 * if the host is known but used to have a different host key. 93 * if the host is known but used to have a different host key.
94 *
95 * If no 'key' has been specified and a key of type 'keytype' is known
96 * for the specified host, then HOST_FOUND is returned.
94 */ 97 */
95 98
96HostStatus 99static HostStatus
97check_host_in_hostfile(const char *filename, const char *host, Key *key, 100check_host_in_hostfile_by_key_or_type(const char *filename,
98 Key *found, int *numret) 101 const char *host, Key *key, int keytype, Key *found, int *numret)
99{ 102{
100 FILE *f; 103 FILE *f;
101 char line[8192]; 104 char line[8192];
@@ -105,8 +108,7 @@ check_host_in_hostfile(const char *filename, const char *host, Key *key,
105 HostStatus end_return; 108 HostStatus end_return;
106 109
107 debug3("check_host_in_hostfile: filename %s", filename); 110 debug3("check_host_in_hostfile: filename %s", filename);
108 if (key == NULL) 111
109 fatal("no key to look up");
110 /* Open the file containing the list of known hosts. */ 112 /* Open the file containing the list of known hosts. */
111 f = fopen(filename, "r"); 113 f = fopen(filename, "r");
112 if (!f) 114 if (!f)
@@ -147,12 +149,20 @@ check_host_in_hostfile(const char *filename, const char *host, Key *key,
147 */ 149 */
148 if (!hostfile_read_key(&cp, &kbits, found)) 150 if (!hostfile_read_key(&cp, &kbits, found))
149 continue; 151 continue;
150 if (!hostfile_check_key(kbits, found, host, filename, linenum))
151 continue;
152 152
153 if (numret != NULL) 153 if (numret != NULL)
154 *numret = linenum; 154 *numret = linenum;
155 155
156 if (key == NULL) {
157 /* we found a key of the requested type */
158 if (found->type == keytype)
159 return HOST_FOUND;
160 continue;
161 }
162
163 if (!hostfile_check_key(kbits, found, host, filename, linenum))
164 continue;
165
156 /* Check if the current key is the same as the given key. */ 166 /* Check if the current key is the same as the given key. */
157 if (key_equal(key, found)) { 167 if (key_equal(key, found)) {
158 /* Ok, they match. */ 168 /* Ok, they match. */
@@ -177,6 +187,24 @@ check_host_in_hostfile(const char *filename, const char *host, Key *key,
177 return end_return; 187 return end_return;
178} 188}
179 189
190HostStatus
191check_host_in_hostfile(const char *filename, const char *host, Key *key,
192 Key *found, int *numret)
193{
194 if (key == NULL)
195 fatal("no key to look up");
196 return (check_host_in_hostfile_by_key_or_type(filename, host, key, 0,
197 found, numret));
198}
199
200int
201lookup_key_in_hostfile_by_type(const char *filename, const char *host,
202 int keytype, Key *found, int *numret)
203{
204 return (check_host_in_hostfile_by_key_or_type(filename, host, NULL,
205 keytype, found, numret) == HOST_FOUND);
206}
207
180/* 208/*
181 * Appends an entry to the host file. Returns false if the entry could not 209 * Appends an entry to the host file. Returns false if the entry could not
182 * be appended. 210 * be appended.