vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jan F. Chadima 3d742c
? .kex.h.swp
Jan F. Chadima 3d742c
? .pc
Jan F. Chadima 3d742c
? openssh-5.0p1-gsskex-20080404.patch
Jan F. Chadima 3d742c
? openssh-5.0p1-gssrenew-20080707.patch
Jan F. Chadima 3d742c
? openssh-5.2p1-gsskex-20090726.patch
Jan F. Chadima 3d742c
? openssh-5.2p1-gsskex-all-20090726.patch
Jan F. Chadima 3d742c
? patches
Jan F. Chadima 3d742c
Index: ChangeLog.gssapi
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: ChangeLog.gssapi
Jan F. Chadima 3d742c
diff -N ChangeLog.gssapi
Jan F. Chadima 3d742c
--- /dev/null	1 Jan 1970 00:00:00 -0000
Jan F. Chadima 3d742c
+++ ChangeLog.gssapi	26 Jul 2009 12:21:52 -0000
Jan F. Chadima 3d742c
@@ -0,0 +1,95 @@
Jan F. Chadima 3d742c
+20090615
Jan F. Chadima 3d742c
+  - [ gss-genr.c gss-serv.c kexgssc.c kexgsss.c monitor.c sshconnect2.c
Jan F. Chadima 3d742c
+      sshd.c ]
Jan F. Chadima 3d742c
+    Fix issues identified by Greg Hudson following a code review
Jan F. Chadima 3d742c
+	Check return value of gss_indicate_mechs
Jan F. Chadima 3d742c
+	Protect GSSAPI calls in monitor, so they can only be used if enabled
Jan F. Chadima 3d742c
+	Check return values of bignum functions in key exchange
Jan F. Chadima 3d742c
+	Use BN_clear_free to clear other side's DH value
Jan F. Chadima 3d742c
+	Make ssh_gssapi_id_kex more robust
Jan F. Chadima 3d742c
+	Only configure kex table pointers if GSSAPI is enabled
Jan F. Chadima 3d742c
+	Don't leak mechanism list, or gss mechanism list
Jan F. Chadima 3d742c
+	Cast data.length before printing
Jan F. Chadima 3d742c
+	If serverkey isn't provided, use an empty string, rather than NULL
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20090201
Jan F. Chadima 3d742c
+  - [ gss-genr.c gss-serv.c kex.h kexgssc.c readconf.c readconf.h ssh-gss.h
Jan F. Chadima 3d742c
+      ssh_config.5 sshconnet2.c ]
Jan F. Chadima 3d742c
+    Add support for the GSSAPIClientIdentity option, which allows the user
Jan F. Chadima 3d742c
+    to specify which GSSAPI identity to use to contact a given server
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20080404
Jan F. Chadima 3d742c
+  - [ gss-serv.c ]
Jan F. Chadima 3d742c
+    Add code to actually implement GSSAPIStrictAcceptCheck, which had somehow
Jan F. Chadima 3d742c
+    been omitted from a previous version of this patch. Reported by Borislav
Jan F. Chadima 3d742c
+    Stoichkov
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20070317
Jan F. Chadima 3d742c
+  - [ gss-serv-krb5.c ]
Jan F. Chadima 3d742c
+    Remove C99ism, where new_ccname was being declared in the middle of a 
Jan F. Chadima 3d742c
+    function
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20061220
Jan F. Chadima 3d742c
+  - [ servconf.c ]
Jan F. Chadima 3d742c
+    Make default for GSSAPIStrictAcceptorCheck be Yes, to match previous, and 
Jan F. Chadima 3d742c
+    documented, behaviour. Reported by Dan Watson.
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20060910
Jan F. Chadima 3d742c
+  - [ gss-genr.c kexgssc.c kexgsss.c kex.h monitor.c sshconnect2.c sshd.c
Jan F. Chadima 3d742c
+      ssh-gss.h ]
Jan F. Chadima 3d742c
+    add support for gss-group14-sha1 key exchange mechanisms
Jan F. Chadima 3d742c
+  - [ gss-serv.c servconf.c servconf.h sshd_config sshd_config.5 ]
Jan F. Chadima 3d742c
+    Add GSSAPIStrictAcceptorCheck option to allow the disabling of
Jan F. Chadima 3d742c
+    acceptor principal checking on multi-homed machines.
Jan F. Chadima 3d742c
+    <Bugzilla #928>
Jan F. Chadima 3d742c
+  - [ sshd_config ssh_config ]
Jan F. Chadima 3d742c
+    Add settings for GSSAPIKeyExchange and GSSAPITrustDNS to the sample
Jan F. Chadima 3d742c
+    configuration files
Jan F. Chadima 3d742c
+  - [ kexgss.c kegsss.c sshconnect2.c sshd.c ]
Jan F. Chadima 3d742c
+    Code cleanup. Replace strlen/xmalloc/snprintf sequences with xasprintf()
Jan F. Chadima 3d742c
+    Limit length of error messages displayed by client
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20060909
Jan F. Chadima 3d742c
+  - [ gss-genr.c gss-serv.c ]
Jan F. Chadima 3d742c
+    move ssh_gssapi_acquire_cred() and ssh_gssapi_server_ctx to be server
Jan F. Chadima 3d742c
+    only, where they belong 
Jan F. Chadima 3d742c
+    <Bugzilla #1225>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20060829
Jan F. Chadima 3d742c
+  - [ gss-serv-krb5.c ]
Jan F. Chadima 3d742c
+    Fix CCAPI credentials cache name when creating KRB5CCNAME environment 
Jan F. Chadima 3d742c
+    variable
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20060828
Jan F. Chadima 3d742c
+  - [ gss-genr.c ]
Jan F. Chadima 3d742c
+    Avoid Heimdal context freeing problem
Jan F. Chadima 3d742c
+    <Fixed upstream 20060829>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20060818
Jan F. Chadima 3d742c
+  - [ gss-genr.c ssh-gss.h sshconnect2.c ]
Jan F. Chadima 3d742c
+    Make sure that SPENGO is disabled 
Jan F. Chadima 3d742c
+    <Bugzilla #1218 - Fixed upstream 20060818>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+20060421
Jan F. Chadima 3d742c
+  - [ gssgenr.c, sshconnect2.c ]
Jan F. Chadima 3d742c
+    a few type changes (signed versus unsigned, int versus size_t) to
Jan F. Chadima 3d742c
+    fix compiler errors/warnings 
Jan F. Chadima 3d742c
+    (from jbasney AT ncsa.uiuc.edu)
Jan F. Chadima 3d742c
+  - [ kexgssc.c, sshconnect2.c ]
Jan F. Chadima 3d742c
+    fix uninitialized variable warnings
Jan F. Chadima 3d742c
+    (from jbasney AT ncsa.uiuc.edu)
Jan F. Chadima 3d742c
+  - [ gssgenr.c ]
Jan F. Chadima 3d742c
+    pass oid to gss_display_status (helpful when using GSSAPI mechglue)
Jan F. Chadima 3d742c
+    (from jbasney AT ncsa.uiuc.edu)
Jan F. Chadima 3d742c
+    <Bugzilla #1220 >
Jan F. Chadima 3d742c
+  - [ gss-serv-krb5.c ]
Jan F. Chadima 3d742c
+    #ifdef HAVE_GSSAPI_KRB5 should be #ifdef HAVE_GSSAPI_KRB5_H
Jan F. Chadima 3d742c
+    (from jbasney AT ncsa.uiuc.edu)
Jan F. Chadima 3d742c
+    <Fixed upstream 20060304>
Jan F. Chadima 3d742c
+  - [ readconf.c, readconf.h, ssh_config.5, sshconnect2.c 
Jan F. Chadima 3d742c
+    add client-side GssapiKeyExchange option
Jan F. Chadima 3d742c
+    (from jbasney AT ncsa.uiuc.edu)
Jan F. Chadima 3d742c
+  - [ sshconnect2.c ]
Jan F. Chadima 3d742c
+    add support for GssapiTrustDns option for gssapi-with-mic
Jan F. Chadima 3d742c
+    (from jbasney AT ncsa.uiuc.edu)
Jan F. Chadima 3d742c
+    <gssapi-with-mic support is Bugzilla #1008>
Jan F. Chadima 3d742c
Index: Makefile.in
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/Makefile.in,v
Jan F. Chadima 3d742c
retrieving revision 1.298
Jan F. Chadima 3d742c
diff -u -r1.298 Makefile.in
Jan F. Chadima 3d742c
--- Makefile.in	5 Nov 2008 05:20:46 -0000	1.298
Jan F. Chadima 3d742c
+++ Makefile.in	26 Jul 2009 12:21:53 -0000
Jan F. Chadima 3d742c
@@ -71,7 +71,8 @@
Jan F. Chadima 3d742c
 	atomicio.o key.o dispatch.o kex.o mac.o uidswap.o uuencode.o misc.o \
Jan F. Chadima 3d742c
 	monitor_fdpass.o rijndael.o ssh-dss.o ssh-rsa.o dh.o kexdh.o \
Jan F. Chadima 3d742c
 	kexgex.o kexdhc.o kexgexc.o scard.o msg.o progressmeter.o dns.o \
Jan F. Chadima 3d742c
-	entropy.o scard-opensc.o gss-genr.o umac.o jpake.o schnorr.o
Jan F. Chadima 3d742c
+	entropy.o scard-opensc.o gss-genr.o umac.o jpake.o schnorr.o \
Jan F. Chadima 3d742c
+	kexgssc.o
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
Jan F. Chadima 3d742c
 	sshconnect.o sshconnect1.o sshconnect2.o mux.o
Jan F. Chadima 3d742c
@@ -84,7 +85,7 @@
Jan F. Chadima 3d742c
 	auth2-none.o auth2-passwd.o auth2-pubkey.o auth2-jpake.o \
Jan F. Chadima 3d742c
 	monitor_mm.o monitor.o monitor_wrap.o kexdhs.o kexgexs.o \
Jan F. Chadima 3d742c
 	auth-krb5.o \
Jan F. Chadima 3d742c
-	auth2-gss.o gss-serv.o gss-serv-krb5.o \
Jan F. Chadima 3d742c
+	auth2-gss.o gss-serv.o gss-serv-krb5.o kexgsss.o\
Jan F. Chadima 3d742c
 	loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
Jan F. Chadima 3d742c
 	audit.o audit-bsm.o platform.o sftp-server.o sftp-common.o
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
Index: auth-krb5.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/auth-krb5.c,v
Jan F. Chadima 3d742c
retrieving revision 1.35
Jan F. Chadima 3d742c
diff -u -r1.35 auth-krb5.c
Jan F. Chadima 3d742c
--- auth-krb5.c	5 Aug 2006 02:39:39 -0000	1.35
Jan F. Chadima 3d742c
+++ auth-krb5.c	26 Jul 2009 12:21:53 -0000
Jan F. Chadima 3d742c
@@ -166,8 +166,13 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	len = strlen(authctxt->krb5_ticket_file) + 6;
Jan F. Chadima 3d742c
 	authctxt->krb5_ccname = xmalloc(len);
Jan F. Chadima 3d742c
+#ifdef USE_CCAPI
Jan F. Chadima 3d742c
+	snprintf(authctxt->krb5_ccname, len, "API:%s",
Jan F. Chadima 3d742c
+	    authctxt->krb5_ticket_file);
Jan F. Chadima 3d742c
+#else
Jan F. Chadima 3d742c
 	snprintf(authctxt->krb5_ccname, len, "FILE:%s",
Jan F. Chadima 3d742c
 	    authctxt->krb5_ticket_file);
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef USE_PAM
Jan F. Chadima 3d742c
 	if (options.use_pam)
Jan F. Chadima 3d742c
@@ -219,15 +224,22 @@
Jan F. Chadima 3d742c
 #ifndef HEIMDAL
Jan F. Chadima 3d742c
 krb5_error_code
Jan F. Chadima 3d742c
 ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
Jan F. Chadima 3d742c
-	int tmpfd, ret;
Jan F. Chadima 3d742c
+	int ret;
Jan F. Chadima 3d742c
 	char ccname[40];
Jan F. Chadima 3d742c
 	mode_t old_umask;
Jan F. Chadima 3d742c
+#ifdef USE_CCAPI
Jan F. Chadima 3d742c
+	char cctemplate[] = "API:krb5cc_%d";
Jan F. Chadima 3d742c
+#else
Jan F. Chadima 3d742c
+	char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
Jan F. Chadima 3d742c
+	int tmpfd;
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	ret = snprintf(ccname, sizeof(ccname),
Jan F. Chadima 3d742c
-	    "FILE:/tmp/krb5cc_%d_XXXXXXXXXX", geteuid());
Jan F. Chadima 3d742c
+	    cctemplate, geteuid());
Jan F. Chadima 3d742c
 	if (ret < 0 || (size_t)ret >= sizeof(ccname))
Jan F. Chadima 3d742c
 		return ENOMEM;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifndef USE_CCAPI
Jan F. Chadima 3d742c
 	old_umask = umask(0177);
Jan F. Chadima 3d742c
 	tmpfd = mkstemp(ccname + strlen("FILE:"));
Jan F. Chadima 3d742c
 	umask(old_umask);
Jan F. Chadima 3d742c
@@ -242,6 +254,7 @@
Jan F. Chadima 3d742c
 		return errno;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 	close(tmpfd);
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	return (krb5_cc_resolve(ctx, ccname, ccache));
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
Index: auth.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/auth.h,v
Jan F. Chadima 3d742c
retrieving revision 1.80
Jan F. Chadima 3d742c
diff -u -r1.80 auth.h
Jan F. Chadima 3d742c
--- auth.h	5 Nov 2008 05:20:46 -0000	1.80
Jan F. Chadima 3d742c
+++ auth.h	26 Jul 2009 12:21:53 -0000
Jan F. Chadima 3d742c
@@ -53,6 +53,7 @@
Jan F. Chadima 3d742c
 	int		 valid;		/* user exists and is allowed to login */
Jan F. Chadima 3d742c
 	int		 attempt;
Jan F. Chadima 3d742c
 	int		 failures;
Jan F. Chadima 3d742c
+	int		 server_caused_failure; 
Jan F. Chadima 3d742c
 	int		 force_pwchange;
Jan F. Chadima 3d742c
 	char		*user;		/* username sent by the client */
Jan F. Chadima 3d742c
 	char		*service;
Jan F. Chadima 3d742c
Index: auth2-gss.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/auth2-gss.c,v
Jan F. Chadima 3d742c
retrieving revision 1.19
Jan F. Chadima 3d742c
diff -u -r1.19 auth2-gss.c
Jan F. Chadima 3d742c
--- auth2-gss.c	2 Dec 2007 11:59:45 -0000	1.19
Jan F. Chadima 3d742c
+++ auth2-gss.c	26 Jul 2009 12:21:54 -0000
Jan F. Chadima 3d742c
@@ -1,7 +1,7 @@
Jan F. Chadima 3d742c
 /* $OpenBSD: auth2-gss.c,v 1.16 2007/10/29 00:52:45 dtucker Exp $ */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /*
Jan F. Chadima 3d742c
- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
  *
Jan F. Chadima 3d742c
  * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
  * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
@@ -52,6 +52,40 @@
Jan F. Chadima 3d742c
 static void input_gssapi_exchange_complete(int type, u_int32_t plen, void *ctxt);
Jan F. Chadima 3d742c
 static void input_gssapi_errtok(int, u_int32_t, void *);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+/* 
Jan F. Chadima 3d742c
+ * The 'gssapi_keyex' userauth mechanism.
Jan F. Chadima 3d742c
+ */
Jan F. Chadima 3d742c
+static int
Jan F. Chadima 3d742c
+userauth_gsskeyex(Authctxt *authctxt)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	int authenticated = 0;
Jan F. Chadima 3d742c
+	Buffer b;
Jan F. Chadima 3d742c
+	gss_buffer_desc mic, gssbuf;
Jan F. Chadima 3d742c
+	u_int len;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	mic.value = packet_get_string(&len;;
Jan F. Chadima 3d742c
+	mic.length = len;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	packet_check_eom();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ssh_gssapi_buildmic(&b, authctxt->user, authctxt->service,
Jan F. Chadima 3d742c
+	    "gssapi-keyex");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gssbuf.value = buffer_ptr(&b);
Jan F. Chadima 3d742c
+	gssbuf.length = buffer_len(&b);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* gss_kex_context is NULL with privsep, so we can't check it here */
Jan F. Chadima 3d742c
+	if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context, 
Jan F. Chadima 3d742c
+	    &gssbuf, &mic))))
Jan F. Chadima 3d742c
+		authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
Jan F. Chadima 3d742c
+		    authctxt->pw));
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	buffer_free(&b);
Jan F. Chadima 3d742c
+	xfree(mic.value);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return (authenticated);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 /*
Jan F. Chadima 3d742c
  * We only support those mechanisms that we know about (ie ones that we know
Jan F. Chadima 3d742c
  * how to check local user kuserok and the like)
Jan F. Chadima 3d742c
@@ -102,6 +136,7 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	if (!present) {
Jan F. Chadima 3d742c
 		xfree(doid);
Jan F. Chadima 3d742c
+		authctxt->server_caused_failure = 1;
Jan F. Chadima 3d742c
 		return (0);
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -109,6 +144,7 @@
Jan F. Chadima 3d742c
 		if (ctxt != NULL)
Jan F. Chadima 3d742c
 			ssh_gssapi_delete_ctx(&ctxt);
Jan F. Chadima 3d742c
 		xfree(doid);
Jan F. Chadima 3d742c
+		authctxt->server_caused_failure = 1;
Jan F. Chadima 3d742c
 		return (0);
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -242,7 +278,8 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	packet_check_eom();
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
Jan F. Chadima 3d742c
+	authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
Jan F. Chadima 3d742c
+	    authctxt->pw));
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	authctxt->postponed = 0;
Jan F. Chadima 3d742c
 	dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_TOKEN, NULL);
Jan F. Chadima 3d742c
@@ -277,7 +314,8 @@
Jan F. Chadima 3d742c
 	gssbuf.length = buffer_len(&b);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
Jan F. Chadima 3d742c
-		authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user));
Jan F. Chadima 3d742c
+		authenticated = 
Jan F. Chadima 3d742c
+		    PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
Jan F. Chadima 3d742c
 	else
Jan F. Chadima 3d742c
 		logit("GSSAPI MIC check failed");
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -291,6 +329,12 @@
Jan F. Chadima 3d742c
 	dispatch_set(SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE, NULL);
Jan F. Chadima 3d742c
 	userauth_finish(authctxt, authenticated, "gssapi-with-mic");
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+Authmethod method_gsskeyex = {
Jan F. Chadima 3d742c
+	"gssapi-keyex",
Jan F. Chadima 3d742c
+	userauth_gsskeyex,
Jan F. Chadima 3d742c
+	&options.gss_authentication
Jan F. Chadima 3d742c
+};
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 Authmethod method_gssapi = {
Jan F. Chadima 3d742c
 	"gssapi-with-mic",
Jan F. Chadima 3d742c
Index: auth2.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/auth2.c,v
Jan F. Chadima 3d742c
retrieving revision 1.149
Jan F. Chadima 3d742c
diff -u -r1.149 auth2.c
Jan F. Chadima 3d742c
--- auth2.c	5 Nov 2008 05:20:46 -0000	1.149
Jan F. Chadima 3d742c
+++ auth2.c	26 Jul 2009 12:21:54 -0000
Jan F. Chadima 3d742c
@@ -69,6 +69,7 @@
Jan F. Chadima 3d742c
 extern Authmethod method_kbdint;
Jan F. Chadima 3d742c
 extern Authmethod method_hostbased;
Jan F. Chadima 3d742c
 #ifdef GSSAPI
Jan F. Chadima 3d742c
+extern Authmethod method_gsskeyex;
Jan F. Chadima 3d742c
 extern Authmethod method_gssapi;
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 #ifdef JPAKE
Jan F. Chadima 3d742c
@@ -79,6 +80,7 @@
Jan F. Chadima 3d742c
 	&method_none,
Jan F. Chadima 3d742c
 	&method_pubkey,
Jan F. Chadima 3d742c
 #ifdef GSSAPI
Jan F. Chadima 3d742c
+	&method_gsskeyex,
Jan F. Chadima 3d742c
 	&method_gssapi,
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 #ifdef JPAKE
Jan F. Chadima 3d742c
@@ -274,6 +276,7 @@
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	authctxt->postponed = 0;
Jan F. Chadima 3d742c
+	authctxt->server_caused_failure = 0;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	/* try to authenticate user */
Jan F. Chadima 3d742c
 	m = authmethod_lookup(method);
Jan F. Chadima 3d742c
@@ -346,7 +349,8 @@
Jan F. Chadima 3d742c
 	} else {
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 		/* Allow initial try of "none" auth without failure penalty */
Jan F. Chadima 3d742c
-		if (authctxt->attempt > 1 || strcmp(method, "none") != 0)
Jan F. Chadima 3d742c
+		if (!authctxt->server_caused_failure &&
Jan F. Chadima 3d742c
+		    (authctxt->attempt > 1 || strcmp(method, "none") != 0))
Jan F. Chadima 3d742c
 			authctxt->failures++;
Jan F. Chadima 3d742c
 		if (authctxt->failures >= options.max_authtries) {
Jan F. Chadima 3d742c
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima 3d742c
Index: clientloop.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/clientloop.c,v
Jan F. Chadima 3d742c
retrieving revision 1.197
Jan F. Chadima 3d742c
diff -u -r1.197 clientloop.c
Jan F. Chadima 3d742c
--- clientloop.c	14 Feb 2009 05:28:21 -0000	1.197
Jan F. Chadima 3d742c
+++ clientloop.c	26 Jul 2009 12:21:56 -0000
Jan F. Chadima 3d742c
@@ -110,6 +110,10 @@
Jan F. Chadima 3d742c
 #include "match.h"
Jan F. Chadima 3d742c
 #include "msg.h"
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+#include "ssh-gss.h"
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 /* import options */
Jan F. Chadima 3d742c
 extern Options options;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -1429,6 +1433,13 @@
Jan F. Chadima 3d742c
 		/* Do channel operations unless rekeying in progress. */
Jan F. Chadima 3d742c
 		if (!rekeying) {
Jan F. Chadima 3d742c
 			channel_after_select(readset, writeset);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			if (options.gss_renewal_rekey &&
Jan F. Chadima 3d742c
+			    ssh_gssapi_credentials_updated(GSS_C_NO_CONTEXT)) {
Jan F. Chadima 3d742c
+				debug("credentials updated - forcing rekey");
Jan F. Chadima 3d742c
+				need_rekeying = 1;
Jan F. Chadima 3d742c
+			}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 			if (need_rekeying || packet_need_rekeying()) {
Jan F. Chadima 3d742c
 				debug("need rekeying");
Jan F. Chadima 3d742c
 				xxx_kex->done = 0;
Jan F. Chadima 3d742c
Index: configure.ac
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/configure.ac,v
Jan F. Chadima 3d742c
retrieving revision 1.415
Jan F. Chadima 3d742c
diff -u -r1.415 configure.ac
Jan F. Chadima 3d742c
--- configure.ac	16 Feb 2009 04:37:03 -0000	1.415
Jan F. Chadima 3d742c
+++ configure.ac	26 Jul 2009 12:22:00 -0000
Jan F. Chadima 3d742c
@@ -473,6 +473,30 @@
Jan F. Chadima 3d742c
 	    [Use tunnel device compatibility to OpenBSD])
Jan F. Chadima 3d742c
 	AC_DEFINE(SSH_TUN_PREPEND_AF, 1,
Jan F. Chadima 3d742c
 	    [Prepend the address family to IP tunnel traffic])
Jan F. Chadima 3d742c
+	AC_MSG_CHECKING(if we have the Security Authorization Session API)
Jan F. Chadima 3d742c
+	AC_TRY_COMPILE([#include <Security/AuthSession.h>],
Jan F. Chadima 3d742c
+		[SessionCreate(0, 0);],
Jan F. Chadima 3d742c
+		[ac_cv_use_security_session_api="yes"
Jan F. Chadima 3d742c
+		 AC_DEFINE(USE_SECURITY_SESSION_API, 1, 
Jan F. Chadima 3d742c
+			[platform has the Security Authorization Session API])
Jan F. Chadima 3d742c
+		 LIBS="$LIBS -framework Security"
Jan F. Chadima 3d742c
+		 AC_MSG_RESULT(yes)],
Jan F. Chadima 3d742c
+		[ac_cv_use_security_session_api="no"
Jan F. Chadima 3d742c
+		 AC_MSG_RESULT(no)])
Jan F. Chadima 3d742c
+	AC_MSG_CHECKING(if we have an in-memory credentials cache)
Jan F. Chadima 3d742c
+	AC_TRY_COMPILE(
Jan F. Chadima 3d742c
+		[#include <Kerberos/Kerberos.h>],
Jan F. Chadima 3d742c
+		[cc_context_t c;
Jan F. Chadima 3d742c
+		 (void) cc_initialize (&c, 0, NULL, NULL);],
Jan F. Chadima 3d742c
+		[AC_DEFINE(USE_CCAPI, 1, 
Jan F. Chadima 3d742c
+			[platform uses an in-memory credentials cache])
Jan F. Chadima 3d742c
+		 LIBS="$LIBS -framework Security"
Jan F. Chadima 3d742c
+		 AC_MSG_RESULT(yes)
Jan F. Chadima 3d742c
+		 if test "x$ac_cv_use_security_session_api" = "xno"; then
Jan F. Chadima 3d742c
+			AC_MSG_ERROR(*** Need a security framework to use the credentials cache API ***)
Jan F. Chadima 3d742c
+		fi],
Jan F. Chadima 3d742c
+		[AC_MSG_RESULT(no)]
Jan F. Chadima 3d742c
+	)
Jan F. Chadima 3d742c
 	m4_pattern_allow(AU_IPv)
Jan F. Chadima 3d742c
 	AC_CHECK_DECL(AU_IPv4, [], 
Jan F. Chadima 3d742c
 	    AC_DEFINE(AU_IPv4, 0, [System only supports IPv4 audit records])
Jan F. Chadima 3d742c
Index: gss-genr.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/gss-genr.c,v
Jan F. Chadima 3d742c
retrieving revision 1.21
Jan F. Chadima 3d742c
diff -u -r1.21 gss-genr.c
Jan F. Chadima 3d742c
--- gss-genr.c	12 Jun 2007 13:44:36 -0000	1.21
Jan F. Chadima 3d742c
+++ gss-genr.c	26 Jul 2009 12:22:01 -0000
Jan F. Chadima 3d742c
@@ -1,7 +1,7 @@
Jan F. Chadima 3d742c
 /* $OpenBSD: gss-genr.c,v 1.19 2007/06/12 11:56:15 dtucker Exp $ */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /*
Jan F. Chadima 3d742c
- * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
  *
Jan F. Chadima 3d742c
  * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
  * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
@@ -39,12 +39,167 @@
Jan F. Chadima 3d742c
 #include "buffer.h"
Jan F. Chadima 3d742c
 #include "log.h"
Jan F. Chadima 3d742c
 #include "ssh2.h"
Jan F. Chadima 3d742c
+#include "cipher.h"
Jan F. Chadima 3d742c
+#include "key.h"
Jan F. Chadima 3d742c
+#include "kex.h"
Jan F. Chadima 3d742c
+#include <openssl/evp.h>
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #include "ssh-gss.h"
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 extern u_char *session_id2;
Jan F. Chadima 3d742c
 extern u_int session_id2_len;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+typedef struct {
Jan F. Chadima 3d742c
+	char *encoded;
Jan F. Chadima 3d742c
+	gss_OID oid;
Jan F. Chadima 3d742c
+} ssh_gss_kex_mapping;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+/*
Jan F. Chadima 3d742c
+ * XXX - It would be nice to find a more elegant way of handling the
Jan F. Chadima 3d742c
+ * XXX   passing of the key exchange context to the userauth routines
Jan F. Chadima 3d742c
+ */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+Gssctxt *gss_kex_context = NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+static ssh_gss_kex_mapping *gss_enc2oid = NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int 
Jan F. Chadima 3d742c
+ssh_gssapi_oid_table_ok() {
Jan F. Chadima 3d742c
+	return (gss_enc2oid != NULL);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+/*
Jan F. Chadima 3d742c
+ * Return a list of the gss-group1-sha1 mechanisms supported by this program
Jan F. Chadima 3d742c
+ *
Jan F. Chadima 3d742c
+ * We test mechanisms to ensure that we can use them, to avoid starting
Jan F. Chadima 3d742c
+ * a key exchange with a bad mechanism
Jan F. Chadima 3d742c
+ */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+char *
Jan F. Chadima 3d742c
+ssh_gssapi_client_mechanisms(const char *host, const char *client) {
Jan F. Chadima 3d742c
+	gss_OID_set gss_supported;
Jan F. Chadima 3d742c
+	OM_uint32 min_status;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (GSS_ERROR(gss_indicate_mechs(&min_status, &gss_supported)))
Jan F. Chadima 3d742c
+		return NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
Jan F. Chadima 3d742c
+	    host, client));
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+char *
Jan F. Chadima 3d742c
+ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
Jan F. Chadima 3d742c
+    const char *host, const char *client) {
Jan F. Chadima 3d742c
+	Buffer buf;
Jan F. Chadima 3d742c
+	size_t i;
Jan F. Chadima 3d742c
+	int oidpos, enclen;
Jan F. Chadima 3d742c
+	char *mechs, *encoded;
Jan F. Chadima 3d742c
+	u_char digest[EVP_MAX_MD_SIZE];
Jan F. Chadima 3d742c
+	char deroid[2];
Jan F. Chadima 3d742c
+	const EVP_MD *evp_md = EVP_md5();
Jan F. Chadima 3d742c
+	EVP_MD_CTX md;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gss_enc2oid != NULL) {
Jan F. Chadima 3d742c
+		for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
Jan F. Chadima 3d742c
+			xfree(gss_enc2oid[i].encoded);
Jan F. Chadima 3d742c
+		xfree(gss_enc2oid);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gss_enc2oid = xmalloc(sizeof(ssh_gss_kex_mapping) *
Jan F. Chadima 3d742c
+	    (gss_supported->count + 1));
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_init(&buf;;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	oidpos = 0;
Jan F. Chadima 3d742c
+	for (i = 0; i < gss_supported->count; i++) {
Jan F. Chadima 3d742c
+		if (gss_supported->elements[i].length < 128 &&
Jan F. Chadima 3d742c
+		    (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			deroid[0] = SSH_GSS_OIDTYPE;
Jan F. Chadima 3d742c
+			deroid[1] = gss_supported->elements[i].length;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			EVP_DigestInit(&md, evp_md);
Jan F. Chadima 3d742c
+			EVP_DigestUpdate(&md, deroid, 2);
Jan F. Chadima 3d742c
+			EVP_DigestUpdate(&md,
Jan F. Chadima 3d742c
+			    gss_supported->elements[i].elements,
Jan F. Chadima 3d742c
+			    gss_supported->elements[i].length);
Jan F. Chadima 3d742c
+			EVP_DigestFinal(&md, digest, NULL);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			encoded = xmalloc(EVP_MD_size(evp_md) * 2);
Jan F. Chadima 3d742c
+			enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
Jan F. Chadima 3d742c
+			    encoded, EVP_MD_size(evp_md) * 2);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			if (oidpos != 0)
Jan F. Chadima 3d742c
+				buffer_put_char(&buf, ',');
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			buffer_append(&buf, KEX_GSS_GEX_SHA1_ID,
Jan F. Chadima 3d742c
+			    sizeof(KEX_GSS_GEX_SHA1_ID) - 1);
Jan F. Chadima 3d742c
+			buffer_append(&buf, encoded, enclen);
Jan F. Chadima 3d742c
+			buffer_put_char(&buf, ',');
Jan F. Chadima 3d742c
+			buffer_append(&buf, KEX_GSS_GRP1_SHA1_ID, 
Jan F. Chadima 3d742c
+			    sizeof(KEX_GSS_GRP1_SHA1_ID) - 1);
Jan F. Chadima 3d742c
+			buffer_append(&buf, encoded, enclen);
Jan F. Chadima 3d742c
+			buffer_put_char(&buf, ',');
Jan F. Chadima 3d742c
+			buffer_append(&buf, KEX_GSS_GRP14_SHA1_ID,
Jan F. Chadima 3d742c
+			    sizeof(KEX_GSS_GRP14_SHA1_ID) - 1);
Jan F. Chadima 3d742c
+			buffer_append(&buf, encoded, enclen);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
Jan F. Chadima 3d742c
+			gss_enc2oid[oidpos].encoded = encoded;
Jan F. Chadima 3d742c
+			oidpos++;
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+	gss_enc2oid[oidpos].oid = NULL;
Jan F. Chadima 3d742c
+	gss_enc2oid[oidpos].encoded = NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_put_char(&buf, '\0');
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	mechs = xmalloc(buffer_len(&buf));
Jan F. Chadima 3d742c
+	buffer_get(&buf, mechs, buffer_len(&buf));
Jan F. Chadima 3d742c
+	buffer_free(&buf;;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (strlen(mechs) == 0) {
Jan F. Chadima 3d742c
+		xfree(mechs);
Jan F. Chadima 3d742c
+		mechs = NULL;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	return (mechs);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+gss_OID
Jan F. Chadima 3d742c
+ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
Jan F. Chadima 3d742c
+	int i = 0;
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	switch (kex_type) {
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP1_SHA1:
Jan F. Chadima 3d742c
+		if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
Jan F. Chadima 3d742c
+			return GSS_C_NO_OID;
Jan F. Chadima 3d742c
+		name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP14_SHA1:
Jan F. Chadima 3d742c
+		if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
Jan F. Chadima 3d742c
+			return GSS_C_NO_OID;
Jan F. Chadima 3d742c
+		name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GEX_SHA1:
Jan F. Chadima 3d742c
+		if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
Jan F. Chadima 3d742c
+			return GSS_C_NO_OID;
Jan F. Chadima 3d742c
+		name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	default:
Jan F. Chadima 3d742c
+		return GSS_C_NO_OID;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	while (gss_enc2oid[i].encoded != NULL &&
Jan F. Chadima 3d742c
+	    strcmp(name, gss_enc2oid[i].encoded) != 0)
Jan F. Chadima 3d742c
+		i++;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gss_enc2oid[i].oid != NULL && ctx != NULL)
Jan F. Chadima 3d742c
+		ssh_gssapi_set_oid(ctx, gss_enc2oid[i].oid);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return gss_enc2oid[i].oid;
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 /* Check that the OID in a data stream matches that in the context */
Jan F. Chadima 3d742c
 int
Jan F. Chadima 3d742c
 ssh_gssapi_check_oid(Gssctxt *ctx, void *data, size_t len)
Jan F. Chadima 3d742c
@@ -197,7 +352,7 @@
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	ctx->major = gss_init_sec_context(&ctx->minor,
Jan F. Chadima 3d742c
-	    GSS_C_NO_CREDENTIAL, &ctx->context, ctx->name, ctx->oid,
Jan F. Chadima 3d742c
+	    ctx->client_creds, &ctx->context, ctx->name, ctx->oid,
Jan F. Chadima 3d742c
 	    GSS_C_MUTUAL_FLAG | GSS_C_INTEG_FLAG | deleg_flag,
Jan F. Chadima 3d742c
 	    0, NULL, recv_tok, NULL, send_tok, flags, NULL);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -227,8 +382,42 @@
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 OM_uint32
Jan F. Chadima 3d742c
+ssh_gssapi_client_identity(Gssctxt *ctx, const char *name)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	gss_buffer_desc gssbuf;
Jan F. Chadima 3d742c
+	gss_name_t gssname;
Jan F. Chadima 3d742c
+	OM_uint32 status;
Jan F. Chadima 3d742c
+	gss_OID_set oidset;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gssbuf.value = (void *) name;
Jan F. Chadima 3d742c
+	gssbuf.length = strlen(gssbuf.value);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gss_create_empty_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
+	gss_add_oid_set_member(&status, ctx->oid, &oidset);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ctx->major = gss_import_name(&ctx->minor, &gssbuf,
Jan F. Chadima 3d742c
+	    GSS_C_NT_USER_NAME, &gssname);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (!ctx->major)
Jan F. Chadima 3d742c
+		ctx->major = gss_acquire_cred(&ctx->minor, 
Jan F. Chadima 3d742c
+		    gssname, 0, oidset, GSS_C_INITIATE, 
Jan F. Chadima 3d742c
+		    &ctx->client_creds, NULL, NULL);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gss_release_name(&status, &gssname);
Jan F. Chadima 3d742c
+	gss_release_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (ctx->major)
Jan F. Chadima 3d742c
+		ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return(ctx->major);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+OM_uint32
Jan F. Chadima 3d742c
 ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_t buffer, gss_buffer_t hash)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
+	if (ctx == NULL) 
Jan F. Chadima 3d742c
+		return -1;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	if ((ctx->major = gss_get_mic(&ctx->minor, ctx->context,
Jan F. Chadima 3d742c
 	    GSS_C_QOP_DEFAULT, buffer, hash)))
Jan F. Chadima 3d742c
 		ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
@@ -236,6 +425,19 @@
Jan F. Chadima 3d742c
 	return (ctx->major);
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+/* Priviledged when used by server */
Jan F. Chadima 3d742c
+OM_uint32
Jan F. Chadima 3d742c
+ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	if (ctx == NULL)
Jan F. Chadima 3d742c
+		return -1;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
Jan F. Chadima 3d742c
+	    gssbuf, gssmic, NULL);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return (ctx->major);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 void
Jan F. Chadima 3d742c
 ssh_gssapi_buildmic(Buffer *b, const char *user, const char *service,
Jan F. Chadima 3d742c
     const char *context)
Jan F. Chadima 3d742c
@@ -249,11 +451,16 @@
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 int
Jan F. Chadima 3d742c
-ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host)
Jan F. Chadima 3d742c
+ssh_gssapi_check_mechanism(Gssctxt **ctx, gss_OID oid, const char *host, 
Jan F. Chadima 3d742c
+    const char *client)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
Jan F. Chadima 3d742c
 	OM_uint32 major, minor;
Jan F. Chadima 3d742c
 	gss_OID_desc spnego_oid = {6, (void *)"\x2B\x06\x01\x05\x05\x02"};
Jan F. Chadima 3d742c
+	Gssctxt *intctx = NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (ctx == NULL)
Jan F. Chadima 3d742c
+		ctx = &intct;;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	/* RFC 4462 says we MUST NOT do SPNEGO */
Jan F. Chadima 3d742c
 	if (oid->length == spnego_oid.length && 
Jan F. Chadima 3d742c
@@ -263,6 +470,10 @@
Jan F. Chadima 3d742c
 	ssh_gssapi_build_ctx(ctx);
Jan F. Chadima 3d742c
 	ssh_gssapi_set_oid(*ctx, oid);
Jan F. Chadima 3d742c
 	major = ssh_gssapi_import_name(*ctx, host);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (!GSS_ERROR(major) && client)
Jan F. Chadima 3d742c
+		major = ssh_gssapi_client_identity(*ctx, client);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	if (!GSS_ERROR(major)) {
Jan F. Chadima 3d742c
 		major = ssh_gssapi_init_ctx(*ctx, 0, GSS_C_NO_BUFFER, &token, 
Jan F. Chadima 3d742c
 		    NULL);
Jan F. Chadima 3d742c
@@ -272,10 +483,67 @@
Jan F. Chadima 3d742c
 			    GSS_C_NO_BUFFER);
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	if (GSS_ERROR(major)) 
Jan F. Chadima 3d742c
+	if (GSS_ERROR(major) || intctx != NULL) 
Jan F. Chadima 3d742c
 		ssh_gssapi_delete_ctx(ctx);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	return (!GSS_ERROR(major));
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int
Jan F. Chadima 3d742c
+ssh_gssapi_credentials_updated(Gssctxt *ctxt) {
Jan F. Chadima 3d742c
+	static gss_name_t saved_name = GSS_C_NO_NAME;
Jan F. Chadima 3d742c
+	static OM_uint32 saved_lifetime = 0;
Jan F. Chadima 3d742c
+	static gss_OID saved_mech = GSS_C_NO_OID;
Jan F. Chadima 3d742c
+	static gss_name_t name;
Jan F. Chadima 3d742c
+	static OM_uint32 last_call = 0;
Jan F. Chadima 3d742c
+	OM_uint32 lifetime, now, major, minor;
Jan F. Chadima 3d742c
+	int equal;
Jan F. Chadima 3d742c
+	gss_cred_usage_t usage = GSS_C_INITIATE;
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	now = time(NULL);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (ctxt) {
Jan F. Chadima 3d742c
+		debug("Rekey has happened - updating saved versions");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (saved_name != GSS_C_NO_NAME)
Jan F. Chadima 3d742c
+			gss_release_name(&minor, &saved_name);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL,
Jan F. Chadima 3d742c
+		    &saved_name, &saved_lifetime, NULL, NULL);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (!GSS_ERROR(major)) {
Jan F. Chadima 3d742c
+			saved_mech = ctxt->oid;
Jan F. Chadima 3d742c
+		        saved_lifetime+= now;
Jan F. Chadima 3d742c
+		} else {
Jan F. Chadima 3d742c
+			/* Handle the error */
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (now - last_call < 10)
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	last_call = now;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (saved_mech == GSS_C_NO_OID)
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	major = gss_inquire_cred(&minor, GSS_C_NO_CREDENTIAL, 
Jan F. Chadima 3d742c
+	    &name, &lifetime, NULL, NULL);
Jan F. Chadima 3d742c
+	if (major == GSS_S_CREDENTIALS_EXPIRED)
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	else if (GSS_ERROR(major))
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	major = gss_compare_name(&minor, saved_name, name, &equal);
Jan F. Chadima 3d742c
+	gss_release_name(&minor, &name);
Jan F. Chadima 3d742c
+	if (GSS_ERROR(major))
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (equal && (saved_lifetime < lifetime + now - 10))
Jan F. Chadima 3d742c
+		return 1;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return 0;
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #endif /* GSSAPI */
Jan F. Chadima 3d742c
Index: gss-serv-krb5.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/gss-serv-krb5.c,v
Jan F. Chadima 3d742c
retrieving revision 1.17
Jan F. Chadima 3d742c
diff -u -r1.17 gss-serv-krb5.c
Jan F. Chadima 3d742c
--- gss-serv-krb5.c	1 Sep 2006 05:38:36 -0000	1.17
Jan F. Chadima 3d742c
+++ gss-serv-krb5.c	26 Jul 2009 12:22:01 -0000
Jan F. Chadima 3d742c
@@ -1,7 +1,7 @@
Jan F. Chadima 3d742c
 /* $OpenBSD: gss-serv-krb5.c,v 1.7 2006/08/03 03:34:42 deraadt Exp $ */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /*
Jan F. Chadima 3d742c
- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2007 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
  *
Jan F. Chadima 3d742c
  * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
  * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
@@ -120,6 +120,7 @@
Jan F. Chadima 3d742c
 	krb5_principal princ;
Jan F. Chadima 3d742c
 	OM_uint32 maj_status, min_status;
Jan F. Chadima 3d742c
 	int len;
Jan F. Chadima 3d742c
+	const char *new_ccname;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	if (client->creds == NULL) {
Jan F. Chadima 3d742c
 		debug("No credentials stored");
Jan F. Chadima 3d742c
@@ -168,11 +169,16 @@
Jan F. Chadima 3d742c
 		return;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache));
Jan F. Chadima 3d742c
+	new_ccname = krb5_cc_get_name(krb_context, ccache);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	client->store.envvar = "KRB5CCNAME";
Jan F. Chadima 3d742c
-	len = strlen(client->store.filename) + 6;
Jan F. Chadima 3d742c
-	client->store.envval = xmalloc(len);
Jan F. Chadima 3d742c
-	snprintf(client->store.envval, len, "FILE:%s", client->store.filename);
Jan F. Chadima 3d742c
+#ifdef USE_CCAPI
Jan F. Chadima 3d742c
+	xasprintf(&client->store.envval, "API:%s", new_ccname);
Jan F. Chadima 3d742c
+	client->store.filename = NULL;
Jan F. Chadima 3d742c
+#else
Jan F. Chadima 3d742c
+	xasprintf(&client->store.envval, "FILE:%s", new_ccname);
Jan F. Chadima 3d742c
+	client->store.filename = xstrdup(new_ccname);
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef USE_PAM
Jan F. Chadima 3d742c
 	if (options.use_pam)
Jan F. Chadima 3d742c
@@ -184,6 +190,71 @@
Jan F. Chadima 3d742c
 	return;
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+int
Jan F. Chadima 3d742c
+ssh_gssapi_krb5_updatecreds(ssh_gssapi_ccache *store, 
Jan F. Chadima 3d742c
+    ssh_gssapi_client *client)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	krb5_ccache ccache = NULL;
Jan F. Chadima 3d742c
+	krb5_principal principal = NULL;
Jan F. Chadima 3d742c
+	char *name = NULL;
Jan F. Chadima 3d742c
+	krb5_error_code problem;
Jan F. Chadima 3d742c
+	OM_uint32 maj_status, min_status;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+   	if ((problem = krb5_cc_resolve(krb_context, store->envval, &ccache))) {
Jan F. Chadima 3d742c
+                logit("krb5_cc_resolve(): %.100s",
Jan F. Chadima 3d742c
+                    krb5_get_err_text(krb_context, problem));
Jan F. Chadima 3d742c
+                return 0;
Jan F. Chadima 3d742c
+       	}
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	/* Find out who the principal in this cache is */
Jan F. Chadima 3d742c
+	if ((problem = krb5_cc_get_principal(krb_context, ccache, 
Jan F. Chadima 3d742c
+	    &principal))) {
Jan F. Chadima 3d742c
+		logit("krb5_cc_get_principal(): %.100s",
Jan F. Chadima 3d742c
+		    krb5_get_err_text(krb_context, problem));
Jan F. Chadima 3d742c
+		krb5_cc_close(krb_context, ccache);
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if ((problem = krb5_unparse_name(krb_context, principal, &name))) {
Jan F. Chadima 3d742c
+		logit("krb5_unparse_name(): %.100s",
Jan F. Chadima 3d742c
+		    krb5_get_err_text(krb_context, problem));
Jan F. Chadima 3d742c
+		krb5_free_principal(krb_context, principal);
Jan F. Chadima 3d742c
+		krb5_cc_close(krb_context, ccache);
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (strcmp(name,client->exportedname.value)!=0) {
Jan F. Chadima 3d742c
+		debug("Name in local credentials cache differs. Not storing");
Jan F. Chadima 3d742c
+		krb5_free_principal(krb_context, principal);
Jan F. Chadima 3d742c
+		krb5_cc_close(krb_context, ccache);
Jan F. Chadima 3d742c
+		krb5_free_unparsed_name(krb_context, name);
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+	krb5_free_unparsed_name(krb_context, name);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Name matches, so lets get on with it! */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if ((problem = krb5_cc_initialize(krb_context, ccache, principal))) {
Jan F. Chadima 3d742c
+		logit("krb5_cc_initialize(): %.100s",
Jan F. Chadima 3d742c
+		    krb5_get_err_text(krb_context, problem));
Jan F. Chadima 3d742c
+		krb5_free_principal(krb_context, principal);
Jan F. Chadima 3d742c
+		krb5_cc_close(krb_context, ccache);
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	krb5_free_principal(krb_context, principal);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if ((maj_status = gss_krb5_copy_ccache(&min_status, client->creds,
Jan F. Chadima 3d742c
+	    ccache))) {
Jan F. Chadima 3d742c
+		logit("gss_krb5_copy_ccache() failed. Sorry!");
Jan F. Chadima 3d742c
+		krb5_cc_close(krb_context, ccache);
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return 1;
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 ssh_gssapi_mech gssapi_kerberos_mech = {
Jan F. Chadima 3d742c
 	"toWM5Slw5Ew8Mqkay+al2g==",
Jan F. Chadima 3d742c
 	"Kerberos",
Jan F. Chadima 3d742c
@@ -191,7 +262,8 @@
Jan F. Chadima 3d742c
 	NULL,
Jan F. Chadima 3d742c
 	&ssh_gssapi_krb5_userok,
Jan F. Chadima 3d742c
 	NULL,
Jan F. Chadima 3d742c
-	&ssh_gssapi_krb5_storecreds
Jan F. Chadima 3d742c
+	&ssh_gssapi_krb5_storecreds,
Jan F. Chadima 3d742c
+	&ssh_gssapi_krb5_updatecreds
Jan F. Chadima 3d742c
 };
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #endif /* KRB5 */
Jan F. Chadima 3d742c
Index: gss-serv.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/gss-serv.c,v
Jan F. Chadima 3d742c
retrieving revision 1.24
Jan F. Chadima 3d742c
diff -u -r1.24 gss-serv.c
Jan F. Chadima 3d742c
--- gss-serv.c	19 May 2008 05:05:07 -0000	1.24
Jan F. Chadima 3d742c
+++ gss-serv.c	26 Jul 2009 12:22:01 -0000
Jan F. Chadima 3d742c
@@ -1,7 +1,7 @@
Jan F. Chadima 3d742c
 /* $OpenBSD: gss-serv.c,v 1.22 2008/05/08 12:02:23 djm Exp $ */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /*
Jan F. Chadima 3d742c
- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
  *
Jan F. Chadima 3d742c
  * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
  * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
@@ -45,15 +45,20 @@
Jan F. Chadima 3d742c
 #include "channels.h"
Jan F. Chadima 3d742c
 #include "session.h"
Jan F. Chadima 3d742c
 #include "misc.h"
Jan F. Chadima 3d742c
+#include "servconf.h"
Jan F. Chadima 3d742c
+#include "uidswap.h"
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #include "ssh-gss.h"
Jan F. Chadima 3d742c
+#include "monitor_wrap.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+extern ServerOptions options;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 static ssh_gssapi_client gssapi_client =
Jan F. Chadima 3d742c
     { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
Jan F. Chadima 3d742c
-    GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL}};
Jan F. Chadima 3d742c
+    GSS_C_NO_CREDENTIAL, GSS_C_NO_NAME,  NULL, {NULL, NULL, NULL}, 0, 0};
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 ssh_gssapi_mech gssapi_null_mech =
Jan F. Chadima 3d742c
-    { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL};
Jan F. Chadima 3d742c
+    { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL, NULL};
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef KRB5
Jan F. Chadima 3d742c
 extern ssh_gssapi_mech gssapi_kerberos_mech;
Jan F. Chadima 3d742c
@@ -81,25 +86,32 @@
Jan F. Chadima 3d742c
 	char lname[MAXHOSTNAMELEN];
Jan F. Chadima 3d742c
 	gss_OID_set oidset;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	gss_create_empty_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
-	gss_add_oid_set_member(&status, ctx->oid, &oidset);
Jan F. Chadima 3d742c
+	if (options.gss_strict_acceptor) {
Jan F. Chadima 3d742c
+		gss_create_empty_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
+		gss_add_oid_set_member(&status, ctx->oid, &oidset);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (gethostname(lname, MAXHOSTNAMELEN)) {
Jan F. Chadima 3d742c
+			gss_release_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
+			return (-1);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	if (gethostname(lname, MAXHOSTNAMELEN)) {
Jan F. Chadima 3d742c
-		gss_release_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
-		return (-1);
Jan F. Chadima 3d742c
-	}
Jan F. Chadima 3d742c
+		if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
Jan F. Chadima 3d742c
+			gss_release_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
+			return (ctx->major);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if ((ctx->major = gss_acquire_cred(&ctx->minor,
Jan F. Chadima 3d742c
+		    ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds, 
Jan F. Chadima 3d742c
+		    NULL, NULL)))
Jan F. Chadima 3d742c
+			ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
Jan F. Chadima 3d742c
 		gss_release_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
 		return (ctx->major);
Jan F. Chadima 3d742c
+	} else {
Jan F. Chadima 3d742c
+		ctx->name = GSS_C_NO_NAME;
Jan F. Chadima 3d742c
+		ctx->creds = GSS_C_NO_CREDENTIAL;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
-
Jan F. Chadima 3d742c
-	if ((ctx->major = gss_acquire_cred(&ctx->minor,
Jan F. Chadima 3d742c
-	    ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds, NULL, NULL)))
Jan F. Chadima 3d742c
-		ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
-
Jan F. Chadima 3d742c
-	gss_release_oid_set(&status, &oidset);
Jan F. Chadima 3d742c
-	return (ctx->major);
Jan F. Chadima 3d742c
+	return GSS_S_COMPLETE;
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /* Privileged */
Jan F. Chadima 3d742c
@@ -114,6 +126,29 @@
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /* Unprivileged */
Jan F. Chadima 3d742c
+char *
Jan F. Chadima 3d742c
+ssh_gssapi_server_mechanisms() {
Jan F. Chadima 3d742c
+	gss_OID_set	supported;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ssh_gssapi_supported_oids(&supported);
Jan F. Chadima 3d742c
+	return (ssh_gssapi_kex_mechs(supported, &ssh_gssapi_server_check_mech,
Jan F. Chadima 3d742c
+	    NULL, NULL));
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+/* Unprivileged */
Jan F. Chadima 3d742c
+int
Jan F. Chadima 3d742c
+ssh_gssapi_server_check_mech(Gssctxt **dum, gss_OID oid, const char *data,
Jan F. Chadima 3d742c
+    const char *dummy) {
Jan F. Chadima 3d742c
+	Gssctxt *ctx = NULL;
Jan F. Chadima 3d742c
+	int res;
Jan F. Chadima 3d742c
+ 
Jan F. Chadima 3d742c
+	res = !GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctx, oid)));
Jan F. Chadima 3d742c
+	ssh_gssapi_delete_ctx(&ctx;;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return (res);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+/* Unprivileged */
Jan F. Chadima 3d742c
 void
Jan F. Chadima 3d742c
 ssh_gssapi_supported_oids(gss_OID_set *oidset)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
@@ -123,7 +158,9 @@
Jan F. Chadima 3d742c
 	gss_OID_set supported;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	gss_create_empty_oid_set(&min_status, oidset);
Jan F. Chadima 3d742c
-	gss_indicate_mechs(&min_status, &supported);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (GSS_ERROR(gss_indicate_mechs(&min_status, &supported)))
Jan F. Chadima 3d742c
+		return;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	while (supported_mechs[i]->name != NULL) {
Jan F. Chadima 3d742c
 		if (GSS_ERROR(gss_test_oid_set_member(&min_status,
Jan F. Chadima 3d742c
@@ -247,8 +284,48 @@
Jan F. Chadima 3d742c
 ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	int i = 0;
Jan F. Chadima 3d742c
+	int equal = 0;
Jan F. Chadima 3d742c
+	gss_name_t new_name = GSS_C_NO_NAME;
Jan F. Chadima 3d742c
+	gss_buffer_desc ename = GSS_C_EMPTY_BUFFER;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (options.gss_store_rekey && client->used && ctx->client_creds) {
Jan F. Chadima 3d742c
+		if (client->mech->oid.length != ctx->oid->length ||
Jan F. Chadima 3d742c
+		    (memcmp(client->mech->oid.elements,
Jan F. Chadima 3d742c
+		     ctx->oid->elements, ctx->oid->length) !=0)) {
Jan F. Chadima 3d742c
+			debug("Rekeyed credentials have different mechanism");
Jan F. Chadima 3d742c
+			return GSS_S_COMPLETE;
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if ((ctx->major = gss_inquire_cred_by_mech(&ctx->minor, 
Jan F. Chadima 3d742c
+		    ctx->client_creds, ctx->oid, &new_name, 
Jan F. Chadima 3d742c
+		    NULL, NULL, NULL))) {
Jan F. Chadima 3d742c
+			ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
+			return (ctx->major);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		ctx->major = gss_compare_name(&ctx->minor, client->name, 
Jan F. Chadima 3d742c
+		    new_name, &equal);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	gss_buffer_desc ename;
Jan F. Chadima 3d742c
+		if (GSS_ERROR(ctx->major)) {
Jan F. Chadima 3d742c
+			ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
+			return (ctx->major);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+ 
Jan F. Chadima 3d742c
+		if (!equal) {
Jan F. Chadima 3d742c
+			debug("Rekeyed credentials have different name");
Jan F. Chadima 3d742c
+			return GSS_S_COMPLETE;
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		debug("Marking rekeyed credentials for export");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		gss_release_name(&ctx->minor, &client->name);
Jan F. Chadima 3d742c
+		gss_release_cred(&ctx->minor, &client->creds);
Jan F. Chadima 3d742c
+		client->name = new_name;
Jan F. Chadima 3d742c
+		client->creds = ctx->client_creds;
Jan F. Chadima 3d742c
+        	ctx->client_creds = GSS_C_NO_CREDENTIAL;
Jan F. Chadima 3d742c
+		client->updated = 1;
Jan F. Chadima 3d742c
+		return GSS_S_COMPLETE;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	client->mech = NULL;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -263,6 +340,13 @@
Jan F. Chadima 3d742c
 	if (client->mech == NULL)
Jan F. Chadima 3d742c
 		return GSS_S_FAILURE;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	if (ctx->client_creds &&
Jan F. Chadima 3d742c
+	    (ctx->major = gss_inquire_cred_by_mech(&ctx->minor,
Jan F. Chadima 3d742c
+	     ctx->client_creds, ctx->oid, &client->name, NULL, NULL, NULL))) {
Jan F. Chadima 3d742c
+		ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
+		return (ctx->major);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
Jan F. Chadima 3d742c
 	    &client->displayname, NULL))) {
Jan F. Chadima 3d742c
 		ssh_gssapi_error(ctx);
Jan F. Chadima 3d742c
@@ -280,6 +364,8 @@
Jan F. Chadima 3d742c
 		return (ctx->major);
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	gss_release_buffer(&ctx->minor, &ename);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	/* We can't copy this structure, so we just move the pointer to it */
Jan F. Chadima 3d742c
 	client->creds = ctx->client_creds;
Jan F. Chadima 3d742c
 	ctx->client_creds = GSS_C_NO_CREDENTIAL;
Jan F. Chadima 3d742c
@@ -327,7 +413,7 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /* Privileged */
Jan F. Chadima 3d742c
 int
Jan F. Chadima 3d742c
-ssh_gssapi_userok(char *user)
Jan F. Chadima 3d742c
+ssh_gssapi_userok(char *user, struct passwd *pw)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	OM_uint32 lmin;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -337,9 +423,11 @@
Jan F. Chadima 3d742c
 		return 0;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 	if (gssapi_client.mech && gssapi_client.mech->userok)
Jan F. Chadima 3d742c
-		if ((*gssapi_client.mech->userok)(&gssapi_client, user))
Jan F. Chadima 3d742c
+		if ((*gssapi_client.mech->userok)(&gssapi_client, user)) {
Jan F. Chadima 3d742c
+			gssapi_client.used = 1;
Jan F. Chadima 3d742c
+			gssapi_client.store.owner = pw;
Jan F. Chadima 3d742c
 			return 1;
Jan F. Chadima 3d742c
-		else {
Jan F. Chadima 3d742c
+		} else {
Jan F. Chadima 3d742c
 			/* Destroy delegated credentials if userok fails */
Jan F. Chadima 3d742c
 			gss_release_buffer(&lmin, &gssapi_client.displayname);
Jan F. Chadima 3d742c
 			gss_release_buffer(&lmin, &gssapi_client.exportedname);
Jan F. Chadima 3d742c
@@ -352,14 +440,90 @@
Jan F. Chadima 3d742c
 	return (0);
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-/* Privileged */
Jan F. Chadima 3d742c
-OM_uint32
Jan F. Chadima 3d742c
-ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
Jan F. Chadima 3d742c
+/* These bits are only used for rekeying. The unpriviledged child is running 
Jan F. Chadima 3d742c
+ * as the user, the monitor is root.
Jan F. Chadima 3d742c
+ *
Jan F. Chadima 3d742c
+ * In the child, we want to :
Jan F. Chadima 3d742c
+ *    *) Ask the monitor to store our credentials into the store we specify
Jan F. Chadima 3d742c
+ *    *) If it succeeds, maybe do a PAM update
Jan F. Chadima 3d742c
+ */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+/* Stuff for PAM */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#ifdef USE_PAM
Jan F. Chadima 3d742c
+static int ssh_gssapi_simple_conv(int n, const struct pam_message **msg, 
Jan F. Chadima 3d742c
+    struct pam_response **resp, void *data)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
-	ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
Jan F. Chadima 3d742c
-	    gssbuf, gssmic, NULL);
Jan F. Chadima 3d742c
+	return (PAM_CONV_ERR);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	return (ctx->major);
Jan F. Chadima 3d742c
+void
Jan F. Chadima 3d742c
+ssh_gssapi_rekey_creds() {
Jan F. Chadima 3d742c
+	int ok;
Jan F. Chadima 3d742c
+	int ret;
Jan F. Chadima 3d742c
+#ifdef USE_PAM
Jan F. Chadima 3d742c
+	pam_handle_t *pamh = NULL;
Jan F. Chadima 3d742c
+	struct pam_conv pamconv = {ssh_gssapi_simple_conv, NULL};
Jan F. Chadima 3d742c
+	char *envstr;
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gssapi_client.store.filename == NULL && 
Jan F. Chadima 3d742c
+	    gssapi_client.store.envval == NULL &&
Jan F. Chadima 3d742c
+	    gssapi_client.store.envvar == NULL)
Jan F. Chadima 3d742c
+		return;
Jan F. Chadima 3d742c
+ 
Jan F. Chadima 3d742c
+	ok = PRIVSEP(ssh_gssapi_update_creds(&gssapi_client.store));
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (!ok)
Jan F. Chadima 3d742c
+		return;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	debug("Rekeyed credentials stored successfully");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Actually managing to play with the ssh pam stack from here will
Jan F. Chadima 3d742c
+	 * be next to impossible. In any case, we may want different options
Jan F. Chadima 3d742c
+	 * for rekeying. So, use our own :)
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+#ifdef USE_PAM	
Jan F. Chadima 3d742c
+	if (!use_privsep) {
Jan F. Chadima 3d742c
+		debug("Not even going to try and do PAM with privsep disabled");
Jan F. Chadima 3d742c
+		return;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ret = pam_start("sshd-rekey", gssapi_client.store.owner->pw_name,
Jan F. Chadima 3d742c
+ 	    &pamconv, &pamh);
Jan F. Chadima 3d742c
+	if (ret)
Jan F. Chadima 3d742c
+		return;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	xasprintf(&envstr, "%s=%s", gssapi_client.store.envvar, 
Jan F. Chadima 3d742c
+	    gssapi_client.store.envval);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ret = pam_putenv(pamh, envstr);
Jan F. Chadima 3d742c
+	if (!ret)
Jan F. Chadima 3d742c
+		pam_setcred(pamh, PAM_REINITIALIZE_CRED);
Jan F. Chadima 3d742c
+	pam_end(pamh, PAM_SUCCESS);
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int 
Jan F. Chadima 3d742c
+ssh_gssapi_update_creds(ssh_gssapi_ccache *store) {
Jan F. Chadima 3d742c
+	int ok = 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Check we've got credentials to store */
Jan F. Chadima 3d742c
+	if (!gssapi_client.updated)
Jan F. Chadima 3d742c
+		return 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gssapi_client.updated = 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	temporarily_use_uid(gssapi_client.store.owner);
Jan F. Chadima 3d742c
+	if (gssapi_client.mech && gssapi_client.mech->updatecreds)
Jan F. Chadima 3d742c
+		ok = (*gssapi_client.mech->updatecreds)(store, &gssapi_client);
Jan F. Chadima 3d742c
+	else
Jan F. Chadima 3d742c
+		debug("No update function for this mechanism");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	restore_uid();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return ok;
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
Index: kex.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/kex.c,v
Jan F. Chadima 3d742c
retrieving revision 1.87
Jan F. Chadima 3d742c
diff -u -r1.87 kex.c
Jan F. Chadima 3d742c
--- kex.c	3 Nov 2008 08:19:12 -0000	1.87
Jan F. Chadima 3d742c
+++ kex.c	26 Jul 2009 12:22:02 -0000
Jan F. Chadima 3d742c
@@ -49,6 +49,10 @@
Jan F. Chadima 3d742c
 #include "dispatch.h"
Jan F. Chadima 3d742c
 #include "monitor.h"
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+#include "ssh-gss.h"
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 #define KEX_COOKIE_LEN	16
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #if OPENSSL_VERSION_NUMBER >= 0x00907000L
Jan F. Chadima 3d742c
@@ -326,6 +330,20 @@
Jan F. Chadima 3d742c
 	} else if (strcmp(k->name, KEX_DHGEX_SHA256) == 0) {
Jan F. Chadima 3d742c
 		k->kex_type = KEX_DH_GEX_SHA256;
Jan F. Chadima 3d742c
 		k->evp_md = evp_ssh_sha256();
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	} else if (strncmp(k->name, KEX_GSS_GEX_SHA1_ID,
Jan F. Chadima 3d742c
+	    sizeof(KEX_GSS_GEX_SHA1_ID) - 1) == 0) {
Jan F. Chadima 3d742c
+		k->kex_type = KEX_GSS_GEX_SHA1;
Jan F. Chadima 3d742c
+		k->evp_md = EVP_sha1();
Jan F. Chadima 3d742c
+	} else if (strncmp(k->name, KEX_GSS_GRP1_SHA1_ID,
Jan F. Chadima 3d742c
+	    sizeof(KEX_GSS_GRP1_SHA1_ID) - 1) == 0) {
Jan F. Chadima 3d742c
+		k->kex_type = KEX_GSS_GRP1_SHA1;
Jan F. Chadima 3d742c
+		k->evp_md = EVP_sha1();
Jan F. Chadima 3d742c
+	} else if (strncmp(k->name, KEX_GSS_GRP14_SHA1_ID,
Jan F. Chadima 3d742c
+	    sizeof(KEX_GSS_GRP14_SHA1_ID) - 1) == 0) {
Jan F. Chadima 3d742c
+		k->kex_type = KEX_GSS_GRP14_SHA1;
Jan F. Chadima 3d742c
+		k->evp_md = EVP_sha1();
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 	} else
Jan F. Chadima 3d742c
 		fatal("bad kex alg %s", k->name);
Jan F. Chadima 3d742c
Index: kex.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/kex.h,v
Jan F. Chadima 3d742c
retrieving revision 1.49
Jan F. Chadima 3d742c
diff -u -r1.49 kex.h
Jan F. Chadima 3d742c
--- kex.h	11 Jun 2007 04:01:42 -0000	1.49
Jan F. Chadima 3d742c
+++ kex.h	26 Jul 2009 12:22:02 -0000
Jan F. Chadima 3d742c
@@ -64,6 +64,9 @@
Jan F. Chadima 3d742c
 	KEX_DH_GRP14_SHA1,
Jan F. Chadima 3d742c
 	KEX_DH_GEX_SHA1,
Jan F. Chadima 3d742c
 	KEX_DH_GEX_SHA256,
Jan F. Chadima 3d742c
+	KEX_GSS_GRP1_SHA1,
Jan F. Chadima 3d742c
+	KEX_GSS_GRP14_SHA1,
Jan F. Chadima 3d742c
+	KEX_GSS_GEX_SHA1,
Jan F. Chadima 3d742c
 	KEX_MAX
Jan F. Chadima 3d742c
 };
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -119,6 +122,12 @@
Jan F. Chadima 3d742c
 	sig_atomic_t done;
Jan F. Chadima 3d742c
 	int	flags;
Jan F. Chadima 3d742c
 	const EVP_MD *evp_md;
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	int	gss_deleg_creds;
Jan F. Chadima 3d742c
+	int	gss_trust_dns;
Jan F. Chadima 3d742c
+	char    *gss_host;
Jan F. Chadima 3d742c
+	char	*gss_client;
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 	char	*client_version_string;
Jan F. Chadima 3d742c
 	char	*server_version_string;
Jan F. Chadima 3d742c
 	int	(*verify_host_key)(Key *);
Jan F. Chadima 3d742c
@@ -140,6 +149,11 @@
Jan F. Chadima 3d742c
 void	 kexdh_server(Kex *);
Jan F. Chadima 3d742c
 void	 kexgex_client(Kex *);
Jan F. Chadima 3d742c
 void	 kexgex_server(Kex *);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+void	kexgss_client(Kex *);
Jan F. Chadima 3d742c
+void	kexgss_server(Kex *);
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 void
Jan F. Chadima 3d742c
 kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
Jan F. Chadima 3d742c
Index: kexgssc.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: kexgssc.c
Jan F. Chadima 3d742c
diff -N kexgssc.c
Jan F. Chadima 3d742c
--- /dev/null	1 Jan 1970 00:00:00 -0000
Jan F. Chadima 3d742c
+++ kexgssc.c	26 Jul 2009 12:22:02 -0000
Jan F. Chadima 3d742c
@@ -0,0 +1,334 @@
Jan F. Chadima 3d742c
+/*
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ *
Jan F. Chadima 3d742c
+ * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
+ * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
+ * are met:
Jan F. Chadima 3d742c
+ * 1. Redistributions of source code must retain the above copyright
Jan F. Chadima 3d742c
+ *    notice, this list of conditions and the following disclaimer.
Jan F. Chadima 3d742c
+ * 2. Redistributions in binary form must reproduce the above copyright
Jan F. Chadima 3d742c
+ *    notice, this list of conditions and the following disclaimer in the
Jan F. Chadima 3d742c
+ *    documentation and/or other materials provided with the distribution.
Jan F. Chadima 3d742c
+ *
Jan F. Chadima 3d742c
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
Jan F. Chadima 3d742c
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Jan F. Chadima 3d742c
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Jan F. Chadima 3d742c
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Jan F. Chadima 3d742c
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Jan F. Chadima 3d742c
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Jan F. Chadima 3d742c
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Jan F. Chadima 3d742c
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Jan F. Chadima 3d742c
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Jan F. Chadima 3d742c
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jan F. Chadima 3d742c
+ */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include "includes.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include "includes.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include <openssl/crypto.h>
Jan F. Chadima 3d742c
+#include <openssl/bn.h>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include <string.h>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include "xmalloc.h"
Jan F. Chadima 3d742c
+#include "buffer.h"
Jan F. Chadima 3d742c
+#include "ssh2.h"
Jan F. Chadima 3d742c
+#include "key.h"
Jan F. Chadima 3d742c
+#include "cipher.h"
Jan F. Chadima 3d742c
+#include "kex.h"
Jan F. Chadima 3d742c
+#include "log.h"
Jan F. Chadima 3d742c
+#include "packet.h"
Jan F. Chadima 3d742c
+#include "dh.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include "ssh-gss.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+void
Jan F. Chadima 3d742c
+kexgss_client(Kex *kex) {
Jan F. Chadima 3d742c
+	gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
Jan F. Chadima 3d742c
+	gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
Jan F. Chadima 3d742c
+	Gssctxt *ctxt;
Jan F. Chadima 3d742c
+	OM_uint32 maj_status, min_status, ret_flags;
Jan F. Chadima 3d742c
+	u_int klen, kout, slen = 0, hashlen, strlen;
Jan F. Chadima 3d742c
+	DH *dh; 
Jan F. Chadima 3d742c
+	BIGNUM *dh_server_pub = NULL;
Jan F. Chadima 3d742c
+	BIGNUM *shared_secret = NULL;
Jan F. Chadima 3d742c
+	BIGNUM *p = NULL;
Jan F. Chadima 3d742c
+	BIGNUM *g = NULL;	
Jan F. Chadima 3d742c
+	u_char *kbuf, *hash;
Jan F. Chadima 3d742c
+	u_char *serverhostkey = NULL;
Jan F. Chadima 3d742c
+	u_char *empty = "";
Jan F. Chadima 3d742c
+	char *msg;
Jan F. Chadima 3d742c
+	char *lang;
Jan F. Chadima 3d742c
+	int type = 0;
Jan F. Chadima 3d742c
+	int first = 1;
Jan F. Chadima 3d742c
+	int nbits = 0, min = DH_GRP_MIN, max = DH_GRP_MAX;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Initialise our GSSAPI world */	
Jan F. Chadima 3d742c
+	ssh_gssapi_build_ctx(&ctxt);
Jan F. Chadima 3d742c
+	if (ssh_gssapi_id_kex(ctxt, kex->name, kex->kex_type) 
Jan F. Chadima 3d742c
+	    == GSS_C_NO_OID)
Jan F. Chadima 3d742c
+		fatal("Couldn't identify host exchange");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (ssh_gssapi_import_name(ctxt, kex->gss_host))
Jan F. Chadima 3d742c
+		fatal("Couldn't import hostname");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (kex->gss_client && 
Jan F. Chadima 3d742c
+	    ssh_gssapi_client_identity(ctxt, kex->gss_client))
Jan F. Chadima 3d742c
+		fatal("Couldn't acquire client credentials");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	switch (kex->kex_type) {
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP1_SHA1:
Jan F. Chadima 3d742c
+		dh = dh_new_group1();
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP14_SHA1:
Jan F. Chadima 3d742c
+		dh = dh_new_group14();
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GEX_SHA1:
Jan F. Chadima 3d742c
+		debug("Doing group exchange\n");
Jan F. Chadima 3d742c
+		nbits = dh_estimate(kex->we_need * 8);
Jan F. Chadima 3d742c
+		packet_start(SSH2_MSG_KEXGSS_GROUPREQ);
Jan F. Chadima 3d742c
+		packet_put_int(min);
Jan F. Chadima 3d742c
+		packet_put_int(nbits);
Jan F. Chadima 3d742c
+		packet_put_int(max);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		packet_send();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		packet_read_expect(SSH2_MSG_KEXGSS_GROUP);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if ((p = BN_new()) == NULL)
Jan F. Chadima 3d742c
+			fatal("BN_new() failed");
Jan F. Chadima 3d742c
+		packet_get_bignum2(p);
Jan F. Chadima 3d742c
+		if ((g = BN_new()) == NULL)
Jan F. Chadima 3d742c
+			fatal("BN_new() failed");
Jan F. Chadima 3d742c
+		packet_get_bignum2(g);
Jan F. Chadima 3d742c
+		packet_check_eom();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (BN_num_bits(p) < min || BN_num_bits(p) > max)
Jan F. Chadima 3d742c
+			fatal("GSSGRP_GEX group out of range: %d !< %d !< %d",
Jan F. Chadima 3d742c
+			    min, BN_num_bits(p), max);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		dh = dh_new_group(g, p);
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	default:
Jan F. Chadima 3d742c
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	/* Step 1 - e is dh->pub_key */
Jan F. Chadima 3d742c
+	dh_gen_key(dh, kex->we_need * 8);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* This is f, we initialise it now to make life easier */
Jan F. Chadima 3d742c
+	dh_server_pub = BN_new();
Jan F. Chadima 3d742c
+	if (dh_server_pub == NULL)
Jan F. Chadima 3d742c
+		fatal("dh_server_pub == NULL");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	token_ptr = GSS_C_NO_BUFFER;
Jan F. Chadima 3d742c
+			 
Jan F. Chadima 3d742c
+	do {
Jan F. Chadima 3d742c
+		debug("Calling gss_init_sec_context");
Jan F. Chadima 3d742c
+		
Jan F. Chadima 3d742c
+		maj_status = ssh_gssapi_init_ctx(ctxt,
Jan F. Chadima 3d742c
+		    kex->gss_deleg_creds, token_ptr, &send_tok,
Jan F. Chadima 3d742c
+		    &ret_flags);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (GSS_ERROR(maj_status)) {
Jan F. Chadima 3d742c
+			if (send_tok.length != 0) {
Jan F. Chadima 3d742c
+				packet_start(SSH2_MSG_KEXGSS_CONTINUE);
Jan F. Chadima 3d742c
+				packet_put_string(send_tok.value,
Jan F. Chadima 3d742c
+				    send_tok.length);
Jan F. Chadima 3d742c
+			}
Jan F. Chadima 3d742c
+			fatal("gss_init_context failed");
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		/* If we've got an old receive buffer get rid of it */
Jan F. Chadima 3d742c
+		if (token_ptr != GSS_C_NO_BUFFER)
Jan F. Chadima 3d742c
+			xfree(recv_tok.value);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (maj_status == GSS_S_COMPLETE) {
Jan F. Chadima 3d742c
+			/* If mutual state flag is not true, kex fails */
Jan F. Chadima 3d742c
+			if (!(ret_flags & GSS_C_MUTUAL_FLAG))
Jan F. Chadima 3d742c
+				fatal("Mutual authentication failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			/* If integ avail flag is not true kex fails */
Jan F. Chadima 3d742c
+			if (!(ret_flags & GSS_C_INTEG_FLAG))
Jan F. Chadima 3d742c
+				fatal("Integrity check failed");
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		/* 
Jan F. Chadima 3d742c
+		 * If we have data to send, then the last message that we
Jan F. Chadima 3d742c
+		 * received cannot have been a 'complete'. 
Jan F. Chadima 3d742c
+		 */
Jan F. Chadima 3d742c
+		if (send_tok.length != 0) {
Jan F. Chadima 3d742c
+			if (first) {
Jan F. Chadima 3d742c
+				packet_start(SSH2_MSG_KEXGSS_INIT);
Jan F. Chadima 3d742c
+				packet_put_string(send_tok.value,
Jan F. Chadima 3d742c
+				    send_tok.length);
Jan F. Chadima 3d742c
+				packet_put_bignum2(dh->pub_key);
Jan F. Chadima 3d742c
+				first = 0;
Jan F. Chadima 3d742c
+			} else {
Jan F. Chadima 3d742c
+				packet_start(SSH2_MSG_KEXGSS_CONTINUE);
Jan F. Chadima 3d742c
+				packet_put_string(send_tok.value,
Jan F. Chadima 3d742c
+				    send_tok.length);
Jan F. Chadima 3d742c
+			}
Jan F. Chadima 3d742c
+			packet_send();
Jan F. Chadima 3d742c
+			gss_release_buffer(&min_status, &send_tok);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			/* If we've sent them data, they should reply */
Jan F. Chadima 3d742c
+			do {	
Jan F. Chadima 3d742c
+				type = packet_read();
Jan F. Chadima 3d742c
+				if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
Jan F. Chadima 3d742c
+					debug("Received KEXGSS_HOSTKEY");
Jan F. Chadima 3d742c
+					if (serverhostkey)
Jan F. Chadima 3d742c
+						fatal("Server host key received more than once");
Jan F. Chadima 3d742c
+					serverhostkey = 
Jan F. Chadima 3d742c
+					    packet_get_string(&slen);
Jan F. Chadima 3d742c
+				}
Jan F. Chadima 3d742c
+			} while (type == SSH2_MSG_KEXGSS_HOSTKEY);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			switch (type) {
Jan F. Chadima 3d742c
+			case SSH2_MSG_KEXGSS_CONTINUE:
Jan F. Chadima 3d742c
+				debug("Received GSSAPI_CONTINUE");
Jan F. Chadima 3d742c
+				if (maj_status == GSS_S_COMPLETE) 
Jan F. Chadima 3d742c
+					fatal("GSSAPI Continue received from server when complete");
Jan F. Chadima 3d742c
+				recv_tok.value = packet_get_string(&strlen);
Jan F. Chadima 3d742c
+				recv_tok.length = strlen; 
Jan F. Chadima 3d742c
+				break;
Jan F. Chadima 3d742c
+			case SSH2_MSG_KEXGSS_COMPLETE:
Jan F. Chadima 3d742c
+				debug("Received GSSAPI_COMPLETE");
Jan F. Chadima 3d742c
+				packet_get_bignum2(dh_server_pub);
Jan F. Chadima 3d742c
+				msg_tok.value =  packet_get_string(&strlen);
Jan F. Chadima 3d742c
+				msg_tok.length = strlen; 
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+				/* Is there a token included? */
Jan F. Chadima 3d742c
+				if (packet_get_char()) {
Jan F. Chadima 3d742c
+					recv_tok.value=
Jan F. Chadima 3d742c
+					    packet_get_string(&strlen);
Jan F. Chadima 3d742c
+					recv_tok.length = strlen;
Jan F. Chadima 3d742c
+					/* If we're already complete - protocol error */
Jan F. Chadima 3d742c
+					if (maj_status == GSS_S_COMPLETE)
Jan F. Chadima 3d742c
+						packet_disconnect("Protocol error: received token when complete");
Jan F. Chadima 3d742c
+					} else {
Jan F. Chadima 3d742c
+						/* No token included */
Jan F. Chadima 3d742c
+						if (maj_status != GSS_S_COMPLETE)
Jan F. Chadima 3d742c
+							packet_disconnect("Protocol error: did not receive final token");
Jan F. Chadima 3d742c
+				}
Jan F. Chadima 3d742c
+				break;
Jan F. Chadima 3d742c
+			case SSH2_MSG_KEXGSS_ERROR:
Jan F. Chadima 3d742c
+				debug("Received Error");
Jan F. Chadima 3d742c
+				maj_status = packet_get_int();
Jan F. Chadima 3d742c
+				min_status = packet_get_int();
Jan F. Chadima 3d742c
+				msg = packet_get_string(NULL);
Jan F. Chadima 3d742c
+				lang = packet_get_string(NULL);
Jan F. Chadima 3d742c
+				fatal("GSSAPI Error: \n%.400s",msg);
Jan F. Chadima 3d742c
+			default:
Jan F. Chadima 3d742c
+				packet_disconnect("Protocol error: didn't expect packet type %d",
Jan F. Chadima 3d742c
+		    		type);
Jan F. Chadima 3d742c
+			}
Jan F. Chadima 3d742c
+			token_ptr = &recv_tok;
Jan F. Chadima 3d742c
+		} else {
Jan F. Chadima 3d742c
+			/* No data, and not complete */
Jan F. Chadima 3d742c
+			if (maj_status != GSS_S_COMPLETE)
Jan F. Chadima 3d742c
+				fatal("Not complete, and no token output");
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+	} while (maj_status & GSS_S_CONTINUE_NEEDED);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* 
Jan F. Chadima 3d742c
+	 * We _must_ have received a COMPLETE message in reply from the 
Jan F. Chadima 3d742c
+	 * server, which will have set dh_server_pub and msg_tok 
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (type != SSH2_MSG_KEXGSS_COMPLETE)
Jan F. Chadima 3d742c
+		fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Check f in range [1, p-1] */
Jan F. Chadima 3d742c
+	if (!dh_pub_is_valid(dh, dh_server_pub))
Jan F. Chadima 3d742c
+		packet_disconnect("bad server public DH value");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* compute K=f^x mod p */
Jan F. Chadima 3d742c
+	klen = DH_size(dh);
Jan F. Chadima 3d742c
+	kbuf = xmalloc(klen);
Jan F. Chadima 3d742c
+	kout = DH_compute_key(kbuf, dh_server_pub, dh);
Jan F. Chadima 3d742c
+	if (kout < 0)
Jan F. Chadima 3d742c
+		fatal("DH_compute_key: failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	shared_secret = BN_new();
Jan F. Chadima 3d742c
+	if (shared_secret == NULL)
Jan F. Chadima 3d742c
+		fatal("kexgss_client: BN_new failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
Jan F. Chadima 3d742c
+		fatal("kexdh_client: BN_bin2bn failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	memset(kbuf, 0, klen);
Jan F. Chadima 3d742c
+	xfree(kbuf);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	switch (kex->kex_type) {
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP1_SHA1:
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP14_SHA1:
Jan F. Chadima 3d742c
+		kex_dh_hash( kex->client_version_string, 
Jan F. Chadima 3d742c
+		    kex->server_version_string,
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->my), buffer_len(&kex->my),
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->peer), buffer_len(&kex->peer),
Jan F. Chadima 3d742c
+		    (serverhostkey ? serverhostkey : empty), slen,
Jan F. Chadima 3d742c
+		    dh->pub_key,	/* e */
Jan F. Chadima 3d742c
+		    dh_server_pub,	/* f */
Jan F. Chadima 3d742c
+		    shared_secret,	/* K */
Jan F. Chadima 3d742c
+		    &hash, &hashlen
Jan F. Chadima 3d742c
+		);
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GEX_SHA1:
Jan F. Chadima 3d742c
+		kexgex_hash(
Jan F. Chadima 3d742c
+		    kex->evp_md,
Jan F. Chadima 3d742c
+		    kex->client_version_string,
Jan F. Chadima 3d742c
+		    kex->server_version_string,
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->my), buffer_len(&kex->my),
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->peer), buffer_len(&kex->peer),
Jan F. Chadima 3d742c
+		    (serverhostkey ? serverhostkey : empty), slen,
Jan F. Chadima 3d742c
+ 		    min, nbits, max,
Jan F. Chadima 3d742c
+		    dh->p, dh->g,
Jan F. Chadima 3d742c
+		    dh->pub_key,
Jan F. Chadima 3d742c
+		    dh_server_pub,
Jan F. Chadima 3d742c
+		    shared_secret,
Jan F. Chadima 3d742c
+		    &hash, &hashlen
Jan F. Chadima 3d742c
+		);
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	default:
Jan F. Chadima 3d742c
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gssbuf.value = hash;
Jan F. Chadima 3d742c
+	gssbuf.length = hashlen;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Verify that the hash matches the MIC we just got. */
Jan F. Chadima 3d742c
+	if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
Jan F. Chadima 3d742c
+		packet_disconnect("Hash's MIC didn't verify");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	xfree(msg_tok.value);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	DH_free(dh);
Jan F. Chadima 3d742c
+	if (serverhostkey)
Jan F. Chadima 3d742c
+		xfree(serverhostkey);
Jan F. Chadima 3d742c
+	BN_clear_free(dh_server_pub);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* save session id */
Jan F. Chadima 3d742c
+	if (kex->session_id == NULL) {
Jan F. Chadima 3d742c
+		kex->session_id_len = hashlen;
Jan F. Chadima 3d742c
+		kex->session_id = xmalloc(kex->session_id_len);
Jan F. Chadima 3d742c
+		memcpy(kex->session_id, hash, kex->session_id_len);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (kex->gss_deleg_creds)
Jan F. Chadima 3d742c
+		ssh_gssapi_credentials_updated(ctxt);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gss_kex_context == NULL)
Jan F. Chadima 3d742c
+		gss_kex_context = ctxt;
Jan F. Chadima 3d742c
+	else
Jan F. Chadima 3d742c
+		ssh_gssapi_delete_ctx(&ctxt);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	kex_derive_keys(kex, hash, hashlen, shared_secret);
Jan F. Chadima 3d742c
+	BN_clear_free(shared_secret);
Jan F. Chadima 3d742c
+	kex_finish(kex);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#endif /* GSSAPI */
Jan F. Chadima 3d742c
Index: kexgsss.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: kexgsss.c
Jan F. Chadima 3d742c
diff -N kexgsss.c
Jan F. Chadima 3d742c
--- /dev/null	1 Jan 1970 00:00:00 -0000
Jan F. Chadima 3d742c
+++ kexgsss.c	26 Jul 2009 12:22:03 -0000
Jan F. Chadima 3d742c
@@ -0,0 +1,288 @@
Jan F. Chadima 3d742c
+/*
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ *
Jan F. Chadima 3d742c
+ * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
+ * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
+ * are met:
Jan F. Chadima 3d742c
+ * 1. Redistributions of source code must retain the above copyright
Jan F. Chadima 3d742c
+ *    notice, this list of conditions and the following disclaimer.
Jan F. Chadima 3d742c
+ * 2. Redistributions in binary form must reproduce the above copyright
Jan F. Chadima 3d742c
+ *    notice, this list of conditions and the following disclaimer in the
Jan F. Chadima 3d742c
+ *    documentation and/or other materials provided with the distribution.
Jan F. Chadima 3d742c
+ *
Jan F. Chadima 3d742c
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
Jan F. Chadima 3d742c
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Jan F. Chadima 3d742c
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Jan F. Chadima 3d742c
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Jan F. Chadima 3d742c
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Jan F. Chadima 3d742c
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Jan F. Chadima 3d742c
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Jan F. Chadima 3d742c
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Jan F. Chadima 3d742c
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Jan F. Chadima 3d742c
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jan F. Chadima 3d742c
+ */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include "includes.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include <string.h>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include <openssl/crypto.h>
Jan F. Chadima 3d742c
+#include <openssl/bn.h>
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+#include "xmalloc.h"
Jan F. Chadima 3d742c
+#include "buffer.h"
Jan F. Chadima 3d742c
+#include "ssh2.h"
Jan F. Chadima 3d742c
+#include "key.h"
Jan F. Chadima 3d742c
+#include "cipher.h"
Jan F. Chadima 3d742c
+#include "kex.h"
Jan F. Chadima 3d742c
+#include "log.h"
Jan F. Chadima 3d742c
+#include "packet.h"
Jan F. Chadima 3d742c
+#include "dh.h"
Jan F. Chadima 3d742c
+#include "ssh-gss.h"
Jan F. Chadima 3d742c
+#include "monitor_wrap.h"
Jan F. Chadima 3d742c
+#include "servconf.h"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+extern ServerOptions options;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+void
Jan F. Chadima 3d742c
+kexgss_server(Kex *kex)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	OM_uint32 maj_status, min_status;
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	/* 
Jan F. Chadima 3d742c
+	 * Some GSSAPI implementations use the input value of ret_flags (an
Jan F. Chadima 3d742c
+ 	 * output variable) as a means of triggering mechanism specific 
Jan F. Chadima 3d742c
+ 	 * features. Initializing it to zero avoids inadvertently 
Jan F. Chadima 3d742c
+ 	 * activating this non-standard behaviour.
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	OM_uint32 ret_flags = 0;
Jan F. Chadima 3d742c
+	gss_buffer_desc gssbuf, recv_tok, msg_tok;
Jan F. Chadima 3d742c
+	gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
Jan F. Chadima 3d742c
+	Gssctxt *ctxt = NULL;
Jan F. Chadima 3d742c
+	u_int slen, klen, kout, hashlen;
Jan F. Chadima 3d742c
+	u_char *kbuf, *hash;
Jan F. Chadima 3d742c
+	DH *dh;
Jan F. Chadima 3d742c
+	int min = -1, max = -1, nbits = -1;
Jan F. Chadima 3d742c
+	BIGNUM *shared_secret = NULL;
Jan F. Chadima 3d742c
+	BIGNUM *dh_client_pub = NULL;
Jan F. Chadima 3d742c
+	int type = 0;
Jan F. Chadima 3d742c
+	gss_OID oid;
Jan F. Chadima 3d742c
+	char *mechs;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Initialise GSSAPI */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* If we're rekeying, privsep means that some of the private structures
Jan F. Chadima 3d742c
+	 * in the GSSAPI code are no longer available. This kludges them back
Jan F. Chadima 3d742c
+	 * into life
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+	if (!ssh_gssapi_oid_table_ok()) 
Jan F. Chadima 3d742c
+		if ((mechs = ssh_gssapi_server_mechanisms()))
Jan F. Chadima 3d742c
+			xfree(mechs);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	debug2("%s: Identifying %s", __func__, kex->name);
Jan F. Chadima 3d742c
+	oid = ssh_gssapi_id_kex(NULL, kex->name, kex->kex_type);
Jan F. Chadima 3d742c
+	if (oid == GSS_C_NO_OID)
Jan F. Chadima 3d742c
+	   fatal("Unknown gssapi mechanism");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	debug2("%s: Acquiring credentials", __func__);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
Jan F. Chadima 3d742c
+		fatal("Unable to acquire credentials for the server");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	switch (kex->kex_type) {
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP1_SHA1:
Jan F. Chadima 3d742c
+		dh = dh_new_group1();
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP14_SHA1:
Jan F. Chadima 3d742c
+		dh = dh_new_group14();
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GEX_SHA1:
Jan F. Chadima 3d742c
+		debug("Doing group exchange");
Jan F. Chadima 3d742c
+		packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
Jan F. Chadima 3d742c
+		min = packet_get_int();
Jan F. Chadima 3d742c
+		nbits = packet_get_int();
Jan F. Chadima 3d742c
+		max = packet_get_int();
Jan F. Chadima 3d742c
+		min = MAX(DH_GRP_MIN, min);
Jan F. Chadima 3d742c
+		max = MIN(DH_GRP_MAX, max);
Jan F. Chadima 3d742c
+		packet_check_eom();
Jan F. Chadima 3d742c
+		if (max < min || nbits < min || max < nbits)
Jan F. Chadima 3d742c
+			fatal("GSS_GEX, bad parameters: %d !< %d !< %d",
Jan F. Chadima 3d742c
+			    min, nbits, max);
Jan F. Chadima 3d742c
+		dh = PRIVSEP(choose_dh(min, nbits, max));
Jan F. Chadima 3d742c
+		if (dh == NULL)
Jan F. Chadima 3d742c
+			packet_disconnect("Protocol error: no matching group found");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		packet_start(SSH2_MSG_KEXGSS_GROUP);
Jan F. Chadima 3d742c
+		packet_put_bignum2(dh->p);
Jan F. Chadima 3d742c
+		packet_put_bignum2(dh->g);
Jan F. Chadima 3d742c
+		packet_send();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		packet_write_wait();
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	default:
Jan F. Chadima 3d742c
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	dh_gen_key(dh, kex->we_need * 8);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	do {
Jan F. Chadima 3d742c
+		debug("Wait SSH2_MSG_GSSAPI_INIT");
Jan F. Chadima 3d742c
+		type = packet_read();
Jan F. Chadima 3d742c
+		switch(type) {
Jan F. Chadima 3d742c
+		case SSH2_MSG_KEXGSS_INIT:
Jan F. Chadima 3d742c
+			if (dh_client_pub != NULL) 
Jan F. Chadima 3d742c
+				fatal("Received KEXGSS_INIT after initialising");
Jan F. Chadima 3d742c
+			recv_tok.value = packet_get_string(&slen);
Jan F. Chadima 3d742c
+			recv_tok.length = slen; 
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			if ((dh_client_pub = BN_new()) == NULL)
Jan F. Chadima 3d742c
+				fatal("dh_client_pub == NULL");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			packet_get_bignum2(dh_client_pub);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			/* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
Jan F. Chadima 3d742c
+			break;
Jan F. Chadima 3d742c
+		case SSH2_MSG_KEXGSS_CONTINUE:
Jan F. Chadima 3d742c
+			recv_tok.value = packet_get_string(&slen);
Jan F. Chadima 3d742c
+			recv_tok.length = slen; 
Jan F. Chadima 3d742c
+			break;
Jan F. Chadima 3d742c
+		default:
Jan F. Chadima 3d742c
+			packet_disconnect(
Jan F. Chadima 3d742c
+			    "Protocol error: didn't expect packet type %d",
Jan F. Chadima 3d742c
+			    type);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok, 
Jan F. Chadima 3d742c
+		    &send_tok, &ret_flags));
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		xfree(recv_tok.value);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
Jan F. Chadima 3d742c
+			fatal("Zero length token output when incomplete");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (dh_client_pub == NULL)
Jan F. Chadima 3d742c
+			fatal("No client public key");
Jan F. Chadima 3d742c
+		
Jan F. Chadima 3d742c
+		if (maj_status & GSS_S_CONTINUE_NEEDED) {
Jan F. Chadima 3d742c
+			debug("Sending GSSAPI_CONTINUE");
Jan F. Chadima 3d742c
+			packet_start(SSH2_MSG_KEXGSS_CONTINUE);
Jan F. Chadima 3d742c
+			packet_put_string(send_tok.value, send_tok.length);
Jan F. Chadima 3d742c
+			packet_send();
Jan F. Chadima 3d742c
+			gss_release_buffer(&min_status, &send_tok);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+	} while (maj_status & GSS_S_CONTINUE_NEEDED);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (GSS_ERROR(maj_status)) {
Jan F. Chadima 3d742c
+		if (send_tok.length > 0) {
Jan F. Chadima 3d742c
+			packet_start(SSH2_MSG_KEXGSS_CONTINUE);
Jan F. Chadima 3d742c
+			packet_put_string(send_tok.value, send_tok.length);
Jan F. Chadima 3d742c
+			packet_send();
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+		fatal("accept_ctx died");
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (!(ret_flags & GSS_C_MUTUAL_FLAG))
Jan F. Chadima 3d742c
+		fatal("Mutual Authentication flag wasn't set");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (!(ret_flags & GSS_C_INTEG_FLAG))
Jan F. Chadima 3d742c
+		fatal("Integrity flag wasn't set");
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	if (!dh_pub_is_valid(dh, dh_client_pub))
Jan F. Chadima 3d742c
+		packet_disconnect("bad client public DH value");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	klen = DH_size(dh);
Jan F. Chadima 3d742c
+	kbuf = xmalloc(klen); 
Jan F. Chadima 3d742c
+	kout = DH_compute_key(kbuf, dh_client_pub, dh);
Jan F. Chadima 3d742c
+	if (kout < 0)
Jan F. Chadima 3d742c
+		fatal("DH_compute_key: failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	shared_secret = BN_new();
Jan F. Chadima 3d742c
+	if (shared_secret == NULL)
Jan F. Chadima 3d742c
+		fatal("kexgss_server: BN_new failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (BN_bin2bn(kbuf, kout, shared_secret) == NULL)
Jan F. Chadima 3d742c
+		fatal("kexgss_server: BN_bin2bn failed");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	memset(kbuf, 0, klen);
Jan F. Chadima 3d742c
+	xfree(kbuf);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	switch (kex->kex_type) {
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP1_SHA1:
Jan F. Chadima 3d742c
+	case KEX_GSS_GRP14_SHA1:
Jan F. Chadima 3d742c
+		kex_dh_hash(
Jan F. Chadima 3d742c
+		    kex->client_version_string, kex->server_version_string,
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->peer), buffer_len(&kex->peer),
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->my), buffer_len(&kex->my),
Jan F. Chadima 3d742c
+		    NULL, 0, /* Change this if we start sending host keys */
Jan F. Chadima 3d742c
+		    dh_client_pub, dh->pub_key, shared_secret,
Jan F. Chadima 3d742c
+		    &hash, &hashlen
Jan F. Chadima 3d742c
+		);
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	case KEX_GSS_GEX_SHA1:
Jan F. Chadima 3d742c
+		kexgex_hash(
Jan F. Chadima 3d742c
+		    kex->evp_md,
Jan F. Chadima 3d742c
+		    kex->client_version_string, kex->server_version_string,
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->peer), buffer_len(&kex->peer),
Jan F. Chadima 3d742c
+		    buffer_ptr(&kex->my), buffer_len(&kex->my),
Jan F. Chadima 3d742c
+		    NULL, 0,
Jan F. Chadima 3d742c
+		    min, nbits, max,
Jan F. Chadima 3d742c
+		    dh->p, dh->g,
Jan F. Chadima 3d742c
+		    dh_client_pub,
Jan F. Chadima 3d742c
+		    dh->pub_key,
Jan F. Chadima 3d742c
+		    shared_secret,
Jan F. Chadima 3d742c
+		    &hash, &hashlen
Jan F. Chadima 3d742c
+		);
Jan F. Chadima 3d742c
+		break;
Jan F. Chadima 3d742c
+	default:
Jan F. Chadima 3d742c
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	BN_clear_free(dh_client_pub);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (kex->session_id == NULL) {
Jan F. Chadima 3d742c
+		kex->session_id_len = hashlen;
Jan F. Chadima 3d742c
+		kex->session_id = xmalloc(kex->session_id_len);
Jan F. Chadima 3d742c
+		memcpy(kex->session_id, hash, kex->session_id_len);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gssbuf.value = hash;
Jan F. Chadima 3d742c
+	gssbuf.length = hashlen;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
Jan F. Chadima 3d742c
+		fatal("Couldn't get MIC");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	packet_start(SSH2_MSG_KEXGSS_COMPLETE);
Jan F. Chadima 3d742c
+	packet_put_bignum2(dh->pub_key);
Jan F. Chadima 3d742c
+	packet_put_string(msg_tok.value,msg_tok.length);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (send_tok.length != 0) {
Jan F. Chadima 3d742c
+		packet_put_char(1); /* true */
Jan F. Chadima 3d742c
+		packet_put_string(send_tok.value, send_tok.length);
Jan F. Chadima 3d742c
+	} else {
Jan F. Chadima 3d742c
+		packet_put_char(0); /* false */
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+	packet_send();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gss_release_buffer(&min_status, &send_tok);
Jan F. Chadima 3d742c
+	gss_release_buffer(&min_status, &msg_tok);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gss_kex_context == NULL)
Jan F. Chadima 3d742c
+		gss_kex_context = ctxt;
Jan F. Chadima 3d742c
+	else 
Jan F. Chadima 3d742c
+		ssh_gssapi_delete_ctx(&ctxt);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	DH_free(dh);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	kex_derive_keys(kex, hash, hashlen, shared_secret);
Jan F. Chadima 3d742c
+	BN_clear_free(shared_secret);
Jan F. Chadima 3d742c
+	kex_finish(kex);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* If this was a rekey, then save out any delegated credentials we
Jan F. Chadima 3d742c
+	 * just exchanged.  */
Jan F. Chadima 3d742c
+	if (options.gss_store_rekey)
Jan F. Chadima 3d742c
+		ssh_gssapi_rekey_creds();
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+#endif /* GSSAPI */
Jan F. Chadima 3d742c
Index: key.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/key.c,v
Jan F. Chadima 3d742c
retrieving revision 1.83
Jan F. Chadima 3d742c
diff -u -r1.83 key.c
Jan F. Chadima 3d742c
--- key.c	3 Nov 2008 08:24:17 -0000	1.83
Jan F. Chadima 3d742c
+++ key.c	26 Jul 2009 12:22:03 -0000
Jan F. Chadima 3d742c
@@ -764,6 +764,8 @@
Jan F. Chadima 3d742c
 		return KEY_RSA;
Jan F. Chadima 3d742c
 	} else if (strcmp(name, "ssh-dss") == 0) {
Jan F. Chadima 3d742c
 		return KEY_DSA;
Jan F. Chadima 3d742c
+	} else if (strcmp(name, "null") == 0) {
Jan F. Chadima 3d742c
+		return KEY_NULL;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 	debug2("key_type_from_name: unknown key type '%s'", name);
Jan F. Chadima 3d742c
 	return KEY_UNSPEC;
Jan F. Chadima 3d742c
Index: key.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/key.h,v
Jan F. Chadima 3d742c
retrieving revision 1.29
Jan F. Chadima 3d742c
diff -u -r1.29 key.h
Jan F. Chadima 3d742c
--- key.h	12 Jun 2008 18:40:35 -0000	1.29
Jan F. Chadima 3d742c
+++ key.h	26 Jul 2009 12:22:03 -0000
Jan F. Chadima 3d742c
@@ -34,6 +34,7 @@
Jan F. Chadima 3d742c
 	KEY_RSA1,
Jan F. Chadima 3d742c
 	KEY_RSA,
Jan F. Chadima 3d742c
 	KEY_DSA,
Jan F. Chadima 3d742c
+	KEY_NULL,
Jan F. Chadima 3d742c
 	KEY_UNSPEC
Jan F. Chadima 3d742c
 };
Jan F. Chadima 3d742c
 enum fp_type {
Jan F. Chadima 3d742c
Index: monitor.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/monitor.c,v
Jan F. Chadima 3d742c
retrieving revision 1.134
Jan F. Chadima 3d742c
diff -u -r1.134 monitor.c
Jan F. Chadima 3d742c
--- monitor.c	14 Feb 2009 05:33:31 -0000	1.134
Jan F. Chadima 3d742c
+++ monitor.c	26 Jul 2009 12:22:06 -0000
Jan F. Chadima 3d742c
@@ -170,6 +170,8 @@
Jan F. Chadima 3d742c
 int mm_answer_gss_accept_ctx(int, Buffer *);
Jan F. Chadima 3d742c
 int mm_answer_gss_userok(int, Buffer *);
Jan F. Chadima 3d742c
 int mm_answer_gss_checkmic(int, Buffer *);
Jan F. Chadima 3d742c
+int mm_answer_gss_sign(int, Buffer *);
Jan F. Chadima 3d742c
+int mm_answer_gss_updatecreds(int, Buffer *);
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef SSH_AUDIT_EVENTS
Jan F. Chadima 3d742c
@@ -239,6 +241,7 @@
Jan F. Chadima 3d742c
     {MONITOR_REQ_GSSSTEP, MON_ISAUTH, mm_answer_gss_accept_ctx},
Jan F. Chadima 3d742c
     {MONITOR_REQ_GSSUSEROK, MON_AUTH, mm_answer_gss_userok},
Jan F. Chadima 3d742c
     {MONITOR_REQ_GSSCHECKMIC, MON_ISAUTH, mm_answer_gss_checkmic},
Jan F. Chadima 3d742c
+    {MONITOR_REQ_GSSSIGN, MON_ONCE, mm_answer_gss_sign},
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 #ifdef JPAKE
Jan F. Chadima 3d742c
     {MONITOR_REQ_JPAKE_GET_PWDATA, MON_ONCE, mm_answer_jpake_get_pwdata},
Jan F. Chadima 3d742c
@@ -251,6 +254,12 @@
Jan F. Chadima 3d742c
 };
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 struct mon_table mon_dispatch_postauth20[] = {
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+    {MONITOR_REQ_GSSSETUP, 0, mm_answer_gss_setup_ctx},
Jan F. Chadima 3d742c
+    {MONITOR_REQ_GSSSTEP, 0, mm_answer_gss_accept_ctx},
Jan F. Chadima 3d742c
+    {MONITOR_REQ_GSSSIGN, 0, mm_answer_gss_sign},
Jan F. Chadima 3d742c
+    {MONITOR_REQ_GSSUPCREDS, 0, mm_answer_gss_updatecreds},
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
     {MONITOR_REQ_MODULI, 0, mm_answer_moduli},
Jan F. Chadima 3d742c
     {MONITOR_REQ_SIGN, 0, mm_answer_sign},
Jan F. Chadima 3d742c
     {MONITOR_REQ_PTY, 0, mm_answer_pty},
Jan F. Chadima 3d742c
@@ -355,6 +364,10 @@
Jan F. Chadima 3d742c
 		/* Permit requests for moduli and signatures */
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+		/* and for the GSSAPI key exchange */
Jan F. Chadima 3d742c
+		monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 	} else {
Jan F. Chadima 3d742c
 		mon_dispatch = mon_dispatch_proto15;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -441,6 +454,10 @@
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_MODULI, 1);
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_SIGN, 1);
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+		/* and for the GSSAPI key exchange */
Jan F. Chadima 3d742c
+		monitor_permit(mon_dispatch, MONITOR_REQ_GSSSETUP, 1);
Jan F. Chadima 3d742c
+#endif		
Jan F. Chadima 3d742c
 	} else {
Jan F. Chadima 3d742c
 		mon_dispatch = mon_dispatch_postauth15;
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_TERM, 1);
Jan F. Chadima 3d742c
@@ -1699,6 +1716,13 @@
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	if (options.gss_keyex) {
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 	kex->server = 1;
Jan F. Chadima 3d742c
 	kex->hostkey_type = buffer_get_int(m);
Jan F. Chadima 3d742c
 	kex->kex_type = buffer_get_int(m);
Jan F. Chadima 3d742c
@@ -1898,6 +1922,9 @@
Jan F. Chadima 3d742c
 	OM_uint32 major;
Jan F. Chadima 3d742c
 	u_int len;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	if (!options.gss_authentication && !options.gss_keyex)
Jan F. Chadima 3d742c
+		fatal("In GSSAPI monitor when GSSAPI is disabled");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	goid.elements = buffer_get_string(m, &len;;
Jan F. Chadima 3d742c
 	goid.length = len;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -1925,6 +1952,9 @@
Jan F. Chadima 3d742c
 	OM_uint32 flags = 0; /* GSI needs this */
Jan F. Chadima 3d742c
 	u_int len;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	if (!options.gss_authentication && !options.gss_keyex)
Jan F. Chadima 3d742c
+		fatal("In GSSAPI monitor when GSSAPI is disabled");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	in.value = buffer_get_string(m, &len;;
Jan F. Chadima 3d742c
 	in.length = len;
Jan F. Chadima 3d742c
 	major = ssh_gssapi_accept_ctx(gsscontext, &in, &out, &flags);
Jan F. Chadima 3d742c
@@ -1942,6 +1972,7 @@
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_GSSSTEP, 0);
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_GSSUSEROK, 1);
Jan F. Chadima 3d742c
 		monitor_permit(mon_dispatch, MONITOR_REQ_GSSCHECKMIC, 1);
Jan F. Chadima 3d742c
+		monitor_permit(mon_dispatch, MONITOR_REQ_GSSSIGN, 1);
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
 	return (0);
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
@@ -1953,6 +1984,9 @@
Jan F. Chadima 3d742c
 	OM_uint32 ret;
Jan F. Chadima 3d742c
 	u_int len;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	if (!options.gss_authentication && !options.gss_keyex)
Jan F. Chadima 3d742c
+		fatal("In GSSAPI monitor when GSSAPI is disabled");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	gssbuf.value = buffer_get_string(m, &len;;
Jan F. Chadima 3d742c
 	gssbuf.length = len;
Jan F. Chadima 3d742c
 	mic.value = buffer_get_string(m, &len;;
Jan F. Chadima 3d742c
@@ -1979,7 +2013,11 @@
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	int authenticated;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
-	authenticated = authctxt->valid && ssh_gssapi_userok(authctxt->user);
Jan F. Chadima 3d742c
+	if (!options.gss_authentication && !options.gss_keyex)
Jan F. Chadima 3d742c
+		fatal("In GSSAPI monitor when GSSAPI is disabled");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	authenticated = authctxt->valid && 
Jan F. Chadima 3d742c
+	    ssh_gssapi_userok(authctxt->user, authctxt->pw);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	buffer_clear(m);
Jan F. Chadima 3d742c
 	buffer_put_int(m, authenticated);
Jan F. Chadima 3d742c
@@ -1992,6 +2030,74 @@
Jan F. Chadima 3d742c
 	/* Monitor loop will terminate if authenticated */
Jan F. Chadima 3d742c
 	return (authenticated);
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int 
Jan F. Chadima 3d742c
+mm_answer_gss_sign(int socket, Buffer *m)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	gss_buffer_desc data;
Jan F. Chadima 3d742c
+	gss_buffer_desc hash = GSS_C_EMPTY_BUFFER;
Jan F. Chadima 3d742c
+	OM_uint32 major, minor;
Jan F. Chadima 3d742c
+	u_int len;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (!options.gss_authentication && !options.gss_keyex)
Jan F. Chadima 3d742c
+		fatal("In GSSAPI monitor when GSSAPI is disabled");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	data.value = buffer_get_string(m, &len;;
Jan F. Chadima 3d742c
+	data.length = len;
Jan F. Chadima 3d742c
+	if (data.length != 20) 
Jan F. Chadima 3d742c
+		fatal("%s: data length incorrect: %d", __func__, 
Jan F. Chadima 3d742c
+		    (int) data.length);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Save the session ID on the first time around */
Jan F. Chadima 3d742c
+	if (session_id2_len == 0) {
Jan F. Chadima 3d742c
+		session_id2_len = data.length;
Jan F. Chadima 3d742c
+		session_id2 = xmalloc(session_id2_len);
Jan F. Chadima 3d742c
+		memcpy(session_id2, data.value, session_id2_len);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+	major = ssh_gssapi_sign(gsscontext, &data, &hash);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	xfree(data.value);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_clear(m);
Jan F. Chadima 3d742c
+	buffer_put_int(m, major);
Jan F. Chadima 3d742c
+	buffer_put_string(m, hash.value, hash.length);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	mm_request_send(socket, MONITOR_ANS_GSSSIGN, m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gss_release_buffer(&minor, &hash);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* Turn on getpwnam permissions */
Jan F. Chadima 3d742c
+	monitor_permit(mon_dispatch, MONITOR_REQ_PWNAM, 1);
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	/* And credential updating, for when rekeying */
Jan F. Chadima 3d742c
+	monitor_permit(mon_dispatch, MONITOR_REQ_GSSUPCREDS, 1);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return (0);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int
Jan F. Chadima 3d742c
+mm_answer_gss_updatecreds(int socket, Buffer *m) {
Jan F. Chadima 3d742c
+	ssh_gssapi_ccache store;
Jan F. Chadima 3d742c
+	int ok;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	store.filename = buffer_get_string(m, NULL);
Jan F. Chadima 3d742c
+	store.envvar   = buffer_get_string(m, NULL);
Jan F. Chadima 3d742c
+	store.envval   = buffer_get_string(m, NULL);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ok = ssh_gssapi_update_creds(&store);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	xfree(store.filename);
Jan F. Chadima 3d742c
+	xfree(store.envvar);
Jan F. Chadima 3d742c
+	xfree(store.envval);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_clear(m);
Jan F. Chadima 3d742c
+	buffer_put_int(m, ok);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	mm_request_send(socket, MONITOR_ANS_GSSUPCREDS, m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return(0);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 #endif /* GSSAPI */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef JPAKE
Jan F. Chadima 3d742c
Index: monitor.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/monitor.h,v
Jan F. Chadima 3d742c
retrieving revision 1.22
Jan F. Chadima 3d742c
diff -u -r1.22 monitor.h
Jan F. Chadima 3d742c
--- monitor.h	5 Nov 2008 05:20:46 -0000	1.22
Jan F. Chadima 3d742c
+++ monitor.h	26 Jul 2009 12:22:06 -0000
Jan F. Chadima 3d742c
@@ -53,6 +53,8 @@
Jan F. Chadima 3d742c
 	MONITOR_REQ_GSSSTEP, MONITOR_ANS_GSSSTEP,
Jan F. Chadima 3d742c
 	MONITOR_REQ_GSSUSEROK, MONITOR_ANS_GSSUSEROK,
Jan F. Chadima 3d742c
 	MONITOR_REQ_GSSCHECKMIC, MONITOR_ANS_GSSCHECKMIC,
Jan F. Chadima 3d742c
+	MONITOR_REQ_GSSSIGN, MONITOR_ANS_GSSSIGN,
Jan F. Chadima 3d742c
+	MONITOR_REQ_GSSUPCREDS, MONITOR_ANS_GSSUPCREDS,
Jan F. Chadima 3d742c
 	MONITOR_REQ_PAM_START,
Jan F. Chadima 3d742c
 	MONITOR_REQ_PAM_ACCOUNT, MONITOR_ANS_PAM_ACCOUNT,
Jan F. Chadima 3d742c
 	MONITOR_REQ_PAM_INIT_CTX, MONITOR_ANS_PAM_INIT_CTX,
Jan F. Chadima 3d742c
Index: monitor_wrap.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/monitor_wrap.c,v
Jan F. Chadima 3d742c
retrieving revision 1.80
Jan F. Chadima 3d742c
diff -u -r1.80 monitor_wrap.c
Jan F. Chadima 3d742c
--- monitor_wrap.c	5 Nov 2008 05:20:47 -0000	1.80
Jan F. Chadima 3d742c
+++ monitor_wrap.c	26 Jul 2009 12:22:07 -0000
Jan F. Chadima 3d742c
@@ -1239,7 +1239,7 @@
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 int
Jan F. Chadima 3d742c
-mm_ssh_gssapi_userok(char *user)
Jan F. Chadima 3d742c
+mm_ssh_gssapi_userok(char *user, struct passwd *pw)
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	Buffer m;
Jan F. Chadima 3d742c
 	int authenticated = 0;
Jan F. Chadima 3d742c
@@ -1256,6 +1256,51 @@
Jan F. Chadima 3d742c
 	debug3("%s: user %sauthenticated",__func__, authenticated ? "" : "not ");
Jan F. Chadima 3d742c
 	return (authenticated);
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+OM_uint32
Jan F. Chadima 3d742c
+mm_ssh_gssapi_sign(Gssctxt *ctx, gss_buffer_desc *data, gss_buffer_desc *hash)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	Buffer m;
Jan F. Chadima 3d742c
+	OM_uint32 major;
Jan F. Chadima 3d742c
+	u_int len;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_init(&m);
Jan F. Chadima 3d742c
+	buffer_put_string(&m, data->value, data->length);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSSIGN, &m);
Jan F. Chadima 3d742c
+	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSSIGN, &m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	major = buffer_get_int(&m);
Jan F. Chadima 3d742c
+	hash->value = buffer_get_string(&m, &len;;
Jan F. Chadima 3d742c
+	hash->length = len;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_free(&m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return(major);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int
Jan F. Chadima 3d742c
+mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *store)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	Buffer m;
Jan F. Chadima 3d742c
+	int ok;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_init(&m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_put_cstring(&m, store->filename ? store->filename : "");
Jan F. Chadima 3d742c
+	buffer_put_cstring(&m, store->envvar ? store->envvar : "");
Jan F. Chadima 3d742c
+	buffer_put_cstring(&m, store->envval ? store->envval : "");
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUPCREDS, &m);
Jan F. Chadima 3d742c
+	mm_request_receive_expect(pmonitor->m_recvfd, MONITOR_ANS_GSSUPCREDS, &m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ok = buffer_get_int(&m);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_free(&m);
Jan F. Chadima 3d742c
+	
Jan F. Chadima 3d742c
+	return (ok);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 #endif /* GSSAPI */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef JPAKE
Jan F. Chadima 3d742c
Index: monitor_wrap.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/monitor_wrap.h,v
Jan F. Chadima 3d742c
retrieving revision 1.28
Jan F. Chadima 3d742c
diff -u -r1.28 monitor_wrap.h
Jan F. Chadima 3d742c
--- monitor_wrap.h	5 Nov 2008 05:20:47 -0000	1.28
Jan F. Chadima 3d742c
+++ monitor_wrap.h	26 Jul 2009 12:22:07 -0000
Jan F. Chadima 3d742c
@@ -57,8 +57,10 @@
Jan F. Chadima 3d742c
 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
Jan F. Chadima 3d742c
 OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
Jan F. Chadima 3d742c
    gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
Jan F. Chadima 3d742c
-int mm_ssh_gssapi_userok(char *user);
Jan F. Chadima 3d742c
+int mm_ssh_gssapi_userok(char *user, struct passwd *);
Jan F. Chadima 3d742c
 OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jan F. Chadima 3d742c
+OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jan F. Chadima 3d742c
+int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #ifdef USE_PAM
Jan F. Chadima 3d742c
Index: readconf.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/readconf.c,v
Jan F. Chadima 3d742c
retrieving revision 1.153
Jan F. Chadima 3d742c
diff -u -r1.153 readconf.c
Jan F. Chadima 3d742c
--- readconf.c	14 Feb 2009 05:28:21 -0000	1.153
Jan F. Chadima 3d742c
+++ readconf.c	26 Jul 2009 12:22:10 -0000
Jan F. Chadima 3d742c
@@ -127,6 +127,7 @@
Jan F. Chadima 3d742c
 	oClearAllForwardings, oNoHostAuthenticationForLocalhost,
Jan F. Chadima 3d742c
 	oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Jan F. Chadima 3d742c
 	oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Jan F. Chadima 3d742c
+	oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
Jan F. Chadima 3d742c
 	oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
Jan F. Chadima 3d742c
 	oSendEnv, oControlPath, oControlMaster, oHashKnownHosts,
Jan F. Chadima 3d742c
 	oTunnel, oTunnelDevice, oLocalCommand, oPermitLocalCommand,
Jan F. Chadima 3d742c
@@ -164,10 +165,18 @@
Jan F. Chadima 3d742c
 	{ "afstokenpassing", oUnsupported },
Jan F. Chadima 3d742c
 #if defined(GSSAPI)
Jan F. Chadima 3d742c
 	{ "gssapiauthentication", oGssAuthentication },
Jan F. Chadima 3d742c
+	{ "gssapikeyexchange", oGssKeyEx },
Jan F. Chadima 3d742c
 	{ "gssapidelegatecredentials", oGssDelegateCreds },
Jan F. Chadima 3d742c
+	{ "gssapitrustdns", oGssTrustDns },
Jan F. Chadima 3d742c
+	{ "gssapiclientidentity", oGssClientIdentity },
Jan F. Chadima 3d742c
+	{ "gssapirenewalforcesrekey", oGssRenewalRekey },
Jan F. Chadima 3d742c
 #else
Jan F. Chadima 3d742c
 	{ "gssapiauthentication", oUnsupported },
Jan F. Chadima 3d742c
+	{ "gssapikeyexchange", oUnsupported },
Jan F. Chadima 3d742c
 	{ "gssapidelegatecredentials", oUnsupported },
Jan F. Chadima 3d742c
+	{ "gssapitrustdns", oUnsupported },
Jan F. Chadima 3d742c
+	{ "gssapiclientidentity", oUnsupported },
Jan F. Chadima 3d742c
+	{ "gssapirenewalforcesrekey", oUnsupported },
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 	{ "fallbacktorsh", oDeprecated },
Jan F. Chadima 3d742c
 	{ "usersh", oDeprecated },
Jan F. Chadima 3d742c
@@ -453,10 +462,26 @@
Jan F. Chadima 3d742c
 		intptr = &options->gss_authentication;
Jan F. Chadima 3d742c
 		goto parse_flag;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	case oGssKeyEx:
Jan F. Chadima 3d742c
+		intptr = &options->gss_keyex;
Jan F. Chadima 3d742c
+		goto parse_flag;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	case oGssDelegateCreds:
Jan F. Chadima 3d742c
 		intptr = &options->gss_deleg_creds;
Jan F. Chadima 3d742c
 		goto parse_flag;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	case oGssTrustDns:
Jan F. Chadima 3d742c
+		intptr = &options->gss_trust_dns;
Jan F. Chadima 3d742c
+		goto parse_flag;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	case oGssClientIdentity:
Jan F. Chadima 3d742c
+		charptr = &options->gss_client_identity;
Jan F. Chadima 3d742c
+		goto parse_string;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	case oGssRenewalRekey:
Jan F. Chadima 3d742c
+		intptr = &options->gss_renewal_rekey;
Jan F. Chadima 3d742c
+		goto parse_flag;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	case oBatchMode:
Jan F. Chadima 3d742c
 		intptr = &options->batch_mode;
Jan F. Chadima 3d742c
 		goto parse_flag;
Jan F. Chadima 3d742c
@@ -1008,7 +1033,11 @@
Jan F. Chadima 3d742c
 	options->pubkey_authentication = -1;
Jan F. Chadima 3d742c
 	options->challenge_response_authentication = -1;
Jan F. Chadima 3d742c
 	options->gss_authentication = -1;
Jan F. Chadima 3d742c
+	options->gss_keyex = -1;
Jan F. Chadima 3d742c
 	options->gss_deleg_creds = -1;
Jan F. Chadima 3d742c
+	options->gss_trust_dns = -1;
Jan F. Chadima 3d742c
+	options->gss_renewal_rekey = -1;
Jan F. Chadima 3d742c
+	options->gss_client_identity = NULL;
Jan F. Chadima 3d742c
 	options->password_authentication = -1;
Jan F. Chadima 3d742c
 	options->kbd_interactive_authentication = -1;
Jan F. Chadima 3d742c
 	options->kbd_interactive_devices = NULL;
Jan F. Chadima 3d742c
@@ -1099,8 +1128,14 @@
Jan F. Chadima 3d742c
 		options->challenge_response_authentication = 1;
Jan F. Chadima 3d742c
 	if (options->gss_authentication == -1)
Jan F. Chadima 3d742c
 		options->gss_authentication = 0;
Jan F. Chadima 3d742c
+	if (options->gss_keyex == -1)
Jan F. Chadima 3d742c
+		options->gss_keyex = 0;
Jan F. Chadima 3d742c
 	if (options->gss_deleg_creds == -1)
Jan F. Chadima 3d742c
 		options->gss_deleg_creds = 0;
Jan F. Chadima 3d742c
+	if (options->gss_trust_dns == -1)
Jan F. Chadima 3d742c
+		options->gss_trust_dns = 0;
Jan F. Chadima 3d742c
+	if (options->gss_renewal_rekey == -1)
Jan F. Chadima 3d742c
+		options->gss_renewal_rekey = 0;
Jan F. Chadima 3d742c
 	if (options->password_authentication == -1)
Jan F. Chadima 3d742c
 		options->password_authentication = 1;
Jan F. Chadima 3d742c
 	if (options->kbd_interactive_authentication == -1)
Jan F. Chadima 3d742c
Index: readconf.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/readconf.h,v
Jan F. Chadima 3d742c
retrieving revision 1.70
Jan F. Chadima 3d742c
diff -u -r1.70 readconf.h
Jan F. Chadima 3d742c
--- readconf.h	14 Feb 2009 05:28:21 -0000	1.70
Jan F. Chadima 3d742c
+++ readconf.h	26 Jul 2009 12:22:10 -0000
Jan F. Chadima 3d742c
@@ -44,7 +44,11 @@
Jan F. Chadima 3d742c
 	int     challenge_response_authentication;
Jan F. Chadima 3d742c
 					/* Try S/Key or TIS, authentication. */
Jan F. Chadima 3d742c
 	int     gss_authentication;	/* Try GSS authentication */
Jan F. Chadima 3d742c
+	int     gss_keyex;		/* Try GSS key exchange */
Jan F. Chadima 3d742c
 	int     gss_deleg_creds;	/* Delegate GSS credentials */
Jan F. Chadima 3d742c
+	int	gss_trust_dns;		/* Trust DNS for GSS canonicalization */
Jan F. Chadima 3d742c
+	int	gss_renewal_rekey;	/* Credential renewal forces rekey */
Jan F. Chadima 3d742c
+	char    *gss_client_identity;   /* Principal to initiate GSSAPI with */
Jan F. Chadima 3d742c
 	int     password_authentication;	/* Try password
Jan F. Chadima 3d742c
 						 * authentication. */
Jan F. Chadima 3d742c
 	int     kbd_interactive_authentication; /* Try keyboard-interactive auth. */
Jan F. Chadima 3d742c
Index: servconf.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/servconf.c,v
Jan F. Chadima 3d742c
retrieving revision 1.186
Jan F. Chadima 3d742c
diff -u -r1.186 servconf.c
Jan F. Chadima 3d742c
--- servconf.c	28 Jan 2009 05:31:23 -0000	1.186
Jan F. Chadima 3d742c
+++ servconf.c	26 Jul 2009 12:22:11 -0000
Jan F. Chadima 3d742c
@@ -92,7 +92,10 @@
Jan F. Chadima 3d742c
 	options->kerberos_ticket_cleanup = -1;
Jan F. Chadima 3d742c
 	options->kerberos_get_afs_token = -1;
Jan F. Chadima 3d742c
 	options->gss_authentication=-1;
Jan F. Chadima 3d742c
+	options->gss_keyex = -1;
Jan F. Chadima 3d742c
 	options->gss_cleanup_creds = -1;
Jan F. Chadima 3d742c
+	options->gss_strict_acceptor = -1;
Jan F. Chadima 3d742c
+	options->gss_store_rekey = -1;
Jan F. Chadima 3d742c
 	options->password_authentication = -1;
Jan F. Chadima 3d742c
 	options->kbd_interactive_authentication = -1;
Jan F. Chadima 3d742c
 	options->challenge_response_authentication = -1;
Jan F. Chadima 3d742c
@@ -210,8 +213,14 @@
Jan F. Chadima 3d742c
 		options->kerberos_get_afs_token = 0;
Jan F. Chadima 3d742c
 	if (options->gss_authentication == -1)
Jan F. Chadima 3d742c
 		options->gss_authentication = 0;
Jan F. Chadima 3d742c
+	if (options->gss_keyex == -1)
Jan F. Chadima 3d742c
+		options->gss_keyex = 0;
Jan F. Chadima 3d742c
 	if (options->gss_cleanup_creds == -1)
Jan F. Chadima 3d742c
 		options->gss_cleanup_creds = 1;
Jan F. Chadima 3d742c
+	if (options->gss_strict_acceptor == -1)
Jan F. Chadima 3d742c
+		options->gss_strict_acceptor = 1;
Jan F. Chadima 3d742c
+	if (options->gss_store_rekey == -1)
Jan F. Chadima 3d742c
+		options->gss_store_rekey = 0;
Jan F. Chadima 3d742c
 	if (options->password_authentication == -1)
Jan F. Chadima 3d742c
 		options->password_authentication = 1;
Jan F. Chadima 3d742c
 	if (options->kbd_interactive_authentication == -1)
Jan F. Chadima 3d742c
@@ -302,7 +311,9 @@
Jan F. Chadima 3d742c
 	sBanner, sUseDNS, sHostbasedAuthentication,
Jan F. Chadima 3d742c
 	sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
Jan F. Chadima 3d742c
 	sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
Jan F. Chadima 3d742c
-	sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
Jan F. Chadima 3d742c
+	sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
Jan F. Chadima 3d742c
+	sGssKeyEx, sGssStoreRekey,
Jan F. Chadima 3d742c
+	sAcceptEnv, sPermitTunnel,
Jan F. Chadima 3d742c
 	sMatch, sPermitOpen, sForceCommand, sChrootDirectory,
Jan F. Chadima 3d742c
 	sUsePrivilegeSeparation, sAllowAgentForwarding,
Jan F. Chadima 3d742c
 	sZeroKnowledgePasswordAuthentication,
Jan F. Chadima 3d742c
@@ -364,9 +375,15 @@
Jan F. Chadima 3d742c
 #ifdef GSSAPI
Jan F. Chadima 3d742c
 	{ "gssapiauthentication", sGssAuthentication, SSHCFG_ALL },
Jan F. Chadima 3d742c
 	{ "gssapicleanupcredentials", sGssCleanupCreds, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
+	{ "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
+	{ "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
+	{ "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
 #else
Jan F. Chadima 3d742c
 	{ "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Jan F. Chadima 3d742c
 	{ "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
+	{ "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
+	{ "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
+	{ "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 	{ "passwordauthentication", sPasswordAuthentication, SSHCFG_ALL },
Jan F. Chadima 3d742c
 	{ "kbdinteractiveauthentication", sKbdInteractiveAuthentication, SSHCFG_ALL },
Jan F. Chadima 3d742c
@@ -891,8 +908,20 @@
Jan F. Chadima 3d742c
 		intptr = &options->gss_authentication;
Jan F. Chadima 3d742c
 		goto parse_flag;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+	case sGssKeyEx:
Jan F. Chadima 3d742c
+		intptr = &options->gss_keyex;
Jan F. Chadima 3d742c
+		goto parse_flag;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	case sGssCleanupCreds:
Jan F. Chadima 3d742c
 		intptr = &options->gss_cleanup_creds;
Jan F. Chadima 3d742c
+		goto parse_flag;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	case sGssStrictAcceptor:
Jan F. Chadima 3d742c
+		intptr = &options->gss_strict_acceptor;
Jan F. Chadima 3d742c
+		goto parse_flag;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	case sGssStoreRekey:
Jan F. Chadima 3d742c
+		intptr = &options->gss_store_rekey;
Jan F. Chadima 3d742c
 		goto parse_flag;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	case sPasswordAuthentication:
Jan F. Chadima 3d742c
Index: servconf.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/servconf.h,v
Jan F. Chadima 3d742c
retrieving revision 1.79
Jan F. Chadima 3d742c
diff -u -r1.79 servconf.h
Jan F. Chadima 3d742c
--- servconf.h	28 Jan 2009 05:31:23 -0000	1.79
Jan F. Chadima 3d742c
+++ servconf.h	26 Jul 2009 12:22:12 -0000
Jan F. Chadima 3d742c
@@ -91,7 +91,10 @@
Jan F. Chadima 3d742c
 	int     kerberos_get_afs_token;		/* If true, try to get AFS token if
Jan F. Chadima 3d742c
 						 * authenticated with Kerberos. */
Jan F. Chadima 3d742c
 	int     gss_authentication;	/* If true, permit GSSAPI authentication */
Jan F. Chadima 3d742c
+	int     gss_keyex;		/* If true, permit GSSAPI key exchange */
Jan F. Chadima 3d742c
 	int     gss_cleanup_creds;	/* If true, destroy cred cache on logout */
Jan F. Chadima 3d742c
+	int 	gss_strict_acceptor;	/* If true, restrict the GSSAPI acceptor name */
Jan F. Chadima 3d742c
+	int 	gss_store_rekey;
Jan F. Chadima 3d742c
 	int     password_authentication;	/* If true, permit password
Jan F. Chadima 3d742c
 						 * authentication. */
Jan F. Chadima 3d742c
 	int     kbd_interactive_authentication;	/* If true, permit */
Jan F. Chadima 3d742c
Index: ssh-gss.h
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/ssh-gss.h,v
Jan F. Chadima 3d742c
retrieving revision 1.12
Jan F. Chadima 3d742c
diff -u -r1.12 ssh-gss.h
Jan F. Chadima 3d742c
--- ssh-gss.h	12 Jun 2007 13:40:39 -0000	1.12
Jan F. Chadima 3d742c
+++ ssh-gss.h	26 Jul 2009 12:22:12 -0000
Jan F. Chadima 3d742c
@@ -1,6 +1,6 @@
Jan F. Chadima 3d742c
 /* $OpenBSD: ssh-gss.h,v 1.10 2007/06/12 08:20:00 djm Exp $ */
Jan F. Chadima 3d742c
 /*
Jan F. Chadima 3d742c
- * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
+ * Copyright (c) 2001-2009 Simon Wilkinson. All rights reserved.
Jan F. Chadima 3d742c
  *
Jan F. Chadima 3d742c
  * Redistribution and use in source and binary forms, with or without
Jan F. Chadima 3d742c
  * modification, are permitted provided that the following conditions
Jan F. Chadima 3d742c
@@ -60,10 +60,22 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #define SSH_GSS_OIDTYPE 0x06
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_INIT                            30
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_CONTINUE                        31
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_COMPLETE                        32
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_HOSTKEY                         33
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_ERROR                           34
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_GROUPREQ			40
Jan F. Chadima 3d742c
+#define SSH2_MSG_KEXGSS_GROUP				41
Jan F. Chadima 3d742c
+#define KEX_GSS_GRP1_SHA1_ID				"gss-group1-sha1-"
Jan F. Chadima 3d742c
+#define KEX_GSS_GRP14_SHA1_ID				"gss-group14-sha1-"
Jan F. Chadima 3d742c
+#define KEX_GSS_GEX_SHA1_ID				"gss-gex-sha1-"
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 typedef struct {
Jan F. Chadima 3d742c
 	char *filename;
Jan F. Chadima 3d742c
 	char *envvar;
Jan F. Chadima 3d742c
 	char *envval;
Jan F. Chadima 3d742c
+	struct passwd *owner;
Jan F. Chadima 3d742c
 	void *data;
Jan F. Chadima 3d742c
 } ssh_gssapi_ccache;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -71,8 +83,11 @@
Jan F. Chadima 3d742c
 	gss_buffer_desc displayname;
Jan F. Chadima 3d742c
 	gss_buffer_desc exportedname;
Jan F. Chadima 3d742c
 	gss_cred_id_t creds;
Jan F. Chadima 3d742c
+	gss_name_t name;
Jan F. Chadima 3d742c
 	struct ssh_gssapi_mech_struct *mech;
Jan F. Chadima 3d742c
 	ssh_gssapi_ccache store;
Jan F. Chadima 3d742c
+	int used;
Jan F. Chadima 3d742c
+	int updated;
Jan F. Chadima 3d742c
 } ssh_gssapi_client;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 typedef struct ssh_gssapi_mech_struct {
Jan F. Chadima 3d742c
@@ -83,6 +98,7 @@
Jan F. Chadima 3d742c
 	int (*userok) (ssh_gssapi_client *, char *);
Jan F. Chadima 3d742c
 	int (*localname) (ssh_gssapi_client *, char **);
Jan F. Chadima 3d742c
 	void (*storecreds) (ssh_gssapi_client *);
Jan F. Chadima 3d742c
+	int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
Jan F. Chadima 3d742c
 } ssh_gssapi_mech;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 typedef struct {
Jan F. Chadima 3d742c
@@ -93,10 +109,11 @@
Jan F. Chadima 3d742c
 	gss_OID		oid; /* client */
Jan F. Chadima 3d742c
 	gss_cred_id_t	creds; /* server */
Jan F. Chadima 3d742c
 	gss_name_t	client; /* server */
Jan F. Chadima 3d742c
-	gss_cred_id_t	client_creds; /* server */
Jan F. Chadima 3d742c
+	gss_cred_id_t	client_creds; /* both */
Jan F. Chadima 3d742c
 } Gssctxt;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 extern ssh_gssapi_mech *supported_mechs[];
Jan F. Chadima 3d742c
+extern Gssctxt *gss_kex_context;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 int  ssh_gssapi_check_oid(Gssctxt *, void *, size_t);
Jan F. Chadima 3d742c
 void ssh_gssapi_set_oid_data(Gssctxt *, void *, size_t);
Jan F. Chadima 3d742c
@@ -116,16 +133,30 @@
Jan F. Chadima 3d742c
 void ssh_gssapi_delete_ctx(Gssctxt **);
Jan F. Chadima 3d742c
 OM_uint32 ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jan F. Chadima 3d742c
 void ssh_gssapi_buildmic(Buffer *, const char *, const char *, const char *);
Jan F. Chadima 3d742c
-int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *);
Jan F. Chadima 3d742c
+int ssh_gssapi_check_mechanism(Gssctxt **, gss_OID, const char *, const char *);
Jan F. Chadima 3d742c
+OM_uint32 ssh_gssapi_client_identity(Gssctxt *, const char *);
Jan F. Chadima 3d742c
+int ssh_gssapi_credentials_updated(Gssctxt *);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 /* In the server */
Jan F. Chadima 3d742c
+typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *, 
Jan F. Chadima 3d742c
+    const char *);
Jan F. Chadima 3d742c
+char *ssh_gssapi_client_mechanisms(const char *, const char *);
Jan F. Chadima 3d742c
+char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
Jan F. Chadima 3d742c
+    const char *);
Jan F. Chadima 3d742c
+gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
Jan F. Chadima 3d742c
+int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *, 
Jan F. Chadima 3d742c
+    const char *);
Jan F. Chadima 3d742c
 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
Jan F. Chadima 3d742c
-int ssh_gssapi_userok(char *name);
Jan F. Chadima 3d742c
+int ssh_gssapi_userok(char *name, struct passwd *);
Jan F. Chadima 3d742c
 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jan F. Chadima 3d742c
 void ssh_gssapi_do_child(char ***, u_int *);
Jan F. Chadima 3d742c
 void ssh_gssapi_cleanup_creds(void);
Jan F. Chadima 3d742c
 void ssh_gssapi_storecreds(void);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+char *ssh_gssapi_server_mechanisms(void);
Jan F. Chadima 3d742c
+int ssh_gssapi_oid_table_ok();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int ssh_gssapi_update_creds(ssh_gssapi_ccache *store);
Jan F. Chadima 3d742c
 #endif /* GSSAPI */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 #endif /* _SSH_GSS_H */
Jan F. Chadima 3d742c
Index: ssh_config
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/ssh_config,v
Jan F. Chadima 3d742c
retrieving revision 1.27
Jan F. Chadima 3d742c
diff -u -r1.27 ssh_config
Jan F. Chadima 3d742c
--- ssh_config	21 Feb 2009 01:45:02 -0000	1.27
Jan F. Chadima 3d742c
+++ ssh_config	26 Jul 2009 12:22:12 -0000
Jan F. Chadima 3d742c
@@ -26,6 +26,8 @@
Jan F. Chadima 3d742c
 #   HostbasedAuthentication no
Jan F. Chadima 3d742c
 #   GSSAPIAuthentication no
Jan F. Chadima 3d742c
 #   GSSAPIDelegateCredentials no
Jan F. Chadima 3d742c
+#   GSSAPIKeyExchange no
Jan F. Chadima 3d742c
+#   GSSAPITrustDNS no
Jan F. Chadima 3d742c
 #   BatchMode no
Jan F. Chadima 3d742c
 #   CheckHostIP yes
Jan F. Chadima 3d742c
 #   AddressFamily any
Jan F. Chadima 3d742c
Index: ssh_config.5
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/ssh_config.5,v
Jan F. Chadima 3d742c
retrieving revision 1.119
Jan F. Chadima 3d742c
diff -u -r1.119 ssh_config.5
Jan F. Chadima 3d742c
--- ssh_config.5	22 Feb 2009 23:53:58 -0000	1.119
Jan F. Chadima 3d742c
+++ ssh_config.5	26 Jul 2009 12:22:13 -0000
Jan F. Chadima 3d742c
@@ -478,11 +478,38 @@
Jan F. Chadima 3d742c
 The default is
Jan F. Chadima 3d742c
 .Dq no .
Jan F. Chadima 3d742c
 Note that this option applies to protocol version 2 only.
Jan F. Chadima 3d742c
+.It Cm GSSAPIKeyExchange
Jan F. Chadima 3d742c
+Specifies whether key exchange based on GSSAPI may be used. When using
Jan F. Chadima 3d742c
+GSSAPI key exchange the server need not have a host key.
Jan F. Chadima 3d742c
+The default is
Jan F. Chadima 3d742c
+.Dq no .
Jan F. Chadima 3d742c
+Note that this option applies to protocol version 2 only.
Jan F. Chadima 3d742c
+.It Cm GSSAPIClientIdentity
Jan F. Chadima 3d742c
+If set, specifies the GSSAPI client identity that ssh should use when 
Jan F. Chadima 3d742c
+connecting to the server. The default is unset, which means that the default 
Jan F. Chadima 3d742c
+identity will be used.
Jan F. Chadima 3d742c
 .It Cm GSSAPIDelegateCredentials
Jan F. Chadima 3d742c
 Forward (delegate) credentials to the server.
Jan F. Chadima 3d742c
 The default is
Jan F. Chadima 3d742c
 .Dq no .
Jan F. Chadima 3d742c
-Note that this option applies to protocol version 2 only.
Jan F. Chadima 3d742c
+Note that this option applies to protocol version 2 connections using GSSAPI.
Jan F. Chadima 3d742c
+.It Cm GSSAPIRenewalForcesRekey
Jan F. Chadima 3d742c
+If set to 
Jan F. Chadima 3d742c
+.Dq yes
Jan F. Chadima 3d742c
+then renewal of the client's GSSAPI credentials will force the rekeying of the
Jan F. Chadima 3d742c
+ssh connection. With a compatible server, this can delegate the renewed 
Jan F. Chadima 3d742c
+credentials to a session on the server.
Jan F. Chadima 3d742c
+The default is
Jan F. Chadima 3d742c
+.Dq no .
Jan F. Chadima 3d742c
+.It Cm GSSAPITrustDns
Jan F. Chadima 3d742c
+Set to 
Jan F. Chadima 3d742c
+.Dq yes to indicate that the DNS is trusted to securely canonicalize
Jan F. Chadima 3d742c
+the name of the host being connected to. If 
Jan F. Chadima 3d742c
+.Dq no, the hostname entered on the
Jan F. Chadima 3d742c
+command line will be passed untouched to the GSSAPI library.
Jan F. Chadima 3d742c
+The default is
Jan F. Chadima 3d742c
+.Dq no .
Jan F. Chadima 3d742c
+This option only applies to protocol version 2 connections using GSSAPI.
Jan F. Chadima 3d742c
 .It Cm HashKnownHosts
Jan F. Chadima 3d742c
 Indicates that
Jan F. Chadima 3d742c
 .Xr ssh 1
Jan F. Chadima 3d742c
Index: sshconnect2.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/sshconnect2.c,v
Jan F. Chadima 3d742c
retrieving revision 1.162
Jan F. Chadima 3d742c
diff -u -r1.162 sshconnect2.c
Jan F. Chadima 3d742c
--- sshconnect2.c	5 Nov 2008 05:20:47 -0000	1.162
Jan F. Chadima 3d742c
+++ sshconnect2.c	26 Jul 2009 12:22:16 -0000
Jan F. Chadima 3d742c
@@ -104,9 +104,34 @@
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	Kex *kex;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	char *orig = NULL, *gss = NULL;
Jan F. Chadima 3d742c
+	char *gss_host = NULL;
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	xxx_host = host;
Jan F. Chadima 3d742c
 	xxx_hostaddr = hostaddr;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	if (options.gss_keyex) {
Jan F. Chadima 3d742c
+		/* Add the GSSAPI mechanisms currently supported on this 
Jan F. Chadima 3d742c
+		 * client to the key exchange algorithm proposal */
Jan F. Chadima 3d742c
+		orig = myproposal[PROPOSAL_KEX_ALGS];
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (options.gss_trust_dns)
Jan F. Chadima 3d742c
+			gss_host = (char *)get_canonical_hostname(1);
Jan F. Chadima 3d742c
+		else
Jan F. Chadima 3d742c
+			gss_host = host;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
Jan F. Chadima 3d742c
+		if (gss) {
Jan F. Chadima 3d742c
+			debug("Offering GSSAPI proposal: %s", gss);
Jan F. Chadima 3d742c
+			xasprintf(&myproposal[PROPOSAL_KEX_ALGS],
Jan F. Chadima 3d742c
+			    "%s,%s", gss, orig);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	if (options.ciphers == (char *)-1) {
Jan F. Chadima 3d742c
 		logit("No valid ciphers for protocol version 2 given, using defaults.");
Jan F. Chadima 3d742c
 		options.ciphers = NULL;
Jan F. Chadima 3d742c
@@ -134,6 +159,17 @@
Jan F. Chadima 3d742c
 		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] =
Jan F. Chadima 3d742c
 		    options.hostkeyalgorithms;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	/* If we've got GSSAPI algorithms, then we also support the
Jan F. Chadima 3d742c
+	 * 'null' hostkey, as a last resort */
Jan F. Chadima 3d742c
+	if (options.gss_keyex && gss) {
Jan F. Chadima 3d742c
+		orig = myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS];
Jan F. Chadima 3d742c
+		xasprintf(&myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS], 
Jan F. Chadima 3d742c
+		    "%s,null", orig);
Jan F. Chadima 3d742c
+		xfree(gss);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	if (options.rekey_limit)
Jan F. Chadima 3d742c
 		packet_set_rekey_limit((u_int32_t)options.rekey_limit);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
@@ -143,10 +179,26 @@
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GRP14_SHA1] = kexdh_client;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GEX_SHA1] = kexgex_client;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GEX_SHA256] = kexgex_client;
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	if (options.gss_keyex) {
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 	kex->client_version_string=client_version_string;
Jan F. Chadima 3d742c
 	kex->server_version_string=server_version_string;
Jan F. Chadima 3d742c
 	kex->verify_host_key=&verify_host_key_callback;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	if (options.gss_keyex) {
Jan F. Chadima 3d742c
+		kex->gss_deleg_creds = options.gss_deleg_creds;
Jan F. Chadima 3d742c
+		kex->gss_trust_dns = options.gss_trust_dns;
Jan F. Chadima 3d742c
+		kex->gss_client = options.gss_client_identity;
Jan F. Chadima 3d742c
+		kex->gss_host = gss_host;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	xxx_kex = kex;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	dispatch_run(DISPATCH_BLOCK, &kex->done, kex);
Jan F. Chadima 3d742c
@@ -235,6 +287,7 @@
Jan F. Chadima 3d742c
 void	input_gssapi_hash(int type, u_int32_t, void *);
Jan F. Chadima 3d742c
 void	input_gssapi_error(int, u_int32_t, void *);
Jan F. Chadima 3d742c
 void	input_gssapi_errtok(int, u_int32_t, void *);
Jan F. Chadima 3d742c
+int	userauth_gsskeyex(Authctxt *authctxt);
Jan F. Chadima 3d742c
 #endif
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 void	userauth(Authctxt *, char *);
Jan F. Chadima 3d742c
@@ -250,6 +303,10 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 Authmethod authmethods[] = {
Jan F. Chadima 3d742c
 #ifdef GSSAPI
Jan F. Chadima 3d742c
+	{"gssapi-keyex",
Jan F. Chadima 3d742c
+		userauth_gsskeyex,
Jan F. Chadima 3d742c
+		&options.gss_authentication,
Jan F. Chadima 3d742c
+		NULL},
Jan F. Chadima 3d742c
 	{"gssapi-with-mic",
Jan F. Chadima 3d742c
 		userauth_gssapi,
Jan F. Chadima 3d742c
 		NULL,
Jan F. Chadima 3d742c
@@ -541,19 +598,29 @@
Jan F. Chadima 3d742c
 	static u_int mech = 0;
Jan F. Chadima 3d742c
 	OM_uint32 min;
Jan F. Chadima 3d742c
 	int ok = 0;
Jan F. Chadima 3d742c
+	const char *gss_host;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (options.gss_trust_dns)
Jan F. Chadima 3d742c
+		gss_host = get_canonical_hostname(1);
Jan F. Chadima 3d742c
+	else
Jan F. Chadima 3d742c
+		gss_host = authctxt->host;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	/* Try one GSSAPI method at a time, rather than sending them all at
Jan F. Chadima 3d742c
 	 * once. */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	if (gss_supported == NULL)
Jan F. Chadima 3d742c
-		gss_indicate_mechs(&min, &gss_supported);
Jan F. Chadima 3d742c
+		if (GSS_ERROR(gss_indicate_mechs(&min, &gss_supported))) {
Jan F. Chadima 3d742c
+			gss_supported = NULL;
Jan F. Chadima 3d742c
+			return 0;
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	/* Check to see if the mechanism is usable before we offer it */
Jan F. Chadima 3d742c
 	while (mech < gss_supported->count && !ok) {
Jan F. Chadima 3d742c
 		/* My DER encoding requires length<128 */
Jan F. Chadima 3d742c
 		if (gss_supported->elements[mech].length < 128 &&
Jan F. Chadima 3d742c
 		    ssh_gssapi_check_mechanism(&gssctxt, 
Jan F. Chadima 3d742c
-		    &gss_supported->elements[mech], authctxt->host)) {
Jan F. Chadima 3d742c
+		    &gss_supported->elements[mech], gss_host, 
Jan F. Chadima 3d742c
+                    options.gss_client_identity)) {
Jan F. Chadima 3d742c
 			ok = 1; /* Mechanism works */
Jan F. Chadima 3d742c
 		} else {
Jan F. Chadima 3d742c
 			mech++;
Jan F. Chadima 3d742c
@@ -650,8 +717,8 @@
Jan F. Chadima 3d742c
 {
Jan F. Chadima 3d742c
 	Authctxt *authctxt = ctxt;
Jan F. Chadima 3d742c
 	Gssctxt *gssctxt;
Jan F. Chadima 3d742c
-	int oidlen;
Jan F. Chadima 3d742c
-	char *oidv;
Jan F. Chadima 3d742c
+	u_int oidlen;
Jan F. Chadima 3d742c
+	u_char *oidv;
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	if (authctxt == NULL)
Jan F. Chadima 3d742c
 		fatal("input_gssapi_response: no authentication context");
Jan F. Chadima 3d742c
@@ -761,6 +828,48 @@
Jan F. Chadima 3d742c
 	xfree(msg);
Jan F. Chadima 3d742c
 	xfree(lang);
Jan F. Chadima 3d742c
 }
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+int
Jan F. Chadima 3d742c
+userauth_gsskeyex(Authctxt *authctxt)
Jan F. Chadima 3d742c
+{
Jan F. Chadima 3d742c
+	Buffer b;
Jan F. Chadima 3d742c
+	gss_buffer_desc gssbuf;
Jan F. Chadima 3d742c
+	gss_buffer_desc mic = GSS_C_EMPTY_BUFFER;
Jan F. Chadima 3d742c
+	OM_uint32 ms;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	static int attempt = 0;
Jan F. Chadima 3d742c
+	if (attempt++ >= 1)
Jan F. Chadima 3d742c
+		return (0);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gss_kex_context == NULL) {
Jan F. Chadima 3d742c
+		debug("No valid Key exchange context"); 
Jan F. Chadima 3d742c
+		return (0);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	ssh_gssapi_buildmic(&b, authctxt->server_user, authctxt->service,
Jan F. Chadima 3d742c
+	    "gssapi-keyex");
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	gssbuf.value = buffer_ptr(&b);
Jan F. Chadima 3d742c
+	gssbuf.length = buffer_len(&b);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (GSS_ERROR(ssh_gssapi_sign(gss_kex_context, &gssbuf, &mic))) {
Jan F. Chadima 3d742c
+		buffer_free(&b);
Jan F. Chadima 3d742c
+		return (0);
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	packet_start(SSH2_MSG_USERAUTH_REQUEST);
Jan F. Chadima 3d742c
+	packet_put_cstring(authctxt->server_user);
Jan F. Chadima 3d742c
+	packet_put_cstring(authctxt->service);
Jan F. Chadima 3d742c
+	packet_put_cstring(authctxt->method->name);
Jan F. Chadima 3d742c
+	packet_put_string(mic.value, mic.length);
Jan F. Chadima 3d742c
+	packet_send();
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	buffer_free(&b);
Jan F. Chadima 3d742c
+	gss_release_buffer(&ms, &mic);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	return (1);
Jan F. Chadima 3d742c
+}
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 #endif /* GSSAPI */
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 int
Jan F. Chadima 3d742c
Index: sshd.c
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/sshd.c,v
Jan F. Chadima 3d742c
retrieving revision 1.384
Jan F. Chadima 3d742c
diff -u -r1.384 sshd.c
Jan F. Chadima 3d742c
--- sshd.c	28 Jan 2009 05:31:23 -0000	1.384
Jan F. Chadima 3d742c
+++ sshd.c	26 Jul 2009 12:22:17 -0000
Jan F. Chadima 3d742c
@@ -119,6 +119,10 @@
Jan F. Chadima 3d742c
 #include "monitor_wrap.h"
Jan F. Chadima 3d742c
 #include "version.h"
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef USE_SECURITY_SESSION_API
Jan F. Chadima 3d742c
+#include <Security/AuthSession.h>
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 #ifdef LIBWRAP
Jan F. Chadima 3d742c
 #include <tcpd.h>
Jan F. Chadima 3d742c
 #include <syslog.h>
Jan F. Chadima 3d742c
@@ -1530,10 +1534,13 @@
Jan F. Chadima 3d742c
 		logit("Disabling protocol version 1. Could not load host key");
Jan F. Chadima 3d742c
 		options.protocol &= ~SSH_PROTO_1;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
+#ifndef GSSAPI
Jan F. Chadima 3d742c
+	/* The GSSAPI key exchange can run without a host key */
Jan F. Chadima 3d742c
 	if ((options.protocol & SSH_PROTO_2) && !sensitive_data.have_ssh2_key) {
Jan F. Chadima 3d742c
 		logit("Disabling protocol version 2. Could not load host key");
Jan F. Chadima 3d742c
 		options.protocol &= ~SSH_PROTO_2;
Jan F. Chadima 3d742c
 	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 	if (!(options.protocol & (SSH_PROTO_1|SSH_PROTO_2))) {
Jan F. Chadima 3d742c
 		logit("sshd: no hostkeys available -- exiting.");
Jan F. Chadima 3d742c
 		exit(1);
Jan F. Chadima 3d742c
@@ -1817,6 +1824,60 @@
Jan F. Chadima 3d742c
 	/* Log the connection. */
Jan F. Chadima 3d742c
 	verbose("Connection from %.500s port %d", remote_ip, remote_port);
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef USE_SECURITY_SESSION_API
Jan F. Chadima 3d742c
+	/*
Jan F. Chadima 3d742c
+	 * Create a new security session for use by the new user login if
Jan F. Chadima 3d742c
+	 * the current session is the root session or we are not launched
Jan F. Chadima 3d742c
+	 * by inetd (eg: debugging mode or server mode).  We do not
Jan F. Chadima 3d742c
+	 * necessarily need to create a session if we are launched from
Jan F. Chadima 3d742c
+	 * inetd because Panther xinetd will create a session for us.
Jan F. Chadima 3d742c
+	 *
Jan F. Chadima 3d742c
+	 * The only case where this logic will fail is if there is an
Jan F. Chadima 3d742c
+	 * inetd running in a non-root session which is not creating
Jan F. Chadima 3d742c
+	 * new sessions for us.  Then all the users will end up in the
Jan F. Chadima 3d742c
+	 * same session (bad).
Jan F. Chadima 3d742c
+	 *
Jan F. Chadima 3d742c
+	 * When the client exits, the session will be destroyed for us
Jan F. Chadima 3d742c
+	 * automatically.
Jan F. Chadima 3d742c
+	 *
Jan F. Chadima 3d742c
+	 * We must create the session before any credentials are stored
Jan F. Chadima 3d742c
+	 * (including AFS pags, which happens a few lines below).
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+	{
Jan F. Chadima 3d742c
+		OSStatus err = 0;
Jan F. Chadima 3d742c
+		SecuritySessionId sid = 0;
Jan F. Chadima 3d742c
+		SessionAttributeBits sattrs = 0;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		err = SessionGetInfo(callerSecuritySession, &sid, &sattrs);
Jan F. Chadima 3d742c
+		if (err)
Jan F. Chadima 3d742c
+			error("SessionGetInfo() failed with error %.8X",
Jan F. Chadima 3d742c
+			    (unsigned) err);
Jan F. Chadima 3d742c
+		else
Jan F. Chadima 3d742c
+			debug("Current Session ID is %.8X / Session Attributes are %.8X",
Jan F. Chadima 3d742c
+			    (unsigned) sid, (unsigned) sattrs);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+		if (inetd_flag && !(sattrs & sessionIsRoot))
Jan F. Chadima 3d742c
+			debug("Running in inetd mode in a non-root session... "
Jan F. Chadima 3d742c
+			    "assuming inetd created the session for us.");
Jan F. Chadima 3d742c
+		else {
Jan F. Chadima 3d742c
+			debug("Creating new security session...");
Jan F. Chadima 3d742c
+			err = SessionCreate(0, sessionHasTTY | sessionIsRemote);
Jan F. Chadima 3d742c
+			if (err)
Jan F. Chadima 3d742c
+				error("SessionCreate() failed with error %.8X",
Jan F. Chadima 3d742c
+				    (unsigned) err);
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+			err = SessionGetInfo(callerSecuritySession, &sid, 
Jan F. Chadima 3d742c
+			    &sattrs);
Jan F. Chadima 3d742c
+			if (err)
Jan F. Chadima 3d742c
+				error("SessionGetInfo() failed with error %.8X",
Jan F. Chadima 3d742c
+				    (unsigned) err);
Jan F. Chadima 3d742c
+			else
Jan F. Chadima 3d742c
+				debug("New Session ID is %.8X / Session Attributes are %.8X",
Jan F. Chadima 3d742c
+				    (unsigned) sid, (unsigned) sattrs);
Jan F. Chadima 3d742c
+		}
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	/*
Jan F. Chadima 3d742c
 	 * We don't want to listen forever unless the other side
Jan F. Chadima 3d742c
 	 * successfully authenticates itself.  So we set up an alarm which is
Jan F. Chadima 3d742c
@@ -2194,12 +2255,61 @@
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 	myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = list_hostkey_types();
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	{
Jan F. Chadima 3d742c
+	char *orig;
Jan F. Chadima 3d742c
+	char *gss = NULL;
Jan F. Chadima 3d742c
+	char *newstr = NULL;
Jan F. Chadima 3d742c
+	orig = myproposal[PROPOSAL_KEX_ALGS];
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* 
Jan F. Chadima 3d742c
+	 * If we don't have a host key, then there's no point advertising
Jan F. Chadima 3d742c
+	 * the other key exchange algorithms
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS]) == 0)
Jan F. Chadima 3d742c
+		orig = NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (options.gss_keyex)
Jan F. Chadima 3d742c
+		gss = ssh_gssapi_server_mechanisms();
Jan F. Chadima 3d742c
+	else
Jan F. Chadima 3d742c
+		gss = NULL;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (gss && orig)
Jan F. Chadima 3d742c
+		xasprintf(&newstr, "%s,%s", gss, orig);
Jan F. Chadima 3d742c
+	else if (gss)
Jan F. Chadima 3d742c
+		newstr = gss;
Jan F. Chadima 3d742c
+	else if (orig)
Jan F. Chadima 3d742c
+		newstr = orig;
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	/* 
Jan F. Chadima 3d742c
+	 * If we've got GSSAPI mechanisms, then we've got the 'null' host
Jan F. Chadima 3d742c
+	 * key alg, but we can't tell people about it unless its the only
Jan F. Chadima 3d742c
+  	 * host key algorithm we support
Jan F. Chadima 3d742c
+	 */
Jan F. Chadima 3d742c
+	if (gss && (strlen(myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS])) == 0)
Jan F. Chadima 3d742c
+		myproposal[PROPOSAL_SERVER_HOST_KEY_ALGS] = "null";
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
+	if (newstr)
Jan F. Chadima 3d742c
+		myproposal[PROPOSAL_KEX_ALGS] = newstr;
Jan F. Chadima 3d742c
+	else
Jan F. Chadima 3d742c
+		fatal("No supported key exchange algorithms");
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
+
Jan F. Chadima 3d742c
 	/* start key exchange */
Jan F. Chadima 3d742c
 	kex = kex_setup(myproposal);
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GRP1_SHA1] = kexdh_server;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GRP14_SHA1] = kexdh_server;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GEX_SHA1] = kexgex_server;
Jan F. Chadima 3d742c
 	kex->kex[KEX_DH_GEX_SHA256] = kexgex_server;
Jan F. Chadima 3d742c
+#ifdef GSSAPI
Jan F. Chadima 3d742c
+	if (options.gss_keyex) {
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
Jan F. Chadima 3d742c
+		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
Jan F. Chadima 3d742c
+	}
Jan F. Chadima 3d742c
+#endif
Jan F. Chadima 3d742c
 	kex->server = 1;
Jan F. Chadima 3d742c
 	kex->client_version_string=client_version_string;
Jan F. Chadima 3d742c
 	kex->server_version_string=server_version_string;
Jan F. Chadima 3d742c
Index: sshd_config
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/sshd_config,v
Jan F. Chadima 3d742c
retrieving revision 1.82
Jan F. Chadima 3d742c
diff -u -r1.82 sshd_config
Jan F. Chadima 3d742c
--- sshd_config	2 Jul 2008 12:35:43 -0000	1.82
Jan F. Chadima 3d742c
+++ sshd_config	26 Jul 2009 12:22:19 -0000
Jan F. Chadima 3d742c
@@ -73,6 +73,8 @@
Jan F. Chadima 3d742c
 # GSSAPI options
Jan F. Chadima 3d742c
 #GSSAPIAuthentication no
Jan F. Chadima 3d742c
 #GSSAPICleanupCredentials yes
Jan F. Chadima 3d742c
+#GSSAPIStrictAcceptorCheck yes
Jan F. Chadima 3d742c
+#GSSAPIKeyExchange no
Jan F. Chadima 3d742c
 
Jan F. Chadima 3d742c
 # Set this to 'yes' to enable PAM authentication, account processing, 
Jan F. Chadima 3d742c
 # and session processing. If this is enabled, PAM authentication will 
Jan F. Chadima 3d742c
Index: sshd_config.5
Jan F. Chadima 3d742c
===================================================================
Jan F. Chadima 3d742c
RCS file: /cvs/openssh/sshd_config.5,v
Jan F. Chadima 3d742c
retrieving revision 1.108
Jan F. Chadima 3d742c
diff -u -r1.108 sshd_config.5
Jan F. Chadima 3d742c
--- sshd_config.5	23 Feb 2009 00:00:24 -0000	1.108
Jan F. Chadima 3d742c
+++ sshd_config.5	26 Jul 2009 12:22:20 -0000
Jan F. Chadima 3d742c
@@ -374,12 +374,40 @@
Jan F. Chadima 3d742c
 The default is
Jan F. Chadima 3d742c
 .Dq no .
Jan F. Chadima 3d742c
 Note that this option applies to protocol version 2 only.
Jan F. Chadima 3d742c
+.It Cm GSSAPIKeyExchange
Jan F. Chadima 3d742c
+Specifies whether key exchange based on GSSAPI is allowed. GSSAPI key exchange
Jan F. Chadima 3d742c
+doesn't rely on ssh keys to verify host identity.
Jan F. Chadima 3d742c
+The default is
Jan F. Chadima 3d742c
+.Dq no .
Jan F. Chadima 3d742c
+Note that this option applies to protocol version 2 only.
Jan F. Chadima 3d742c
 .It Cm GSSAPICleanupCredentials
Jan F. Chadima 3d742c
 Specifies whether to automatically destroy the user's credentials cache
Jan F. Chadima 3d742c
 on logout.
Jan F. Chadima 3d742c
 The default is
Jan F. Chadima 3d742c
 .Dq yes .
Jan F. Chadima 3d742c
 Note that this option applies to protocol version 2 only.
Jan F. Chadima 3d742c
+.It Cm GSSAPIStrictAcceptorCheck
Jan F. Chadima 3d742c
+Determines whether to be strict about the identity of the GSSAPI acceptor 
Jan F. Chadima 3d742c
+a client authenticates against. If
Jan F. Chadima 3d742c
+.Dq yes
Jan F. Chadima 3d742c
+then the client must authenticate against the
Jan F. Chadima 3d742c
+.Pa host
Jan F. Chadima 3d742c
+service on the current hostname. If 
Jan F. Chadima 3d742c
+.Dq no
Jan F. Chadima 3d742c
+then the client may authenticate against any service key stored in the 
Jan F. Chadima 3d742c
+machine's default store. This facility is provided to assist with operation 
Jan F. Chadima 3d742c
+on multi homed machines. 
Jan F. Chadima 3d742c
+The default is
Jan F. Chadima 3d742c
+.Dq yes .
Jan F. Chadima 3d742c
+Note that this option applies only to protocol version 2 GSSAPI connections,
Jan F. Chadima 3d742c
+and setting it to 
Jan F. Chadima 3d742c
+.Dq no
Jan F. Chadima 3d742c
+may only work with recent Kerberos GSSAPI libraries.
Jan F. Chadima 3d742c
+.It Cm GSSAPIStoreCredentialsOnRekey
Jan F. Chadima 3d742c
+Controls whether the user's GSSAPI credentials should be updated following a 
Jan F. Chadima 3d742c
+successful connection rekeying. This option can be used to accepted renewed 
Jan F. Chadima 3d742c
+or updated credentials from a compatible client. The default is
Jan F. Chadima 3d742c
+.Dq no .
Jan F. Chadima 3d742c
 .It Cm HostbasedAuthentication
Jan F. Chadima 3d742c
 Specifies whether rhosts or /etc/hosts.equiv authentication together
Jan F. Chadima 3d742c
 with successful public key client host authentication is allowed