Skip to content

Commit 937b9c8

Browse files
committed
better debug diagnostics when loading keys. Will now list key fingerprint
and algorithm (not just algorithm number) as well as making it explicit which keys didn't load.
1 parent be73e93 commit 937b9c8

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

usr.bin/ssh/ssh.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ssh.c,v 1.613 2025/05/06 05:40:56 djm Exp $ */
1+
/* $OpenBSD: ssh.c,v 1.614 2025/06/19 05:49:05 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <[email protected]>
44
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
@@ -513,16 +513,28 @@ resolve_canonicalize(char **hostp, int port)
513513
static void
514514
check_load(int r, struct sshkey **k, const char *path, const char *message)
515515
{
516+
char *fp;
517+
516518
switch (r) {
517519
case 0:
520+
if (k == NULL || *k == NULL)
521+
return;
518522
/* Check RSA keys size and discard if undersized */
519-
if (k != NULL && *k != NULL &&
520-
(r = sshkey_check_rsa_length(*k,
523+
if ((r = sshkey_check_rsa_length(*k,
521524
options.required_rsa_size)) != 0) {
522525
error_r(r, "load %s \"%s\"", message, path);
523526
free(*k);
524527
*k = NULL;
528+
break;
529+
}
530+
if ((fp = sshkey_fingerprint(*k,
531+
options.fingerprint_hash, SSH_FP_DEFAULT)) == NULL) {
532+
fatal_f("failed to fingerprint %s %s key from %s",
533+
sshkey_type(*k), message, path);
525534
}
535+
debug("loaded %s from %s: %s %s", message, path,
536+
sshkey_type(*k), fp);
537+
free(fp);
526538
break;
527539
case SSH_ERR_INTERNAL_ERROR:
528540
case SSH_ERR_ALLOC_FAIL:
@@ -536,6 +548,8 @@ check_load(int r, struct sshkey **k, const char *path, const char *message)
536548
error_r(r, "load %s \"%s\"", message, path);
537549
break;
538550
}
551+
if (k != NULL && *k == NULL)
552+
debug("no %s loaded from %s", message, path);
539553
}
540554

541555
/*
@@ -1702,21 +1716,19 @@ main(int ac, char **av)
17021716
if ((o) >= sensitive_data.nkeys) \
17031717
fatal_f("pubkey out of array bounds"); \
17041718
check_load(sshkey_load_public(p, &(sensitive_data.keys[o]), NULL), \
1705-
&(sensitive_data.keys[o]), p, "pubkey"); \
1719+
&(sensitive_data.keys[o]), p, "hostbased pubkey"); \
17061720
if (sensitive_data.keys[o] != NULL) { \
1707-
debug2("hostbased key %d: %s key from \"%s\"", o, \
1708-
sshkey_ssh_name(sensitive_data.keys[o]), p); \
1721+
debug2("hostbased pubkey \"%s\" in slot %d", p, o); \
17091722
loaded++; \
17101723
} \
17111724
} while (0)
17121725
#define L_CERT(p,o) do { \
17131726
if ((o) >= sensitive_data.nkeys) \
17141727
fatal_f("cert out of array bounds"); \
17151728
check_load(sshkey_load_cert(p, &(sensitive_data.keys[o])), \
1716-
&(sensitive_data.keys[o]), p, "cert"); \
1729+
&(sensitive_data.keys[o]), p, "hostbased cert"); \
17171730
if (sensitive_data.keys[o] != NULL) { \
1718-
debug2("hostbased key %d: %s cert from \"%s\"", o, \
1719-
sshkey_ssh_name(sensitive_data.keys[o]), p); \
1731+
debug2("hostbased cert \"%s\" in slot %d", p, o); \
17201732
loaded++; \
17211733
} \
17221734
} while (0)
@@ -2421,9 +2433,7 @@ load_public_identity_files(const struct ssh_conn_info *cinfo)
24212433
continue;
24222434
xasprintf(&cp, "%s-cert", filename);
24232435
check_load(sshkey_load_public(cp, &public, NULL),
2424-
&public, filename, "pubkey");
2425-
debug("identity file %s type %d", cp,
2426-
public ? public->type : -1);
2436+
&public, filename, "identity pubkey");
24272437
if (public == NULL) {
24282438
free(cp);
24292439
continue;
@@ -2452,9 +2462,7 @@ load_public_identity_files(const struct ssh_conn_info *cinfo)
24522462
free(cp);
24532463

24542464
check_load(sshkey_load_public(filename, &public, NULL),
2455-
&public, filename, "certificate");
2456-
debug("certificate file %s type %d", filename,
2457-
public ? public->type : -1);
2465+
&public, filename, "identity cert");
24582466
free(options.certificate_files[i]);
24592467
options.certificate_files[i] = NULL;
24602468
if (public == NULL) {

0 commit comments

Comments
 (0)