summaryrefslogtreecommitdiff
path: root/authfd.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-08-24 12:49:36 +0100
committerColin Watson <cjwatson@debian.org>2018-08-24 12:49:36 +0100
commite6547182a54f0f268ee36e7c99319eeddffbaff2 (patch)
tree417527229ad3f3764ba71ea383f478a168895087 /authfd.c
parented6ae9c1a014a08ff5db3d768f01f2e427eeb476 (diff)
parent71508e06fab14bc415a79a08f5535ad7bffa93d9 (diff)
Import openssh_7.8p1.orig.tar.gz
Diffstat (limited to 'authfd.c')
-rw-r--r--authfd.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/authfd.c b/authfd.c
index 1eff7ba94..ecdd869ab 100644
--- a/authfd.c
+++ b/authfd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfd.c,v 1.108 2018/02/23 15:58:37 markus Exp $ */ 1/* $OpenBSD: authfd.c,v 1.111 2018/07/09 21:59:10 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -133,7 +133,7 @@ ssh_request_reply(int sock, struct sshbuf *request, struct sshbuf *reply)
133 133
134 /* Send the length and then the packet to the agent. */ 134 /* Send the length and then the packet to the agent. */
135 if (atomicio(vwrite, sock, buf, 4) != 4 || 135 if (atomicio(vwrite, sock, buf, 4) != 4 ||
136 atomicio(vwrite, sock, (u_char *)sshbuf_ptr(request), 136 atomicio(vwrite, sock, sshbuf_mutable_ptr(request),
137 sshbuf_len(request)) != sshbuf_len(request)) 137 sshbuf_len(request)) != sshbuf_len(request))
138 return SSH_ERR_AGENT_COMMUNICATION; 138 return SSH_ERR_AGENT_COMMUNICATION;
139 /* 139 /*
@@ -323,7 +323,7 @@ ssh_free_identitylist(struct ssh_identitylist *idl)
323 */ 323 */
324 324
325 325
326/* encode signature algoritm in flag bits, so we can keep the msg format */ 326/* encode signature algorithm in flag bits, so we can keep the msg format */
327static u_int 327static u_int
328agent_encode_alg(const struct sshkey *key, const char *alg) 328agent_encode_alg(const struct sshkey *key, const char *alg)
329{ 329{
@@ -343,8 +343,8 @@ ssh_agent_sign(int sock, const struct sshkey *key,
343 const u_char *data, size_t datalen, const char *alg, u_int compat) 343 const u_char *data, size_t datalen, const char *alg, u_int compat)
344{ 344{
345 struct sshbuf *msg; 345 struct sshbuf *msg;
346 u_char *blob = NULL, type; 346 u_char *sig = NULL, type = 0;
347 size_t blen = 0, len = 0; 347 size_t len = 0;
348 u_int flags = 0; 348 u_int flags = 0;
349 int r = SSH_ERR_INTERNAL_ERROR; 349 int r = SSH_ERR_INTERNAL_ERROR;
350 350
@@ -355,11 +355,9 @@ ssh_agent_sign(int sock, const struct sshkey *key,
355 return SSH_ERR_INVALID_ARGUMENT; 355 return SSH_ERR_INVALID_ARGUMENT;
356 if ((msg = sshbuf_new()) == NULL) 356 if ((msg = sshbuf_new()) == NULL)
357 return SSH_ERR_ALLOC_FAIL; 357 return SSH_ERR_ALLOC_FAIL;
358 if ((r = sshkey_to_blob(key, &blob, &blen)) != 0)
359 goto out;
360 flags |= agent_encode_alg(key, alg); 358 flags |= agent_encode_alg(key, alg);
361 if ((r = sshbuf_put_u8(msg, SSH2_AGENTC_SIGN_REQUEST)) != 0 || 359 if ((r = sshbuf_put_u8(msg, SSH2_AGENTC_SIGN_REQUEST)) != 0 ||
362 (r = sshbuf_put_string(msg, blob, blen)) != 0 || 360 (r = sshkey_puts(key, msg)) != 0 ||
363 (r = sshbuf_put_string(msg, data, datalen)) != 0 || 361 (r = sshbuf_put_string(msg, data, datalen)) != 0 ||
364 (r = sshbuf_put_u32(msg, flags)) != 0) 362 (r = sshbuf_put_u32(msg, flags)) != 0)
365 goto out; 363 goto out;
@@ -374,15 +372,19 @@ ssh_agent_sign(int sock, const struct sshkey *key,
374 r = SSH_ERR_INVALID_FORMAT; 372 r = SSH_ERR_INVALID_FORMAT;
375 goto out; 373 goto out;
376 } 374 }
377 if ((r = sshbuf_get_string(msg, sigp, &len)) != 0) 375 if ((r = sshbuf_get_string(msg, &sig, &len)) != 0)
376 goto out;
377 /* Check what we actually got back from the agent. */
378 if ((r = sshkey_check_sigtype(sig, len, alg)) != 0)
378 goto out; 379 goto out;
380 /* success */
381 *sigp = sig;
379 *lenp = len; 382 *lenp = len;
383 sig = NULL;
384 len = 0;
380 r = 0; 385 r = 0;
381 out: 386 out:
382 if (blob != NULL) { 387 freezero(sig, len);
383 explicit_bzero(blob, blen);
384 free(blob);
385 }
386 sshbuf_free(msg); 388 sshbuf_free(msg);
387 return r; 389 return r;
388} 390}