summaryrefslogtreecommitdiff
path: root/kexgexs.c
diff options
context:
space:
mode:
Diffstat (limited to 'kexgexs.c')
-rw-r--r--kexgexs.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/kexgexs.c b/kexgexs.c
index f6983fd69..dc9c0bc60 100644
--- a/kexgexs.c
+++ b/kexgexs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexgexs.c,v 1.33 2018/04/10 00:10:49 djm Exp $ */ 1/* $OpenBSD: kexgexs.c,v 1.35 2018/10/04 00:04:41 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2000 Niels Provos. All rights reserved.
4 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * Copyright (c) 2001 Markus Friedl. All rights reserved.
@@ -36,6 +36,8 @@
36 36
37#include <openssl/dh.h> 37#include <openssl/dh.h>
38 38
39#include "openbsd-compat/openssl-compat.h"
40
39#include "sshkey.h" 41#include "sshkey.h"
40#include "cipher.h" 42#include "cipher.h"
41#include "digest.h" 43#include "digest.h"
@@ -72,6 +74,7 @@ input_kex_dh_gex_request(int type, u_int32_t seq, struct ssh *ssh)
72 struct kex *kex = ssh->kex; 74 struct kex *kex = ssh->kex;
73 int r; 75 int r;
74 u_int min = 0, max = 0, nbits = 0; 76 u_int min = 0, max = 0, nbits = 0;
77 const BIGNUM *dh_p, *dh_g;
75 78
76 debug("SSH2_MSG_KEX_DH_GEX_REQUEST received"); 79 debug("SSH2_MSG_KEX_DH_GEX_REQUEST received");
77 if ((r = sshpkt_get_u32(ssh, &min)) != 0 || 80 if ((r = sshpkt_get_u32(ssh, &min)) != 0 ||
@@ -101,9 +104,10 @@ input_kex_dh_gex_request(int type, u_int32_t seq, struct ssh *ssh)
101 goto out; 104 goto out;
102 } 105 }
103 debug("SSH2_MSG_KEX_DH_GEX_GROUP sent"); 106 debug("SSH2_MSG_KEX_DH_GEX_GROUP sent");
107 DH_get0_pqg(kex->dh, &dh_p, NULL, &dh_g);
104 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_GROUP)) != 0 || 108 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_GROUP)) != 0 ||
105 (r = sshpkt_put_bignum2(ssh, kex->dh->p)) != 0 || 109 (r = sshpkt_put_bignum2(ssh, dh_p)) != 0 ||
106 (r = sshpkt_put_bignum2(ssh, kex->dh->g)) != 0 || 110 (r = sshpkt_put_bignum2(ssh, dh_g)) != 0 ||
107 (r = sshpkt_send(ssh)) != 0) 111 (r = sshpkt_send(ssh)) != 0)
108 goto out; 112 goto out;
109 113
@@ -123,6 +127,7 @@ input_kex_dh_gex_init(int type, u_int32_t seq, struct ssh *ssh)
123{ 127{
124 struct kex *kex = ssh->kex; 128 struct kex *kex = ssh->kex;
125 BIGNUM *shared_secret = NULL, *dh_client_pub = NULL; 129 BIGNUM *shared_secret = NULL, *dh_client_pub = NULL;
130 const BIGNUM *pub_key, *dh_p, *dh_g;
126 struct sshkey *server_host_public, *server_host_private; 131 struct sshkey *server_host_public, *server_host_private;
127 u_char *kbuf = NULL, *signature = NULL, *server_host_key_blob = NULL; 132 u_char *kbuf = NULL, *signature = NULL, *server_host_key_blob = NULL;
128 u_char hash[SSH_DIGEST_MAX_LENGTH]; 133 u_char hash[SSH_DIGEST_MAX_LENGTH];
@@ -153,17 +158,17 @@ input_kex_dh_gex_init(int type, u_int32_t seq, struct ssh *ssh)
153 (r = sshpkt_get_end(ssh)) != 0) 158 (r = sshpkt_get_end(ssh)) != 0)
154 goto out; 159 goto out;
155 160
161 DH_get0_key(kex->dh, &pub_key, NULL);
162 DH_get0_pqg(kex->dh, &dh_p, NULL, &dh_g);
163
156#ifdef DEBUG_KEXDH 164#ifdef DEBUG_KEXDH
157 fprintf(stderr, "dh_client_pub= "); 165 fprintf(stderr, "dh_client_pub= ");
158 BN_print_fp(stderr, dh_client_pub); 166 BN_print_fp(stderr, dh_client_pub);
159 fprintf(stderr, "\n"); 167 fprintf(stderr, "\n");
160 debug("bits %d", BN_num_bits(dh_client_pub)); 168 debug("bits %d", BN_num_bits(dh_client_pub));
161#endif
162
163#ifdef DEBUG_KEXDH
164 DHparams_print_fp(stderr, kex->dh); 169 DHparams_print_fp(stderr, kex->dh);
165 fprintf(stderr, "pub= "); 170 fprintf(stderr, "pub= ");
166 BN_print_fp(stderr, kex->dh->pub_key); 171 BN_print_fp(stderr, pub_key);
167 fprintf(stderr, "\n"); 172 fprintf(stderr, "\n");
168#endif 173#endif
169 if (!dh_pub_is_valid(kex->dh, dh_client_pub)) { 174 if (!dh_pub_is_valid(kex->dh, dh_client_pub)) {
@@ -199,9 +204,9 @@ input_kex_dh_gex_init(int type, u_int32_t seq, struct ssh *ssh)
199 sshbuf_ptr(kex->my), sshbuf_len(kex->my), 204 sshbuf_ptr(kex->my), sshbuf_len(kex->my),
200 server_host_key_blob, sbloblen, 205 server_host_key_blob, sbloblen,
201 kex->min, kex->nbits, kex->max, 206 kex->min, kex->nbits, kex->max,
202 kex->dh->p, kex->dh->g, 207 dh_p, dh_g,
203 dh_client_pub, 208 dh_client_pub,
204 kex->dh->pub_key, 209 pub_key,
205 shared_secret, 210 shared_secret,
206 hash, &hashlen)) != 0) 211 hash, &hashlen)) != 0)
207 goto out; 212 goto out;
@@ -227,7 +232,7 @@ input_kex_dh_gex_init(int type, u_int32_t seq, struct ssh *ssh)
227 /* send server hostkey, DH pubkey 'f' and signed H */ 232 /* send server hostkey, DH pubkey 'f' and signed H */
228 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REPLY)) != 0 || 233 if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REPLY)) != 0 ||
229 (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 || 234 (r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
230 (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 || /* f */ 235 (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */
231 (r = sshpkt_put_string(ssh, signature, slen)) != 0 || 236 (r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
232 (r = sshpkt_send(ssh)) != 0) 237 (r = sshpkt_send(ssh)) != 0)
233 goto out; 238 goto out;
@@ -235,6 +240,7 @@ input_kex_dh_gex_init(int type, u_int32_t seq, struct ssh *ssh)
235 if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) == 0) 240 if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) == 0)
236 r = kex_send_newkeys(ssh); 241 r = kex_send_newkeys(ssh);
237 out: 242 out:
243 explicit_bzero(hash, sizeof(hash));
238 DH_free(kex->dh); 244 DH_free(kex->dh);
239 kex->dh = NULL; 245 kex->dh = NULL;
240 BN_clear_free(dh_client_pub); 246 BN_clear_free(dh_client_pub);