xref: /titanic_50/usr/src/cmd/ssh/libssh/common/kexgssc.c (revision c15e4e4b931f60f7af37864eb58a2cb72782abeb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
57c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
67c478bd9Sstevel@tonic-gate  * are met:
77c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
87c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
97c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
107c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
117c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
147c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
157c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
167c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
177c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
187c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
197c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
207c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
217c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
227c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate /*
25*c15e4e4bSjp161948  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include "includes.h"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef GSSAPI
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <openssl/crypto.h>
377c478bd9Sstevel@tonic-gate #include <openssl/bn.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include "xmalloc.h"
407c478bd9Sstevel@tonic-gate #include "buffer.h"
417c478bd9Sstevel@tonic-gate #include "bufaux.h"
427c478bd9Sstevel@tonic-gate #include "kex.h"
437c478bd9Sstevel@tonic-gate #include "log.h"
447c478bd9Sstevel@tonic-gate #include "packet.h"
457c478bd9Sstevel@tonic-gate #include "dh.h"
467c478bd9Sstevel@tonic-gate #include "canohost.h"
477c478bd9Sstevel@tonic-gate #include "ssh2.h"
487c478bd9Sstevel@tonic-gate #include "ssh-gss.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate extern char *xxx_host;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate Gssctxt *xxx_gssctxt;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate static void kexgss_verbose_cleanup(void *arg);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate void
kexgss_client(Kex * kex)577c478bd9Sstevel@tonic-gate kexgss_client(Kex *kex)
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	gss_buffer_desc gssbuf, send_tok, recv_tok, msg_tok;
607c478bd9Sstevel@tonic-gate 	gss_buffer_t token_ptr;
617c478bd9Sstevel@tonic-gate 	gss_OID mech = GSS_C_NULL_OID;
627c478bd9Sstevel@tonic-gate 	Gssctxt *ctxt = NULL;
637c478bd9Sstevel@tonic-gate 	OM_uint32 maj_status, min_status, smaj_status, smin_status;
647c478bd9Sstevel@tonic-gate 	unsigned int klen, kout;
657c478bd9Sstevel@tonic-gate 	DH *dh;
667c478bd9Sstevel@tonic-gate 	BIGNUM *dh_server_pub = 0;
677c478bd9Sstevel@tonic-gate 	BIGNUM *shared_secret = 0;
687c478bd9Sstevel@tonic-gate 	Key *server_host_key = NULL;
697c478bd9Sstevel@tonic-gate 	unsigned char *kbuf;
707c478bd9Sstevel@tonic-gate 	unsigned char *hash;
717c478bd9Sstevel@tonic-gate 	unsigned char *server_host_key_blob = NULL;
727c478bd9Sstevel@tonic-gate 	char *msg, *lang;
737c478bd9Sstevel@tonic-gate 	int type = 0;
747c478bd9Sstevel@tonic-gate 	int first = 1;
75*c15e4e4bSjp161948 	uint_t sbloblen = 0;
76*c15e4e4bSjp161948 	uint_t strlen;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	/* Map the negotiated kex name to a mech OID */
797c478bd9Sstevel@tonic-gate 	ssh_gssapi_oid_of_kexname(kex->name, &mech);
807c478bd9Sstevel@tonic-gate 	if (mech == GSS_C_NULL_OID)
817c478bd9Sstevel@tonic-gate 		fatal("Couldn't match the negotiated GSS key exchange");
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	ssh_gssapi_build_ctx(&ctxt, 1, mech);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	/* This code should match that in ssh_dh1_client */
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	/* Step 1 - e is dh->pub_key */
887c478bd9Sstevel@tonic-gate 	dh = dh_new_group1();
897c478bd9Sstevel@tonic-gate 	dh_gen_key(dh, kex->we_need * 8);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	/* This is f, we initialise it now to make life easier */
927c478bd9Sstevel@tonic-gate 	dh_server_pub = BN_new();
937c478bd9Sstevel@tonic-gate 	if (dh_server_pub == NULL) {
947c478bd9Sstevel@tonic-gate 		fatal("dh_server_pub == NULL");
957c478bd9Sstevel@tonic-gate 	}
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	token_ptr = GSS_C_NO_BUFFER;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	recv_tok.value = NULL;
1007c478bd9Sstevel@tonic-gate 	recv_tok.length = 0;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	do {
1037c478bd9Sstevel@tonic-gate 		debug("Calling gss_init_sec_context");
1047c478bd9Sstevel@tonic-gate 
105*c15e4e4bSjp161948 		maj_status = ssh_gssapi_init_ctx(ctxt, xxx_host,
106*c15e4e4bSjp161948 		    kex->options.gss_deleg_creds, token_ptr, &send_tok);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 		if (GSS_ERROR(maj_status)) {
1097c478bd9Sstevel@tonic-gate 			ssh_gssapi_error(ctxt, "performing GSS-API protected "
1107c478bd9Sstevel@tonic-gate 			    "SSHv2 key exchange");
1117c478bd9Sstevel@tonic-gate 			(void) gss_release_buffer(&min_status, &send_tok);
1127c478bd9Sstevel@tonic-gate 			packet_disconnect("A GSS-API error occurred during "
1137c478bd9Sstevel@tonic-gate 			    "GSS-API protected SSHv2 key exchange\n");
1147c478bd9Sstevel@tonic-gate 		}
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 		/* If we've got an old receive buffer get rid of it */
1177c478bd9Sstevel@tonic-gate 		if (token_ptr != GSS_C_NO_BUFFER) {
1187c478bd9Sstevel@tonic-gate 			/* We allocated recv_tok */
1197c478bd9Sstevel@tonic-gate 			xfree(recv_tok.value);
1207c478bd9Sstevel@tonic-gate 			recv_tok.value = NULL;
1217c478bd9Sstevel@tonic-gate 			recv_tok.length = 0;
1227c478bd9Sstevel@tonic-gate 			token_ptr = GSS_C_NO_BUFFER;
1237c478bd9Sstevel@tonic-gate 		}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 		if (maj_status == GSS_S_COMPLETE) {
1267c478bd9Sstevel@tonic-gate 			/* If mutual state flag is not true, kex fails */
1277c478bd9Sstevel@tonic-gate 			if (!(ctxt->flags & GSS_C_MUTUAL_FLAG)) {
1287c478bd9Sstevel@tonic-gate 				fatal("Mutual authentication failed");
1297c478bd9Sstevel@tonic-gate 			}
1307c478bd9Sstevel@tonic-gate 			/* If integ avail flag is not true kex fails */
1317c478bd9Sstevel@tonic-gate 			if (!(ctxt->flags & GSS_C_INTEG_FLAG)) {
1327c478bd9Sstevel@tonic-gate 				fatal("Integrity check failed");
1337c478bd9Sstevel@tonic-gate 			}
1347c478bd9Sstevel@tonic-gate 		}
1357c478bd9Sstevel@tonic-gate 
136*c15e4e4bSjp161948 		/*
137*c15e4e4bSjp161948 		 * If we have data to send, then the last message that we
138*c15e4e4bSjp161948 		 * received cannot have been a 'complete'.
139*c15e4e4bSjp161948 		 */
1407c478bd9Sstevel@tonic-gate 		if (send_tok.length != 0) {
1417c478bd9Sstevel@tonic-gate 			if (first) {
1427c478bd9Sstevel@tonic-gate 				packet_start(SSH2_MSG_KEXGSS_INIT);
1437c478bd9Sstevel@tonic-gate 				packet_put_string(send_tok.value,
1447c478bd9Sstevel@tonic-gate 				    send_tok.length);
1457c478bd9Sstevel@tonic-gate 				packet_put_bignum2(dh->pub_key);
1467c478bd9Sstevel@tonic-gate 				first = 0;
1477c478bd9Sstevel@tonic-gate 			} else {
1487c478bd9Sstevel@tonic-gate 				packet_start(SSH2_MSG_KEXGSS_CONTINUE);
1497c478bd9Sstevel@tonic-gate 				packet_put_string(send_tok.value,
1507c478bd9Sstevel@tonic-gate 				    send_tok.length);
1517c478bd9Sstevel@tonic-gate 			}
1527c478bd9Sstevel@tonic-gate 			(void) gss_release_buffer(&min_status, &send_tok);
1537c478bd9Sstevel@tonic-gate 			packet_send();
1547c478bd9Sstevel@tonic-gate 			packet_write_wait();
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 
157*c15e4e4bSjp161948 			/*
158*c15e4e4bSjp161948 			 * If we've sent them data, they'd better be polite and
159*c15e4e4bSjp161948 			 * reply.
160*c15e4e4bSjp161948 			 */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate next_packet:
1637c478bd9Sstevel@tonic-gate 			/*
1647c478bd9Sstevel@tonic-gate 			 * We need to catch connection closing w/o error
1657c478bd9Sstevel@tonic-gate 			 * tokens or messages so we can tell the user
1667c478bd9Sstevel@tonic-gate 			 * _something_ more useful than "Connection
1677c478bd9Sstevel@tonic-gate 			 * closed by ..."
1687c478bd9Sstevel@tonic-gate 			 *
1697c478bd9Sstevel@tonic-gate 			 * We use a fatal cleanup function as that's
1707c478bd9Sstevel@tonic-gate 			 * all, really, that we can do for now.
1717c478bd9Sstevel@tonic-gate 			 */
1727c478bd9Sstevel@tonic-gate 			fatal_add_cleanup(kexgss_verbose_cleanup, NULL);
1737c478bd9Sstevel@tonic-gate 			type = packet_read();
1747c478bd9Sstevel@tonic-gate 			fatal_remove_cleanup(kexgss_verbose_cleanup, NULL);
1757c478bd9Sstevel@tonic-gate 			switch (type) {
1767c478bd9Sstevel@tonic-gate 			case SSH2_MSG_KEXGSS_HOSTKEY:
1777c478bd9Sstevel@tonic-gate 				debug("Received KEXGSS_HOSTKEY");
1787c478bd9Sstevel@tonic-gate 				server_host_key_blob =
1797c478bd9Sstevel@tonic-gate 				    packet_get_string(&sbloblen);
1807c478bd9Sstevel@tonic-gate 				server_host_key =
1817c478bd9Sstevel@tonic-gate 				    key_from_blob(server_host_key_blob,
1827c478bd9Sstevel@tonic-gate 				    sbloblen);
1837c478bd9Sstevel@tonic-gate 				goto next_packet; /* there MUSt be another */
1847c478bd9Sstevel@tonic-gate 				break;
1857c478bd9Sstevel@tonic-gate 			case SSH2_MSG_KEXGSS_CONTINUE:
1867c478bd9Sstevel@tonic-gate 				debug("Received GSSAPI_CONTINUE");
1877c478bd9Sstevel@tonic-gate 				if (maj_status == GSS_S_COMPLETE)
1887c478bd9Sstevel@tonic-gate 					packet_disconnect("Protocol error: "
1897c478bd9Sstevel@tonic-gate 					    "received GSS-API context token "
1907c478bd9Sstevel@tonic-gate 					    "though the context was already "
1917c478bd9Sstevel@tonic-gate 					    "established");
1927c478bd9Sstevel@tonic-gate 				recv_tok.value = packet_get_string(&strlen);
1937c478bd9Sstevel@tonic-gate 				recv_tok.length = strlen; /* u_int vs. size_t */
1947c478bd9Sstevel@tonic-gate 				break;
1957c478bd9Sstevel@tonic-gate 			case SSH2_MSG_KEXGSS_COMPLETE:
1967c478bd9Sstevel@tonic-gate 				debug("Received GSSAPI_COMPLETE");
1977c478bd9Sstevel@tonic-gate 				packet_get_bignum2(dh_server_pub);
1987c478bd9Sstevel@tonic-gate 				msg_tok.value = packet_get_string(&strlen);
1997c478bd9Sstevel@tonic-gate 				msg_tok.length = strlen; /* u_int vs. size_t */
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 				/* Is there a token included? */
2027c478bd9Sstevel@tonic-gate 				if (packet_get_char()) {
2037c478bd9Sstevel@tonic-gate 					recv_tok.value =
2047c478bd9Sstevel@tonic-gate 					    packet_get_string(&strlen);
205*c15e4e4bSjp161948 					/* u_int/size_t */
206*c15e4e4bSjp161948 					recv_tok.length = strlen;
2077c478bd9Sstevel@tonic-gate 				}
2087c478bd9Sstevel@tonic-gate 				if (recv_tok.length > 0 &&
2097c478bd9Sstevel@tonic-gate 				    maj_status == GSS_S_COMPLETE) {
2107c478bd9Sstevel@tonic-gate 					packet_disconnect("Protocol error: "
2117c478bd9Sstevel@tonic-gate 					    "received GSS-API context token "
2127c478bd9Sstevel@tonic-gate 					    "though the context was already "
2137c478bd9Sstevel@tonic-gate 					    "established");
2147c478bd9Sstevel@tonic-gate 				} else if (recv_tok.length == 0 &&
2157c478bd9Sstevel@tonic-gate 				    maj_status == GSS_S_CONTINUE_NEEDED) {
2167c478bd9Sstevel@tonic-gate 					/* No token included */
2177c478bd9Sstevel@tonic-gate 					packet_disconnect("Protocol error: "
2187c478bd9Sstevel@tonic-gate 					    "did not receive expected "
2197c478bd9Sstevel@tonic-gate 					    "GSS-API context token");
2207c478bd9Sstevel@tonic-gate 				}
2217c478bd9Sstevel@tonic-gate 				break;
2227c478bd9Sstevel@tonic-gate 			case SSH2_MSG_KEXGSS_ERROR:
2237c478bd9Sstevel@tonic-gate 				smaj_status = packet_get_int();
2247c478bd9Sstevel@tonic-gate 				smin_status = packet_get_int();
2257c478bd9Sstevel@tonic-gate 				msg = packet_get_string(NULL);
2267c478bd9Sstevel@tonic-gate 				lang = packet_get_string(NULL);
2277c478bd9Sstevel@tonic-gate 				xfree(lang);
2287c478bd9Sstevel@tonic-gate 				error("Server had a GSS-API error; the "
2297c478bd9Sstevel@tonic-gate 				    "connection will close (%d/%d):\n%s",
2307c478bd9Sstevel@tonic-gate 				    smaj_status, smin_status, msg);
2317c478bd9Sstevel@tonic-gate 				error("Use the GssKeyEx option to disable "
2327c478bd9Sstevel@tonic-gate 				    "GSS-API key exchange and try again.");
2337c478bd9Sstevel@tonic-gate 				packet_disconnect("The server had a GSS-API "
2347c478bd9Sstevel@tonic-gate 				    "error during GSS-API protected SSHv2 "
2357c478bd9Sstevel@tonic-gate 				    "key exchange\n");
2367c478bd9Sstevel@tonic-gate 				break;
2377c478bd9Sstevel@tonic-gate 			default:
2387c478bd9Sstevel@tonic-gate 				packet_disconnect("Protocol error: "
2397c478bd9Sstevel@tonic-gate 				    "didn't expect packet type %d", type);
2407c478bd9Sstevel@tonic-gate 			}
2417c478bd9Sstevel@tonic-gate 			if (recv_tok.value)
2427c478bd9Sstevel@tonic-gate 				token_ptr = &recv_tok;
2437c478bd9Sstevel@tonic-gate 		} else {
2447c478bd9Sstevel@tonic-gate 			/* No data, and not complete */
2457c478bd9Sstevel@tonic-gate 			if (maj_status != GSS_S_COMPLETE) {
2467c478bd9Sstevel@tonic-gate 				fatal("Not complete, and no token output");
2477c478bd9Sstevel@tonic-gate 			}
2487c478bd9Sstevel@tonic-gate 		}
2497c478bd9Sstevel@tonic-gate 	} while (maj_status == GSS_S_CONTINUE_NEEDED);
2507c478bd9Sstevel@tonic-gate 
251*c15e4e4bSjp161948 	/*
252*c15e4e4bSjp161948 	 * We _must_ have received a COMPLETE message in reply from the
253*c15e4e4bSjp161948 	 * server, which will have set dh_server_pub and msg_tok.
254*c15e4e4bSjp161948 	 */
2557c478bd9Sstevel@tonic-gate 	if (type != SSH2_MSG_KEXGSS_COMPLETE)
2567c478bd9Sstevel@tonic-gate 		fatal("Expected SSH2_MSG_KEXGSS_COMPLETE never arrived");
2577c478bd9Sstevel@tonic-gate 	if (maj_status != GSS_S_COMPLETE)
2587c478bd9Sstevel@tonic-gate 		fatal("Internal error in GSS-API protected SSHv2 key exchange");
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate 	/* Check f in range [1, p-1] */
2617c478bd9Sstevel@tonic-gate 	if (!dh_pub_is_valid(dh, dh_server_pub))
2627c478bd9Sstevel@tonic-gate 		packet_disconnect("bad server public DH value");
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	/* compute K=f^x mod p */
2657c478bd9Sstevel@tonic-gate 	klen = DH_size(dh);
2667c478bd9Sstevel@tonic-gate 	kbuf = xmalloc(klen);
2677c478bd9Sstevel@tonic-gate 	kout = DH_compute_key(kbuf, dh_server_pub, dh);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	shared_secret = BN_new();
2707c478bd9Sstevel@tonic-gate 	BN_bin2bn(kbuf, kout, shared_secret);
2717c478bd9Sstevel@tonic-gate 	(void) memset(kbuf, 0, klen);
2727c478bd9Sstevel@tonic-gate 	xfree(kbuf);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	/* The GSS hash is identical to the DH one */
2757c478bd9Sstevel@tonic-gate 	hash = kex_dh_hash(
2767c478bd9Sstevel@tonic-gate 	    kex->client_version_string,
2777c478bd9Sstevel@tonic-gate 	    kex->server_version_string,
2787c478bd9Sstevel@tonic-gate 	    buffer_ptr(&kex->my), buffer_len(&kex->my),
2797c478bd9Sstevel@tonic-gate 	    buffer_ptr(&kex->peer), buffer_len(&kex->peer),
2807c478bd9Sstevel@tonic-gate 	    server_host_key_blob, sbloblen, /* server host key */
2817c478bd9Sstevel@tonic-gate 	    dh->pub_key,	/* e */
2827c478bd9Sstevel@tonic-gate 	    dh_server_pub,	/* f */
283*c15e4e4bSjp161948 	    shared_secret);	/* K */
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	gssbuf.value = hash;
2867c478bd9Sstevel@tonic-gate 	gssbuf.length = 20;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	/* Verify that H matches the token we just got. */
289*c15e4e4bSjp161948 	if ((maj_status = gss_verify_mic(&min_status, ctxt->context, &gssbuf,
290*c15e4e4bSjp161948 	    &msg_tok, NULL))) {
2917c478bd9Sstevel@tonic-gate 		packet_disconnect("Hash's MIC didn't verify");
2927c478bd9Sstevel@tonic-gate 	}
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	if (server_host_key && kex->accept_host_key != NULL)
2957c478bd9Sstevel@tonic-gate 		(void) kex->accept_host_key(server_host_key);
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	DH_free(dh);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	xxx_gssctxt = ctxt; /* for gss keyex w/ mic userauth */
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	/* save session id */
3027c478bd9Sstevel@tonic-gate 	if (kex->session_id == NULL) {
3037c478bd9Sstevel@tonic-gate 		kex->session_id_len = 20;
3047c478bd9Sstevel@tonic-gate 		kex->session_id = xmalloc(kex->session_id_len);
3057c478bd9Sstevel@tonic-gate 		(void) memcpy(kex->session_id, hash, kex->session_id_len);
3067c478bd9Sstevel@tonic-gate 	}
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	kex_derive_keys(kex, hash, shared_secret);
3097c478bd9Sstevel@tonic-gate 	BN_clear_free(shared_secret);
3107c478bd9Sstevel@tonic-gate 	kex_finish(kex);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /* ARGSUSED */
3147c478bd9Sstevel@tonic-gate static
3157c478bd9Sstevel@tonic-gate void
kexgss_verbose_cleanup(void * arg)3167c478bd9Sstevel@tonic-gate kexgss_verbose_cleanup(void *arg)
3177c478bd9Sstevel@tonic-gate {
3187c478bd9Sstevel@tonic-gate 	error("The GSS-API protected key exchange has failed without "
3197c478bd9Sstevel@tonic-gate 	    "indication\nfrom the server, possibly due to misconfiguration "
3207c478bd9Sstevel@tonic-gate 	    "of the server.");
3217c478bd9Sstevel@tonic-gate 	error("Use the GssKeyEx option to disable GSS-API key exchange "
3227c478bd9Sstevel@tonic-gate 	    "and try again.");
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate #endif /* GSSAPI */
326