1 /* $OpenBSD: hostfile.c,v 1.71 2017/05/31 09:15:42 deraadt Exp $ */
3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6 * Functions for manipulating the known hosts files.
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".
15 * Copyright (c) 1999, 2000 Markus Friedl. All rights reserved.
16 * Copyright (c) 1999 Niels Provos. All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
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.
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.
41 #include <sys/types.h>
44 #include <netinet/in.h>
66 struct hostkey_entry
*entries
;
70 /* XXX hmac is too easy to dictionary attack; use bcrypt? */
73 extract_salt(const char *s
, u_int l
, u_char
*salt
, size_t salt_len
)
79 if (l
< sizeof(HASH_MAGIC
) - 1) {
80 debug2("extract_salt: string too short");
83 if (strncmp(s
, HASH_MAGIC
, sizeof(HASH_MAGIC
) - 1) != 0) {
84 debug2("extract_salt: invalid magic identifier");
87 s
+= sizeof(HASH_MAGIC
) - 1;
88 l
-= sizeof(HASH_MAGIC
) - 1;
89 if ((p
= memchr(s
, HASH_DELIM
, l
)) == NULL
) {
90 debug2("extract_salt: missing salt termination character");
96 if (b64len
== 0 || b64len
> 1024) {
97 debug2("extract_salt: bad encoded salt length %u", b64len
);
100 b64salt
= xmalloc(1 + b64len
);
101 memcpy(b64salt
, s
, b64len
);
102 b64salt
[b64len
] = '\0';
104 ret
= __b64_pton(b64salt
, salt
, salt_len
);
107 debug2("extract_salt: salt decode error");
110 if (ret
!= (int)ssh_hmac_bytes(SSH_DIGEST_SHA1
)) {
111 debug2("extract_salt: expected salt len %zd, got %d",
112 ssh_hmac_bytes(SSH_DIGEST_SHA1
), ret
);
120 host_hash(const char *host
, const char *name_from_hostfile
, u_int src_len
)
122 struct ssh_hmac_ctx
*ctx
;
123 u_char salt
[256], result
[256];
124 char uu_salt
[512], uu_result
[512];
125 static char encoded
[1024];
128 len
= ssh_digest_bytes(SSH_DIGEST_SHA1
);
130 if (name_from_hostfile
== NULL
) {
131 /* Create new salt */
132 arc4random_buf(salt
, len
);
134 /* Extract salt from known host entry */
135 if (extract_salt(name_from_hostfile
, src_len
, salt
,
140 if ((ctx
= ssh_hmac_start(SSH_DIGEST_SHA1
)) == NULL
||
141 ssh_hmac_init(ctx
, salt
, len
) < 0 ||
142 ssh_hmac_update(ctx
, host
, strlen(host
)) < 0 ||
143 ssh_hmac_final(ctx
, result
, sizeof(result
)))
144 fatal("%s: ssh_hmac failed", __func__
);
147 if (__b64_ntop(salt
, len
, uu_salt
, sizeof(uu_salt
)) == -1 ||
148 __b64_ntop(result
, len
, uu_result
, sizeof(uu_result
)) == -1)
149 fatal("%s: __b64_ntop failed", __func__
);
151 snprintf(encoded
, sizeof(encoded
), "%s%s%c%s", HASH_MAGIC
, uu_salt
,
152 HASH_DELIM
, uu_result
);
158 * Parses an RSA (number of bits, e, n) or DSA key from a string. Moves the
159 * pointer over the key. Skips any whitespace at the beginning and at end.
163 hostfile_read_key(char **cpp
, u_int
*bitsp
, struct sshkey
*ret
)
168 /* Skip leading whitespace. */
169 for (cp
= *cpp
; *cp
== ' ' || *cp
== '\t'; cp
++)
172 if ((r
= sshkey_read(ret
, &cp
)) != 0)
175 /* Skip trailing whitespace. */
176 for (; *cp
== ' ' || *cp
== '\t'; cp
++)
179 /* Return results. */
182 *bitsp
= sshkey_size(ret
);
187 check_markers(char **cpp
)
189 char marker
[32], *sp
, *cp
= *cpp
;
193 /* Only one marker is allowed */
196 /* Markers are terminated by whitespace */
197 if ((sp
= strchr(cp
, ' ')) == NULL
&&
198 (sp
= strchr(cp
, '\t')) == NULL
)
200 /* Extract marker for comparison */
201 if (sp
<= cp
+ 1 || sp
>= cp
+ sizeof(marker
))
203 memcpy(marker
, cp
, sp
- cp
);
204 marker
[sp
- cp
] = '\0';
205 if (strcmp(marker
, CA_MARKER
) == 0)
207 else if (strcmp(marker
, REVOKE_MARKER
) == 0)
212 /* Skip past marker and any whitespace that follows it */
214 for (; *cp
== ' ' || *cp
== '\t'; cp
++)
224 struct hostkeys
*ret
= xcalloc(1, sizeof(*ret
));
230 struct load_callback_ctx
{
233 struct hostkeys
*hostkeys
;
237 record_hostkey(struct hostkey_foreach_line
*l
, void *_ctx
)
239 struct load_callback_ctx
*ctx
= (struct load_callback_ctx
*)_ctx
;
240 struct hostkeys
*hostkeys
= ctx
->hostkeys
;
241 struct hostkey_entry
*tmp
;
243 if (l
->status
== HKF_STATUS_INVALID
) {
244 /* XXX make this verbose() in the future */
245 debug("%s:%ld: parse error in hostkeys file",
246 l
->path
, l
->linenum
);
250 debug3("%s: found %skey type %s in file %s:%lu", __func__
,
251 l
->marker
== MRK_NONE
? "" :
252 (l
->marker
== MRK_CA
? "ca " : "revoked "),
253 sshkey_type(l
->key
), l
->path
, l
->linenum
);
254 if ((tmp
= recallocarray(hostkeys
->entries
, hostkeys
->num_entries
,
255 hostkeys
->num_entries
+ 1, sizeof(*hostkeys
->entries
))) == NULL
)
256 return SSH_ERR_ALLOC_FAIL
;
257 hostkeys
->entries
= tmp
;
258 hostkeys
->entries
[hostkeys
->num_entries
].host
= xstrdup(ctx
->host
);
259 hostkeys
->entries
[hostkeys
->num_entries
].file
= xstrdup(l
->path
);
260 hostkeys
->entries
[hostkeys
->num_entries
].line
= l
->linenum
;
261 hostkeys
->entries
[hostkeys
->num_entries
].key
= l
->key
;
262 l
->key
= NULL
; /* steal it */
263 hostkeys
->entries
[hostkeys
->num_entries
].marker
= l
->marker
;
264 hostkeys
->num_entries
++;
271 load_hostkeys(struct hostkeys
*hostkeys
, const char *host
, const char *path
)
274 struct load_callback_ctx ctx
;
278 ctx
.hostkeys
= hostkeys
;
280 if ((r
= hostkeys_foreach(path
, record_hostkey
, &ctx
, host
, NULL
,
281 HKF_WANT_MATCH
|HKF_WANT_PARSE_KEY
)) != 0) {
282 if (r
!= SSH_ERR_SYSTEM_ERROR
&& errno
!= ENOENT
)
283 debug("%s: hostkeys_foreach failed for %s: %s",
284 __func__
, path
, ssh_err(r
));
286 if (ctx
.num_loaded
!= 0)
287 debug3("%s: loaded %lu keys from %s", __func__
,
288 ctx
.num_loaded
, host
);
292 free_hostkeys(struct hostkeys
*hostkeys
)
296 for (i
= 0; i
< hostkeys
->num_entries
; i
++) {
297 free(hostkeys
->entries
[i
].host
);
298 free(hostkeys
->entries
[i
].file
);
299 sshkey_free(hostkeys
->entries
[i
].key
);
300 explicit_bzero(hostkeys
->entries
+ i
, sizeof(*hostkeys
->entries
));
302 free(hostkeys
->entries
);
303 explicit_bzero(hostkeys
, sizeof(*hostkeys
));
308 check_key_not_revoked(struct hostkeys
*hostkeys
, struct sshkey
*k
)
310 int is_cert
= sshkey_is_cert(k
);
313 for (i
= 0; i
< hostkeys
->num_entries
; i
++) {
314 if (hostkeys
->entries
[i
].marker
!= MRK_REVOKE
)
316 if (sshkey_equal_public(k
, hostkeys
->entries
[i
].key
))
319 sshkey_equal_public(k
->cert
->signature_key
,
320 hostkeys
->entries
[i
].key
))
327 * Match keys against a specified key, or look one up by key type.
329 * If looking for a keytype (key == NULL) and one is found then return
330 * HOST_FOUND, otherwise HOST_NEW.
332 * If looking for a key (key != NULL):
333 * 1. If the key is a cert and a matching CA is found, return HOST_OK
334 * 2. If the key is not a cert and a matching key is found, return HOST_OK
335 * 3. If no key matches but a key with a different type is found, then
336 * return HOST_CHANGED
337 * 4. If no matching keys are found, then return HOST_NEW.
339 * Finally, check any found key is not revoked.
342 check_hostkeys_by_key_or_type(struct hostkeys
*hostkeys
,
343 struct sshkey
*k
, int keytype
, const struct hostkey_entry
**found
)
346 HostStatus end_return
= HOST_NEW
;
347 int want_cert
= sshkey_is_cert(k
);
348 HostkeyMarker want_marker
= want_cert
? MRK_CA
: MRK_NONE
;
353 for (i
= 0; i
< hostkeys
->num_entries
; i
++) {
354 if (hostkeys
->entries
[i
].marker
!= want_marker
)
357 if (hostkeys
->entries
[i
].key
->type
!= keytype
)
359 end_return
= HOST_FOUND
;
361 *found
= hostkeys
->entries
+ i
;
362 k
= hostkeys
->entries
[i
].key
;
366 if (sshkey_equal_public(k
->cert
->signature_key
,
367 hostkeys
->entries
[i
].key
)) {
368 /* A matching CA exists */
369 end_return
= HOST_OK
;
371 *found
= hostkeys
->entries
+ i
;
375 if (sshkey_equal(k
, hostkeys
->entries
[i
].key
)) {
376 end_return
= HOST_OK
;
378 *found
= hostkeys
->entries
+ i
;
381 /* A non-maching key exists */
382 end_return
= HOST_CHANGED
;
384 *found
= hostkeys
->entries
+ i
;
387 if (check_key_not_revoked(hostkeys
, k
) != 0) {
388 end_return
= HOST_REVOKED
;
396 check_key_in_hostkeys(struct hostkeys
*hostkeys
, struct sshkey
*key
,
397 const struct hostkey_entry
**found
)
400 fatal("no key to look up");
401 return check_hostkeys_by_key_or_type(hostkeys
, key
, 0, found
);
405 lookup_key_in_hostkeys_by_type(struct hostkeys
*hostkeys
, int keytype
,
406 const struct hostkey_entry
**found
)
408 return (check_hostkeys_by_key_or_type(hostkeys
, NULL
, keytype
,
409 found
) == HOST_FOUND
);
413 write_host_entry(FILE *f
, const char *host
, const char *ip
,
414 const struct sshkey
*key
, int store_hash
)
417 char *hashed_host
= NULL
, *lhost
;
419 lhost
= xstrdup(host
);
423 if ((hashed_host
= host_hash(lhost
, NULL
, 0)) == NULL
) {
424 error("%s: host_hash failed", __func__
);
428 fprintf(f
, "%s ", hashed_host
);
429 } else if (ip
!= NULL
)
430 fprintf(f
, "%s,%s ", lhost
, ip
);
432 fprintf(f
, "%s ", lhost
);
435 if ((r
= sshkey_write(key
, f
)) == 0)
438 error("%s: sshkey_write failed: %s", __func__
, ssh_err(r
));
444 * Appends an entry to the host file. Returns false if the entry could not
448 add_host_to_hostfile(const char *filename
, const char *host
,
449 const struct sshkey
*key
, int store_hash
)
455 return 1; /* XXX ? */
456 f
= fopen(filename
, "a");
459 success
= write_host_entry(f
, host
, NULL
, key
, store_hash
);
464 struct host_delete_ctx
{
468 int *skip_keys
; /* XXX split for host/ip? might want to ensure both */
469 struct sshkey
* const *keys
;
475 host_delete(struct hostkey_foreach_line
*l
, void *_ctx
)
477 struct host_delete_ctx
*ctx
= (struct host_delete_ctx
*)_ctx
;
478 int loglevel
= ctx
->quiet
? SYSLOG_LEVEL_DEBUG1
: SYSLOG_LEVEL_VERBOSE
;
481 if (l
->status
== HKF_STATUS_MATCHED
) {
482 if (l
->marker
!= MRK_NONE
) {
483 /* Don't remove CA and revocation lines */
484 fprintf(ctx
->out
, "%s\n", l
->line
);
489 * If this line contains one of the keys that we will be
490 * adding later, then don't change it and mark the key for
493 for (i
= 0; i
< ctx
->nkeys
; i
++) {
494 if (sshkey_equal(ctx
->keys
[i
], l
->key
)) {
495 ctx
->skip_keys
[i
] = 1;
496 fprintf(ctx
->out
, "%s\n", l
->line
);
497 debug3("%s: %s key already at %s:%ld", __func__
,
498 sshkey_type(l
->key
), l
->path
, l
->linenum
);
504 * Hostname matches and has no CA/revoke marker, delete it
505 * by *not* writing the line to ctx->out.
507 do_log2(loglevel
, "%s%s%s:%ld: Removed %s key for host %s",
508 ctx
->quiet
? __func__
: "", ctx
->quiet
? ": " : "",
509 l
->path
, l
->linenum
, sshkey_type(l
->key
), ctx
->host
);
513 /* Retain non-matching hosts and invalid lines when deleting */
514 if (l
->status
== HKF_STATUS_INVALID
) {
515 do_log2(loglevel
, "%s%s%s:%ld: invalid known_hosts entry",
516 ctx
->quiet
? __func__
: "", ctx
->quiet
? ": " : "",
517 l
->path
, l
->linenum
);
519 fprintf(ctx
->out
, "%s\n", l
->line
);
524 hostfile_replace_entries(const char *filename
, const char *host
, const char *ip
,
525 struct sshkey
**keys
, size_t nkeys
, int store_hash
, int quiet
, int hash_alg
)
527 int r
, fd
, oerrno
= 0;
528 int loglevel
= quiet
? SYSLOG_LEVEL_DEBUG1
: SYSLOG_LEVEL_VERBOSE
;
529 struct host_delete_ctx ctx
;
530 char *fp
, *temp
= NULL
, *back
= NULL
;
536 memset(&ctx
, 0, sizeof(ctx
));
539 if ((ctx
.skip_keys
= calloc(nkeys
, sizeof(*ctx
.skip_keys
))) == NULL
)
540 return SSH_ERR_ALLOC_FAIL
;
546 * Prepare temporary file for in-place deletion.
548 if ((r
= asprintf(&temp
, "%s.XXXXXXXXXXX", filename
)) < 0 ||
549 (r
= asprintf(&back
, "%s.old", filename
)) < 0) {
550 r
= SSH_ERR_ALLOC_FAIL
;
554 if ((fd
= mkstemp(temp
)) == -1) {
556 error("%s: mkstemp: %s", __func__
, strerror(oerrno
));
557 r
= SSH_ERR_SYSTEM_ERROR
;
560 if ((ctx
.out
= fdopen(fd
, "w")) == NULL
) {
563 error("%s: fdopen: %s", __func__
, strerror(oerrno
));
564 r
= SSH_ERR_SYSTEM_ERROR
;
568 /* Remove all entries for the specified host from the file */
569 if ((r
= hostkeys_foreach(filename
, host_delete
, &ctx
, host
, ip
,
570 HKF_WANT_PARSE_KEY
)) != 0) {
571 error("%s: hostkeys_foreach failed: %s", __func__
, ssh_err(r
));
575 /* Add the requested keys */
576 for (i
= 0; i
< nkeys
; i
++) {
577 if (ctx
.skip_keys
[i
])
579 if ((fp
= sshkey_fingerprint(keys
[i
], hash_alg
,
580 SSH_FP_DEFAULT
)) == NULL
) {
581 r
= SSH_ERR_ALLOC_FAIL
;
584 do_log2(loglevel
, "%s%sAdding new key for %s to %s: %s %s",
585 quiet
? __func__
: "", quiet
? ": " : "", host
, filename
,
586 sshkey_ssh_name(keys
[i
]), fp
);
588 if (!write_host_entry(ctx
.out
, host
, ip
, keys
[i
], store_hash
)) {
589 r
= SSH_ERR_INTERNAL_ERROR
;
598 /* Backup the original file and replace it with the temporary */
599 if (unlink(back
) == -1 && errno
!= ENOENT
) {
601 error("%s: unlink %.100s: %s", __func__
,
602 back
, strerror(errno
));
603 r
= SSH_ERR_SYSTEM_ERROR
;
606 if (link(filename
, back
) == -1) {
608 error("%s: link %.100s to %.100s: %s", __func__
,
609 filename
, back
, strerror(errno
));
610 r
= SSH_ERR_SYSTEM_ERROR
;
613 if (rename(temp
, filename
) == -1) {
615 error("%s: rename \"%s\" to \"%s\": %s", __func__
,
616 temp
, filename
, strerror(errno
));
617 r
= SSH_ERR_SYSTEM_ERROR
;
621 /* No changes made; just delete the temporary file */
622 if (unlink(temp
) != 0)
623 error("%s: unlink \"%s\": %s", __func__
,
624 temp
, strerror(errno
));
630 if (temp
!= NULL
&& r
!= 0)
638 if (r
== SSH_ERR_SYSTEM_ERROR
)
644 match_maybe_hashed(const char *host
, const char *names
, int *was_hashed
)
646 int hashed
= *names
== HASH_DELIM
;
647 const char *hashed_host
;
648 size_t nlen
= strlen(names
);
650 if (was_hashed
!= NULL
)
651 *was_hashed
= hashed
;
653 if ((hashed_host
= host_hash(host
, names
, nlen
)) == NULL
)
655 return nlen
== strlen(hashed_host
) &&
656 strncmp(hashed_host
, names
, nlen
) == 0;
658 return match_hostname(host
, names
) == 1;
662 hostkeys_foreach(const char *path
, hostkeys_foreach_fn
*callback
, void *ctx
,
663 const char *host
, const char *ip
, u_int options
)
666 char line
[8192], oline
[8192], ktype
[128];
672 struct hostkey_foreach_line lineinfo
;
675 memset(&lineinfo
, 0, sizeof(lineinfo
));
676 if (host
== NULL
&& (options
& HKF_WANT_MATCH
) != 0)
677 return SSH_ERR_INVALID_ARGUMENT
;
678 if ((f
= fopen(path
, "r")) == NULL
)
679 return SSH_ERR_SYSTEM_ERROR
;
681 debug3("%s: reading file \"%s\"", __func__
, path
);
682 while (read_keyfile_line(f
, path
, line
, sizeof(line
), &linenum
) == 0) {
683 line
[strcspn(line
, "\n")] = '\0';
684 strlcpy(oline
, line
, sizeof(oline
));
686 sshkey_free(lineinfo
.key
);
687 memset(&lineinfo
, 0, sizeof(lineinfo
));
688 lineinfo
.path
= path
;
689 lineinfo
.linenum
= linenum
;
690 lineinfo
.line
= oline
;
691 lineinfo
.marker
= MRK_NONE
;
692 lineinfo
.status
= HKF_STATUS_OK
;
693 lineinfo
.keytype
= KEY_UNSPEC
;
695 /* Skip any leading whitespace, comments and empty lines. */
696 for (cp
= line
; *cp
== ' ' || *cp
== '\t'; cp
++)
698 if (!*cp
|| *cp
== '#' || *cp
== '\n') {
699 if ((options
& HKF_WANT_MATCH
) == 0) {
700 lineinfo
.status
= HKF_STATUS_COMMENT
;
701 if ((r
= callback(&lineinfo
, ctx
)) != 0)
707 if ((lineinfo
.marker
= check_markers(&cp
)) == MRK_ERROR
) {
708 verbose("%s: invalid marker at %s:%lu",
709 __func__
, path
, linenum
);
710 if ((options
& HKF_WANT_MATCH
) == 0)
715 /* Find the end of the host name portion. */
716 for (cp2
= cp
; *cp2
&& *cp2
!= ' ' && *cp2
!= '\t'; cp2
++)
721 /* Check if the host name matches. */
723 if ((s
= match_maybe_hashed(host
, lineinfo
.hosts
,
725 debug2("%s: %s:%ld: bad host hash \"%.32s\"",
726 __func__
, path
, linenum
, lineinfo
.hosts
);
730 lineinfo
.status
= HKF_STATUS_MATCHED
;
731 lineinfo
.match
|= HKF_MATCH_HOST
|
732 (hashed
? HKF_MATCH_HOST_HASHED
: 0);
734 /* Try matching IP address if supplied */
736 if ((s
= match_maybe_hashed(ip
, lineinfo
.hosts
,
738 debug2("%s: %s:%ld: bad ip hash "
739 "\"%.32s\"", __func__
, path
,
740 linenum
, lineinfo
.hosts
);
744 lineinfo
.status
= HKF_STATUS_MATCHED
;
745 lineinfo
.match
|= HKF_MATCH_IP
|
746 (hashed
? HKF_MATCH_IP_HASHED
: 0);
750 * Skip this line if host matching requested and
751 * neither host nor address matched.
753 if ((options
& HKF_WANT_MATCH
) != 0 &&
754 lineinfo
.status
!= HKF_STATUS_MATCHED
)
758 /* Got a match. Skip host name and any following whitespace */
759 for (; *cp2
== ' ' || *cp2
== '\t'; cp2
++)
761 if (*cp2
== '\0' || *cp2
== '#') {
762 debug2("%s:%ld: truncated before key type",
766 lineinfo
.rawkey
= cp
= cp2
;
768 if ((options
& HKF_WANT_PARSE_KEY
) != 0) {
770 * Extract the key from the line. This will skip
771 * any leading whitespace. Ignore badly formatted
774 if ((lineinfo
.key
= sshkey_new(KEY_UNSPEC
)) == NULL
) {
775 error("%s: sshkey_new failed", __func__
);
776 r
= SSH_ERR_ALLOC_FAIL
;
779 if (!hostfile_read_key(&cp
, &kbits
, lineinfo
.key
)) {
782 lineinfo
.keytype
= lineinfo
.key
->type
;
783 lineinfo
.comment
= cp
;
785 /* Extract and parse key type */
786 l
= strcspn(lineinfo
.rawkey
, " \t");
787 if (l
<= 1 || l
>= sizeof(ktype
) ||
788 lineinfo
.rawkey
[l
] == '\0')
790 memcpy(ktype
, lineinfo
.rawkey
, l
);
792 lineinfo
.keytype
= sshkey_type_from_name(ktype
);
795 * Assume legacy RSA1 if the first component is a short
798 if (lineinfo
.keytype
== KEY_UNSPEC
&& l
< 8 &&
799 strspn(ktype
, "0123456789") == l
)
803 * Check that something other than whitespace follows
804 * the key type. This won't catch all corruption, but
805 * it does catch trivial truncation.
807 cp2
+= l
; /* Skip past key type */
808 for (; *cp2
== ' ' || *cp2
== '\t'; cp2
++)
810 if (*cp2
== '\0' || *cp2
== '#') {
811 debug2("%s:%ld: truncated after key type",
813 lineinfo
.keytype
= KEY_UNSPEC
;
815 if (lineinfo
.keytype
== KEY_UNSPEC
) {
817 sshkey_free(lineinfo
.key
);
819 lineinfo
.status
= HKF_STATUS_INVALID
;
820 if ((r
= callback(&lineinfo
, ctx
)) != 0)
825 if ((r
= callback(&lineinfo
, ctx
)) != 0)
828 sshkey_free(lineinfo
.key
);