summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-04-20 04:43:57 +0000
committerDamien Miller <djm@mindrot.org>2020-04-20 14:46:40 +1000
commita98d5ba31e5e7e01317352f85fa63b846a960f8c (patch)
treec8b830d753f55f8366c1e4766243cffd2a9d98ac
parent32f2d0aad42c15e19bd3b07496076ca891573a58 (diff)
upstream: fix a bug I introduced in r1.406: when printing private key
fingerprint of old-format key, key comments were not being displayed. Spotted by loic AT venez.fr, ok dtucker OpenBSD-Commit-ID: 2d98e4f9eb168eea733d17e141e1ead9fe26e533
-rw-r--r--ssh-keygen.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index c181b58aa..d50ca5f28 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.406 2020/04/17 07:16:07 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.407 2020/04/20 04:43:57 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -910,21 +910,25 @@ fingerprint_private(const char *path)
910{ 910{
911 struct stat st; 911 struct stat st;
912 char *comment = NULL; 912 char *comment = NULL;
913 struct sshkey *key = NULL; 913 struct sshkey *privkey = NULL, *pubkey = NULL;
914 int r; 914 int r;
915 915
916 if (stat(identity_file, &st) == -1) 916 if (stat(identity_file, &st) == -1)
917 fatal("%s: %s", path, strerror(errno)); 917 fatal("%s: %s", path, strerror(errno));
918 if ((r = sshkey_load_private(path, NULL, &key, &comment)) != 0) { 918 if ((r = sshkey_load_public(path, &pubkey, &comment)) != 0)
919 debug("load private \"%s\": %s", path, ssh_err(r)); 919 debug("load public \"%s\": %s", path, ssh_err(r));
920 if ((r = sshkey_load_public(path, &key, &comment)) != 0) { 920 if (pubkey == NULL || comment == NULL || *comment == '\0') {
921 debug("load public \"%s\": %s", path, ssh_err(r)); 921 free(comment);
922 fatal("%s is not a key file.", path); 922 if ((r = sshkey_load_private(path, NULL,
923 } 923 &privkey, &comment)) != 0)
924 debug("load private \"%s\": %s", path, ssh_err(r));
924 } 925 }
926 if (pubkey == NULL && privkey == NULL)
927 fatal("%s is not a key file.", path);
925 928
926 fingerprint_one_key(key, comment); 929 fingerprint_one_key(pubkey == NULL ? privkey : pubkey, comment);
927 sshkey_free(key); 930 sshkey_free(pubkey);
931 sshkey_free(privkey);
928 free(comment); 932 free(comment);
929} 933}
930 934