kexgexc.c (126274) | kexgexc.c (157016) |
---|---|
1/* 2 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "includes.h" | 1/* 2 * Copyright (c) 2000 Niels Provos. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include "includes.h" |
27RCSID("$OpenBSD: kexgexc.c,v 1.2 2003/12/08 11:00:47 markus Exp $"); | 27RCSID("$OpenBSD: kexgexc.c,v 1.3 2005/11/04 05:15:59 djm Exp $"); |
28 29#include "xmalloc.h" 30#include "key.h" 31#include "kex.h" 32#include "log.h" 33#include "packet.h" 34#include "dh.h" 35#include "ssh2.h" 36#include "compat.h" 37 38void 39kexgex_client(Kex *kex) 40{ 41 BIGNUM *dh_server_pub = NULL, *shared_secret = NULL; 42 BIGNUM *p = NULL, *g = NULL; 43 Key *server_host_key; 44 u_char *kbuf, *hash, *signature = NULL, *server_host_key_blob = NULL; | 28 29#include "xmalloc.h" 30#include "key.h" 31#include "kex.h" 32#include "log.h" 33#include "packet.h" 34#include "dh.h" 35#include "ssh2.h" 36#include "compat.h" 37 38void 39kexgex_client(Kex *kex) 40{ 41 BIGNUM *dh_server_pub = NULL, *shared_secret = NULL; 42 BIGNUM *p = NULL, *g = NULL; 43 Key *server_host_key; 44 u_char *kbuf, *hash, *signature = NULL, *server_host_key_blob = NULL; |
45 u_int klen, kout, slen, sbloblen; | 45 u_int klen, kout, slen, sbloblen, hashlen; |
46 int min, max, nbits; 47 DH *dh; 48 49 nbits = dh_estimate(kex->we_need * 8); 50 51 if (datafellows & SSH_OLD_DHGEX) { 52 /* Old GEX request */ 53 packet_start(SSH2_MSG_KEX_DH_GEX_REQUEST_OLD); --- 96 unchanged lines hidden (view full) --- 150 BN_bin2bn(kbuf, kout, shared_secret); 151 memset(kbuf, 0, klen); 152 xfree(kbuf); 153 154 if (datafellows & SSH_OLD_DHGEX) 155 min = max = -1; 156 157 /* calc and verify H */ | 46 int min, max, nbits; 47 DH *dh; 48 49 nbits = dh_estimate(kex->we_need * 8); 50 51 if (datafellows & SSH_OLD_DHGEX) { 52 /* Old GEX request */ 53 packet_start(SSH2_MSG_KEX_DH_GEX_REQUEST_OLD); --- 96 unchanged lines hidden (view full) --- 150 BN_bin2bn(kbuf, kout, shared_secret); 151 memset(kbuf, 0, klen); 152 xfree(kbuf); 153 154 if (datafellows & SSH_OLD_DHGEX) 155 min = max = -1; 156 157 /* calc and verify H */ |
158 hash = kexgex_hash( | 158 kexgex_hash( 159 kex->evp_md, |
159 kex->client_version_string, 160 kex->server_version_string, 161 buffer_ptr(&kex->my), buffer_len(&kex->my), 162 buffer_ptr(&kex->peer), buffer_len(&kex->peer), 163 server_host_key_blob, sbloblen, 164 min, nbits, max, 165 dh->p, dh->g, 166 dh->pub_key, 167 dh_server_pub, | 160 kex->client_version_string, 161 kex->server_version_string, 162 buffer_ptr(&kex->my), buffer_len(&kex->my), 163 buffer_ptr(&kex->peer), buffer_len(&kex->peer), 164 server_host_key_blob, sbloblen, 165 min, nbits, max, 166 dh->p, dh->g, 167 dh->pub_key, 168 dh_server_pub, |
168 shared_secret | 169 shared_secret, 170 &hash, &hashlen |
169 ); | 171 ); |
172 |
|
170 /* have keys, free DH */ 171 DH_free(dh); 172 xfree(server_host_key_blob); 173 BN_clear_free(dh_server_pub); 174 | 173 /* have keys, free DH */ 174 DH_free(dh); 175 xfree(server_host_key_blob); 176 BN_clear_free(dh_server_pub); 177 |
175 if (key_verify(server_host_key, signature, slen, hash, 20) != 1) | 178 if (key_verify(server_host_key, signature, slen, hash, hashlen) != 1) |
176 fatal("key_verify failed for server_host_key"); 177 key_free(server_host_key); 178 xfree(signature); 179 180 /* save session id */ 181 if (kex->session_id == NULL) { | 179 fatal("key_verify failed for server_host_key"); 180 key_free(server_host_key); 181 xfree(signature); 182 183 /* save session id */ 184 if (kex->session_id == NULL) { |
182 kex->session_id_len = 20; | 185 kex->session_id_len = hashlen; |
183 kex->session_id = xmalloc(kex->session_id_len); 184 memcpy(kex->session_id, hash, kex->session_id_len); 185 } | 186 kex->session_id = xmalloc(kex->session_id_len); 187 memcpy(kex->session_id, hash, kex->session_id_len); 188 } |
186 kex_derive_keys(kex, hash, shared_secret); | 189 kex_derive_keys(kex, hash, hashlen, shared_secret); |
187 BN_clear_free(shared_secret); 188 189 kex_finish(kex); 190} | 190 BN_clear_free(shared_secret); 191 192 kex_finish(kex); 193} |