ssh-sk-client.c revision 1.1.1.4 1 1.1.1.4 christos /* $OpenBSD: ssh-sk-client.c,v 1.12 2022/01/14 03:34:00 djm Exp $ */
2 1.1 christos /*
3 1.1 christos * Copyright (c) 2019 Google LLC
4 1.1 christos *
5 1.1 christos * Permission to use, copy, modify, and distribute this software for any
6 1.1 christos * purpose with or without fee is hereby granted, provided that the above
7 1.1 christos * copyright notice and this permission notice appear in all copies.
8 1.1 christos *
9 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 1.1 christos * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 1.1 christos */
17 1.1 christos
18 1.1 christos #include <sys/types.h>
19 1.1 christos #include <sys/socket.h>
20 1.1 christos #include <sys/wait.h>
21 1.1 christos
22 1.1 christos #include <fcntl.h>
23 1.1 christos #include <limits.h>
24 1.1 christos #include <errno.h>
25 1.1 christos #include <signal.h>
26 1.1 christos #include <stdarg.h>
27 1.1 christos #include <stdio.h>
28 1.1 christos #include <stdlib.h>
29 1.1 christos #include <string.h>
30 1.1 christos #include <unistd.h>
31 1.1 christos
32 1.1 christos #include "log.h"
33 1.1 christos #include "ssherr.h"
34 1.1 christos #include "sshbuf.h"
35 1.1 christos #include "sshkey.h"
36 1.1 christos #include "msg.h"
37 1.1 christos #include "digest.h"
38 1.1 christos #include "pathnames.h"
39 1.1 christos #include "ssh-sk.h"
40 1.1 christos #include "misc.h"
41 1.1 christos
42 1.1 christos /* #define DEBUG_SK 1 */
43 1.1 christos
44 1.1 christos static int
45 1.1 christos start_helper(int *fdp, pid_t *pidp, void (**osigchldp)(int))
46 1.1 christos {
47 1.1 christos void (*osigchld)(int);
48 1.1.1.2 christos int oerrno, pair[2];
49 1.1 christos pid_t pid;
50 1.1 christos char *helper, *verbosity = NULL;
51 1.1 christos
52 1.1 christos *fdp = -1;
53 1.1 christos *pidp = 0;
54 1.1 christos *osigchldp = SIG_DFL;
55 1.1 christos
56 1.1 christos helper = getenv("SSH_SK_HELPER");
57 1.1 christos if (helper == NULL || strlen(helper) == 0)
58 1.1 christos helper = _PATH_SSH_SK_HELPER;
59 1.1 christos if (access(helper, X_OK) != 0) {
60 1.1 christos oerrno = errno;
61 1.1.1.2 christos error_f("helper \"%s\" unusable: %s", helper, strerror(errno));
62 1.1 christos errno = oerrno;
63 1.1 christos return SSH_ERR_SYSTEM_ERROR;
64 1.1 christos }
65 1.1 christos #ifdef DEBUG_SK
66 1.1 christos verbosity = "-vvv";
67 1.1 christos #endif
68 1.1 christos
69 1.1 christos /* Start helper */
70 1.1 christos if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
71 1.1 christos error("socketpair: %s", strerror(errno));
72 1.1 christos return SSH_ERR_SYSTEM_ERROR;
73 1.1 christos }
74 1.1 christos osigchld = ssh_signal(SIGCHLD, SIG_DFL);
75 1.1 christos if ((pid = fork()) == -1) {
76 1.1 christos oerrno = errno;
77 1.1 christos error("fork: %s", strerror(errno));
78 1.1 christos close(pair[0]);
79 1.1 christos close(pair[1]);
80 1.1 christos ssh_signal(SIGCHLD, osigchld);
81 1.1 christos errno = oerrno;
82 1.1 christos return SSH_ERR_SYSTEM_ERROR;
83 1.1 christos }
84 1.1 christos if (pid == 0) {
85 1.1 christos if ((dup2(pair[1], STDIN_FILENO) == -1) ||
86 1.1 christos (dup2(pair[1], STDOUT_FILENO) == -1)) {
87 1.1.1.2 christos error_f("dup2: %s", strerror(errno));
88 1.1 christos _exit(1);
89 1.1 christos }
90 1.1 christos close(pair[0]);
91 1.1 christos close(pair[1]);
92 1.1 christos closefrom(STDERR_FILENO + 1);
93 1.1.1.2 christos debug_f("starting %s %s", helper,
94 1.1 christos verbosity == NULL ? "" : verbosity);
95 1.1 christos execlp(helper, helper, verbosity, (char *)NULL);
96 1.1.1.2 christos error_f("execlp: %s", strerror(errno));
97 1.1 christos _exit(1);
98 1.1 christos }
99 1.1 christos close(pair[1]);
100 1.1 christos
101 1.1 christos /* success */
102 1.1.1.2 christos debug3_f("started pid=%ld", (long)pid);
103 1.1 christos *fdp = pair[0];
104 1.1 christos *pidp = pid;
105 1.1 christos *osigchldp = osigchld;
106 1.1 christos return 0;
107 1.1 christos }
108 1.1 christos
109 1.1 christos static int
110 1.1 christos reap_helper(pid_t pid)
111 1.1 christos {
112 1.1 christos int status, oerrno;
113 1.1 christos
114 1.1.1.2 christos debug3_f("pid=%ld", (long)pid);
115 1.1 christos
116 1.1 christos errno = 0;
117 1.1 christos while (waitpid(pid, &status, 0) == -1) {
118 1.1 christos if (errno == EINTR) {
119 1.1 christos errno = 0;
120 1.1 christos continue;
121 1.1 christos }
122 1.1 christos oerrno = errno;
123 1.1.1.2 christos error_f("waitpid: %s", strerror(errno));
124 1.1 christos errno = oerrno;
125 1.1 christos return SSH_ERR_SYSTEM_ERROR;
126 1.1 christos }
127 1.1 christos if (!WIFEXITED(status)) {
128 1.1.1.2 christos error_f("helper exited abnormally");
129 1.1 christos return SSH_ERR_AGENT_FAILURE;
130 1.1 christos } else if (WEXITSTATUS(status) != 0) {
131 1.1.1.2 christos error_f("helper exited with non-zero exit status");
132 1.1 christos return SSH_ERR_AGENT_FAILURE;
133 1.1 christos }
134 1.1 christos return 0;
135 1.1 christos }
136 1.1 christos
137 1.1 christos static int
138 1.1 christos client_converse(struct sshbuf *msg, struct sshbuf **respp, u_int type)
139 1.1 christos {
140 1.1 christos int oerrno, fd, r2, ll, r = SSH_ERR_INTERNAL_ERROR;
141 1.1 christos u_int rtype, rerr;
142 1.1 christos pid_t pid;
143 1.1 christos u_char version;
144 1.1 christos void (*osigchld)(int);
145 1.1 christos struct sshbuf *req = NULL, *resp = NULL;
146 1.1 christos *respp = NULL;
147 1.1 christos
148 1.1 christos if ((r = start_helper(&fd, &pid, &osigchld)) != 0)
149 1.1 christos return r;
150 1.1 christos
151 1.1 christos if ((req = sshbuf_new()) == NULL || (resp = sshbuf_new()) == NULL) {
152 1.1 christos r = SSH_ERR_ALLOC_FAIL;
153 1.1 christos goto out;
154 1.1 christos }
155 1.1 christos /* Request preamble: type, log_on_stderr, log_level */
156 1.1 christos ll = log_level_get();
157 1.1 christos if ((r = sshbuf_put_u32(req, type)) != 0 ||
158 1.1.1.3 christos (r = sshbuf_put_u8(req, log_is_on_stderr() != 0)) != 0 ||
159 1.1.1.3 christos (r = sshbuf_put_u32(req, ll < 0 ? 0 : ll)) != 0 ||
160 1.1.1.3 christos (r = sshbuf_putb(req, msg)) != 0) {
161 1.1.1.2 christos error_fr(r, "compose");
162 1.1 christos goto out;
163 1.1 christos }
164 1.1 christos if ((r = ssh_msg_send(fd, SSH_SK_HELPER_VERSION, req)) != 0) {
165 1.1.1.2 christos error_fr(r, "send");
166 1.1 christos goto out;
167 1.1 christos }
168 1.1 christos if ((r = ssh_msg_recv(fd, resp)) != 0) {
169 1.1.1.2 christos error_fr(r, "receive");
170 1.1 christos goto out;
171 1.1 christos }
172 1.1 christos if ((r = sshbuf_get_u8(resp, &version)) != 0) {
173 1.1.1.2 christos error_fr(r, "parse version");
174 1.1 christos goto out;
175 1.1 christos }
176 1.1 christos if (version != SSH_SK_HELPER_VERSION) {
177 1.1.1.2 christos error_f("unsupported version: got %u, expected %u",
178 1.1.1.2 christos version, SSH_SK_HELPER_VERSION);
179 1.1 christos r = SSH_ERR_INVALID_FORMAT;
180 1.1 christos goto out;
181 1.1 christos }
182 1.1 christos if ((r = sshbuf_get_u32(resp, &rtype)) != 0) {
183 1.1.1.2 christos error_fr(r, "parse message type");
184 1.1 christos goto out;
185 1.1 christos }
186 1.1 christos if (rtype == SSH_SK_HELPER_ERROR) {
187 1.1 christos if ((r = sshbuf_get_u32(resp, &rerr)) != 0) {
188 1.1.1.2 christos error_fr(r, "parse");
189 1.1 christos goto out;
190 1.1 christos }
191 1.1.1.2 christos debug_f("helper returned error -%u", rerr);
192 1.1 christos /* OpenSSH error values are negative; encoded as -err on wire */
193 1.1 christos if (rerr == 0 || rerr >= INT_MAX)
194 1.1 christos r = SSH_ERR_INTERNAL_ERROR;
195 1.1 christos else
196 1.1 christos r = -(int)rerr;
197 1.1 christos goto out;
198 1.1 christos } else if (rtype != type) {
199 1.1.1.2 christos error_f("helper returned incorrect message type %u, "
200 1.1.1.2 christos "expecting %u", rtype, type);
201 1.1 christos r = SSH_ERR_INTERNAL_ERROR;
202 1.1 christos goto out;
203 1.1 christos }
204 1.1 christos /* success */
205 1.1 christos r = 0;
206 1.1 christos out:
207 1.1 christos oerrno = errno;
208 1.1 christos close(fd);
209 1.1 christos if ((r2 = reap_helper(pid)) != 0) {
210 1.1 christos if (r == 0) {
211 1.1 christos r = r2;
212 1.1 christos oerrno = errno;
213 1.1 christos }
214 1.1 christos }
215 1.1 christos if (r == 0) {
216 1.1 christos *respp = resp;
217 1.1 christos resp = NULL;
218 1.1 christos }
219 1.1 christos sshbuf_free(req);
220 1.1 christos sshbuf_free(resp);
221 1.1 christos ssh_signal(SIGCHLD, osigchld);
222 1.1 christos errno = oerrno;
223 1.1 christos return r;
224 1.1 christos
225 1.1 christos }
226 1.1 christos
227 1.1 christos int
228 1.1 christos sshsk_sign(const char *provider, struct sshkey *key,
229 1.1 christos u_char **sigp, size_t *lenp, const u_char *data, size_t datalen,
230 1.1 christos u_int compat, const char *pin)
231 1.1 christos {
232 1.1 christos int oerrno, r = SSH_ERR_INTERNAL_ERROR;
233 1.1 christos struct sshbuf *kbuf = NULL, *req = NULL, *resp = NULL;
234 1.1 christos
235 1.1 christos *sigp = NULL;
236 1.1 christos *lenp = 0;
237 1.1 christos
238 1.1 christos if ((kbuf = sshbuf_new()) == NULL ||
239 1.1 christos (req = sshbuf_new()) == NULL) {
240 1.1 christos r = SSH_ERR_ALLOC_FAIL;
241 1.1 christos goto out;
242 1.1 christos }
243 1.1 christos
244 1.1 christos if ((r = sshkey_private_serialize(key, kbuf)) != 0) {
245 1.1.1.2 christos error_fr(r, "encode key");
246 1.1 christos goto out;
247 1.1 christos }
248 1.1 christos if ((r = sshbuf_put_stringb(req, kbuf)) != 0 ||
249 1.1 christos (r = sshbuf_put_cstring(req, provider)) != 0 ||
250 1.1 christos (r = sshbuf_put_string(req, data, datalen)) != 0 ||
251 1.1 christos (r = sshbuf_put_cstring(req, NULL)) != 0 || /* alg */
252 1.1 christos (r = sshbuf_put_u32(req, compat)) != 0 ||
253 1.1 christos (r = sshbuf_put_cstring(req, pin)) != 0) {
254 1.1.1.2 christos error_fr(r, "compose");
255 1.1 christos goto out;
256 1.1 christos }
257 1.1 christos
258 1.1 christos if ((r = client_converse(req, &resp, SSH_SK_HELPER_SIGN)) != 0)
259 1.1 christos goto out;
260 1.1 christos
261 1.1 christos if ((r = sshbuf_get_string(resp, sigp, lenp)) != 0) {
262 1.1.1.2 christos error_fr(r, "parse signature");
263 1.1 christos r = SSH_ERR_INVALID_FORMAT;
264 1.1 christos goto out;
265 1.1 christos }
266 1.1 christos if (sshbuf_len(resp) != 0) {
267 1.1.1.2 christos error_f("trailing data in response");
268 1.1 christos r = SSH_ERR_INVALID_FORMAT;
269 1.1 christos goto out;
270 1.1 christos }
271 1.1 christos /* success */
272 1.1 christos r = 0;
273 1.1 christos out:
274 1.1 christos oerrno = errno;
275 1.1 christos if (r != 0) {
276 1.1 christos freezero(*sigp, *lenp);
277 1.1 christos *sigp = NULL;
278 1.1 christos *lenp = 0;
279 1.1 christos }
280 1.1 christos sshbuf_free(kbuf);
281 1.1 christos sshbuf_free(req);
282 1.1 christos sshbuf_free(resp);
283 1.1 christos errno = oerrno;
284 1.1 christos return r;
285 1.1 christos }
286 1.1 christos
287 1.1 christos int
288 1.1 christos sshsk_enroll(int type, const char *provider_path, const char *device,
289 1.1 christos const char *application, const char *userid, uint8_t flags,
290 1.1 christos const char *pin, struct sshbuf *challenge_buf,
291 1.1 christos struct sshkey **keyp, struct sshbuf *attest)
292 1.1 christos {
293 1.1 christos int oerrno, r = SSH_ERR_INTERNAL_ERROR;
294 1.1 christos struct sshbuf *kbuf = NULL, *abuf = NULL, *req = NULL, *resp = NULL;
295 1.1 christos struct sshkey *key = NULL;
296 1.1 christos
297 1.1 christos *keyp = NULL;
298 1.1 christos if (attest != NULL)
299 1.1 christos sshbuf_reset(attest);
300 1.1 christos
301 1.1 christos if (type < 0)
302 1.1 christos return SSH_ERR_INVALID_ARGUMENT;
303 1.1 christos
304 1.1 christos if ((abuf = sshbuf_new()) == NULL ||
305 1.1 christos (kbuf = sshbuf_new()) == NULL ||
306 1.1 christos (req = sshbuf_new()) == NULL) {
307 1.1 christos r = SSH_ERR_ALLOC_FAIL;
308 1.1 christos goto out;
309 1.1 christos }
310 1.1 christos
311 1.1 christos if ((r = sshbuf_put_u32(req, (u_int)type)) != 0 ||
312 1.1 christos (r = sshbuf_put_cstring(req, provider_path)) != 0 ||
313 1.1 christos (r = sshbuf_put_cstring(req, device)) != 0 ||
314 1.1 christos (r = sshbuf_put_cstring(req, application)) != 0 ||
315 1.1 christos (r = sshbuf_put_cstring(req, userid)) != 0 ||
316 1.1 christos (r = sshbuf_put_u8(req, flags)) != 0 ||
317 1.1 christos (r = sshbuf_put_cstring(req, pin)) != 0 ||
318 1.1 christos (r = sshbuf_put_stringb(req, challenge_buf)) != 0) {
319 1.1.1.2 christos error_fr(r, "compose");
320 1.1 christos goto out;
321 1.1 christos }
322 1.1 christos
323 1.1 christos if ((r = client_converse(req, &resp, SSH_SK_HELPER_ENROLL)) != 0)
324 1.1 christos goto out;
325 1.1 christos
326 1.1 christos if ((r = sshbuf_get_stringb(resp, kbuf)) != 0 ||
327 1.1 christos (r = sshbuf_get_stringb(resp, abuf)) != 0) {
328 1.1.1.2 christos error_fr(r, "parse");
329 1.1 christos r = SSH_ERR_INVALID_FORMAT;
330 1.1 christos goto out;
331 1.1 christos }
332 1.1 christos if (sshbuf_len(resp) != 0) {
333 1.1.1.2 christos error_f("trailing data in response");
334 1.1 christos r = SSH_ERR_INVALID_FORMAT;
335 1.1 christos goto out;
336 1.1 christos }
337 1.1 christos if ((r = sshkey_private_deserialize(kbuf, &key)) != 0) {
338 1.1.1.2 christos error_fr(r, "encode");
339 1.1 christos goto out;
340 1.1 christos }
341 1.1 christos if (attest != NULL && (r = sshbuf_putb(attest, abuf)) != 0) {
342 1.1.1.2 christos error_fr(r, "encode attestation information");
343 1.1 christos goto out;
344 1.1 christos }
345 1.1 christos
346 1.1 christos /* success */
347 1.1 christos r = 0;
348 1.1 christos *keyp = key;
349 1.1 christos key = NULL;
350 1.1 christos out:
351 1.1 christos oerrno = errno;
352 1.1 christos sshkey_free(key);
353 1.1 christos sshbuf_free(kbuf);
354 1.1 christos sshbuf_free(abuf);
355 1.1 christos sshbuf_free(req);
356 1.1 christos sshbuf_free(resp);
357 1.1 christos errno = oerrno;
358 1.1 christos return r;
359 1.1 christos }
360 1.1 christos
361 1.1.1.4 christos static void
362 1.1.1.4 christos sshsk_free_resident_key(struct sshsk_resident_key *srk)
363 1.1.1.4 christos {
364 1.1.1.4 christos if (srk == NULL)
365 1.1.1.4 christos return;
366 1.1.1.4 christos sshkey_free(srk->key);
367 1.1.1.4 christos freezero(srk->user_id, srk->user_id_len);
368 1.1.1.4 christos free(srk);
369 1.1.1.4 christos }
370 1.1.1.4 christos
371 1.1.1.4 christos
372 1.1.1.4 christos void
373 1.1.1.4 christos sshsk_free_resident_keys(struct sshsk_resident_key **srks, size_t nsrks)
374 1.1.1.4 christos {
375 1.1.1.4 christos size_t i;
376 1.1.1.4 christos
377 1.1.1.4 christos if (srks == NULL || nsrks == 0)
378 1.1.1.4 christos return;
379 1.1.1.4 christos
380 1.1.1.4 christos for (i = 0; i < nsrks; i++)
381 1.1.1.4 christos sshsk_free_resident_key(srks[i]);
382 1.1.1.4 christos free(srks);
383 1.1.1.4 christos }
384 1.1.1.4 christos
385 1.1 christos int
386 1.1 christos sshsk_load_resident(const char *provider_path, const char *device,
387 1.1.1.4 christos const char *pin, u_int flags, struct sshsk_resident_key ***srksp,
388 1.1.1.4 christos size_t *nsrksp)
389 1.1 christos {
390 1.1 christos int oerrno, r = SSH_ERR_INTERNAL_ERROR;
391 1.1 christos struct sshbuf *kbuf = NULL, *req = NULL, *resp = NULL;
392 1.1.1.4 christos struct sshkey *key = NULL;
393 1.1.1.4 christos struct sshsk_resident_key *srk = NULL, **srks = NULL, **tmp;
394 1.1.1.4 christos u_char *userid = NULL;
395 1.1.1.4 christos size_t userid_len = 0, nsrks = 0;
396 1.1 christos
397 1.1.1.4 christos *srksp = NULL;
398 1.1.1.4 christos *nsrksp = 0;
399 1.1 christos
400 1.1.1.4 christos if ((kbuf = sshbuf_new()) == NULL ||
401 1.1 christos (req = sshbuf_new()) == NULL) {
402 1.1 christos r = SSH_ERR_ALLOC_FAIL;
403 1.1 christos goto out;
404 1.1 christos }
405 1.1 christos
406 1.1 christos if ((r = sshbuf_put_cstring(req, provider_path)) != 0 ||
407 1.1 christos (r = sshbuf_put_cstring(req, device)) != 0 ||
408 1.1.1.4 christos (r = sshbuf_put_cstring(req, pin)) != 0 ||
409 1.1.1.4 christos (r = sshbuf_put_u32(req, flags)) != 0) {
410 1.1.1.2 christos error_fr(r, "compose");
411 1.1 christos goto out;
412 1.1 christos }
413 1.1 christos
414 1.1 christos if ((r = client_converse(req, &resp, SSH_SK_HELPER_LOAD_RESIDENT)) != 0)
415 1.1 christos goto out;
416 1.1 christos
417 1.1 christos while (sshbuf_len(resp) != 0) {
418 1.1.1.4 christos /* key, comment, user_id */
419 1.1 christos if ((r = sshbuf_get_stringb(resp, kbuf)) != 0 ||
420 1.1.1.4 christos (r = sshbuf_get_cstring(resp, NULL, NULL)) != 0 ||
421 1.1.1.4 christos (r = sshbuf_get_string(resp, &userid, &userid_len)) != 0) {
422 1.1.1.4 christos error_fr(r, "parse");
423 1.1 christos r = SSH_ERR_INVALID_FORMAT;
424 1.1 christos goto out;
425 1.1 christos }
426 1.1 christos if ((r = sshkey_private_deserialize(kbuf, &key)) != 0) {
427 1.1.1.2 christos error_fr(r, "decode key");
428 1.1 christos goto out;
429 1.1 christos }
430 1.1.1.4 christos if ((srk = calloc(1, sizeof(*srk))) == NULL) {
431 1.1.1.4 christos error_f("calloc failed");
432 1.1 christos goto out;
433 1.1 christos }
434 1.1.1.4 christos srk->key = key;
435 1.1 christos key = NULL;
436 1.1.1.4 christos srk->user_id = userid;
437 1.1.1.4 christos srk->user_id_len = userid_len;
438 1.1.1.4 christos userid = NULL;
439 1.1.1.4 christos userid_len = 0;
440 1.1.1.4 christos if ((tmp = recallocarray(srks, nsrks, nsrks + 1,
441 1.1.1.4 christos sizeof(*srks))) == NULL) {
442 1.1.1.4 christos error_f("recallocarray keys failed");
443 1.1.1.4 christos goto out;
444 1.1.1.4 christos }
445 1.1.1.4 christos debug_f("srks[%zu]: %s %s uidlen %zu", nsrks,
446 1.1.1.4 christos sshkey_type(srk->key), srk->key->sk_application,
447 1.1.1.4 christos srk->user_id_len);
448 1.1.1.4 christos srks = tmp;
449 1.1.1.4 christos srks[nsrks++] = srk;
450 1.1.1.4 christos srk = NULL;
451 1.1 christos }
452 1.1 christos
453 1.1 christos /* success */
454 1.1 christos r = 0;
455 1.1.1.4 christos *srksp = srks;
456 1.1.1.4 christos *nsrksp = nsrks;
457 1.1.1.4 christos srks = NULL;
458 1.1.1.4 christos nsrks = 0;
459 1.1 christos out:
460 1.1 christos oerrno = errno;
461 1.1.1.4 christos sshsk_free_resident_key(srk);
462 1.1.1.4 christos sshsk_free_resident_keys(srks, nsrks);
463 1.1.1.4 christos freezero(userid, userid_len);
464 1.1 christos sshkey_free(key);
465 1.1 christos sshbuf_free(kbuf);
466 1.1 christos sshbuf_free(req);
467 1.1 christos sshbuf_free(resp);
468 1.1 christos errno = oerrno;
469 1.1 christos return r;
470 1.1 christos }
471