summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-09-01 23:47:32 +0000
committerDamien Miller <djm@mindrot.org>2019-09-02 10:32:42 +1000
commit0713322e18162463c5ab5ddfb9f935055ca775d8 (patch)
treed1efe8514b54414fa02f2fdce3b83a7d62495aed
parent368f1cc2fbd6ad10c66bc1b67c2c04aebf8a04a8 (diff)
upstream: print comment when printing pubkey from private
bz#3052; ok dtucker OpenBSD-Commit-ID: a91b2a8d5f1053d34d7fce44523c53fb534ba914
-rw-r--r--ssh-keygen.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index d71548803..bb108519c 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.340 2019/08/08 08:02:57 dtucker Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.341 2019/09/01 23:47:32 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
@@ -271,13 +271,15 @@ ask_filename(struct passwd *pw, const char *prompt)
271} 271}
272 272
273static struct sshkey * 273static struct sshkey *
274load_identity(char *filename) 274load_identity(char *filename, char **commentp)
275{ 275{
276 char *pass; 276 char *pass;
277 struct sshkey *prv; 277 struct sshkey *prv;
278 int r; 278 int r;
279 279
280 if ((r = sshkey_load_private(filename, "", &prv, NULL)) == 0) 280 if (commentp != NULL)
281 *commentp = NULL;
282 if ((r = sshkey_load_private(filename, "", &prv, commentp)) == 0)
281 return prv; 283 return prv;
282 if (r != SSH_ERR_KEY_WRONG_PASSPHRASE) 284 if (r != SSH_ERR_KEY_WRONG_PASSPHRASE)
283 fatal("Load key \"%s\": %s", filename, ssh_err(r)); 285 fatal("Load key \"%s\": %s", filename, ssh_err(r));
@@ -285,7 +287,7 @@ load_identity(char *filename)
285 pass = xstrdup(identity_passphrase); 287 pass = xstrdup(identity_passphrase);
286 else 288 else
287 pass = read_passphrase("Enter passphrase: ", RP_ALLOW_STDIN); 289 pass = read_passphrase("Enter passphrase: ", RP_ALLOW_STDIN);
288 r = sshkey_load_private(filename, pass, &prv, NULL); 290 r = sshkey_load_private(filename, pass, &prv, commentp);
289 explicit_bzero(pass, strlen(pass)); 291 explicit_bzero(pass, strlen(pass));
290 free(pass); 292 free(pass);
291 if (r != 0) 293 if (r != 0)
@@ -379,7 +381,7 @@ do_convert_to(struct passwd *pw)
379 if (stat(identity_file, &st) == -1) 381 if (stat(identity_file, &st) == -1)
380 fatal("%s: %s: %s", __progname, identity_file, strerror(errno)); 382 fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
381 if ((r = sshkey_load_public(identity_file, &k, NULL)) != 0) 383 if ((r = sshkey_load_public(identity_file, &k, NULL)) != 0)
382 k = load_identity(identity_file); 384 k = load_identity(identity_file, NULL);
383 switch (convert_format) { 385 switch (convert_format) {
384 case FMT_RFC4716: 386 case FMT_RFC4716:
385 do_convert_to_ssh2(pw, k); 387 do_convert_to_ssh2(pw, k);
@@ -752,16 +754,20 @@ do_print_public(struct passwd *pw)
752 struct sshkey *prv; 754 struct sshkey *prv;
753 struct stat st; 755 struct stat st;
754 int r; 756 int r;
757 char *comment = NULL;
755 758
756 if (!have_identity) 759 if (!have_identity)
757 ask_filename(pw, "Enter file in which the key is"); 760 ask_filename(pw, "Enter file in which the key is");
758 if (stat(identity_file, &st) == -1) 761 if (stat(identity_file, &st) == -1)
759 fatal("%s: %s", identity_file, strerror(errno)); 762 fatal("%s: %s", identity_file, strerror(errno));
760 prv = load_identity(identity_file); 763 prv = load_identity(identity_file, &comment);
761 if ((r = sshkey_write(prv, stdout)) != 0) 764 if ((r = sshkey_write(prv, stdout)) != 0)
762 error("sshkey_write failed: %s", ssh_err(r)); 765 error("sshkey_write failed: %s", ssh_err(r));
763 sshkey_free(prv); 766 sshkey_free(prv);
767 if (comment != NULL && *comment != '\0')
768 fprintf(stdout, " %s", comment);
764 fprintf(stdout, "\n"); 769 fprintf(stdout, "\n");
770 free(comment);
765 exit(0); 771 exit(0);
766} 772}
767 773
@@ -1721,7 +1727,7 @@ do_ca_sign(struct passwd *pw, const char *ca_key_path, int prefer_agent,
1721 ca->flags |= SSHKEY_FLAG_EXT; 1727 ca->flags |= SSHKEY_FLAG_EXT;
1722 } else { 1728 } else {
1723 /* CA key is assumed to be a private key on the filesystem */ 1729 /* CA key is assumed to be a private key on the filesystem */
1724 ca = load_identity(tmp); 1730 ca = load_identity(tmp, NULL);
1725 } 1731 }
1726 free(tmp); 1732 free(tmp);
1727 1733