vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/gss-genr.c.gsskexalg openssh-7.0p1/gss-genr.c
Jakub Jelen bc4ef0
--- openssh-7.0p1/gss-genr.c.gsskexalg	2015-08-19 12:28:38.024518959 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/gss-genr.c	2015-08-19 12:28:38.078518839 +0200
Jakub Jelen bc4ef0
@@ -78,7 +78,8 @@ ssh_gssapi_oid_table_ok() {
Jakub Jelen bc4ef0
  */
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 char *
Jakub Jelen bc4ef0
-ssh_gssapi_client_mechanisms(const char *host, const char *client) {
Jakub Jelen bc4ef0
+ssh_gssapi_client_mechanisms(const char *host, const char *client,
Jakub Jelen bc4ef0
+    const char *kex) {
Jakub Jelen bc4ef0
 	gss_OID_set gss_supported;
Jakub Jelen bc4ef0
 	OM_uint32 min_status;
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
@@ -86,12 +87,12 @@ ssh_gssapi_client_mechanisms(const char
Jakub Jelen bc4ef0
 		return NULL;
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 	return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
Jakub Jelen bc4ef0
-	    host, client));
Jakub Jelen bc4ef0
+	    host, client, kex));
Jakub Jelen bc4ef0
 }
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 char *
Jakub Jelen bc4ef0
 ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
Jakub Jelen bc4ef0
-    const char *host, const char *client) {
Jakub Jelen bc4ef0
+    const char *host, const char *client, const char *kex) {
Jakub Jelen bbf61d
 	struct sshbuf *buf;
Jakub Jelen bc4ef0
 	size_t i;
Jakub Jelen bbf61d
 	int oidpos, enclen, r;
Jakub Jelen bc4ef0
@@ -100,6 +101,7 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
Jakub Jelen bc4ef0
 	char deroid[2];
Jakub Jelen bc4ef0
 	const EVP_MD *evp_md = EVP_md5();
Jakub Jelen eaa7af
 	EVP_MD_CTX *md;
Jakub Jelen bc4ef0
+	char *s, *cp, *p;
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 	if (gss_enc2oid != NULL) {
Jakub Jelen bc4ef0
 		for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
Jakub Jelen bc4ef0
@@ -113,6 +115,7 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
Jakub Jelen bc4ef0
 
Jakub Jelen eaa7af
 	md = EVP_MD_CTX_new();
Jakub Jelen bc4ef0
 	oidpos = 0;
Jakub Jelen bc4ef0
+	s = cp = xstrdup(kex);
Jakub Jelen bc4ef0
 	for (i = 0; i < gss_supported->count; i++) {
Jakub Jelen bc4ef0
 		if (gss_supported->elements[i].length < 128 &&
Jakub Jelen bc4ef0
 		    (*check)(NULL, &(gss_supported->elements[i]), host, client)) {
Jakub Jelen bbf61d
@@ -131,28 +134,25 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
Jakub Jelen bc4ef0
 			enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
Jakub Jelen bc4ef0
 			    encoded, EVP_MD_size(evp_md) * 2);
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
-			if (oidpos != 0)
Jakub Jelen bbf61d
-				if ((r = sshbuf_put_u8(buf, ',')) != 0)
Jakub Jelen bbf61d
-					fatal("%s: buffer error: %s", __func__, ssh_err(r));
Jakub Jelen bc4ef0
-
Jakub Jelen bbf61d
-			if ((r = sshbuf_put(buf, KEX_GSS_GEX_SHA1_ID,
Jakub Jelen bbf61d
-			    sizeof(KEX_GSS_GEX_SHA1_ID) - 1)) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put(buf, encoded, enclen)) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put_u8(buf, ',')) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put(buf, KEX_GSS_GRP1_SHA1_ID, 
Jakub Jelen bbf61d
-			    sizeof(KEX_GSS_GRP1_SHA1_ID) - 1)) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put(buf, encoded, enclen)) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put_u8(buf, ',')) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put(buf, KEX_GSS_GRP14_SHA1_ID,
Jakub Jelen bbf61d
-			    sizeof(KEX_GSS_GRP14_SHA1_ID) - 1)) != 0 ||
Jakub Jelen bbf61d
-			    (r = sshbuf_put(buf, encoded, enclen)) != 0)
Jakub Jelen bbf61d
-		 		fatal("%s: buffer error: %s", __func__, ssh_err(r));
Jakub Jelen bc4ef0
+			cp = strncpy(s, kex, strlen(kex));
Jakub Jelen bc4ef0
+			for ((p = strsep(&cp, ",")); p && *p != '\0';
Jakub Jelen bc4ef0
+				(p = strsep(&cp, ","))) {
Jakub Jelen bbf61d
+				if (sshbuf_len(buf) != 0)
Jakub Jelen bbf61d
+					if ((r = sshbuf_put_u8(buf, ',')) != 0)
Jakub Jelen bbf61d
+			 			fatal("%s: buffer error: %s",
Jakub Jelen bbf61d
+						    __func__, ssh_err(r));
Jakub Jelen bbf61d
+				if ((r = sshbuf_put(buf, p, strlen(p))) != 0 ||
Jakub Jelen bbf61d
+				    (r = sshbuf_put(buf, encoded, enclen)) != 0)
Jakub Jelen bbf61d
+			 		fatal("%s: buffer error: %s",
Jakub Jelen bbf61d
+					    __func__, ssh_err(r));
Jakub Jelen bc4ef0
+			}
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 			gss_enc2oid[oidpos].oid = &(gss_supported->elements[i]);
Jakub Jelen bc4ef0
 			gss_enc2oid[oidpos].encoded = encoded;
Jakub Jelen bc4ef0
 			oidpos++;
Jakub Jelen bc4ef0
 		}
Jakub Jelen bc4ef0
 	}
Jakub Jelen bc4ef0
+	free(s);
Jakub Jelen eaa7af
 	EVP_MD_CTX_free(md);
Jakub Jelen bc4ef0
 	gss_enc2oid[oidpos].oid = NULL;
Jakub Jelen bc4ef0
 	gss_enc2oid[oidpos].encoded = NULL;
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/gss-serv.c.gsskexalg openssh-7.0p1/gss-serv.c
Jakub Jelen bc4ef0
--- openssh-7.0p1/gss-serv.c.gsskexalg	2015-08-19 12:28:38.024518959 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/gss-serv.c	2015-08-19 12:28:38.078518839 +0200
Jakub Jelen 4189ce
@@ -149,7 +149,8 @@ ssh_gssapi_server_mechanisms() {
Jakub Jelen 4189ce
 	if (supported_oids == NULL)
Jakub Jelen 4189ce
 		ssh_gssapi_prepare_supported_oids();
Jakub Jelen 4189ce
 	return (ssh_gssapi_kex_mechs(supported_oids,
Jakub Jelen 4189ce
-	    &ssh_gssapi_server_check_mech, NULL, NULL));
Jakub Jelen 4189ce
+	    &ssh_gssapi_server_check_mech, NULL, NULL,
Jakub Jelen 4189ce
+	    options.gss_kex_algorithms));
Jakub Jelen bc4ef0
 }
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 /* Unprivileged */
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/kex.c.gsskexalg openssh-7.0p1/kex.c
Jakub Jelen bc4ef0
--- openssh-7.0p1/kex.c.gsskexalg	2015-08-19 12:28:38.078518839 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/kex.c	2015-08-19 12:30:13.249306371 +0200
Jakub Jelen c4c52b
@@ -50,6 +50,7 @@
Jakub Jelen 13073f
 #include "misc.h"
Jakub Jelen c4c52b
 #include "dispatch.h"
Jakub Jelen c4c52b
 #include "monitor.h"
Jakub Jelen c4c52b
+#include "xmalloc.h"
Jakub Jelen c4c52b
 
Jakub Jelen c4c52b
 #include "ssherr.h"
Jakub Jelen c4c52b
 #include "sshbuf.h"
Jakub Jelen bc4ef0
@@ -232,6 +232,29 @@ kex_assemble_names(const char *def, char
Jakub Jelen bbf61d
 	return r;
Jakub Jelen bc4ef0
 }
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
+/* Validate GSS KEX method name list */
Jakub Jelen bc4ef0
+int
Jakub Jelen bc4ef0
+gss_kex_names_valid(const char *names)
Jakub Jelen bc4ef0
+{
Jakub Jelen bc4ef0
+	char *s, *cp, *p;
Jakub Jelen bc4ef0
+
Jakub Jelen bc4ef0
+	if (names == NULL || *names == '\0')
Jakub Jelen bc4ef0
+		return 0;
Jakub Jelen bc4ef0
+	s = cp = xstrdup(names);
Jakub Jelen bc4ef0
+	for ((p = strsep(&cp, ",")); p && *p != '\0';
Jakub Jelen bc4ef0
+	    (p = strsep(&cp, ","))) {
Jakub Jelen bc4ef0
+		if (strncmp(p, "gss-", 4) != 0
Jakub Jelen bc4ef0
+		  || kex_alg_by_name(p) == NULL) {
Jakub Jelen bc4ef0
+			error("Unsupported KEX algorithm \"%.100s\"", p);
Jakub Jelen bc4ef0
+			free(s);
Jakub Jelen bc4ef0
+			return 0;
Jakub Jelen bc4ef0
+		}
Jakub Jelen bc4ef0
+	}
Jakub Jelen bc4ef0
+	debug3("gss kex names ok: [%s]", names);
Jakub Jelen bc4ef0
+	free(s);
Jakub Jelen bc4ef0
+	return 1;
Jakub Jelen bc4ef0
+}
Jakub Jelen bc4ef0
+
Jakub Jelen bc4ef0
 /* put algorithm proposal into buffer */
Jakub Jelen bc4ef0
 int
Jakub Jelen bc4ef0
 kex_prop2buf(struct sshbuf *b, char *proposal[PROPOSAL_MAX])
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/kex.h.gsskexalg openssh-7.0p1/kex.h
Jakub Jelen bc4ef0
--- openssh-7.0p1/kex.h.gsskexalg	2015-08-19 12:28:38.078518839 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/kex.h	2015-08-19 12:30:52.404218958 +0200
Jakub Jelen bc4ef0
@@ -173,6 +173,7 @@ int	 kex_names_valid(const char *);
Jakub Jelen bc4ef0
 char	*kex_alg_list(char);
Jakub Jelen bc4ef0
 char	*kex_names_cat(const char *, const char *);
Jakub Jelen bbf61d
 int	 kex_assemble_names(char **, const char *, const char *);
Jakub Jelen bc4ef0
+int	 gss_kex_names_valid(const char *);
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 int	 kex_new(struct ssh *, char *[PROPOSAL_MAX], struct kex **);
Jakub Jelen bc4ef0
 int	 kex_setup(struct ssh *, char *[PROPOSAL_MAX]);
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/readconf.c.gsskexalg openssh-7.0p1/readconf.c
Jakub Jelen bc4ef0
--- openssh-7.0p1/readconf.c.gsskexalg	2015-08-19 12:28:38.026518955 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/readconf.c	2015-08-19 12:31:28.333138747 +0200
Jakub Jelen bc4ef0
@@ -61,6 +61,7 @@
Jakub Jelen bc4ef0
 #include "uidswap.h"
Jakub Jelen bc4ef0
 #include "myproposal.h"
Jakub Jelen bc4ef0
 #include "digest.h"
Jakub Jelen bc4ef0
+#include "ssh-gss.h"
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
 /* Format of the configuration file:
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
@@ -148,7 +149,7 @@ typedef enum {
Jakub Jelen bc4ef0
 	oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
Jakub Jelen bc4ef0
 	oAddressFamily, oGssAuthentication, oGssDelegateCreds,
Jakub Jelen bc4ef0
 	oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
Jakub Jelen bc4ef0
-	oGssServerIdentity, 
Jakub Jelen bc4ef0
+	oGssServerIdentity, oGssKexAlgorithms,
Jakub Jelen bc4ef0
 	oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
Jakub Jelen bbf61d
 	oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
Jakub Jelen bc4ef0
 	oHashKnownHosts,
Jakub Jelen bc4ef0
@@ -200,6 +201,7 @@ static struct {
Jakub Jelen bc4ef0
 	{ "gssapiclientidentity", oGssClientIdentity },
Jakub Jelen bc4ef0
 	{ "gssapiserveridentity", oGssServerIdentity },
Jakub Jelen bc4ef0
 	{ "gssapirenewalforcesrekey", oGssRenewalRekey },
Jakub Jelen bc4ef0
+	{ "gssapikexalgorithms", oGssKexAlgorithms },
Jakub Jelen 17b491
 # else
Jakub Jelen bc4ef0
 	{ "gssapiauthentication", oUnsupported },
Jakub Jelen bc4ef0
 	{ "gssapikeyexchange", oUnsupported },
Jakub Jelen bc4ef0
@@ -207,6 +209,7 @@ static struct {
Jakub Jelen bc4ef0
 	{ "gssapitrustdns", oUnsupported },
Jakub Jelen bc4ef0
 	{ "gssapiclientidentity", oUnsupported },
Jakub Jelen bc4ef0
 	{ "gssapirenewalforcesrekey", oUnsupported },
Jakub Jelen bc4ef0
+	{ "gssapikexalgorithms", oUnsupported },
Jakub Jelen bc4ef0
 #endif
Jakub Jelen 17b491
 #ifdef ENABLE_PKCS11
Jakub Jelen 17b491
 	{ "smartcarddevice", oPKCS11Provider },
Jakub Jelen bc4ef0
@@ -929,6 +932,18 @@ parse_time:
Jakub Jelen bc4ef0
 		intptr = &options->gss_renewal_rekey;
Jakub Jelen bc4ef0
 		goto parse_flag;
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
+	case oGssKexAlgorithms:
Jakub Jelen bc4ef0
+		arg = strdelim(&s);
Jakub Jelen bc4ef0
+		if (!arg || *arg == '\0')
Jakub Jelen bc4ef0
+			fatal("%.200s line %d: Missing argument.",
Jakub Jelen bc4ef0
+			    filename, linenum);
Jakub Jelen bc4ef0
+		if (!gss_kex_names_valid(arg))
Jakub Jelen bc4ef0
+			fatal("%.200s line %d: Bad GSSAPI KexAlgorithms '%s'.",
Jakub Jelen bc4ef0
+			    filename, linenum, arg ? arg : "<NONE>");
Jakub Jelen bc4ef0
+		if (*activep && options->gss_kex_algorithms == NULL)
Jakub Jelen bc4ef0
+			options->gss_kex_algorithms = xstrdup(arg);
Jakub Jelen bc4ef0
+		break;
Jakub Jelen bc4ef0
+
Jakub Jelen bc4ef0
 	case oBatchMode:
Jakub Jelen bc4ef0
 		intptr = &options->batch_mode;
Jakub Jelen bc4ef0
 		goto parse_flag;
Jakub Jelen bc4ef0
@@ -1638,6 +1653,7 @@ initialize_options(Options * options)
Jakub Jelen bc4ef0
 	options->gss_renewal_rekey = -1;
Jakub Jelen bc4ef0
 	options->gss_client_identity = NULL;
Jakub Jelen bc4ef0
 	options->gss_server_identity = NULL;
Jakub Jelen bc4ef0
+	options->gss_kex_algorithms = NULL;
Jakub Jelen bc4ef0
 	options->password_authentication = -1;
Jakub Jelen bc4ef0
 	options->kbd_interactive_authentication = -1;
Jakub Jelen bc4ef0
 	options->kbd_interactive_devices = NULL;
Jakub Jelen 62897e
@@ -1773,6 +1789,10 @@ fill_default_options(Options * options)
Jakub Jelen bc4ef0
 		options->gss_trust_dns = 0;
Jakub Jelen bc4ef0
 	if (options->gss_renewal_rekey == -1)
Jakub Jelen bc4ef0
 		options->gss_renewal_rekey = 0;
Jakub Jelen 62897e
+#ifdef GSSAPI
Jakub Jelen bc4ef0
+	if (options->gss_kex_algorithms == NULL)
Jakub Jelen bc4ef0
+		options->gss_kex_algorithms = strdup(GSS_KEX_DEFAULT_KEX);
Jakub Jelen 62897e
+#endif
Jakub Jelen bc4ef0
 	if (options->password_authentication == -1)
Jakub Jelen bc4ef0
 		options->password_authentication = 1;
Jakub Jelen bc4ef0
 	if (options->kbd_interactive_authentication == -1)
Jakub Jelen 3ae9c1
@@ -2651,6 +2671,8 @@ dump_client_config(Options *o, const cha
Jakub Jelen 3ae9c1
 	dump_cfg_string(oGssClientIdentity, o->gss_client_identity);
Jakub Jelen 3ae9c1
 	dump_cfg_string(oGssServerIdentity, o->gss_client_identity);
Jakub Jelen 3ae9c1
 	dump_cfg_fmtint(oGssRenewalRekey, o->gss_renewal_rekey);
Jakub Jelen 3ae9c1
+	dump_cfg_string(oKexAlgorithms, o->gss_kex_algorithms ?
Jakub Jelen 3ae9c1
+		o->gss_kex_algorithms : GSS_KEX_DEFAULT_KEX);
Jakub Jelen 3ae9c1
 #endif /* GSSAPI */
Jakub Jelen 3ae9c1
 	dump_cfg_fmtint(oHashKnownHosts, o->hash_known_hosts);
Jakub Jelen 3ae9c1
 	dump_cfg_fmtint(oHostbasedAuthentication, o->hostbased_authentication);
Jakub Jelen 3ae9c1
diff -up openssh-7.9p1/readconf.h.gsskexalg openssh-7.9p1/readconf.h
Jakub Jelen 3ae9c1
--- openssh-7.9p1/readconf.h.gsskexalg	2018-11-14 09:20:06.616350574 +0100
Jakub Jelen 3ae9c1
+++ openssh-7.9p1/readconf.h	2018-11-14 09:20:06.647350828 +0100
Jakub Jelen 3ae9c1
@@ -46,6 +46,7 @@ typedef struct {
Jakub Jelen bc4ef0
 	int	gss_renewal_rekey;	/* Credential renewal forces rekey */
Jakub Jelen bc4ef0
 	char    *gss_client_identity;   /* Principal to initiate GSSAPI with */
Jakub Jelen bc4ef0
 	char    *gss_server_identity;   /* GSSAPI target principal */
Jakub Jelen bc4ef0
+	char   *gss_kex_algorithms;	/* GSSAPI kex methods to be offered by client. */
Jakub Jelen bc4ef0
 	int     password_authentication;	/* Try password
Jakub Jelen bc4ef0
 						 * authentication. */
Jakub Jelen bc4ef0
 	int     kbd_interactive_authentication; /* Try keyboard-interactive auth. */
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/servconf.c.gsskexalg openssh-7.0p1/servconf.c
Jakub Jelen bc4ef0
--- openssh-7.0p1/servconf.c.gsskexalg	2015-08-19 12:28:38.074518847 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/servconf.c	2015-08-19 12:33:13.599902732 +0200
Jakub Jelen bc4ef0
@@ -57,6 +57,7 @@
Jakub Jelen bc4ef0
 #include "auth.h"
Jakub Jelen bc4ef0
 #include "myproposal.h"
Jakub Jelen bc4ef0
 #include "digest.h"
Jakub Jelen bc4ef0
+#include "ssh-gss.h"
Jakub Jelen bc4ef0
 
Jakub Jelen 3cd489
 static void add_listen_addr(ServerOptions *, const char *,
Jakub Jelen 3cd489
     const char *, int);
Jakub Jelen bc4ef0
@@ -121,6 +122,7 @@ initialize_server_options(ServerOptions
Jakub Jelen bc4ef0
 	options->gss_cleanup_creds = -1;
Jakub Jelen bc4ef0
 	options->gss_strict_acceptor = -1;
Jakub Jelen bc4ef0
 	options->gss_store_rekey = -1;
Jakub Jelen bc4ef0
+	options->gss_kex_algorithms = NULL;
Jakub Jelen 5b55d0
 	options->use_kuserok = -1;
Jakub Jelen 5b55d0
 	options->enable_k5users = -1;
Jakub Jelen bc4ef0
 	options->password_authentication = -1;
Jakub Jelen 62897e
@@ -288,6 +290,10 @@ fill_default_server_options(ServerOption
Jakub Jelen 17b491
 		options->gss_strict_acceptor = 1;
Jakub Jelen bc4ef0
 	if (options->gss_store_rekey == -1)
Jakub Jelen bc4ef0
 		options->gss_store_rekey = 0;
Jakub Jelen 62897e
+#ifdef GSSAPI
Jakub Jelen bc4ef0
+	if (options->gss_kex_algorithms == NULL)
Jakub Jelen bc4ef0
+		options->gss_kex_algorithms = strdup(GSS_KEX_DEFAULT_KEX);
Jakub Jelen 62897e
+#endif
Jakub Jelen 5b55d0
 	if (options->use_kuserok == -1)
Jakub Jelen 5b55d0
 		options->use_kuserok = 1;
Jakub Jelen 5b55d0
 	if (options->enable_k5users == -1)
Jakub Jelen bc4ef0
@@ -427,7 +431,7 @@ typedef enum {
Jakub Jelen bc4ef0
 	sHostKeyAlgorithms,
Jakub Jelen bc4ef0
 	sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
Jakub Jelen bc4ef0
 	sGssAuthentication, sGssCleanupCreds, sGssEnablek5users, sGssStrictAcceptor,
Jakub Jelen bbf61d
-	sGssKeyEx, sGssStoreRekey, sAcceptEnv, sSetEnv, sPermitTunnel,
Jakub Jelen bbf61d
+	sGssKeyEx, sGssStoreRekey, sGssKexAlgorithms, sAcceptEnv, sSetEnv, sPermitTunnel,
Jakub Jelen bbf61d
 	sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
Jakub Jelen bc4ef0
 	sUsePrivilegeSeparation, sAllowAgentForwarding,
Jakub Jelen bc4ef0
 	sHostCertificate,
Jakub Jelen bc4ef0
@@ -506,6 +510,7 @@ static struct {
Jakub Jelen bc4ef0
 	{ "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 	{ "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 	{ "gssapienablek5users", sGssEnablek5users, SSHCFG_ALL },
Jakub Jelen bc4ef0
+	{ "gssapikexalgorithms", sGssKexAlgorithms, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 #else
Jakub Jelen bc4ef0
 	{ "gssapiauthentication", sUnsupported, SSHCFG_ALL },
Jakub Jelen bc4ef0
 	{ "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
@@ -513,6 +518,7 @@ static struct {
Jakub Jelen bc4ef0
 	{ "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 	{ "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 	{ "gssapienablek5users", sUnsupported, SSHCFG_ALL },
Jakub Jelen bc4ef0
+	{ "gssapikexalgorithms", sUnsupported, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 #endif
Jakub Jelen bc4ef0
 	{ "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
 	{ "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
Jakub Jelen bc4ef0
@@ -1273,6 +1279,18 @@ process_server_config_line(ServerOptions
Jakub Jelen bc4ef0
 		intptr = &options->gss_store_rekey;
Jakub Jelen bc4ef0
 		goto parse_flag;
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
+	case sGssKexAlgorithms:
Jakub Jelen bc4ef0
+		arg = strdelim(&cp;;
Jakub Jelen bc4ef0
+		if (!arg || *arg == '\0')
Jakub Jelen bc4ef0
+			fatal("%.200s line %d: Missing argument.",
Jakub Jelen bc4ef0
+			    filename, linenum);
Jakub Jelen bc4ef0
+		if (!gss_kex_names_valid(arg))
Jakub Jelen bc4ef0
+			fatal("%.200s line %d: Bad GSSAPI KexAlgorithms '%s'.",
Jakub Jelen bc4ef0
+			    filename, linenum, arg ? arg : "<NONE>");
Jakub Jelen bc4ef0
+		if (*activep && options->gss_kex_algorithms == NULL)
Jakub Jelen bc4ef0
+			options->gss_kex_algorithms = xstrdup(arg);
Jakub Jelen bc4ef0
+		break;
Jakub Jelen bc4ef0
+
Jakub Jelen bc4ef0
 	case sPasswordAuthentication:
Jakub Jelen bc4ef0
 		intptr = &options->password_authentication;
Jakub Jelen bc4ef0
 		goto parse_flag;
Jakub Jelen bc4ef0
@@ -2304,6 +2322,7 @@ dump_config(ServerOptions *o)
Jakub Jelen bc4ef0
 	dump_cfg_fmtint(sGssKeyEx, o->gss_keyex);
Jakub Jelen bc4ef0
 	dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
Jakub Jelen bc4ef0
 	dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
Jakub Jelen bc4ef0
+	dump_cfg_string(sGssKexAlgorithms, o->gss_kex_algorithms);
Jakub Jelen bc4ef0
 #endif
Jakub Jelen bc4ef0
 	dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
Jakub Jelen bc4ef0
 	dump_cfg_fmtint(sKbdInteractiveAuthentication,
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/servconf.h.gsskexalg openssh-7.0p1/servconf.h
Jakub Jelen bc4ef0
--- openssh-7.0p1/servconf.h.gsskexalg	2015-08-19 12:28:38.080518834 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/servconf.h	2015-08-19 12:34:46.328693944 +0200
Jakub Jelen bc4ef0
@@ -122,6 +122,7 @@ typedef struct {
Jakub Jelen bc4ef0
 	int     gss_cleanup_creds;	/* If true, destroy cred cache on logout */
Jakub Jelen bc4ef0
 	int     gss_strict_acceptor;	/* If true, restrict the GSSAPI acceptor name */
Jakub Jelen bc4ef0
 	int 	gss_store_rekey;
Jakub Jelen bc4ef0
+	char   *gss_kex_algorithms;	/* GSSAPI kex methods to be offered by client. */
Jakub Jelen bc4ef0
 	int     password_authentication;	/* If true, permit password
Jakub Jelen bc4ef0
 						 * authentication. */
Jakub Jelen bc4ef0
 	int     kbd_interactive_authentication;	/* If true, permit */
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/ssh.1.gsskexalg openssh-7.0p1/ssh.1
Jakub Jelen bc4ef0
--- openssh-7.0p1/ssh.1.gsskexalg	2015-08-19 12:28:38.081518832 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/ssh.1	2015-08-19 12:35:31.741591692 +0200
Jakub Jelen bc4ef0
@@ -496,6 +496,7 @@ For full details of the options listed b
Jakub Jelen bc4ef0
 .It GSSAPIDelegateCredentials
Jakub Jelen bc4ef0
 .It GSSAPIRenewalForcesRekey
Jakub Jelen bc4ef0
 .It GSSAPITrustDNS
Jakub Jelen bc4ef0
+.It GSSAPIKexAlgorithms
Jakub Jelen bc4ef0
 .It HashKnownHosts
Jakub Jelen bc4ef0
 .It Host
Jakub Jelen bc4ef0
 .It HostbasedAuthentication
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/ssh_config.5.gsskexalg openssh-7.0p1/ssh_config.5
Jakub Jelen bc4ef0
--- openssh-7.0p1/ssh_config.5.gsskexalg	2015-08-19 12:28:38.028518950 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/ssh_config.5	2015-08-19 12:28:38.082518830 +0200
Jakub Jelen bc4ef0
@@ -786,6 +786,18 @@ command line will be passed untouched to
Jakub Jelen 13073f
 command line will be passed untouched to the GSSAPI library.
Jakub Jelen bc4ef0
 The default is
Jakub Jelen bc4ef0
 .Dq no .
Jakub Jelen bc4ef0
+.It Cm GSSAPIKexAlgorithms
Jakub Jelen bc4ef0
+The list of key exchange algorithms that are offered for GSSAPI
Jakub Jelen bc4ef0
+key exchange. Possible values are
Jakub Jelen bc4ef0
+.Bd -literal -offset 3n
Jakub Jelen bc4ef0
+gss-gex-sha1-,
Jakub Jelen bc4ef0
+gss-group1-sha1-,
Jakub Jelen bc4ef0
+gss-group14-sha1-
Jakub Jelen bc4ef0
+.Ed
Jakub Jelen bc4ef0
+.Pp
Jakub Jelen bc4ef0
+The default is
Jakub Jelen bc4ef0
+.Dq gss-gex-sha1-,gss-group14-sha1- .
Jakub Jelen bc4ef0
+This option only applies to protocol version 2 connections using GSSAPI.
Jakub Jelen bc4ef0
 .It Cm HashKnownHosts
Jakub Jelen bc4ef0
 Indicates that
Jakub Jelen bc4ef0
 .Xr ssh 1
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/sshconnect2.c.gsskexalg openssh-7.0p1/sshconnect2.c
Jakub Jelen bc4ef0
--- openssh-7.0p1/sshconnect2.c.gsskexalg	2015-08-19 12:28:38.045518912 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/sshconnect2.c	2015-08-19 12:28:38.081518832 +0200
Jakub Jelen bc4ef0
@@ -179,7 +179,8 @@ ssh_kex2(char *host, struct sockaddr *ho
Jakub Jelen bc4ef0
 		else
Jakub Jelen bc4ef0
 			gss_host = host;
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
-		gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity);
Jakub Jelen bc4ef0
+		gss = ssh_gssapi_client_mechanisms(gss_host,
Jakub Jelen bc4ef0
+		    options.gss_client_identity, options.gss_kex_algorithms);
Jakub Jelen bc4ef0
 		if (gss) {
Jakub Jelen bc4ef0
 			debug("Offering GSSAPI proposal: %s", gss);
Jakub Jelen 9a804f
 			xasprintf(&options.kex_algorithms,
Jakub Jelen d9d957
--- openssh-7.1p1/sshd_config.5.gsskexalg	2015-12-10 15:32:48.105418092 +0100
Jakub Jelen d9d957
+++ openssh-7.1p1/sshd_config.5	2015-12-10 15:33:47.771279548 +0100
Jakub Jelen d9d957
@@ -663,6 +663,18 @@ or updated credentials from a compatible
Jakub Jelen d9d957
 For this to work
Jakub Jelen d9d957
 .Cm GSSAPIKeyExchange
Jakub Jelen d9d957
 needs to be enabled in the server and also used by the client.
Jakub Jelen bc4ef0
+.It Cm GSSAPIKexAlgorithms
Jakub Jelen bc4ef0
+The list of key exchange algorithms that are accepted by GSSAPI
Jakub Jelen bc4ef0
+key exchange. Possible values are
Jakub Jelen bc4ef0
+.Bd -literal -offset 3n
Jakub Jelen bc4ef0
+gss-gex-sha1-,
Jakub Jelen bc4ef0
+gss-group1-sha1-,
Jakub Jelen bc4ef0
+gss-group14-sha1-
Jakub Jelen bc4ef0
+.Ed
Jakub Jelen bc4ef0
+.Pp
Jakub Jelen bc4ef0
+The default is
Jakub Jelen bc4ef0
+.Dq gss-gex-sha1-,gss-group14-sha1- .
Jakub Jelen bc4ef0
+This option only applies to protocol version 2 connections using GSSAPI.
Jakub Jelen bc4ef0
 .It Cm HostbasedAcceptedKeyTypes
Jakub Jelen bc4ef0
 Specifies the key types that will be accepted for hostbased authentication
Jakub Jelen bbf61d
 as a list of comma-separated patterns.
Jakub Jelen bc4ef0
diff -up openssh-7.0p1/ssh-gss.h.gsskexalg openssh-7.0p1/ssh-gss.h
Jakub Jelen bc4ef0
--- openssh-7.0p1/ssh-gss.h.gsskexalg	2015-08-19 12:28:38.031518944 +0200
Jakub Jelen bc4ef0
+++ openssh-7.0p1/ssh-gss.h	2015-08-19 12:28:38.081518832 +0200
Jakub Jelen bc4ef0
@@ -76,6 +76,10 @@ extern char **k5users_allowed_cmds;
Jakub Jelen bc4ef0
 #define KEX_GSS_GRP14_SHA1_ID				"gss-group14-sha1-"
Jakub Jelen bc4ef0
 #define KEX_GSS_GEX_SHA1_ID				"gss-gex-sha1-"
Jakub Jelen bc4ef0
 
Jakub Jelen bc4ef0
+#define        GSS_KEX_DEFAULT_KEX \
Jakub Jelen bc4ef0
+	KEX_GSS_GEX_SHA1_ID "," \
Jakub Jelen bc4ef0
+	KEX_GSS_GRP14_SHA1_ID
Jakub Jelen bc4ef0
+
Jakub Jelen bc4ef0
 typedef struct {
Jakub Jelen bc4ef0
 	char *envvar;
Jakub Jelen 117678
 	char *envval;
Jakub Jelen bc4ef0
@@ -147,9 +151,9 @@ int ssh_gssapi_credentials_updated(Gssct
Jakub Jelen bc4ef0
 /* In the server */
Jakub Jelen bc4ef0
 typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *, 
Jakub Jelen bc4ef0
     const char *);
Jakub Jelen bc4ef0
-char *ssh_gssapi_client_mechanisms(const char *, const char *);
Jakub Jelen bc4ef0
+char *ssh_gssapi_client_mechanisms(const char *, const char *, const char *);
Jakub Jelen bc4ef0
 char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
Jakub Jelen bc4ef0
-    const char *);
Jakub Jelen bc4ef0
+    const char *, const char *);
Jakub Jelen bc4ef0
 gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
Jakub Jelen bc4ef0
 int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *, 
Jakub Jelen bc4ef0
     const char *);