diff options
author | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:38:40 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:38:40 +0000 |
commit | 1b816ea846aca3ee89e7995373ace609e9518424 (patch) | |
tree | b41cdc8495cae7fa9c2e0f98a5f2e71656b61f9a /kexgsss.c | |
parent | fa585019a79ebcb4e0202b1c33f87ff1c5c9ce1c (diff) | |
parent | 086ea76990b1e6287c24b6db74adffd4605eb3b0 (diff) |
import openssh-4.6p1-gsskex-20070312.patch
Diffstat (limited to 'kexgsss.c')
-rw-r--r-- | kexgsss.c | 71 |
1 files changed, 43 insertions, 28 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2001-2005 Simon Wilkinson. All rights reserved. | 2 | * Copyright (c) 2001-2006 Simon Wilkinson. All rights reserved. |
3 | * | 3 | * |
4 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
@@ -26,17 +26,20 @@ | |||
26 | 26 | ||
27 | #ifdef GSSAPI | 27 | #ifdef GSSAPI |
28 | 28 | ||
29 | #include <string.h> | ||
30 | |||
29 | #include <openssl/crypto.h> | 31 | #include <openssl/crypto.h> |
30 | #include <openssl/bn.h> | 32 | #include <openssl/bn.h> |
31 | 33 | ||
32 | #include "xmalloc.h" | 34 | #include "xmalloc.h" |
33 | #include "buffer.h" | 35 | #include "buffer.h" |
34 | #include "bufaux.h" | 36 | #include "ssh2.h" |
37 | #include "key.h" | ||
38 | #include "cipher.h" | ||
35 | #include "kex.h" | 39 | #include "kex.h" |
36 | #include "log.h" | 40 | #include "log.h" |
37 | #include "packet.h" | 41 | #include "packet.h" |
38 | #include "dh.h" | 42 | #include "dh.h" |
39 | #include "ssh2.h" | ||
40 | #include "ssh-gss.h" | 43 | #include "ssh-gss.h" |
41 | #include "monitor_wrap.h" | 44 | #include "monitor_wrap.h" |
42 | 45 | ||
@@ -63,29 +66,35 @@ kexgss_server(Kex *kex) | |||
63 | BIGNUM *shared_secret = NULL; | 66 | BIGNUM *shared_secret = NULL; |
64 | BIGNUM *dh_client_pub = NULL; | 67 | BIGNUM *dh_client_pub = NULL; |
65 | int type = 0; | 68 | int type = 0; |
66 | int gex; | ||
67 | gss_OID oid; | 69 | gss_OID oid; |
68 | 70 | ||
69 | /* Initialise GSSAPI */ | 71 | /* Initialise GSSAPI */ |
70 | 72 | ||
71 | /* If we're rekeying, privsep means that some of the private structures | 73 | /* If we're rekeying, privsep means that some of the private structures |
72 | * in the GSSAPI code are no longer available. This kludges them back | 74 | * in the GSSAPI code are no longer available. This kludges them back |
73 | * into life | 75 | * into life |
74 | */ | 76 | */ |
75 | if (!ssh_gssapi_oid_table_ok()) | 77 | if (!ssh_gssapi_oid_table_ok()) |
76 | ssh_gssapi_server_mechanisms(); | 78 | ssh_gssapi_server_mechanisms(); |
77 | 79 | ||
78 | debug2("%s: Identifying %s", __func__, kex->name); | 80 | debug2("%s: Identifying %s", __func__, kex->name); |
79 | oid = ssh_gssapi_id_kex(NULL, kex->name, &gex); | 81 | oid = ssh_gssapi_id_kex(NULL, kex->name, kex->kex_type); |
80 | if (oid == NULL) | 82 | if (oid == GSS_C_NO_OID) |
81 | fatal("Unknown gssapi mechanism"); | 83 | fatal("Unknown gssapi mechanism"); |
82 | 84 | ||
83 | debug2("%s: Acquiring credentials", __func__); | 85 | debug2("%s: Acquiring credentials", __func__); |
84 | 86 | ||
85 | if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid)))) | 87 | if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid)))) |
86 | fatal("Unable to acquire credentials for the server"); | 88 | fatal("Unable to acquire credentials for the server"); |
87 | 89 | ||
88 | if (gex) { | 90 | switch (kex->kex_type) { |
91 | case KEX_GSS_GRP1_SHA1: | ||
92 | dh = dh_new_group1(); | ||
93 | break; | ||
94 | case KEX_GSS_GRP14_SHA1: | ||
95 | dh = dh_new_group14(); | ||
96 | break; | ||
97 | case KEX_GSS_GEX_SHA1: | ||
89 | debug("Doing group exchange"); | 98 | debug("Doing group exchange"); |
90 | packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ); | 99 | packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ); |
91 | min = packet_get_int(); | 100 | min = packet_get_int(); |
@@ -107,10 +116,11 @@ kexgss_server(Kex *kex) | |||
107 | packet_send(); | 116 | packet_send(); |
108 | 117 | ||
109 | packet_write_wait(); | 118 | packet_write_wait(); |
110 | 119 | break; | |
111 | } else { | 120 | default: |
112 | dh = dh_new_group1(); | 121 | fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type); |
113 | } | 122 | } |
123 | |||
114 | dh_gen_key(dh, kex->we_need * 8); | 124 | dh_gen_key(dh, kex->we_need * 8); |
115 | 125 | ||
116 | do { | 126 | do { |
@@ -187,7 +197,19 @@ kexgss_server(Kex *kex) | |||
187 | memset(kbuf, 0, klen); | 197 | memset(kbuf, 0, klen); |
188 | xfree(kbuf); | 198 | xfree(kbuf); |
189 | 199 | ||
190 | if (gex) { | 200 | switch (kex->kex_type) { |
201 | case KEX_GSS_GRP1_SHA1: | ||
202 | case KEX_GSS_GRP14_SHA1: | ||
203 | kex_dh_hash( | ||
204 | kex->client_version_string, kex->server_version_string, | ||
205 | buffer_ptr(&kex->peer), buffer_len(&kex->peer), | ||
206 | buffer_ptr(&kex->my), buffer_len(&kex->my), | ||
207 | NULL, 0, /* Change this if we start sending host keys */ | ||
208 | dh_client_pub, dh->pub_key, shared_secret, | ||
209 | &hash, &hashlen | ||
210 | ); | ||
211 | break; | ||
212 | case KEX_GSS_GEX_SHA1: | ||
191 | kexgex_hash( | 213 | kexgex_hash( |
192 | kex->evp_md, | 214 | kex->evp_md, |
193 | kex->client_version_string, kex->server_version_string, | 215 | kex->client_version_string, kex->server_version_string, |
@@ -201,18 +223,11 @@ kexgss_server(Kex *kex) | |||
201 | shared_secret, | 223 | shared_secret, |
202 | &hash, &hashlen | 224 | &hash, &hashlen |
203 | ); | 225 | ); |
226 | break; | ||
227 | default: | ||
228 | fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type); | ||
204 | } | 229 | } |
205 | else { | 230 | |
206 | /* The GSSAPI hash is identical to the Diffie Helman one */ | ||
207 | kex_dh_hash( | ||
208 | kex->client_version_string, kex->server_version_string, | ||
209 | buffer_ptr(&kex->peer), buffer_len(&kex->peer), | ||
210 | buffer_ptr(&kex->my), buffer_len(&kex->my), | ||
211 | NULL, 0, /* Change this if we start sending host keys */ | ||
212 | dh_client_pub, dh->pub_key, shared_secret, | ||
213 | &hash, &hashlen | ||
214 | ); | ||
215 | } | ||
216 | BN_free(dh_client_pub); | 231 | BN_free(dh_client_pub); |
217 | 232 | ||
218 | if (kex->session_id == NULL) { | 233 | if (kex->session_id == NULL) { |
@@ -229,11 +244,11 @@ kexgss_server(Kex *kex) | |||
229 | 244 | ||
230 | packet_start(SSH2_MSG_KEXGSS_COMPLETE); | 245 | packet_start(SSH2_MSG_KEXGSS_COMPLETE); |
231 | packet_put_bignum2(dh->pub_key); | 246 | packet_put_bignum2(dh->pub_key); |
232 | packet_put_string((char *)msg_tok.value,msg_tok.length); | 247 | packet_put_string(msg_tok.value,msg_tok.length); |
233 | 248 | ||
234 | if (send_tok.length != 0) { | 249 | if (send_tok.length != 0) { |
235 | packet_put_char(1); /* true */ | 250 | packet_put_char(1); /* true */ |
236 | packet_put_string((char *)send_tok.value, send_tok.length); | 251 | packet_put_string(send_tok.value, send_tok.length); |
237 | } else { | 252 | } else { |
238 | packet_put_char(0); /* false */ | 253 | packet_put_char(0); /* false */ |
239 | } | 254 | } |