summaryrefslogtreecommitdiff
path: root/sshconnect2.c
diff options
context:
space:
mode:
Diffstat (limited to 'sshconnect2.c')
-rw-r--r--sshconnect2.c124
1 files changed, 120 insertions, 4 deletions
diff --git a/sshconnect2.c b/sshconnect2.c
index 7c369d743..11dd3e720 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -160,9 +160,34 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
160{ 160{
161 Kex *kex; 161 Kex *kex;
162 162
163#ifdef GSSAPI
164 char *orig = NULL, *gss = NULL;
165 char *gss_host = NULL;
166#endif
167
163 xxx_host = host; 168 xxx_host = host;
164 xxx_hostaddr = hostaddr; 169 xxx_hostaddr = hostaddr;
165 170
171#ifdef GSSAPI
172 if (options.gss_keyex) {
173 /* Add the GSSAPI mechanisms currently supported on this
174 * client to the key exchange algorithm proposal */
175 orig = myproposal[PROPOSAL_KEX_ALGS];
176
177 if (options.gss_trust_dns)
178 gss_host = (char *)get_canonical_hostname(1);
179 else
180 gss_host = host;
181
182 gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
183 if (gss) {
184 debug("Offering GSSAPI proposal: %s", gss);
185 xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
186 "%s,%s", gss, orig);
187 }
188 }
189#endif
190
166 if (options.ciphers == (char *)-1) { 191 if (options.ciphers == (char *)-1) {
167 logit("No valid ciphers for protocol version 2 given, using defaults."); 192 logit("No valid ciphers for protocol version 2 given, using defaults.");
168 options.ciphers = NULL; 193 options.ciphers = NULL;
@@ -197,6 +222,17 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
197 if (options.kex_algorithms != NULL) 222 if (options.kex_algorithms != NULL)
198 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms; 223 myproposal[PROPOSAL_KEX_ALGS] = options.kex_algorithms;
199 224
225#ifdef GSSAPI
226 /* If we've got GSSAPI algorithms, then we also support the
227 * 'null' hostkey, as a last resort */
228 if (options.gss_keyex && gss) {
229 orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
230 xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS],
231 "%s,null", orig);
232 xfree(gss);
233 }
234#endif
235
200 if (options.rekey_limit) 236 if (options.rekey_limit)
201 packet_set_rekey_limit((u_int32_t)options.rekey_limit); 237 packet_set_rekey_limit((u_int32_t)options.rekey_limit);
202 238
@@ -207,10 +243,30 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
207 kex->kex[KEX_DH_GEX_SHA1] = kexgex_client; 243 kex->kex[KEX_DH_GEX_SHA1] = kexgex_client;
208 kex->kex[KEX_DH_GEX_SHA256] = kexgex_client; 244 kex->kex[KEX_DH_GEX_SHA256] = kexgex_client;
209 kex->kex[KEX_ECDH_SHA2] = kexecdh_client; 245 kex->kex[KEX_ECDH_SHA2] = kexecdh_client;
246#ifdef GSSAPI
247 if (options.gss_keyex) {
248 kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
249 kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
250 kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
251 }
252#endif
210 kex->client_version_string=client_version_string; 253 kex->client_version_string=client_version_string;
211 kex->server_version_string=server_version_string; 254 kex->server_version_string=server_version_string;
212 kex->verify_host_key=&verify_host_key_callback; 255 kex->verify_host_key=&verify_host_key_callback;
213 256
257#ifdef GSSAPI
258 if (options.gss_keyex) {
259 kex->gss_deleg_creds = options.gss_deleg_creds;
260 kex->gss_trust_dns = options.gss_trust_dns;
261 kex->gss_client = options.gss_client_identity;
262 if (options.gss_server_identity) {
263 kex->gss_host = options.gss_server_identity;
264 } else {
265 kex->gss_host = gss_host;
266 }
267 }
268#endif
269
214 xxx_kex = kex; 270 xxx_kex = kex;
215 271
216 dispatch_run(DISPATCH_BLOCK, &kex->done, kex); 272 dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
@@ -305,6 +361,7 @@ void input_gssapi_token(int type, u_int32_t, void *);
305void input_gssapi_hash(int type, u_int32_t, void *); 361void input_gssapi_hash(int type, u_int32_t, void *);
306void input_gssapi_error(int, u_int32_t, void *); 362void input_gssapi_error(int, u_int32_t, void *);
307void input_gssapi_errtok(int, u_int32_t, void *); 363void input_gssapi_errtok(int, u_int32_t, void *);
364int userauth_gsskeyex(Authctxt *authctxt);
308#endif 365#endif
309 366
310void userauth(Authctxt *, char *); 367void userauth(Authctxt *, char *);
@@ -320,6 +377,11 @@ static char *authmethods_get(void);
320 377
321Authmethod authmethods[] = { 378Authmethod authmethods[] = {
322#ifdef GSSAPI 379#ifdef GSSAPI
380 {"gssapi-keyex",
381 userauth_gsskeyex,
382 NULL,
383 &options.gss_authentication,
384 NULL},
323 {"gssapi-with-mic", 385 {"gssapi-with-mic",
324 userauth_gssapi, 386 userauth_gssapi,
325 NULL, 387 NULL,
@@ -626,19 +688,31 @@ userauth_gssapi(Authctxt *authctxt)
626 static u_int mech = 0; 688 static u_int mech = 0;
627 OM_uint32 min; 689 OM_uint32 min;
628 int ok = 0; 690 int ok = 0;
691 const char *gss_host;
692
693 if (options.gss_server_identity)
694 gss_host = options.gss_server_identity;
695 else if (options.gss_trust_dns)
696 gss_host = get_canonical_hostname(1);
697 else
698 gss_host = authctxt->host;
629 699
630 /* Try one GSSAPI method at a time, rather than sending them all at 700 /* Try one GSSAPI method at a time, rather than sending them all at
631 * once. */ 701 * once. */
632 702
633 if (gss_supported == NULL) 703 if (gss_supported == NULL)
634 gss_indicate_mechs(&min, &gss_supported); 704 if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
705 gss_supported = NULL;
706 return 0;
707 }
635 708
636 /* Check to see if the mechanism is usable before we offer it */ 709 /* Check to see if the mechanism is usable before we offer it */
637 while (mech < gss_supported->count && !ok) { 710 while (mech < gss_supported->count && !ok) {
638 /* My DER encoding requires length<128 */ 711 /* My DER encoding requires length<128 */
639 if (gss_supported->elements[mech].length < 128 && 712 if (gss_supported->elements[mech].length < 128 &&
640 ssh_gssapi_check_mechanism(&gssctxt, 713 ssh_gssapi_check_mechanism(&gssctxt,
641 &gss_supported->elements[mech], authctxt->host)) { 714 &gss_supported->elements[mech], gss_host,
715 options.gss_client_identity)) {
642 ok = 1; /* Mechanism works */ 716 ok = 1; /* Mechanism works */
643 } else { 717 } else {
644 mech++; 718 mech++;
@@ -735,8 +809,8 @@ input_gssapi_response(int type, u_int32_t plen, void *ctxt)
735{ 809{
736 Authctxt *authctxt = ctxt; 810 Authctxt *authctxt = ctxt;
737 Gssctxt *gssctxt; 811 Gssctxt *gssctxt;
738 int oidlen; 812 u_int oidlen;
739 char *oidv; 813 u_char *oidv;
740 814
741 if (authctxt == NULL) 815 if (authctxt == NULL)
742 fatal("input_gssapi_response: no authentication context"); 816 fatal("input_gssapi_response: no authentication context");
@@ -846,6 +920,48 @@ input_gssapi_error(int type, u_int32_t plen, void *ctxt)
846 xfree(msg); 920 xfree(msg);
847 xfree(lang); 921 xfree(lang);
848} 922}
923
924int
925userauth_gsskeyex(Authctxt *authctxt)
926{
927 Buffer b;
928 gss_buffer_desc gssbuf;
929 gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
930 OM_uint32 ms;
931
932 static int attempt = 0;
933 if (attempt++ >= 1)
934 return (0);
935
936 if (gss_kex_context == NULL) {
937 debug("No valid Key exchange context");
938 return (0);
939 }
940
941 ssh_gssapi_buildmic(&b, authctxt->server_user, authctxt->service,
942 "gssapi-keyex");
943
944 gssbuf.value = buffer_ptr(&b);
945 gssbuf.length = buffer_len(&b);
946
947 if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
948 buffer_free(&b);
949 return (0);
950 }
951
952 packet_start(SSH2_MSG_USERAUTH_REQUEST);
953 packet_put_cstring(authctxt->server_user);
954 packet_put_cstring(authctxt->service);
955 packet_put_cstring(authctxt->method->name);
956 packet_put_string(mic.value, mic.length);
957 packet_send();
958
959 buffer_free(&b);
960 gss_release_buffer(&ms, &mic);
961
962 return (1);
963}
964
849#endif /* GSSAPI */ 965#endif /* GSSAPI */
850 966
851int 967int