Deleted Added
full compact
kexdhs.c (137015) kexdhs.c (157016)
1/*
2 * Copyright (c) 2001 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
1/*
2 * Copyright (c) 2001 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26RCSID("$OpenBSD: kexdhs.c,v 1.2 2004/06/13 12:53:24 djm Exp $");
26RCSID("$OpenBSD: kexdhs.c,v 1.3 2005/11/04 05:15:59 djm Exp $");
27
28#include "xmalloc.h"
29#include "key.h"
30#include "kex.h"
31#include "log.h"
32#include "packet.h"
33#include "dh.h"
34#include "ssh2.h"
35#include "monitor_wrap.h"
36
37void
38kexdh_server(Kex *kex)
39{
40 BIGNUM *shared_secret = NULL, *dh_client_pub = NULL;
41 DH *dh;
42 Key *server_host_key;
43 u_char *kbuf, *hash, *signature = NULL, *server_host_key_blob = NULL;
27
28#include "xmalloc.h"
29#include "key.h"
30#include "kex.h"
31#include "log.h"
32#include "packet.h"
33#include "dh.h"
34#include "ssh2.h"
35#include "monitor_wrap.h"
36
37void
38kexdh_server(Kex *kex)
39{
40 BIGNUM *shared_secret = NULL, *dh_client_pub = NULL;
41 DH *dh;
42 Key *server_host_key;
43 u_char *kbuf, *hash, *signature = NULL, *server_host_key_blob = NULL;
44 u_int sbloblen, klen, kout;
44 u_int sbloblen, klen, kout, hashlen;
45 u_int slen;
46
47 /* generate server DH public key */
48 switch (kex->kex_type) {
49 case KEX_DH_GRP1_SHA1:
50 dh = dh_new_group1();
51 break;
52 case KEX_DH_GRP14_SHA1:

--- 45 unchanged lines hidden (view full) ---

98 fatal("kexdh_server: BN_new failed");
99 BN_bin2bn(kbuf, kout, shared_secret);
100 memset(kbuf, 0, klen);
101 xfree(kbuf);
102
103 key_to_blob(server_host_key, &server_host_key_blob, &sbloblen);
104
105 /* calc H */
45 u_int slen;
46
47 /* generate server DH public key */
48 switch (kex->kex_type) {
49 case KEX_DH_GRP1_SHA1:
50 dh = dh_new_group1();
51 break;
52 case KEX_DH_GRP14_SHA1:

--- 45 unchanged lines hidden (view full) ---

98 fatal("kexdh_server: BN_new failed");
99 BN_bin2bn(kbuf, kout, shared_secret);
100 memset(kbuf, 0, klen);
101 xfree(kbuf);
102
103 key_to_blob(server_host_key, &server_host_key_blob, &sbloblen);
104
105 /* calc H */
106 hash = kex_dh_hash(
106 kex_dh_hash(
107 kex->client_version_string,
108 kex->server_version_string,
109 buffer_ptr(&kex->peer), buffer_len(&kex->peer),
110 buffer_ptr(&kex->my), buffer_len(&kex->my),
111 server_host_key_blob, sbloblen,
112 dh_client_pub,
113 dh->pub_key,
107 kex->client_version_string,
108 kex->server_version_string,
109 buffer_ptr(&kex->peer), buffer_len(&kex->peer),
110 buffer_ptr(&kex->my), buffer_len(&kex->my),
111 server_host_key_blob, sbloblen,
112 dh_client_pub,
113 dh->pub_key,
114 shared_secret
114 shared_secret,
115 &hash, &hashlen
115 );
116 BN_clear_free(dh_client_pub);
117
118 /* save session id := H */
116 );
117 BN_clear_free(dh_client_pub);
118
119 /* save session id := H */
119 /* XXX hashlen depends on KEX */
120 if (kex->session_id == NULL) {
120 if (kex->session_id == NULL) {
121 kex->session_id_len = 20;
121 kex->session_id_len = hashlen;
122 kex->session_id = xmalloc(kex->session_id_len);
123 memcpy(kex->session_id, hash, kex->session_id_len);
124 }
125
126 /* sign H */
122 kex->session_id = xmalloc(kex->session_id_len);
123 memcpy(kex->session_id, hash, kex->session_id_len);
124 }
125
126 /* sign H */
127 /* XXX hashlen depends on KEX */
128 PRIVSEP(key_sign(server_host_key, &signature, &slen, hash, 20));
127 PRIVSEP(key_sign(server_host_key, &signature, &slen, hash, hashlen));
129
130 /* destroy_sensitive_data(); */
131
132 /* send server hostkey, DH pubkey 'f' and singed H */
133 packet_start(SSH2_MSG_KEXDH_REPLY);
134 packet_put_string(server_host_key_blob, sbloblen);
135 packet_put_bignum2(dh->pub_key); /* f */
136 packet_put_string(signature, slen);
137 packet_send();
138
139 xfree(signature);
140 xfree(server_host_key_blob);
141 /* have keys, free DH */
142 DH_free(dh);
143
128
129 /* destroy_sensitive_data(); */
130
131 /* send server hostkey, DH pubkey 'f' and singed H */
132 packet_start(SSH2_MSG_KEXDH_REPLY);
133 packet_put_string(server_host_key_blob, sbloblen);
134 packet_put_bignum2(dh->pub_key); /* f */
135 packet_put_string(signature, slen);
136 packet_send();
137
138 xfree(signature);
139 xfree(server_host_key_blob);
140 /* have keys, free DH */
141 DH_free(dh);
142
144 kex_derive_keys(kex, hash, shared_secret);
143 kex_derive_keys(kex, hash, hashlen, shared_secret);
145 BN_clear_free(shared_secret);
146 kex_finish(kex);
147}
144 BN_clear_free(shared_secret);
145 kex_finish(kex);
146}