djm@openbsd.org | c29811c | 2015-01-18 21:40:23 +0000 | [diff] [blame^] | 1 | /* $OpenBSD: hostfile.c,v 1.60 2015/01/18 21:40:23 djm Exp $ */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 2 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
| 5 | * All rights reserved |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 6 | * Functions for manipulating the known hosts files. |
Damien Miller | 4af5130 | 2000-04-16 11:18:38 +1000 | [diff] [blame] | 7 | * |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 8 | * As far as I am concerned, the code I have written for this software |
| 9 | * can be used freely for any purpose. Any derived versions of this |
| 10 | * software must be clearly marked as such, and if the derived work is |
| 11 | * incompatible with the protocol description in the RFC file, it must be |
| 12 | * called by a name other than "ssh" or "Secure Shell". |
| 13 | * |
| 14 | * |
Ben Lindstrom | 4469723 | 2001-07-04 03:32:30 +0000 | [diff] [blame] | 15 | * Copyright (c) 1999, 2000 Markus Friedl. All rights reserved. |
Damien Miller | e4340be | 2000-09-16 13:29:08 +1100 | [diff] [blame] | 16 | * Copyright (c) 1999 Niels Provos. All rights reserved. |
| 17 | * |
| 18 | * Redistribution and use in source and binary forms, with or without |
| 19 | * modification, are permitted provided that the following conditions |
| 20 | * are met: |
| 21 | * 1. Redistributions of source code must retain the above copyright |
| 22 | * notice, this list of conditions and the following disclaimer. |
| 23 | * 2. Redistributions in binary form must reproduce the above copyright |
| 24 | * notice, this list of conditions and the following disclaimer in the |
| 25 | * documentation and/or other materials provided with the distribution. |
| 26 | * |
| 27 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 28 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 29 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 30 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 32 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 33 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 34 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 35 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 36 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 37 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 38 | |
| 39 | #include "includes.h" |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 40 | |
Damien Miller | 8ec8c3e | 2006-07-10 20:35:38 +1000 | [diff] [blame] | 41 | #include <sys/types.h> |
| 42 | |
| 43 | #include <netinet/in.h> |
| 44 | |
djm@openbsd.org | c29811c | 2015-01-18 21:40:23 +0000 | [diff] [blame^] | 45 | #include <errno.h> |
Damien Miller | e7a1e5c | 2006-08-05 11:34:19 +1000 | [diff] [blame] | 46 | #include <resolv.h> |
Damien Miller | ded319c | 2006-09-01 15:38:36 +1000 | [diff] [blame] | 47 | #include <stdarg.h> |
Damien Miller | a7a73ee | 2006-08-05 11:37:59 +1000 | [diff] [blame] | 48 | #include <stdio.h> |
Damien Miller | e7a1e5c | 2006-08-05 11:34:19 +1000 | [diff] [blame] | 49 | #include <stdlib.h> |
| 50 | #include <string.h> |
Damien Miller | 8668706 | 2014-07-02 15:28:02 +1000 | [diff] [blame] | 51 | #include <stdarg.h> |
Damien Miller | e7a1e5c | 2006-08-05 11:34:19 +1000 | [diff] [blame] | 52 | |
Damien Miller | d783435 | 2006-08-05 12:39:39 +1000 | [diff] [blame] | 53 | #include "xmalloc.h" |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 54 | #include "match.h" |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 55 | #include "sshkey.h" |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 56 | #include "hostfile.h" |
Ben Lindstrom | 226cfa0 | 2001-01-22 05:34:40 +0000 | [diff] [blame] | 57 | #include "log.h" |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 58 | #include "misc.h" |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 59 | #include "ssherr.h" |
Damien Miller | b3051d0 | 2014-01-10 10:58:53 +1100 | [diff] [blame] | 60 | #include "digest.h" |
Damien Miller | 4e8d937 | 2014-02-04 11:02:42 +1100 | [diff] [blame] | 61 | #include "hmac.h" |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 62 | |
| 63 | struct hostkeys { |
| 64 | struct hostkey_entry *entries; |
| 65 | u_int num_entries; |
| 66 | }; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 67 | |
djm@openbsd.org | c29811c | 2015-01-18 21:40:23 +0000 | [diff] [blame^] | 68 | /* XXX hmac is too easy to dictionary attack; use bcrypt? */ |
| 69 | |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 70 | static int |
Damien Miller | ce98654 | 2013-07-18 16:12:44 +1000 | [diff] [blame] | 71 | extract_salt(const char *s, u_int l, u_char *salt, size_t salt_len) |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 72 | { |
| 73 | char *p, *b64salt; |
| 74 | u_int b64len; |
| 75 | int ret; |
| 76 | |
| 77 | if (l < sizeof(HASH_MAGIC) - 1) { |
| 78 | debug2("extract_salt: string too short"); |
| 79 | return (-1); |
| 80 | } |
| 81 | if (strncmp(s, HASH_MAGIC, sizeof(HASH_MAGIC) - 1) != 0) { |
| 82 | debug2("extract_salt: invalid magic identifier"); |
| 83 | return (-1); |
| 84 | } |
| 85 | s += sizeof(HASH_MAGIC) - 1; |
| 86 | l -= sizeof(HASH_MAGIC) - 1; |
| 87 | if ((p = memchr(s, HASH_DELIM, l)) == NULL) { |
| 88 | debug2("extract_salt: missing salt termination character"); |
| 89 | return (-1); |
| 90 | } |
| 91 | |
| 92 | b64len = p - s; |
| 93 | /* Sanity check */ |
| 94 | if (b64len == 0 || b64len > 1024) { |
| 95 | debug2("extract_salt: bad encoded salt length %u", b64len); |
| 96 | return (-1); |
| 97 | } |
| 98 | b64salt = xmalloc(1 + b64len); |
| 99 | memcpy(b64salt, s, b64len); |
| 100 | b64salt[b64len] = '\0'; |
| 101 | |
| 102 | ret = __b64_pton(b64salt, salt, salt_len); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 103 | free(b64salt); |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 104 | if (ret == -1) { |
| 105 | debug2("extract_salt: salt decode error"); |
| 106 | return (-1); |
| 107 | } |
Damien Miller | 4e8d937 | 2014-02-04 11:02:42 +1100 | [diff] [blame] | 108 | if (ret != (int)ssh_hmac_bytes(SSH_DIGEST_SHA1)) { |
| 109 | debug2("extract_salt: expected salt len %zd, got %d", |
| 110 | ssh_hmac_bytes(SSH_DIGEST_SHA1), ret); |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 111 | return (-1); |
| 112 | } |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 113 | |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 114 | return (0); |
| 115 | } |
| 116 | |
| 117 | char * |
| 118 | host_hash(const char *host, const char *name_from_hostfile, u_int src_len) |
| 119 | { |
Damien Miller | 4e8d937 | 2014-02-04 11:02:42 +1100 | [diff] [blame] | 120 | struct ssh_hmac_ctx *ctx; |
Damien Miller | ce98654 | 2013-07-18 16:12:44 +1000 | [diff] [blame] | 121 | u_char salt[256], result[256]; |
| 122 | char uu_salt[512], uu_result[512]; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 123 | static char encoded[1024]; |
| 124 | u_int i, len; |
| 125 | |
Damien Miller | 4e8d937 | 2014-02-04 11:02:42 +1100 | [diff] [blame] | 126 | len = ssh_digest_bytes(SSH_DIGEST_SHA1); |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 127 | |
| 128 | if (name_from_hostfile == NULL) { |
| 129 | /* Create new salt */ |
| 130 | for (i = 0; i < len; i++) |
| 131 | salt[i] = arc4random(); |
| 132 | } else { |
| 133 | /* Extract salt from known host entry */ |
| 134 | if (extract_salt(name_from_hostfile, src_len, salt, |
| 135 | sizeof(salt)) == -1) |
| 136 | return (NULL); |
| 137 | } |
| 138 | |
Damien Miller | 4e8d937 | 2014-02-04 11:02:42 +1100 | [diff] [blame] | 139 | if ((ctx = ssh_hmac_start(SSH_DIGEST_SHA1)) == NULL || |
| 140 | ssh_hmac_init(ctx, salt, len) < 0 || |
| 141 | ssh_hmac_update(ctx, host, strlen(host)) < 0 || |
| 142 | ssh_hmac_final(ctx, result, sizeof(result))) |
| 143 | fatal("%s: ssh_hmac failed", __func__); |
| 144 | ssh_hmac_free(ctx); |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 145 | |
Darren Tucker | 47eede7 | 2005-03-14 23:08:12 +1100 | [diff] [blame] | 146 | if (__b64_ntop(salt, len, uu_salt, sizeof(uu_salt)) == -1 || |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 147 | __b64_ntop(result, len, uu_result, sizeof(uu_result)) == -1) |
Damien Miller | 4e8d937 | 2014-02-04 11:02:42 +1100 | [diff] [blame] | 148 | fatal("%s: __b64_ntop failed", __func__); |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 149 | |
| 150 | snprintf(encoded, sizeof(encoded), "%s%s%c%s", HASH_MAGIC, uu_salt, |
| 151 | HASH_DELIM, uu_result); |
| 152 | |
| 153 | return (encoded); |
| 154 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 155 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 156 | /* |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 157 | * Parses an RSA (number of bits, e, n) or DSA key from a string. Moves the |
| 158 | * pointer over the key. Skips any whitespace at the beginning and at end. |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 159 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 160 | |
Damien Miller | 5b2aea9 | 2001-12-21 12:47:09 +1100 | [diff] [blame] | 161 | int |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 162 | hostfile_read_key(char **cpp, u_int *bitsp, struct sshkey *ret) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 163 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 164 | char *cp; |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 165 | int r; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 166 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 167 | /* Skip leading whitespace. */ |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 168 | for (cp = *cpp; *cp == ' ' || *cp == '\t'; cp++) |
| 169 | ; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 170 | |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 171 | if ((r = sshkey_read(ret, &cp)) != 0) |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 172 | return 0; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 173 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 174 | /* Skip trailing whitespace. */ |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 175 | for (; *cp == ' ' || *cp == '\t'; cp++) |
| 176 | ; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 177 | |
| 178 | /* Return results. */ |
| 179 | *cpp = cp; |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 180 | if (bitsp != NULL) |
| 181 | *bitsp = sshkey_size(ret); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 182 | return 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 183 | } |
| 184 | |
Ben Lindstrom | bba8121 | 2001-06-25 05:01:22 +0000 | [diff] [blame] | 185 | static int |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 186 | hostfile_check_key(int bits, const struct sshkey *key, const char *host, |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 187 | const char *filename, u_long linenum) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 188 | { |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 189 | #ifdef WITH_SSH1 |
Damien Miller | 0bc1bd8 | 2000-11-13 22:57:25 +1100 | [diff] [blame] | 190 | if (key == NULL || key->type != KEY_RSA1 || key->rsa == NULL) |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 191 | return 1; |
| 192 | if (bits != BN_num_bits(key->rsa->n)) { |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 193 | logit("Warning: %s, line %lu: keysize mismatch for host %s: " |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 194 | "actual %d vs. announced %d.", |
| 195 | filename, linenum, host, BN_num_bits(key->rsa->n), bits); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 196 | logit("Warning: replace %d with %d in %s, line %lu.", |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 197 | bits, BN_num_bits(key->rsa->n), filename, linenum); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 198 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 199 | #endif |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 200 | return 1; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 201 | } |
| 202 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 203 | static HostkeyMarker |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 204 | check_markers(char **cpp) |
| 205 | { |
| 206 | char marker[32], *sp, *cp = *cpp; |
| 207 | int ret = MRK_NONE; |
| 208 | |
| 209 | while (*cp == '@') { |
| 210 | /* Only one marker is allowed */ |
| 211 | if (ret != MRK_NONE) |
| 212 | return MRK_ERROR; |
| 213 | /* Markers are terminated by whitespace */ |
| 214 | if ((sp = strchr(cp, ' ')) == NULL && |
| 215 | (sp = strchr(cp, '\t')) == NULL) |
| 216 | return MRK_ERROR; |
| 217 | /* Extract marker for comparison */ |
| 218 | if (sp <= cp + 1 || sp >= cp + sizeof(marker)) |
| 219 | return MRK_ERROR; |
| 220 | memcpy(marker, cp, sp - cp); |
| 221 | marker[sp - cp] = '\0'; |
| 222 | if (strcmp(marker, CA_MARKER) == 0) |
| 223 | ret = MRK_CA; |
| 224 | else if (strcmp(marker, REVOKE_MARKER) == 0) |
| 225 | ret = MRK_REVOKE; |
| 226 | else |
| 227 | return MRK_ERROR; |
| 228 | |
| 229 | /* Skip past marker and any whitespace that follows it */ |
| 230 | cp = sp; |
| 231 | for (; *cp == ' ' || *cp == '\t'; cp++) |
| 232 | ; |
| 233 | } |
| 234 | *cpp = cp; |
| 235 | return ret; |
| 236 | } |
| 237 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 238 | struct hostkeys * |
| 239 | init_hostkeys(void) |
| 240 | { |
| 241 | struct hostkeys *ret = xcalloc(1, sizeof(*ret)); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 242 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 243 | ret->entries = NULL; |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | void |
| 248 | load_hostkeys(struct hostkeys *hostkeys, const char *host, const char *path) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 249 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 250 | FILE *f; |
| 251 | char line[8192]; |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 252 | u_long linenum = 0, num_loaded = 0; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 253 | char *cp, *cp2, *hashed_host; |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 254 | HostkeyMarker marker; |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 255 | struct sshkey *key; |
| 256 | u_int kbits; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 257 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 258 | if ((f = fopen(path, "r")) == NULL) |
| 259 | return; |
| 260 | debug3("%s: loading entries for host \"%.100s\" from file \"%s\"", |
| 261 | __func__, host, path); |
| 262 | while (read_keyfile_line(f, path, line, sizeof(line), &linenum) == 0) { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 263 | cp = line; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 264 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 265 | /* Skip any leading whitespace, comments and empty lines. */ |
| 266 | for (; *cp == ' ' || *cp == '\t'; cp++) |
| 267 | ; |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 268 | if (!*cp || *cp == '#' || *cp == '\n') |
| 269 | continue; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 270 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 271 | if ((marker = check_markers(&cp)) == MRK_ERROR) { |
| 272 | verbose("%s: invalid marker at %s:%lu", |
| 273 | __func__, path, linenum); |
Damien Miller | 1aed65e | 2010-03-04 21:53:35 +1100 | [diff] [blame] | 274 | continue; |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 275 | } |
Damien Miller | 0a80ca1 | 2010-02-27 07:55:05 +1100 | [diff] [blame] | 276 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 277 | /* Find the end of the host name portion. */ |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 278 | for (cp2 = cp; *cp2 && *cp2 != ' ' && *cp2 != '\t'; cp2++) |
| 279 | ; |
Damien Miller | 7e8e820 | 1999-11-16 13:37:16 +1100 | [diff] [blame] | 280 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 281 | /* Check if the host name matches. */ |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 282 | if (match_hostname(host, cp, (u_int) (cp2 - cp)) != 1) { |
| 283 | if (*cp != HASH_DELIM) |
| 284 | continue; |
| 285 | hashed_host = host_hash(host, cp, (u_int) (cp2 - cp)); |
| 286 | if (hashed_host == NULL) { |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 287 | debug("Invalid hashed host line %lu of %s", |
| 288 | linenum, path); |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 289 | continue; |
| 290 | } |
| 291 | if (strncmp(hashed_host, cp, (u_int) (cp2 - cp)) != 0) |
| 292 | continue; |
| 293 | } |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 294 | |
| 295 | /* Got a match. Skip host name. */ |
| 296 | cp = cp2; |
| 297 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 298 | /* |
| 299 | * Extract the key from the line. This will skip any leading |
| 300 | * whitespace. Ignore badly formatted lines. |
| 301 | */ |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 302 | if ((key = sshkey_new(KEY_UNSPEC)) == NULL) { |
| 303 | error("%s: sshkey_new failed", __func__); |
| 304 | break; |
| 305 | } |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 306 | if (!hostfile_read_key(&cp, &kbits, key)) { |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 307 | sshkey_free(key); |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 308 | #ifdef WITH_SSH1 |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 309 | if ((key = sshkey_new(KEY_RSA1)) == NULL) { |
| 310 | error("%s: sshkey_new failed", __func__); |
| 311 | break; |
| 312 | } |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 313 | if (!hostfile_read_key(&cp, &kbits, key)) { |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 314 | sshkey_free(key); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 315 | continue; |
Damien Miller | 6db780e | 2006-03-26 13:52:20 +1100 | [diff] [blame] | 316 | } |
Damien Miller | 1f0311c | 2014-05-15 14:24:09 +1000 | [diff] [blame] | 317 | #else |
| 318 | continue; |
| 319 | #endif |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 320 | } |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 321 | if (!hostfile_check_key(kbits, key, host, path, linenum)) |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 322 | continue; |
| 323 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 324 | debug3("%s: found %skey type %s in file %s:%lu", __func__, |
| 325 | marker == MRK_NONE ? "" : |
| 326 | (marker == MRK_CA ? "ca " : "revoked "), |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 327 | sshkey_type(key), path, linenum); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 328 | hostkeys->entries = xrealloc(hostkeys->entries, |
| 329 | hostkeys->num_entries + 1, sizeof(*hostkeys->entries)); |
| 330 | hostkeys->entries[hostkeys->num_entries].host = xstrdup(host); |
| 331 | hostkeys->entries[hostkeys->num_entries].file = xstrdup(path); |
| 332 | hostkeys->entries[hostkeys->num_entries].line = linenum; |
| 333 | hostkeys->entries[hostkeys->num_entries].key = key; |
| 334 | hostkeys->entries[hostkeys->num_entries].marker = marker; |
| 335 | hostkeys->num_entries++; |
| 336 | num_loaded++; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 337 | } |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 338 | debug3("%s: loaded %lu keys", __func__, num_loaded); |
Darren Tucker | 094f1e9 | 2010-12-05 09:03:31 +1100 | [diff] [blame] | 339 | fclose(f); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 340 | return; |
djm@openbsd.org | 6fdcaeb | 2014-10-20 03:43:01 +0000 | [diff] [blame] | 341 | } |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 342 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 343 | void |
| 344 | free_hostkeys(struct hostkeys *hostkeys) |
| 345 | { |
| 346 | u_int i; |
| 347 | |
| 348 | for (i = 0; i < hostkeys->num_entries; i++) { |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 349 | free(hostkeys->entries[i].host); |
| 350 | free(hostkeys->entries[i].file); |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 351 | sshkey_free(hostkeys->entries[i].key); |
Damien Miller | 1d2c456 | 2014-02-04 11:18:20 +1100 | [diff] [blame] | 352 | explicit_bzero(hostkeys->entries + i, sizeof(*hostkeys->entries)); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 353 | } |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 354 | free(hostkeys->entries); |
Damien Miller | 1d2c456 | 2014-02-04 11:18:20 +1100 | [diff] [blame] | 355 | explicit_bzero(hostkeys, sizeof(*hostkeys)); |
Darren Tucker | a627d42 | 2013-06-02 07:31:17 +1000 | [diff] [blame] | 356 | free(hostkeys); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 357 | } |
| 358 | |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 359 | static int |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 360 | check_key_not_revoked(struct hostkeys *hostkeys, struct sshkey *k) |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 361 | { |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 362 | int is_cert = sshkey_is_cert(k); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 363 | u_int i; |
| 364 | |
| 365 | for (i = 0; i < hostkeys->num_entries; i++) { |
| 366 | if (hostkeys->entries[i].marker != MRK_REVOKE) |
| 367 | continue; |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 368 | if (sshkey_equal_public(k, hostkeys->entries[i].key)) |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 369 | return -1; |
| 370 | if (is_cert && |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 371 | sshkey_equal_public(k->cert->signature_key, |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 372 | hostkeys->entries[i].key)) |
| 373 | return -1; |
| 374 | } |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Match keys against a specified key, or look one up by key type. |
| 380 | * |
| 381 | * If looking for a keytype (key == NULL) and one is found then return |
| 382 | * HOST_FOUND, otherwise HOST_NEW. |
| 383 | * |
| 384 | * If looking for a key (key != NULL): |
| 385 | * 1. If the key is a cert and a matching CA is found, return HOST_OK |
| 386 | * 2. If the key is not a cert and a matching key is found, return HOST_OK |
| 387 | * 3. If no key matches but a key with a different type is found, then |
| 388 | * return HOST_CHANGED |
| 389 | * 4. If no matching keys are found, then return HOST_NEW. |
| 390 | * |
| 391 | * Finally, check any found key is not revoked. |
| 392 | */ |
| 393 | static HostStatus |
| 394 | check_hostkeys_by_key_or_type(struct hostkeys *hostkeys, |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 395 | struct sshkey *k, int keytype, const struct hostkey_entry **found) |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 396 | { |
| 397 | u_int i; |
| 398 | HostStatus end_return = HOST_NEW; |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 399 | int want_cert = sshkey_is_cert(k); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 400 | HostkeyMarker want_marker = want_cert ? MRK_CA : MRK_NONE; |
| 401 | int proto = (k ? k->type : keytype) == KEY_RSA1 ? 1 : 2; |
| 402 | |
| 403 | if (found != NULL) |
| 404 | *found = NULL; |
| 405 | |
| 406 | for (i = 0; i < hostkeys->num_entries; i++) { |
| 407 | if (proto == 1 && hostkeys->entries[i].key->type != KEY_RSA1) |
| 408 | continue; |
| 409 | if (proto == 2 && hostkeys->entries[i].key->type == KEY_RSA1) |
| 410 | continue; |
| 411 | if (hostkeys->entries[i].marker != want_marker) |
| 412 | continue; |
| 413 | if (k == NULL) { |
| 414 | if (hostkeys->entries[i].key->type != keytype) |
| 415 | continue; |
| 416 | end_return = HOST_FOUND; |
| 417 | if (found != NULL) |
| 418 | *found = hostkeys->entries + i; |
| 419 | k = hostkeys->entries[i].key; |
| 420 | break; |
| 421 | } |
| 422 | if (want_cert) { |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 423 | if (sshkey_equal_public(k->cert->signature_key, |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 424 | hostkeys->entries[i].key)) { |
| 425 | /* A matching CA exists */ |
| 426 | end_return = HOST_OK; |
| 427 | if (found != NULL) |
| 428 | *found = hostkeys->entries + i; |
| 429 | break; |
| 430 | } |
| 431 | } else { |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 432 | if (sshkey_equal(k, hostkeys->entries[i].key)) { |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 433 | end_return = HOST_OK; |
| 434 | if (found != NULL) |
| 435 | *found = hostkeys->entries + i; |
| 436 | break; |
| 437 | } |
| 438 | /* A non-maching key exists */ |
| 439 | end_return = HOST_CHANGED; |
| 440 | if (found != NULL) |
| 441 | *found = hostkeys->entries + i; |
| 442 | } |
| 443 | } |
| 444 | if (check_key_not_revoked(hostkeys, k) != 0) { |
| 445 | end_return = HOST_REVOKED; |
| 446 | if (found != NULL) |
| 447 | *found = NULL; |
| 448 | } |
| 449 | return end_return; |
| 450 | } |
djm@openbsd.org | 6fdcaeb | 2014-10-20 03:43:01 +0000 | [diff] [blame] | 451 | |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 452 | HostStatus |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 453 | check_key_in_hostkeys(struct hostkeys *hostkeys, struct sshkey *key, |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 454 | const struct hostkey_entry **found) |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 455 | { |
| 456 | if (key == NULL) |
| 457 | fatal("no key to look up"); |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 458 | return check_hostkeys_by_key_or_type(hostkeys, key, 0, found); |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | int |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 462 | lookup_key_in_hostkeys_by_type(struct hostkeys *hostkeys, int keytype, |
| 463 | const struct hostkey_entry **found) |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 464 | { |
Damien Miller | d925dcd | 2010-12-01 12:21:51 +1100 | [diff] [blame] | 465 | return (check_hostkeys_by_key_or_type(hostkeys, NULL, keytype, |
| 466 | found) == HOST_FOUND); |
Ben Lindstrom | 3ed6640 | 2002-08-01 01:21:56 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 469 | /* |
| 470 | * Appends an entry to the host file. Returns false if the entry could not |
| 471 | * be appended. |
| 472 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 473 | |
| 474 | int |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 475 | add_host_to_hostfile(const char *filename, const char *host, |
| 476 | const struct sshkey *key, int store_hash) |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 477 | { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 478 | FILE *f; |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 479 | int r, success = 0; |
Darren Tucker | 4085853 | 2005-08-02 17:07:07 +1000 | [diff] [blame] | 480 | char *hashed_host = NULL; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 481 | |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 482 | if (key == NULL) |
Damien Miller | eba71ba | 2000-04-29 23:57:08 +1000 | [diff] [blame] | 483 | return 1; /* XXX ? */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 484 | f = fopen(filename, "a"); |
| 485 | if (!f) |
| 486 | return 0; |
Damien Miller | e177615 | 2005-03-01 21:47:37 +1100 | [diff] [blame] | 487 | |
| 488 | if (store_hash) { |
| 489 | if ((hashed_host = host_hash(host, NULL, 0)) == NULL) { |
| 490 | error("add_host_to_hostfile: host_hash failed"); |
| 491 | fclose(f); |
| 492 | return 0; |
| 493 | } |
| 494 | } |
| 495 | fprintf(f, "%s ", store_hash ? hashed_host : host); |
| 496 | |
djm@openbsd.org | 1129dcf | 2015-01-15 09:40:00 +0000 | [diff] [blame] | 497 | if ((r = sshkey_write(key, f)) != 0) { |
| 498 | error("%s: saving key in %s failed: %s", |
| 499 | __func__, filename, ssh_err(r)); |
| 500 | } else |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 501 | success = 1; |
djm@openbsd.org | c29811c | 2015-01-18 21:40:23 +0000 | [diff] [blame^] | 502 | fputc('\n', f); |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 503 | fclose(f); |
Damien Miller | 450a7a1 | 2000-03-26 13:04:51 +1000 | [diff] [blame] | 504 | return success; |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 505 | } |
djm@openbsd.org | c29811c | 2015-01-18 21:40:23 +0000 | [diff] [blame^] | 506 | |
| 507 | static int |
| 508 | match_maybe_hashed(const char *host, const char *names, int *was_hashed) |
| 509 | { |
| 510 | int hashed = *names == HASH_DELIM; |
| 511 | const char *hashed_host; |
| 512 | size_t nlen = strlen(names); |
| 513 | |
| 514 | if (was_hashed != NULL) |
| 515 | *was_hashed = hashed; |
| 516 | if (hashed) { |
| 517 | if ((hashed_host = host_hash(host, names, nlen)) == NULL) |
| 518 | return -1; |
| 519 | return nlen == strlen(hashed_host) && |
| 520 | strncmp(hashed_host, names, nlen) == 0; |
| 521 | } |
| 522 | return match_hostname(host, names, nlen) == 1; |
| 523 | } |
| 524 | |
| 525 | int |
| 526 | hostkeys_foreach(const char *path, hostkeys_foreach_fn *callback, void *ctx, |
| 527 | const char *host, u_int options) |
| 528 | { |
| 529 | FILE *f; |
| 530 | char line[8192], oline[8192]; |
| 531 | u_long linenum = 0; |
| 532 | char *cp, *cp2; |
| 533 | u_int kbits; |
| 534 | int s, r = 0; |
| 535 | struct hostkey_foreach_line lineinfo; |
| 536 | |
| 537 | memset(&lineinfo, 0, sizeof(lineinfo)); |
| 538 | if (host == NULL && (options & HKF_WANT_MATCH_HOST) != 0) |
| 539 | return SSH_ERR_INVALID_ARGUMENT; |
| 540 | if ((f = fopen(path, "r")) == NULL) |
| 541 | return SSH_ERR_SYSTEM_ERROR; |
| 542 | |
| 543 | debug3("%s: reading file \"%s\"", __func__, path); |
| 544 | while (read_keyfile_line(f, path, line, sizeof(line), &linenum) == 0) { |
| 545 | line[strcspn(line, "\n")] = '\0'; |
| 546 | strlcpy(oline, line, sizeof(oline)); |
| 547 | |
| 548 | sshkey_free(lineinfo.key); |
| 549 | memset(&lineinfo, 0, sizeof(lineinfo)); |
| 550 | lineinfo.path = path; |
| 551 | lineinfo.linenum = linenum; |
| 552 | lineinfo.line = oline; |
| 553 | lineinfo.status = HKF_STATUS_OK; |
| 554 | |
| 555 | /* Skip any leading whitespace, comments and empty lines. */ |
| 556 | for (cp = line; *cp == ' ' || *cp == '\t'; cp++) |
| 557 | ; |
| 558 | if (!*cp || *cp == '#' || *cp == '\n') { |
| 559 | if ((options & HKF_WANT_MATCH_HOST) == 0) { |
| 560 | lineinfo.status = HKF_STATUS_COMMENT; |
| 561 | if ((r = callback(&lineinfo, ctx)) != 0) |
| 562 | break; |
| 563 | } |
| 564 | continue; |
| 565 | } |
| 566 | |
| 567 | if ((lineinfo.marker = check_markers(&cp)) == MRK_ERROR) { |
| 568 | verbose("%s: invalid marker at %s:%lu", |
| 569 | __func__, path, linenum); |
| 570 | if ((options & HKF_WANT_MATCH_HOST) == 0) |
| 571 | goto bad; |
| 572 | continue; |
| 573 | } |
| 574 | |
| 575 | /* Find the end of the host name portion. */ |
| 576 | for (cp2 = cp; *cp2 && *cp2 != ' ' && *cp2 != '\t'; cp2++) |
| 577 | ; |
| 578 | lineinfo.hosts = cp; |
| 579 | *cp2++ = '\0'; |
| 580 | |
| 581 | /* Check if the host name matches. */ |
| 582 | if (host != NULL) { |
| 583 | s = match_maybe_hashed(host, lineinfo.hosts, |
| 584 | &lineinfo.was_hashed); |
| 585 | if (s == 1) |
| 586 | lineinfo.status = HKF_STATUS_HOST_MATCHED; |
| 587 | else if ((options & HKF_WANT_MATCH_HOST) != 0) |
| 588 | continue; |
| 589 | else if (s == -1) { |
| 590 | debug2("%s: %s:%ld: bad host hash \"%.32s\"", |
| 591 | __func__, path, linenum, lineinfo.hosts); |
| 592 | goto bad; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | /* Got a match. Skip host name and any following whitespace */ |
| 597 | for (; *cp2 == ' ' || *cp2 == '\t'; cp2++) |
| 598 | ; |
| 599 | if (*cp2 == '\0' || *cp2 == '#') { |
| 600 | debug2("%s:%ld: truncated before key", path, linenum); |
| 601 | goto bad; |
| 602 | } |
| 603 | lineinfo.rawkey = cp = cp2; |
| 604 | |
| 605 | if ((options & HKF_WANT_PARSE_KEY) != 0) { |
| 606 | /* |
| 607 | * Extract the key from the line. This will skip |
| 608 | * any leading whitespace. Ignore badly formatted |
| 609 | * lines. |
| 610 | */ |
| 611 | if ((lineinfo.key = sshkey_new(KEY_UNSPEC)) == NULL) { |
| 612 | error("%s: sshkey_new failed", __func__); |
| 613 | return SSH_ERR_ALLOC_FAIL; |
| 614 | } |
| 615 | if (!hostfile_read_key(&cp, &kbits, lineinfo.key)) { |
| 616 | #ifdef WITH_SSH1 |
| 617 | sshkey_free(lineinfo.key); |
| 618 | lineinfo.key = sshkey_new(KEY_RSA1); |
| 619 | if (lineinfo.key == NULL) { |
| 620 | error("%s: sshkey_new fail", __func__); |
| 621 | return SSH_ERR_ALLOC_FAIL; |
| 622 | } |
| 623 | if (!hostfile_read_key(&cp, &kbits, |
| 624 | lineinfo.key)) |
| 625 | goto bad; |
| 626 | #else |
| 627 | goto bad; |
| 628 | #endif |
| 629 | } |
| 630 | if (!hostfile_check_key(kbits, lineinfo.key, host, |
| 631 | path, linenum)) { |
| 632 | bad: |
| 633 | lineinfo.status = HKF_STATUS_INVALID; |
| 634 | if ((r = callback(&lineinfo, ctx)) != 0) |
| 635 | break; |
| 636 | continue; |
| 637 | } |
| 638 | } |
| 639 | if ((r = callback(&lineinfo, ctx)) != 0) |
| 640 | break; |
| 641 | } |
| 642 | sshkey_free(lineinfo.key); |
| 643 | fclose(f); |
| 644 | return r; |
| 645 | } |