[openssh-commits] [openssh] 06/10: upstream: add a "hexdump" export mode that dumps the key blob in

git+noreply at mindrot.org git+noreply at mindrot.org
Tue Sep 15 15:38:10 AEST 2026


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 7cc27ceb87d4707323ba682a6b03f1810971167f
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Tue Sep 8 02:55:58 2026 +0000

    upstream: add a "hexdump" export mode that dumps the key blob in
    
    hex format. Very useful when writing internet-drafts.
    
    E.g. ssh-keygen -em hexdump -f /path/key
    
    OpenBSD-Commit-ID: 922f997de2c691cf7ddf4067a5406d39b36b25ef
---
 ssh-keygen.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/ssh-keygen.c b/ssh-keygen.c
index be782df31..4231487a6 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.494 2026/08/22 12:48:18 dtucker Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.495 2026/09/08 02:55:58 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo at cs.hut.fi>
  * Copyright (c) 1994 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -141,7 +141,8 @@ static size_t ncert_ext;
 enum {
 	FMT_RFC4716,
 	FMT_PKCS8,
-	FMT_PEM
+	FMT_PEM,
+	FMT_HEXDUMP
 } convert_format = FMT_RFC4716;
 
 static char *key_type_name = NULL;
@@ -388,10 +389,34 @@ do_convert_to_pem(struct sshkey *k)
 	}
 }
 
+static void
+do_convert_to_hexdump(struct sshkey *k)
+{
+	struct sshbuf *b;
+	int r;
+
+	if ((b = sshbuf_new()) == NULL)
+		fatal_f("sshbuf_new failed");
+	/* pubkey */
+	if ((r = sshkey_putb(k, b)) != 0)
+		fatal_fr(r, "serialise private");
+	printf("Public %s key:\n", sshkey_type(k));
+	sshbuf_dump(b, stdout);
+	sshbuf_reset(b);
+	if ((r = sshkey_private_serialize(k, b)) != 0) {
+		debug_fr(r, "serialise private");
+		goto out;
+	}
+	printf("\nPrivate %s key:\n", sshkey_type(k));
+	sshbuf_dump(b, stdout);
+ out:
+	sshbuf_free(b);
+}
+
 static void
 do_convert_to(struct passwd *pw)
 {
-	struct sshkey *k;
+	struct sshkey *k = NULL;
 	struct stat st;
 	int r;
 
@@ -399,8 +424,17 @@ do_convert_to(struct passwd *pw)
 		ask_filename(pw, "Enter file in which the key is");
 	if (stat(identity_file, &st) == -1)
 		fatal("%s: %s: %s", __progname, identity_file, strerror(errno));
-	if ((r = sshkey_load_public(identity_file, &k, NULL)) != 0)
+
+	/* If we're trying to hexdump, then prefer the private key */
+	if (convert_format == FMT_HEXDUMP) {
+		if ((r = sshkey_load_private(identity_file,
+		    NULL, &k, NULL)) != 0 &&
+		    r == SSH_ERR_KEY_WRONG_PASSPHRASE)
+			k = load_identity(identity_file, NULL);
+	}
+	if (k == NULL && (r = sshkey_load_public(identity_file, &k, NULL)) != 0)
 		k = load_identity(identity_file, NULL);
+
 	switch (convert_format) {
 	case FMT_RFC4716:
 		do_convert_to_ssh2(pw, k);
@@ -411,6 +445,9 @@ do_convert_to(struct passwd *pw)
 	case FMT_PEM:
 		do_convert_to_pem(k);
 		break;
+	case FMT_HEXDUMP:
+		do_convert_to_hexdump(k);
+		break;
 	default:
 		fatal_f("unknown key format %d", convert_format);
 	}
@@ -3420,6 +3457,10 @@ main(int argc, char **argv)
 				private_key_format = SSHKEY_PRIVATE_PEM;
 				break;
 			}
+			if (strcasecmp(optarg, "hexdump") == 0) {
+				convert_format = FMT_HEXDUMP;
+				break;
+			}
 			fatal("Unsupported conversion format \"%s\"", optarg);
 		case 'n':
 			cert_principals = optarg;
@@ -3908,6 +3949,8 @@ main(int argc, char **argv)
 		snprintf(comment, sizeof comment, "%s@%s", pw->pw_name, hostname);
 	}
 
+
+
 	/* Save the key with the given passphrase and comment. */
 	if ((r = sshkey_save_private(private, identity_file, passphrase,
 	    comment, private_key_format, openssh_format_cipher, rounds)) != 0) {

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list