summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/ssh-pkcs11-client.c
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2020-01-25 00:03:37 +0000
committerDamien Miller <djm@cvs.openbsd.org>2020-01-25 00:03:37 +0000
commit85c9568845c5930d5ce54984e4dbe8ced31c5ddc (patch)
tree94be5889df86ba7df9dd530a84e50765da6d3df7 /usr.bin/ssh/ssh-pkcs11-client.c
parent748aea8a0df76938e66e1db79f28c7d9d52714be (diff)
expose PKCS#11 key labels/X.509 subjects as comments
Extract the key label or X.509 subject string when PKCS#11 keys are retrieved from the token and plumb this through to places where it may be used as a comment. based on https://github.com/openssh/openssh-portable/pull/138 by Danielle Church feedback and ok markus@
Diffstat (limited to 'usr.bin/ssh/ssh-pkcs11-client.c')
-rw-r--r--usr.bin/ssh/ssh-pkcs11-client.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/usr.bin/ssh/ssh-pkcs11-client.c b/usr.bin/ssh/ssh-pkcs11-client.c
index 20284d98ecf..b40cfe8becc 100644
--- a/usr.bin/ssh/ssh-pkcs11-client.c
+++ b/usr.bin/ssh/ssh-pkcs11-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-pkcs11-client.c,v 1.15 2019/01/21 12:53:35 djm Exp $ */
+/* $OpenBSD: ssh-pkcs11-client.c,v 1.16 2020/01/25 00:03:36 djm Exp $ */
/*
* Copyright (c) 2010 Markus Friedl. All rights reserved.
* Copyright (c) 2014 Pedro Martelletto. All rights reserved.
@@ -296,11 +296,13 @@ pkcs11_start_helper(void)
}
int
-pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp)
+pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp,
+ char ***labelsp)
{
struct sshkey *k;
int r, type;
u_char *blob;
+ char *label;
size_t blen;
u_int nkeys, i;
struct sshbuf *msg;
@@ -322,16 +324,22 @@ pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp)
if ((r = sshbuf_get_u32(msg, &nkeys)) != 0)
fatal("%s: buffer error: %s", __func__, ssh_err(r));
*keysp = xcalloc(nkeys, sizeof(struct sshkey *));
+ if (labelsp)
+ *labelsp = xcalloc(nkeys, sizeof(char *));
for (i = 0; i < nkeys; i++) {
/* XXX clean up properly instead of fatal() */
if ((r = sshbuf_get_string(msg, &blob, &blen)) != 0 ||
- (r = sshbuf_skip_string(msg)) != 0)
+ (r = sshbuf_get_cstring(msg, &label, NULL)) != 0)
fatal("%s: buffer error: %s",
__func__, ssh_err(r));
if ((r = sshkey_from_blob(blob, blen, &k)) != 0)
fatal("%s: bad key: %s", __func__, ssh_err(r));
wrap_key(k);
(*keysp)[i] = k;
+ if (labelsp)
+ (*labelsp)[i] = label;
+ else
+ free(label);
free(blob);
}
} else if (type == SSH2_AGENT_FAILURE) {