=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/kexgexs.c,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- src/usr.bin/ssh/kexgexs.c 2019/01/21 10:05:09 1.41 +++ src/usr.bin/ssh/kexgexs.c 2019/01/23 00:30:41 1.42 @@ -1,4 +1,4 @@ -/* $OpenBSD: kexgexs.c,v 1.41 2019/01/21 10:05:09 djm Exp $ */ +/* $OpenBSD: kexgexs.c,v 1.42 2019/01/23 00:30:41 djm Exp $ */ /* * Copyright (c) 2000 Niels Provos. All rights reserved. * Copyright (c) 2001 Markus Friedl. All rights reserved. @@ -122,11 +122,11 @@ BIGNUM *dh_client_pub = NULL; const BIGNUM *pub_key, *dh_p, *dh_g; struct sshbuf *shared_secret = NULL; + struct sshbuf *server_host_key_blob = NULL; struct sshkey *server_host_public, *server_host_private; - u_char *signature = NULL, *server_host_key_blob = NULL; + u_char *signature = NULL; u_char hash[SSH_DIGEST_MAX_LENGTH]; - size_t sbloblen, slen; - size_t hashlen; + size_t slen, hashlen; int r; if ((r = kex_load_hostkey(ssh, &server_host_private, @@ -143,9 +143,12 @@ } if ((r = kex_dh_compute_key(kex, dh_client_pub, shared_secret)) != 0) goto out; - if ((r = sshkey_to_blob(server_host_public, &server_host_key_blob, - &sbloblen)) != 0) + if ((server_host_key_blob = sshbuf_new()) == NULL) { + r = SSH_ERR_ALLOC_FAIL; goto out; + } + if ((r = sshkey_putb(server_host_public, server_host_key_blob)) != 0) + goto out; /* calc H */ DH_get0_key(kex->dh, &pub_key, NULL); @@ -155,9 +158,9 @@ kex->hash_alg, kex->client_version, kex->server_version, - sshbuf_ptr(kex->peer), sshbuf_len(kex->peer), - sshbuf_ptr(kex->my), sshbuf_len(kex->my), - server_host_key_blob, sbloblen, + kex->peer, + kex->my, + server_host_key_blob, kex->min, kex->nbits, kex->max, dh_p, dh_g, dh_client_pub, @@ -173,7 +176,7 @@ /* send server hostkey, DH pubkey 'f' and signed H */ if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REPLY)) != 0 || - (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 || + (r = sshpkt_put_stringb(ssh, server_host_key_blob)) != 0 || (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */ (r = sshpkt_put_string(ssh, signature, slen)) != 0 || (r = sshpkt_send(ssh)) != 0) @@ -187,7 +190,7 @@ kex->dh = NULL; BN_clear_free(dh_client_pub); sshbuf_free(shared_secret); - free(server_host_key_blob); + sshbuf_free(server_host_key_blob); free(signature); return r; }