summaryrefslogtreecommitdiff
path: root/ssh-pkcs11-helper.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2020-02-21 11:57:14 +0000
committerColin Watson <cjwatson@debian.org>2020-02-21 11:57:14 +0000
commitf0de78bd4f29fa688c5df116f3f9cd43543a76d0 (patch)
tree856b0dee3f2764c13a32dad5ffe2424fab7fef41 /ssh-pkcs11-helper.c
parent4213eec74e74de6310c27a40c3e9759a08a73996 (diff)
parent8aa3455b16fddea4c0144a7c4a1edb10ec67dcc8 (diff)
Import openssh_8.2p1.orig.tar.gz
Diffstat (limited to 'ssh-pkcs11-helper.c')
-rw-r--r--ssh-pkcs11-helper.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/ssh-pkcs11-helper.c b/ssh-pkcs11-helper.c
index 3bcc2440b..17220d624 100644
--- a/ssh-pkcs11-helper.c
+++ b/ssh-pkcs11-helper.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-pkcs11-helper.c,v 1.21 2019/09/06 05:23:55 djm Exp $ */ 1/* $OpenBSD: ssh-pkcs11-helper.c,v 1.22 2020/01/25 00:03:36 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2010 Markus Friedl. All rights reserved. 3 * Copyright (c) 2010 Markus Friedl. All rights reserved.
4 * 4 *
@@ -26,7 +26,9 @@
26 26
27#include <stdlib.h> 27#include <stdlib.h>
28#include <errno.h> 28#include <errno.h>
29#ifdef HAVE_POLL_H
29#include <poll.h> 30#include <poll.h>
31#endif
30#include <stdarg.h> 32#include <stdarg.h>
31#include <string.h> 33#include <string.h>
32#include <unistd.h> 34#include <unistd.h>
@@ -48,7 +50,7 @@
48 50
49struct pkcs11_keyinfo { 51struct pkcs11_keyinfo {
50 struct sshkey *key; 52 struct sshkey *key;
51 char *providername; 53 char *providername, *label;
52 TAILQ_ENTRY(pkcs11_keyinfo) next; 54 TAILQ_ENTRY(pkcs11_keyinfo) next;
53}; 55};
54 56
@@ -61,13 +63,14 @@ struct sshbuf *iqueue;
61struct sshbuf *oqueue; 63struct sshbuf *oqueue;
62 64
63static void 65static void
64add_key(struct sshkey *k, char *name) 66add_key(struct sshkey *k, char *name, char *label)
65{ 67{
66 struct pkcs11_keyinfo *ki; 68 struct pkcs11_keyinfo *ki;
67 69
68 ki = xcalloc(1, sizeof(*ki)); 70 ki = xcalloc(1, sizeof(*ki));
69 ki->providername = xstrdup(name); 71 ki->providername = xstrdup(name);
70 ki->key = k; 72 ki->key = k;
73 ki->label = xstrdup(label);
71 TAILQ_INSERT_TAIL(&pkcs11_keylist, ki, next); 74 TAILQ_INSERT_TAIL(&pkcs11_keylist, ki, next);
72} 75}
73 76
@@ -81,6 +84,7 @@ del_keys_by_name(char *name)
81 if (!strcmp(ki->providername, name)) { 84 if (!strcmp(ki->providername, name)) {
82 TAILQ_REMOVE(&pkcs11_keylist, ki, next); 85 TAILQ_REMOVE(&pkcs11_keylist, ki, next);
83 free(ki->providername); 86 free(ki->providername);
87 free(ki->label);
84 sshkey_free(ki->key); 88 sshkey_free(ki->key);
85 free(ki); 89 free(ki);
86 } 90 }
@@ -94,7 +98,7 @@ lookup_key(struct sshkey *k)
94 struct pkcs11_keyinfo *ki; 98 struct pkcs11_keyinfo *ki;
95 99
96 TAILQ_FOREACH(ki, &pkcs11_keylist, next) { 100 TAILQ_FOREACH(ki, &pkcs11_keylist, next) {
97 debug("check %p %s", ki, ki->providername); 101 debug("check %p %s %s", ki, ki->providername, ki->label);
98 if (sshkey_equal(k, ki->key)) 102 if (sshkey_equal(k, ki->key))
99 return (ki->key); 103 return (ki->key);
100 } 104 }
@@ -119,13 +123,14 @@ process_add(void)
119 u_char *blob; 123 u_char *blob;
120 size_t blen; 124 size_t blen;
121 struct sshbuf *msg; 125 struct sshbuf *msg;
126 char **labels = NULL;
122 127
123 if ((msg = sshbuf_new()) == NULL) 128 if ((msg = sshbuf_new()) == NULL)
124 fatal("%s: sshbuf_new failed", __func__); 129 fatal("%s: sshbuf_new failed", __func__);
125 if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || 130 if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 ||
126 (r = sshbuf_get_cstring(iqueue, &pin, NULL)) != 0) 131 (r = sshbuf_get_cstring(iqueue, &pin, NULL)) != 0)
127 fatal("%s: buffer error: %s", __func__, ssh_err(r)); 132 fatal("%s: buffer error: %s", __func__, ssh_err(r));
128 if ((nkeys = pkcs11_add_provider(name, pin, &keys)) > 0) { 133 if ((nkeys = pkcs11_add_provider(name, pin, &keys, &labels)) > 0) {
129 if ((r = sshbuf_put_u8(msg, 134 if ((r = sshbuf_put_u8(msg,
130 SSH2_AGENT_IDENTITIES_ANSWER)) != 0 || 135 SSH2_AGENT_IDENTITIES_ANSWER)) != 0 ||
131 (r = sshbuf_put_u32(msg, nkeys)) != 0) 136 (r = sshbuf_put_u32(msg, nkeys)) != 0)
@@ -137,11 +142,12 @@ process_add(void)
137 continue; 142 continue;
138 } 143 }
139 if ((r = sshbuf_put_string(msg, blob, blen)) != 0 || 144 if ((r = sshbuf_put_string(msg, blob, blen)) != 0 ||
140 (r = sshbuf_put_cstring(msg, name)) != 0) 145 (r = sshbuf_put_cstring(msg, labels[i])) != 0)
141 fatal("%s: buffer error: %s", 146 fatal("%s: buffer error: %s",
142 __func__, ssh_err(r)); 147 __func__, ssh_err(r));
143 free(blob); 148 free(blob);
144 add_key(keys[i], name); 149 add_key(keys[i], name, labels[i]);
150 free(labels[i]);
145 } 151 }
146 } else { 152 } else {
147 if ((r = sshbuf_put_u8(msg, SSH_AGENT_FAILURE)) != 0) 153 if ((r = sshbuf_put_u8(msg, SSH_AGENT_FAILURE)) != 0)
@@ -149,7 +155,8 @@ process_add(void)
149 if ((r = sshbuf_put_u32(msg, -nkeys)) != 0) 155 if ((r = sshbuf_put_u32(msg, -nkeys)) != 0)
150 fatal("%s: buffer error: %s", __func__, ssh_err(r)); 156 fatal("%s: buffer error: %s", __func__, ssh_err(r));
151 } 157 }
152 free(keys); 158 free(labels);
159 free(keys); /* keys themselves are transferred to pkcs11_keylist */
153 free(pin); 160 free(pin);
154 free(name); 161 free(name);
155 send_msg(msg); 162 send_msg(msg);