72514f7
From 6ff8f667f792052fd47689c3e421fcd6ddca1cd0 Mon Sep 17 00:00:00 2001
72514f7
From: Jakub Jelen <jjelen@redhat.com>
72514f7
Date: Fri, 25 Aug 2017 19:15:48 +0200
72514f7
Subject: [PATCH 1/3] GSSAPI Key exchange methods with DH and SHA2
72514f7
72514f7
---
72514f7
 gss-genr.c         | 10 ++++++++++
72514f7
 kex.c              |  2 ++
72514f7
 kex.h              |  2 ++
72514f7
 kexgssc.c          |  6 ++++++
72514f7
 kexgsss.c          |  6 ++++++
72514f7
 monitor.c          |  2 ++
72514f7
 regress/kextype.sh |  4 +++-
72514f7
 regress/rekey.sh   |  8 ++++++--
72514f7
 ssh-gss.h          |  2 ++
72514f7
 ssh_config.5       |  4 +++-
72514f7
 sshconnect2.c      |  2 ++
72514f7
 sshd.c             |  2 ++
72514f7
 sshd_config.5      |  4 +++-
72514f7
 13 files changed, 49 insertions(+), 5 deletions(-)
72514f7
72514f7
diff --git a/gss-genr.c b/gss-genr.c
72514f7
index dc63682d..c6eff3d7 100644
72514f7
--- a/gss-genr.c
72514f7
+++ b/gss-genr.c
72514f7
@@ -183,6 +183,16 @@ ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
72514f7
 			return GSS_C_NO_OID;
72514f7
 		name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
72514f7
 		break;
72514f7
+	case KEX_GSS_GRP14_SHA256:
72514f7
+		if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA256_ID))
72514f7
+			return GSS_C_NO_OID;
72514f7
+		name += sizeof(KEX_GSS_GRP14_SHA256_ID) - 1;
72514f7
+		break;
72514f7
+	case KEX_GSS_GRP16_SHA512:
72514f7
+		if (strlen(name) < sizeof(KEX_GSS_GRP16_SHA512_ID))
72514f7
+			return GSS_C_NO_OID;
72514f7
+		name += sizeof(KEX_GSS_GRP16_SHA512_ID) - 1;
72514f7
+		break;
72514f7
 	case KEX_GSS_GEX_SHA1:
72514f7
 		if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
72514f7
 			return GSS_C_NO_OID;
72514f7
diff --git a/kex.c b/kex.c
72514f7
index 63e028fa..e798fecb 100644
72514f7
--- a/kex.c
72514f7
+++ b/kex.c
72514f7
@@ -112,6 +112,8 @@ static const struct kexalg kexalgs[] = {
72514f7
 	{ KEX_GSS_GEX_SHA1_ID, KEX_GSS_GEX_SHA1, 0, SSH_DIGEST_SHA1 },
72514f7
 	{ KEX_GSS_GRP1_SHA1_ID, KEX_GSS_GRP1_SHA1, 0, SSH_DIGEST_SHA1 },
72514f7
 	{ KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
72514f7
+	{ KEX_GSS_GRP14_SHA256_ID, KEX_GSS_GRP14_SHA256, 0, SSH_DIGEST_SHA256 },
72514f7
+	{ KEX_GSS_GRP16_SHA512_ID, KEX_GSS_GRP16_SHA512, 0, SSH_DIGEST_SHA512 },
72514f7
 #endif
72514f7
 	{ NULL, -1, -1, -1},
72514f7
 };
72514f7
diff --git a/kex.h b/kex.h
72514f7
index 8a2b37c5..f27958ae 100644
72514f7
--- a/kex.h
72514f7
+++ b/kex.h
72514f7
@@ -102,6 +102,8 @@ enum kex_exchange {
72514f7
 #ifdef GSSAPI
72514f7
 	KEX_GSS_GRP1_SHA1,
72514f7
 	KEX_GSS_GRP14_SHA1,
72514f7
+	KEX_GSS_GRP14_SHA256,
72514f7
+	KEX_GSS_GRP16_SHA512,
72514f7
 	KEX_GSS_GEX_SHA1,
72514f7
 #endif
72514f7
 	KEX_MAX
72514f7
diff --git a/kexgssc.c b/kexgssc.c
72514f7
index 132df8b5..ed23f06d 100644
72514f7
--- a/kexgssc.c
72514f7
+++ b/kexgssc.c
72514f7
@@ -88,8 +88,12 @@ kexgss_client(struct ssh *ssh) {
72514f7
 		dh = dh_new_group1();
72514f7
 		break;
72514f7
 	case KEX_GSS_GRP14_SHA1:
72514f7
+	case KEX_GSS_GRP14_SHA256:
72514f7
 		dh = dh_new_group14();
72514f7
 		break;
72514f7
+	case KEX_GSS_GRP16_SHA512:
72514f7
+		dh = dh_new_group16();
72514f7
+		break;
72514f7
 	case KEX_GSS_GEX_SHA1:
72514f7
 		debug("Doing group exchange\n");
72514f7
 		nbits = dh_estimate(ssh->kex->we_need * 8);
72514f7
@@ -272,6 +276,8 @@ kexgss_client(struct ssh *ssh) {
72514f7
 	switch (ssh->kex->kex_type) {
72514f7
 	case KEX_GSS_GRP1_SHA1:
72514f7
 	case KEX_GSS_GRP14_SHA1:
72514f7
+	case KEX_GSS_GRP14_SHA256:
72514f7
+	case KEX_GSS_GRP16_SHA512:
72514f7
 		kex_dh_hash(ssh->kex->hash_alg, ssh->kex->client_version_string, 
72514f7
 		    ssh->kex->server_version_string,
72514f7
 		    buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
72514f7
diff --git a/kexgsss.c b/kexgsss.c
72514f7
index 82a715cc..b7da8823 100644
72514f7
--- a/kexgsss.c
72514f7
+++ b/kexgsss.c
72514f7
@@ -104,8 +104,12 @@ kexgss_server(struct ssh *ssh)
72514f7
 		dh = dh_new_group1();
72514f7
 		break;
72514f7
 	case KEX_GSS_GRP14_SHA1:
72514f7
+	case KEX_GSS_GRP14_SHA256:
72514f7
 		dh = dh_new_group14();
72514f7
 		break;
72514f7
+	case KEX_GSS_GRP16_SHA512:
72514f7
+		dh = dh_new_group16();
72514f7
+		break;
72514f7
 	case KEX_GSS_GEX_SHA1:
72514f7
 		debug("Doing group exchange");
72514f7
 		packet_read_expect(SSH2_MSG_KEXGSS_GROUPREQ);
72514f7
@@ -223,6 +227,8 @@ kexgss_server(struct ssh *ssh)
72514f7
 	switch (ssh->kex->kex_type) {
72514f7
 	case KEX_GSS_GRP1_SHA1:
72514f7
 	case KEX_GSS_GRP14_SHA1:
72514f7
+	case KEX_GSS_GRP14_SHA256:
72514f7
+	case KEX_GSS_GRP16_SHA512:
72514f7
 		kex_dh_hash(ssh->kex->hash_alg,
72514f7
 		    ssh->kex->client_version_string, ssh->kex->server_version_string,
72514f7
 		    buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
72514f7
diff --git a/monitor.c b/monitor.c
72514f7
index 17046936..d6bc7ac7 100644
72514f7
--- a/monitor.c
72514f7
+++ b/monitor.c
72514f7
@@ -1648,6 +1648,8 @@ monitor_apply_keystate(struct monitor *pmonitor)
72514f7
 	if (options.gss_keyex) {
72514f7
 		kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
72514f7
+		kex->kex[KEX_GSS_GRP14_SHA256] = kexgss_server;
72514f7
+		kex->kex[KEX_GSS_GRP16_SHA512] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
72514f7
 	}
72514f7
 #endif
72514f7
diff --git a/regress/kextype.sh b/regress/kextype.sh
72514f7
index 780362ca..45f4f16d 100644
72514f7
--- a/regress/kextype.sh
72514f7
+++ b/regress/kextype.sh
72514f7
@@ -14,7 +14,9 @@ echo "KexAlgorithms=$KEXOPT" >> $OBJ/sshd_proxy
72514f7
 
72514f7
 tries="1 2 3 4"
72514f7
 for k in `${SSH} -Q kex`; do
72514f7
-	if [ $k = "gss-gex-sha1-" -o $k = "gss-group1-sha1-" -o $k = "gss-group14-sha1-" ]; then
72514f7
+	if [ $k = "gss-gex-sha1-" -o $k = "gss-group1-sha1-" -o \
72514f7
+	    $k = "gss-group14-sha1-" -o $k = "gss-group14-sha256-" -o \
72514f7
+	    $k = "gss-group16-sha512-" ]; then
72514f7
 		continue
72514f7
 	fi
72514f7
 	verbose "kex $k"
72514f7
diff --git a/regress/rekey.sh b/regress/rekey.sh
72514f7
index 9fbe9b38..a2921bef 100644
72514f7
--- a/regress/rekey.sh
72514f7
+++ b/regress/rekey.sh
72514f7
@@ -38,7 +38,9 @@ increase_datafile_size 300
72514f7
 
72514f7
 opts=""
72514f7
 for i in `${SSH} -Q kex`; do
72514f7
-	if [ $i = "gss-gex-sha1-" -o $i = "gss-group1-sha1-" -o $i = "gss-group14-sha1-" ]; then
72514f7
+	if [ $i = "gss-gex-sha1-" -o $i = "gss-group1-sha1-" -o \
72514f7
+	    $i = "gss-group14-sha1-" -o $i = "gss-group14-sha256-" -o \
72514f7
+	    $i = "gss-group16-sha512-" ]; then
72514f7
 		continue
72514f7
 	fi
72514f7
 	opts="$opts KexAlgorithms=$i"
72514f7
@@ -59,7 +61,9 @@ done
72514f7
 if ${SSH} -Q cipher-auth | grep '^.*$' >/dev/null 2>&1 ; then
72514f7
   for c in `${SSH} -Q cipher-auth`; do
72514f7
     for kex in `${SSH} -Q kex`; do
72514f7
-	if [ $kex = "gss-gex-sha1-" -o $kex = "gss-group1-sha1-" -o $kex = "gss-group14-sha1-" ]; then
72514f7
+	if [ $kex = "gss-gex-sha1-" -o $kex = "gss-group1-sha1-" -o \
72514f7
+	    $kex = "gss-group14-sha1-" -o $kex = "gss-group14-sha256-" -o \
72514f7
+	    $kex = "gss-group16-sha512-" ]; then
72514f7
 		continue
72514f7
 	fi
72514f7
 	verbose "client rekey $c $kex"
72514f7
diff --git a/ssh-gss.h b/ssh-gss.h
72514f7
index 6b6adb2b..7bf8d75e 100644
72514f7
--- a/ssh-gss.h
72514f7
+++ b/ssh-gss.h
72514f7
@@ -70,6 +70,8 @@
72514f7
 #define SSH2_MSG_KEXGSS_GROUP				41
72514f7
 #define KEX_GSS_GRP1_SHA1_ID				"gss-group1-sha1-"
72514f7
 #define KEX_GSS_GRP14_SHA1_ID				"gss-group14-sha1-"
72514f7
+#define KEX_GSS_GRP14_SHA256_ID			"gss-group14-sha256-"
72514f7
+#define KEX_GSS_GRP16_SHA512_ID			"gss-group16-sha512-"
72514f7
 #define KEX_GSS_GEX_SHA1_ID				"gss-gex-sha1-"
72514f7
 
72514f7
 #define        GSS_KEX_DEFAULT_KEX \
72514f7
diff --git a/ssh_config.5 b/ssh_config.5
72514f7
index 6b24649e..3d6da510 100644
72514f7
--- a/ssh_config.5
72514f7
+++ b/ssh_config.5
72514f7
@@ -760,7 +760,9 @@ key exchange. Possible values are
72514f7
 .Bd -literal -offset 3n
72514f7
 gss-gex-sha1-,
72514f7
 gss-group1-sha1-,
72514f7
-gss-group14-sha1-
72514f7
+gss-group14-sha1-,
72514f7
+gss-group14-sha256-,
72514f7
+gss-group16-sha512-
72514f7
 .Ed
72514f7
 .Pp
72514f7
 The default is
72514f7
diff --git a/sshconnect2.c b/sshconnect2.c
72514f7
index 8db98293..5d6b8be0 100644
72514f7
--- a/sshconnect2.c
72514f7
+++ b/sshconnect2.c
72514f7
@@ -253,6 +253,8 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
72514f7
 	if (options.gss_keyex) {
72514f7
 		kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_client;
72514f7
 		kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_client;
72514f7
+		kex->kex[KEX_GSS_GRP14_SHA256] = kexgss_client;
72514f7
+		kex->kex[KEX_GSS_GRP16_SHA512] = kexgss_client;
72514f7
 		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
72514f7
 	}
72514f7
 #endif
72514f7
diff --git a/sshd.c b/sshd.c
72514f7
index 895df26f..e4c879a2 100644
72514f7
--- a/sshd.c
72514f7
+++ b/sshd.c
72514f7
@@ -2244,6 +2244,8 @@ do_ssh2_kex(void)
72514f7
 	if (options.gss_keyex) {
72514f7
 		kex->kex[KEX_GSS_GRP1_SHA1] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GRP14_SHA1] = kexgss_server;
72514f7
+		kex->kex[KEX_GSS_GRP14_SHA256] = kexgss_server;
72514f7
+		kex->kex[KEX_GSS_GRP16_SHA512] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
72514f7
 	}
72514f7
 #endif
72514f7
diff --git a/sshd_config.5 b/sshd_config.5
72514f7
index bf81f6af..0793418b 100644
72514f7
--- a/sshd_config.5
72514f7
+++ b/sshd_config.5
72514f7
@@ -675,7 +675,9 @@ key exchange. Possible values are
72514f7
 .Bd -literal -offset 3n
72514f7
 gss-gex-sha1-,
72514f7
 gss-group1-sha1-,
72514f7
-gss-group14-sha1-
72514f7
+gss-group14-sha1-,
72514f7
+gss-group14-sha256-,
72514f7
+gss-group16-sha512-
72514f7
 .Ed
72514f7
 .Pp
72514f7
 The default is
72514f7
-- 
72514f7
2.13.5
72514f7
72514f7
72514f7
From 7d56144903fc625c33da7fabf103f4f6bba4d43a Mon Sep 17 00:00:00 2001
72514f7
From: Jakub Jelen <jjelen@redhat.com>
72514f7
Date: Tue, 29 Aug 2017 15:32:14 +0200
72514f7
Subject: [PATCH 2/3] GSSAPI Key exchange using ECDH and SHA2
72514f7
72514f7
---
72514f7
 gss-genr.c         |  10 ++
72514f7
 kex.c              |   3 +
72514f7
 kex.h              |   4 +
72514f7
 kexgssc.c          | 392 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
72514f7
 kexgsss.c          | 333 +++++++++++++++++++++++++++++++++++++++++++++
72514f7
 monitor.c          |   5 +-
72514f7
 regress/kextype.sh |   1 +
72514f7
 regress/rekey.sh   |   2 +
72514f7
 ssh-gss.h          |   2 +
72514f7
 ssh_config.5       |   4 +-
72514f7
 sshconnect2.c      |   2 +
72514f7
 sshd.c             |   2 +
72514f7
 sshd_config.5      |   4 +-
72514f7
 13 files changed, 754 insertions(+), 10 deletions(-)
72514f7
72514f7
diff --git a/gss-genr.c b/gss-genr.c
72514f7
index c6eff3d7..22040244 100644
72514f7
--- a/gss-genr.c
72514f7
+++ b/gss-genr.c
72514f7
@@ -198,6 +198,16 @@ ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
72514f7
 			return GSS_C_NO_OID;
72514f7
 		name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
72514f7
 		break;
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if (strlen(name) < sizeof(KEX_GSS_NISTP256_SHA256_ID))
72514f7
+			return GSS_C_NO_OID;
72514f7
+		name += sizeof(KEX_GSS_NISTP256_SHA256_ID) - 1;
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		if (strlen(name) < sizeof(KEX_GSS_C25519_SHA256_ID))
72514f7
+			return GSS_C_NO_OID;
72514f7
+		name += sizeof(KEX_GSS_C25519_SHA256_ID) - 1;
72514f7
+		break;
72514f7
 	default:
72514f7
 		return GSS_C_NO_OID;
72514f7
 	}
72514f7
diff --git a/kex.c b/kex.c
72514f7
index e798fecb..bdeeada9 100644
72514f7
--- a/kex.c
72514f7
+++ b/kex.c
72514f7
@@ -114,6 +114,9 @@ static const struct kexalg kexalgs[] = {
72514f7
 	{ KEX_GSS_GRP14_SHA1_ID, KEX_GSS_GRP14_SHA1, 0, SSH_DIGEST_SHA1 },
72514f7
 	{ KEX_GSS_GRP14_SHA256_ID, KEX_GSS_GRP14_SHA256, 0, SSH_DIGEST_SHA256 },
72514f7
 	{ KEX_GSS_GRP16_SHA512_ID, KEX_GSS_GRP16_SHA512, 0, SSH_DIGEST_SHA512 },
72514f7
+	{ KEX_GSS_NISTP256_SHA256_ID, KEX_GSS_NISTP256_SHA256,
72514f7
+	    NID_X9_62_prime256v1, SSH_DIGEST_SHA256 },
72514f7
+	{ KEX_GSS_C25519_SHA256_ID, KEX_GSS_C25519_SHA256, 0, SSH_DIGEST_SHA256 },
72514f7
 #endif
72514f7
 	{ NULL, -1, -1, -1},
72514f7
 };
72514f7
diff --git a/kex.h b/kex.h
72514f7
index f27958ae..7def8561 100644
72514f7
--- a/kex.h
72514f7
+++ b/kex.h
72514f7
@@ -105,6 +105,8 @@ enum kex_exchange {
72514f7
 	KEX_GSS_GRP14_SHA256,
72514f7
 	KEX_GSS_GRP16_SHA512,
72514f7
 	KEX_GSS_GEX_SHA1,
72514f7
+	KEX_GSS_NISTP256_SHA256,
72514f7
+	KEX_GSS_C25519_SHA256,
72514f7
 #endif
72514f7
 	KEX_MAX
72514f7
 };
72514f7
@@ -211,6 +213,8 @@ int	 kexecdh_server(struct ssh *);
72514f7
 int	 kexc25519_client(struct ssh *);
72514f7
 int	 kexc25519_server(struct ssh *);
72514f7
 #ifdef GSSAPI
72514f7
+int	 kexecgss_client(struct ssh *);
72514f7
+int	 kexecgss_server(struct ssh *);
72514f7
 int	 kexgss_client(struct ssh *);
72514f7
 int	 kexgss_server(struct ssh *);
72514f7
 #endif
72514f7
diff --git a/kexgssc.c b/kexgssc.c
72514f7
index ed23f06d..bdb3109a 100644
72514f7
--- a/kexgssc.c
72514f7
+++ b/kexgssc.c
72514f7
@@ -43,6 +43,7 @@
72514f7
 #include "packet.h"
72514f7
 #include "dh.h"
72514f7
 #include "digest.h"
72514f7
+#include "ssherr.h"
72514f7
 
72514f7
 #include "ssh-gss.h"
72514f7
 
72514f7
@@ -52,7 +53,7 @@ kexgss_client(struct ssh *ssh) {
72514f7
 	gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
72514f7
 	Gssctxt *ctxt;
72514f7
 	OM_uint32 maj_status, min_status, ret_flags;
72514f7
-	u_int klen, kout, slen = 0, strlen;
72514f7
+	u_int klen, kout, slen = 0, packet_len;
72514f7
 	DH *dh; 
72514f7
 	BIGNUM *dh_server_pub = NULL;
72514f7
 	BIGNUM *shared_secret = NULL;
72514f7
@@ -201,20 +202,20 @@ kexgss_client(struct ssh *ssh) {
72514f7
 				debug("Received GSSAPI_CONTINUE");
72514f7
 				if (maj_status == GSS_S_COMPLETE) 
72514f7
 					fatal("GSSAPI Continue received from server when complete");
72514f7
-				recv_tok.value = packet_get_string(&strlen);
72514f7
-				recv_tok.length = strlen; 
72514f7
+				recv_tok.value = packet_get_string(&packet_len);
72514f7
+				recv_tok.length = packet_len;
72514f7
 				break;
72514f7
 			case SSH2_MSG_KEXGSS_COMPLETE:
72514f7
 				debug("Received GSSAPI_COMPLETE");
72514f7
 				packet_get_bignum2(dh_server_pub);
72514f7
-				msg_tok.value =  packet_get_string(&strlen);
72514f7
-				msg_tok.length = strlen; 
72514f7
+				msg_tok.value =  packet_get_string(&packet_len);
72514f7
+				msg_tok.length = packet_len;
72514f7
 
72514f7
 				/* Is there a token included? */
72514f7
 				if (packet_get_char()) {
72514f7
 					recv_tok.value=
72514f7
-					    packet_get_string(&strlen);
72514f7
-					recv_tok.length = strlen;
72514f7
+					    packet_get_string(&packet_len);
72514f7
+					recv_tok.length = packet_len;
72514f7
 					/* If we're already complete - protocol error */
72514f7
 					if (maj_status == GSS_S_COMPLETE)
72514f7
 						packet_disconnect("Protocol error: received token when complete");
72514f7
@@ -344,4 +345,381 @@ kexgss_client(struct ssh *ssh) {
72514f7
 	return kex_send_newkeys(ssh);
72514f7
 }
72514f7
 
72514f7
+int
72514f7
+kexecgss_client(struct ssh *ssh) {
72514f7
+	gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
72514f7
+	gss_buffer_desc recv_tok, gssbuf, msg_tok, *token_ptr;
72514f7
+	Gssctxt *ctxt;
72514f7
+	OM_uint32 maj_status, min_status, ret_flags;
72514f7
+	u_int klen = 0, slen = 0, packet_len;
72514f7
+	u_char *server_pub = NULL;
72514f7
+	u_int server_pub_len = 0;
72514f7
+	BIGNUM *shared_secret = NULL;
72514f7
+	u_char *kbuf;
72514f7
+	u_char *serverhostkey = NULL;
72514f7
+	u_char *empty = "";
72514f7
+	char *msg;
72514f7
+	char *lang;
72514f7
+	int type = 0;
72514f7
+	int first = 1;
72514f7
+	u_char hash[SSH_DIGEST_MAX_LENGTH];
72514f7
+	size_t hashlen;
72514f7
+	const EC_GROUP *group = NULL;
72514f7
+	const EC_POINT *public_key;
72514f7
+	struct sshbuf *Q_C = NULL;
72514f7
+	struct kex *kex = ssh->kex;
72514f7
+	EC_POINT *server_public = NULL;
72514f7
+	struct sshbuf *c25519_shared_secret = NULL;
72514f7
+	int r;
72514f7
+
72514f7
+	/* Initialise our GSSAPI world */
72514f7
+	ssh_gssapi_build_ctx(&ctxt);
72514f7
+	if (ssh_gssapi_id_kex(ctxt, kex->name, kex->kex_type)
72514f7
+	    == GSS_C_NO_OID)
72514f7
+		fatal("Couldn't identify host exchange");
72514f7
+
72514f7
+	if (ssh_gssapi_import_name(ctxt, kex->gss_host))
72514f7
+		fatal("Couldn't import hostname");
72514f7
+
72514f7
+	if (kex->gss_client &&
72514f7
+	    ssh_gssapi_client_identity(ctxt, kex->gss_client))
72514f7
+		fatal("Couldn't acquire client credentials");
72514f7
+
72514f7
+	if ((Q_C = sshbuf_new()) == NULL) {
72514f7
+		r = SSH_ERR_ALLOC_FAIL;
72514f7
+		goto out;
72514f7
+	}
72514f7
+
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if ((kex->ec_client_key = EC_KEY_new_by_curve_name(kex->ec_nid)) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		if (EC_KEY_generate_key(kex->ec_client_key) != 1) {
72514f7
+			r = SSH_ERR_LIBCRYPTO_ERROR;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		group = EC_KEY_get0_group(kex->ec_client_key);
72514f7
+		public_key = EC_KEY_get0_public_key(kex->ec_client_key);
72514f7
+#ifdef DEBUG_KEXECDH
72514f7
+	fputs("client private key:\n", stderr);
72514f7
+	sshkey_dump_ec_key(kex->ec_client_key);
72514f7
+#endif
72514f7
+
72514f7
+		sshbuf_put_ec(Q_C, public_key, group);
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		kexc25519_keygen(kex->c25519_client_key, kex->c25519_client_pubkey);
72514f7
+#ifdef DEBUG_KEXECDH
72514f7
+		dump_digest("client private key:", kex->c25519_client_key,
72514f7
+		    sizeof(kex->c25519_client_key));
72514f7
+#endif
72514f7
+
72514f7
+		sshbuf_put_string(Q_C, kex->c25519_client_pubkey,
72514f7
+		    sizeof(kex->c25519_client_pubkey));
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+
72514f7
+	token_ptr = GSS_C_NO_BUFFER;
72514f7
+
72514f7
+	do {
72514f7
+		/* Step 2 - call GSS_Init_sec_context() */
72514f7
+		debug("Calling gss_init_sec_context");
72514f7
+
72514f7
+		maj_status = ssh_gssapi_init_ctx(ctxt,
72514f7
+		    kex->gss_deleg_creds, token_ptr, &send_tok,
72514f7
+		    &ret_flags);
72514f7
+
72514f7
+		if (GSS_ERROR(maj_status)) {
72514f7
+			if (send_tok.length != 0) {
72514f7
+				packet_start(SSH2_MSG_KEXGSS_CONTINUE);
72514f7
+				packet_put_string(send_tok.value,
72514f7
+				    send_tok.length);
72514f7
+			}
72514f7
+			fatal("gss_init_context failed");
72514f7
+		}
72514f7
+
72514f7
+		/* If we've got an old receive buffer get rid of it */
72514f7
+		if (token_ptr != GSS_C_NO_BUFFER)
72514f7
+			free(recv_tok.value);
72514f7
+
72514f7
+		if (maj_status == GSS_S_COMPLETE) {
72514f7
+			/* If mutual state flag is not true, kex fails */
72514f7
+			if (!(ret_flags & GSS_C_MUTUAL_FLAG))
72514f7
+				fatal("Mutual authentication failed");
72514f7
+
72514f7
+			/* If integ avail flag is not true kex fails */
72514f7
+			if (!(ret_flags & GSS_C_INTEG_FLAG))
72514f7
+				fatal("Integrity check failed");
72514f7
+		}
72514f7
+
72514f7
+		/*
72514f7
+		 * If we have data to send, then the last message that we
72514f7
+		 * received cannot have been a 'complete'.
72514f7
+		 */
72514f7
+		if (send_tok.length != 0) {
72514f7
+			if (first) {
72514f7
+				const u_char * ptr;
72514f7
+				size_t len;
72514f7
+
72514f7
+				packet_start(SSH2_MSG_KEXGSS_INIT);
72514f7
+				packet_put_string(send_tok.value,
72514f7
+				    send_tok.length);
72514f7
+				sshbuf_get_string_direct(Q_C, &ptr, &len;;
72514f7
+				packet_put_string(ptr, len);
72514f7
+				first = 0;
72514f7
+			} else {
72514f7
+				packet_start(SSH2_MSG_KEXGSS_CONTINUE);
72514f7
+				packet_put_string(send_tok.value,
72514f7
+				    send_tok.length);
72514f7
+			}
72514f7
+			packet_send();
72514f7
+			gss_release_buffer(&min_status, &send_tok);
72514f7
+
72514f7
+			/* If we've sent them data, they should reply */
72514f7
+			do {
72514f7
+				type = packet_read();
72514f7
+				if (type == SSH2_MSG_KEXGSS_HOSTKEY) {
72514f7
+					debug("Received KEXGSS_HOSTKEY");
72514f7
+					if (serverhostkey)
72514f7
+						fatal("Server host key received more than once");
72514f7
+					serverhostkey =
72514f7
+					    packet_get_string(&slen);
72514f7
+				}
72514f7
+			} while (type == SSH2_MSG_KEXGSS_HOSTKEY);
72514f7
+
72514f7
+			switch (type) {
72514f7
+			case SSH2_MSG_KEXGSS_CONTINUE:
72514f7
+				debug("Received GSSAPI_CONTINUE");
72514f7
+				if (maj_status == GSS_S_COMPLETE)
72514f7
+					fatal("GSSAPI Continue received from server when complete");
72514f7
+				recv_tok.value = packet_get_string(&packet_len);
72514f7
+				recv_tok.length = packet_len;
72514f7
+				break;
72514f7
+			case SSH2_MSG_KEXGSS_COMPLETE:
72514f7
+				debug("Received GSSAPI_COMPLETE");
72514f7
+				server_pub = packet_get_string(&server_pub_len);
72514f7
+				msg_tok.value = packet_get_string(&packet_len);
72514f7
+				msg_tok.length = packet_len;
72514f7
+
72514f7
+				/* Is there a token included? */
72514f7
+				if (packet_get_char()) {
72514f7
+					recv_tok.value=
72514f7
+					    packet_get_string(&packet_len);
72514f7
+					recv_tok.length = packet_len;
72514f7
+					/* If we're already complete - protocol error */
72514f7
+					if (maj_status == GSS_S_COMPLETE)
72514f7
+						packet_disconnect("Protocol error: received token when complete");
72514f7
+					} else {
72514f7
+						/* No token included */
72514f7
+						if (maj_status != GSS_S_COMPLETE)
72514f7
+							packet_disconnect("Protocol error: did not receive final token");
72514f7
+				}
72514f7
+				break;
72514f7
+			case SSH2_MSG_KEXGSS_ERROR:
72514f7
+				debug("Received Error");
72514f7
+				maj_status = packet_get_int();
72514f7
+				min_status = packet_get_int();
72514f7
+				msg = packet_get_string(NULL);
72514f7
+				lang = packet_get_string(NULL);
72514f7
+				fatal("GSSAPI Error: \n%.400s",msg);
72514f7
+			default:
72514f7
+				packet_disconnect("Protocol error: didn't expect packet type %d",
72514f7
+				    type);
72514f7
+			}
72514f7
+			token_ptr = &recv_tok;
72514f7
+		} else {
72514f7
+			/* No data, and not complete */
72514f7
+			if (maj_status != GSS_S_COMPLETE)
72514f7
+				fatal("Not complete, and no token output");
72514f7
+		}
72514f7
+	} while (maj_status & GSS_S_CONTINUE_NEEDED);
72514f7
+
72514f7
+	/*
72514f7
+	 * We _must_ have received a COMPLETE message in reply from the
72514f7
+	 * server, which will have set dh_server_pub and msg_tok
72514f7
+	 */
72514f7
+
72514f7
+	if (type != SSH2_MSG_KEXGSS_COMPLETE)
72514f7
+		fatal("Didn't receive a SSH2_MSG_KEXGSS_COMPLETE when I expected it");
72514f7
+
72514f7
+	/* 7. C verifies that the key Q_S is valid */
72514f7
+	/* 8. C computes shared secret */
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if (server_pub_len != 65)
72514f7
+			fatal("The received NIST-P256 key did not match"
72514f7
+			    "expected length (expected 65, got %d)", server_pub_len);
72514f7
+
72514f7
+		if (server_pub[0] != POINT_CONVERSION_UNCOMPRESSED)
72514f7
+			fatal("The received NIST-P256 key does not have first octet 0x04");
72514f7
+
72514f7
+		if ((server_public = EC_POINT_new(group)) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+
72514f7
+		if (!EC_POINT_oct2point(group, server_public, server_pub,
72514f7
+		    server_pub_len, NULL))
72514f7
+			fatal("Can not decode received NIST-P256 client key");
72514f7
+#ifdef DEBUG_KEXECDH
72514f7
+		fputs("server public key:\n", stderr);
72514f7
+		sshkey_dump_ec_point(group, server_public);
72514f7
+#endif
72514f7
+
72514f7
+		if (sshkey_ec_validate_public(group, server_public) != 0) {
72514f7
+			sshpkt_disconnect(ssh, "invalid client public key");
72514f7
+			r = SSH_ERR_MESSAGE_INCOMPLETE;
72514f7
+			goto out;
72514f7
+		}
72514f7
+
72514f7
+		if (!EC_POINT_is_on_curve(group, server_public, NULL))
72514f7
+			fatal("Received NIST-P256 client key is not on curve");
72514f7
+
72514f7
+		/* Calculate shared_secret */
72514f7
+		klen = (EC_GROUP_get_degree(group) + 7) / 8;
72514f7
+		if ((kbuf = malloc(klen)) == NULL ||
72514f7
+		    (shared_secret = BN_new()) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		if (ECDH_compute_key(kbuf, klen, server_public,
72514f7
+		    kex->ec_client_key, NULL) != (int)klen ||
72514f7
+		    BN_bin2bn(kbuf, klen, shared_secret) == NULL) {
72514f7
+			r = SSH_ERR_LIBCRYPTO_ERROR;
72514f7
+			goto out;
72514f7
+		}
72514f7
+#ifdef DEBUG_KEXECDH
72514f7
+		dump_digest("shared secret", kbuf, klen);
72514f7
+#endif
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		if (server_pub_len != 32)
72514f7
+			fatal("The received curve25519 key did not match"
72514f7
+			    "expected length (expected 32, got %d)", server_pub_len);
72514f7
+
72514f7
+		if (server_pub[server_pub_len-1] & 0x80)
72514f7
+			fatal("The received key has MSB of last octet set!");
72514f7
+#ifdef DEBUG_KEXECDH
72514f7
+		dump_digest("server public key:", server_pub, CURVE25519_SIZE);
72514f7
+#endif
72514f7
+
72514f7
+		/* generate shared secret */
72514f7
+		if ((c25519_shared_secret = sshbuf_new()) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		if ((r = kexc25519_shared_key(kex->c25519_client_key,
72514f7
+		    server_pub, c25519_shared_secret)) < 0)
72514f7
+			goto out;
72514f7
+
72514f7
+		/* if all octets of the shared secret are zero octets,
72514f7
+		 * is already checked in kexc25519_shared_key() */
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+
72514f7
+	hashlen = sizeof(hash);
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		kex_ecdh_hash(
72514f7
+		    kex->hash_alg,
72514f7
+		    group,
72514f7
+		    kex->client_version_string,
72514f7
+		    kex->server_version_string,
72514f7
+		    sshbuf_ptr(kex->my), sshbuf_len(kex->my),
72514f7
+		    sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
72514f7
+		    (serverhostkey ? serverhostkey : empty), slen,
72514f7
+		    EC_KEY_get0_public_key(kex->ec_client_key),
72514f7
+		    server_public,
72514f7
+		    shared_secret,
72514f7
+		    hash, &hashlen
72514f7
+		);
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		kex_c25519_hash(
72514f7
+		    kex->hash_alg,
72514f7
+		    kex->client_version_string, kex->server_version_string,
72514f7
+		    buffer_ptr(kex->my), buffer_len(kex->my),
72514f7
+		    buffer_ptr(kex->peer), buffer_len(kex->peer),
72514f7
+		    (serverhostkey ? serverhostkey : empty), slen,
72514f7
+		    kex->c25519_client_pubkey, server_pub,
72514f7
+		    sshbuf_ptr(c25519_shared_secret), sshbuf_len(c25519_shared_secret),
72514f7
+		    hash, &hashlen
72514f7
+		);
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+
72514f7
+	gssbuf.value = hash;
72514f7
+	gssbuf.length = hashlen;
72514f7
+
72514f7
+	/* Verify that the hash matches the MIC we just got. */
72514f7
+	if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
72514f7
+		packet_disconnect("Hash's MIC didn't verify");
72514f7
+
72514f7
+	free(msg_tok.value);
72514f7
+
72514f7
+	/* save session id */
72514f7
+	if (kex->session_id == NULL) {
72514f7
+		kex->session_id_len = hashlen;
72514f7
+		kex->session_id = xmalloc(kex->session_id_len);
72514f7
+		memcpy(kex->session_id, hash, kex->session_id_len);
72514f7
+	}
72514f7
+
72514f7
+	if (kex->gss_deleg_creds)
72514f7
+		ssh_gssapi_credentials_updated(ctxt);
72514f7
+
72514f7
+	if (gss_kex_context == NULL)
72514f7
+		gss_kex_context = ctxt;
72514f7
+	else
72514f7
+		ssh_gssapi_delete_ctx(&ctxt);
72514f7
+
72514f7
+	/* Finally derive the keys and send them */
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) != 0)
72514f7
+			goto out;
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		if ((r = kex_derive_keys(ssh, hash, hashlen, c25519_shared_secret)) != 0)
72514f7
+			goto out;
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+	r = kex_send_newkeys(ssh);
72514f7
+out:
72514f7
+	free(serverhostkey);
72514f7
+	explicit_bzero(hash, sizeof(hash));
72514f7
+	sshbuf_free(Q_C);
72514f7
+	if (server_pub)
72514f7
+		free(server_pub);
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if (kex->ec_client_key) {
72514f7
+			EC_KEY_free(kex->ec_client_key);
72514f7
+			kex->ec_client_key = NULL;
72514f7
+		}
72514f7
+		if (server_public)
72514f7
+			EC_POINT_clear_free(server_public);
72514f7
+		if (kbuf) {
72514f7
+			explicit_bzero(kbuf, klen);
72514f7
+			free(kbuf);
72514f7
+		}
72514f7
+		if (shared_secret)
72514f7
+			BN_clear_free(shared_secret);
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		explicit_bzero(kex->c25519_client_key, sizeof(kex->c25519_client_key));
72514f7
+		sshbuf_free(c25519_shared_secret);
72514f7
+		break;
72514f7
+	}
72514f7
+	return r;
72514f7
+}
72514f7
 #endif /* GSSAPI */
72514f7
diff --git a/kexgsss.c b/kexgsss.c
72514f7
index b7da8823..a7c42803 100644
72514f7
--- a/kexgsss.c
72514f7
+++ b/kexgsss.c
72514f7
@@ -46,6 +46,7 @@
72514f7
 #include "servconf.h"
72514f7
 #include "ssh-gss.h"
72514f7
 #include "digest.h"
72514f7
+#include "ssherr.h"
72514f7
 
72514f7
 extern ServerOptions options;
72514f7
 
72514f7
@@ -303,4 +304,336 @@ kexgss_server(struct ssh *ssh)
72514f7
 		ssh_gssapi_rekey_creds();
72514f7
 	return 0;
72514f7
 }
72514f7
+
72514f7
+int
72514f7
+kexecgss_server(struct ssh *ssh)
72514f7
+{
72514f7
+	OM_uint32 maj_status, min_status;
72514f7
+
72514f7
+	/*
72514f7
+	 * Some GSSAPI implementations use the input value of ret_flags (an
72514f7
+	 * output variable) as a means of triggering mechanism specific
72514f7
+	 * features. Initializing it to zero avoids inadvertently
72514f7
+	 * activating this non-standard behaviour.
72514f7
+	 */
72514f7
+
72514f7
+	OM_uint32 ret_flags = 0;
72514f7
+	gss_buffer_desc gssbuf, recv_tok, msg_tok;
72514f7
+	gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
72514f7
+	Gssctxt *ctxt = NULL;
72514f7
+	u_int slen, klen = 0;
72514f7
+	u_char *kbuf;
72514f7
+	BIGNUM *shared_secret = NULL;
72514f7
+	int type = 0;
72514f7
+	gss_OID oid;
72514f7
+	char *mechs;
72514f7
+	u_char hash[SSH_DIGEST_MAX_LENGTH];
72514f7
+	size_t hashlen;
72514f7
+	u_char *client_pub = NULL;
72514f7
+	u_int client_pub_len = 0;
72514f7
+	const EC_GROUP *group = NULL;
72514f7
+	EC_POINT *client_public = NULL;
72514f7
+	EC_KEY *server_key = NULL;
72514f7
+	const EC_POINT *public_key;
72514f7
+	u_char c25519_server_key[CURVE25519_SIZE];
72514f7
+	u_char c25519_server_pubkey[CURVE25519_SIZE];
72514f7
+	struct sshbuf *c25519_shared_secret = NULL;
72514f7
+	struct sshbuf *Q_S;
72514f7
+	struct kex *kex = ssh->kex;
72514f7
+	int r;
72514f7
+
72514f7
+	/* Initialise GSSAPI */
72514f7
+
72514f7
+	/* If we're rekeying, privsep means that some of the private structures
72514f7
+	 * in the GSSAPI code are no longer available. This kludges them back
72514f7
+	 * into life
72514f7
+	 */
72514f7
+	if (!ssh_gssapi_oid_table_ok())
72514f7
+		if ((mechs = ssh_gssapi_server_mechanisms()))
72514f7
+			free(mechs);
72514f7
+
72514f7
+	debug2("%s: Identifying %s", __func__, kex->name);
72514f7
+	oid = ssh_gssapi_id_kex(NULL, kex->name, kex->kex_type);
72514f7
+	if (oid == GSS_C_NO_OID)
72514f7
+	   fatal("Unknown gssapi mechanism");
72514f7
+
72514f7
+	debug2("%s: Acquiring credentials", __func__);
72514f7
+
72514f7
+	if (GSS_ERROR(PRIVSEP(ssh_gssapi_server_ctx(&ctxt, oid))))
72514f7
+		fatal("Unable to acquire credentials for the server");
72514f7
+
72514f7
+	if ((Q_S = sshbuf_new()) == NULL) {
72514f7
+		r = SSH_ERR_ALLOC_FAIL;
72514f7
+		goto out;
72514f7
+	}
72514f7
+
72514f7
+	/* 5. S generates an ephemeral key pair (do the allocations early) */
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if ((server_key = EC_KEY_new_by_curve_name(kex->ec_nid)) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		if (EC_KEY_generate_key(server_key) != 1) {
72514f7
+			r = SSH_ERR_LIBCRYPTO_ERROR;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		group = EC_KEY_get0_group(server_key);
72514f7
+		public_key = EC_KEY_get0_public_key(server_key);
72514f7
+
72514f7
+		sshbuf_put_ec(Q_S, public_key, group);
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		kexc25519_keygen(c25519_server_key, c25519_server_pubkey);
72514f7
+#ifdef DEBUG_KEXECDH
72514f7
+		dump_digest("server private key:", c25519_server_key,
72514f7
+		    sizeof(c25519_server_key));
72514f7
+#endif
72514f7
+		sshbuf_put_string(Q_S, c25519_server_pubkey,
72514f7
+		    sizeof(c25519_server_pubkey));
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+
72514f7
+	do {
72514f7
+		debug("Wait SSH2_MSG_GSSAPI_INIT");
72514f7
+		type = packet_read();
72514f7
+		switch(type) {
72514f7
+		case SSH2_MSG_KEXGSS_INIT:
72514f7
+			if (client_pub != NULL)
72514f7
+				fatal("Received KEXGSS_INIT after initialising");
72514f7
+			recv_tok.value = packet_get_string(&slen);
72514f7
+			recv_tok.length = slen;
72514f7
+
72514f7
+			client_pub = packet_get_string(&client_pub_len);
72514f7
+
72514f7
+			/* Send SSH_MSG_KEXGSS_HOSTKEY here, if we want */
72514f7
+			break;
72514f7
+		case SSH2_MSG_KEXGSS_CONTINUE:
72514f7
+			recv_tok.value = packet_get_string(&slen);
72514f7
+			recv_tok.length = slen;
72514f7
+			break;
72514f7
+		default:
72514f7
+			packet_disconnect(
72514f7
+			    "Protocol error: didn't expect packet type %d",
72514f7
+			    type);
72514f7
+		}
72514f7
+
72514f7
+		maj_status = PRIVSEP(ssh_gssapi_accept_ctx(ctxt, &recv_tok,
72514f7
+		    &send_tok, &ret_flags));
72514f7
+
72514f7
+		free(recv_tok.value);
72514f7
+
72514f7
+		if (maj_status != GSS_S_COMPLETE && send_tok.length == 0)
72514f7
+			fatal("Zero length token output when incomplete");
72514f7
+
72514f7
+		if (client_pub == NULL)
72514f7
+			fatal("No client public key");
72514f7
+
72514f7
+		if (maj_status & GSS_S_CONTINUE_NEEDED) {
72514f7
+			debug("Sending GSSAPI_CONTINUE");
72514f7
+			packet_start(SSH2_MSG_KEXGSS_CONTINUE);
72514f7
+			packet_put_string(send_tok.value, send_tok.length);
72514f7
+			packet_send();
72514f7
+			gss_release_buffer(&min_status, &send_tok);
72514f7
+		}
72514f7
+	} while (maj_status & GSS_S_CONTINUE_NEEDED);
72514f7
+
72514f7
+	if (GSS_ERROR(maj_status)) {
72514f7
+		if (send_tok.length > 0) {
72514f7
+			packet_start(SSH2_MSG_KEXGSS_CONTINUE);
72514f7
+			packet_put_string(send_tok.value, send_tok.length);
72514f7
+			packet_send();
72514f7
+		}
72514f7
+		fatal("accept_ctx died");
72514f7
+	}
72514f7
+
72514f7
+	if (!(ret_flags & GSS_C_MUTUAL_FLAG))
72514f7
+		fatal("Mutual Authentication flag wasn't set");
72514f7
+
72514f7
+	if (!(ret_flags & GSS_C_INTEG_FLAG))
72514f7
+		fatal("Integrity flag wasn't set");
72514f7
+
72514f7
+	/* 3. S verifies that the (client) key is valid */
72514f7
+	/* calculate shared secret */
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if (client_pub_len != 65)
72514f7
+			fatal("The received NIST-P256 key did not match"
72514f7
+			    "expected length (expected 65, got %d)", client_pub_len);
72514f7
+
72514f7
+		if (client_pub[0] != POINT_CONVERSION_UNCOMPRESSED)
72514f7
+			fatal("The received NIST-P256 key does not have first octet 0x04");
72514f7
+
72514f7
+		if ((client_public = EC_POINT_new(group)) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+
72514f7
+		if (!EC_POINT_oct2point(group, client_public, client_pub,
72514f7
+		    client_pub_len, NULL))
72514f7
+			fatal("Can not decode received NIST-P256 client key");
72514f7
+
72514f7
+		if (sshkey_ec_validate_public(group, client_public) != 0) {
72514f7
+			sshpkt_disconnect(ssh, "invalid client public key");
72514f7
+			r = SSH_ERR_MESSAGE_INCOMPLETE;
72514f7
+			goto out;
72514f7
+		}
72514f7
+
72514f7
+		if (!EC_POINT_is_on_curve(group, client_public, NULL))
72514f7
+			fatal("Received NIST-P256 client key is not on curve");
72514f7
+
72514f7
+		/* Calculate shared_secret */
72514f7
+		klen = (EC_GROUP_get_degree(group) + 7) / 8;
72514f7
+		if ((kbuf = malloc(klen)) == NULL ||
72514f7
+		    (shared_secret = BN_new()) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		if (ECDH_compute_key(kbuf, klen, client_public,
72514f7
+		    server_key, NULL) != (int)klen ||
72514f7
+		    BN_bin2bn(kbuf, klen, shared_secret) == NULL) {
72514f7
+			r = SSH_ERR_LIBCRYPTO_ERROR;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		if (client_pub_len != 32)
72514f7
+			fatal("The received curve25519 key did not match"
72514f7
+			    "expected length (expected 32, got %d)", client_pub_len);
72514f7
+
72514f7
+		if (client_pub[client_pub_len-1] & 0x80)
72514f7
+			fatal("The received key has MSB of last octet set!");
72514f7
+
72514f7
+		/* generate shared secret */
72514f7
+		if ((c25519_shared_secret = sshbuf_new()) == NULL) {
72514f7
+			r = SSH_ERR_ALLOC_FAIL;
72514f7
+			goto out;
72514f7
+		}
72514f7
+		if ((r = kexc25519_shared_key(c25519_server_key,
72514f7
+		    client_pub, c25519_shared_secret)) < 0)
72514f7
+			goto out;
72514f7
+
72514f7
+		/* if all octets of the shared secret are zero octets,
72514f7
+		 * is already checked in kexc25519_shared_key() */
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+
72514f7
+	hashlen = sizeof(hash);
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		kex_ecdh_hash(
72514f7
+		    kex->hash_alg,
72514f7
+		    group,
72514f7
+		    kex->client_version_string,
72514f7
+		    kex->server_version_string,
72514f7
+		    sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
72514f7
+		    sshbuf_ptr(kex->my), sshbuf_len(kex->my),
72514f7
+		    NULL, 0,
72514f7
+		    client_public,
72514f7
+		    EC_KEY_get0_public_key(server_key),
72514f7
+		    shared_secret,
72514f7
+		    hash, &hashlen
72514f7
+		);
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		kex_c25519_hash(
72514f7
+		    kex->hash_alg,
72514f7
+		    kex->client_version_string, kex->server_version_string,
72514f7
+		    buffer_ptr(kex->peer), buffer_len(kex->peer),
72514f7
+		    buffer_ptr(kex->my), buffer_len(kex->my),
72514f7
+		    NULL, 0,
72514f7
+		    client_pub, c25519_server_pubkey,
72514f7
+		    sshbuf_ptr(c25519_shared_secret), sshbuf_len(c25519_shared_secret),
72514f7
+		    hash, &hashlen
72514f7
+		);
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+
72514f7
+	if (kex->session_id == NULL) {
72514f7
+		kex->session_id_len = hashlen;
72514f7
+		kex->session_id = xmalloc(kex->session_id_len);
72514f7
+		memcpy(kex->session_id, hash, kex->session_id_len);
72514f7
+	}
72514f7
+
72514f7
+	gssbuf.value = hash;
72514f7
+	gssbuf.length = hashlen;
72514f7
+
72514f7
+	if (GSS_ERROR(PRIVSEP(ssh_gssapi_sign(ctxt,&gssbuf,&msg_tok))))
72514f7
+		fatal("Couldn't get MIC");
72514f7
+
72514f7
+	packet_start(SSH2_MSG_KEXGSS_COMPLETE);
72514f7
+	{
72514f7
+		const u_char *ptr;
72514f7
+		size_t len;
72514f7
+		sshbuf_get_string_direct(Q_S, &ptr, &len;;
72514f7
+		packet_put_string(ptr, len);
72514f7
+	}
72514f7
+	packet_put_string(msg_tok.value, msg_tok.length);
72514f7
+
72514f7
+	if (send_tok.length != 0) {
72514f7
+		packet_put_char(1); /* true */
72514f7
+		packet_put_string(send_tok.value, send_tok.length);
72514f7
+	} else {
72514f7
+		packet_put_char(0); /* false */
72514f7
+	}
72514f7
+	packet_send();
72514f7
+
72514f7
+	gss_release_buffer(&min_status, &send_tok);
72514f7
+	gss_release_buffer(&min_status, &msg_tok);
72514f7
+
72514f7
+	if (gss_kex_context == NULL)
72514f7
+		gss_kex_context = ctxt;
72514f7
+	else
72514f7
+		ssh_gssapi_delete_ctx(&ctxt);
72514f7
+
72514f7
+	/* Finally derive the keys and send them */
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if ((r = kex_derive_keys_bn(ssh, hash, hashlen, shared_secret)) != 0)
72514f7
+			goto out;
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		if ((r = kex_derive_keys(ssh, hash, hashlen, c25519_shared_secret)) != 0)
72514f7
+			goto out;
72514f7
+		break;
72514f7
+	default:
72514f7
+		fatal("%s: Unexpected KEX type %d", __func__, kex->kex_type);
72514f7
+	}
72514f7
+	if ((r = kex_send_newkeys(ssh)) != 0)
72514f7
+		goto out;
72514f7
+
72514f7
+	/* If this was a rekey, then save out any delegated credentials we
72514f7
+	 * just exchanged.  */
72514f7
+	if (options.gss_store_rekey)
72514f7
+		ssh_gssapi_rekey_creds();
72514f7
+out:
72514f7
+	explicit_bzero(hash, sizeof(hash));
72514f7
+	if (Q_S)
72514f7
+		sshbuf_free(Q_S);
72514f7
+	if (client_pub)
72514f7
+		free(client_pub);
72514f7
+	switch (kex->kex_type) {
72514f7
+	case KEX_GSS_NISTP256_SHA256:
72514f7
+		if (server_key)
72514f7
+			EC_KEY_free(server_key);
72514f7
+		if (kbuf) {
72514f7
+			explicit_bzero(kbuf, klen);
72514f7
+			free(kbuf);
72514f7
+		}
72514f7
+		if (shared_secret)
72514f7
+			BN_clear_free(shared_secret);
72514f7
+		break;
72514f7
+	case KEX_GSS_C25519_SHA256:
72514f7
+		explicit_bzero(c25519_server_key, sizeof(c25519_server_key));
72514f7
+		sshbuf_free(c25519_shared_secret);
72514f7
+		break;
72514f7
+	}
72514f7
+	return r;
72514f7
+}
72514f7
 #endif /* GSSAPI */
72514f7
diff --git a/monitor.c b/monitor.c
72514f7
index d6bc7ac7..b11616c8 100644
72514f7
--- a/monitor.c
72514f7
+++ b/monitor.c
72514f7
@@ -1651,6 +1651,8 @@ monitor_apply_keystate(struct monitor *pmonitor)
72514f7
 		kex->kex[KEX_GSS_GRP14_SHA256] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GRP16_SHA512] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
72514f7
+		kex->kex[KEX_GSS_NISTP256_SHA256] = kexecgss_server;
72514f7
+		kex->kex[KEX_GSS_C25519_SHA256] = kexecgss_server;
72514f7
 	}
72514f7
 #endif
72514f7
 		kex->load_host_public_key=&get_hostkey_public_by_type;
72514f7
@@ -1867,7 +1869,8 @@ mm_answer_gss_sign(int socket, Buffer *m)
72514f7
 
72514f7
 	data.value = buffer_get_string(m, &len;;
72514f7
 	data.length = len;
72514f7
-	if (data.length != 20) 
72514f7
+	/* Lengths of SHA-1, SHA-256 and SHA-512 hashes that are used */
72514f7
+	if (data.length != 20 && data.length != 32 && data.length != 64)
72514f7
 		fatal("%s: data length incorrect: %d", __func__, 
72514f7
 		    (int) data.length);
72514f7
 
72514f7
diff --git a/regress/kextype.sh b/regress/kextype.sh
72514f7
index 45f4f16d..d5b4a713 100644
72514f7
--- a/regress/kextype.sh
72514f7
+++ b/regress/kextype.sh
72514f7
@@ -15,6 +15,7 @@ echo "KexAlgorithms=$KEXOPT" >> $OBJ/sshd_proxy
72514f7
 tries="1 2 3 4"
72514f7
 for k in `${SSH} -Q kex`; do
72514f7
 	if [ $k = "gss-gex-sha1-" -o $k = "gss-group1-sha1-" -o \
72514f7
+	    $k = "gss-nistp256-sha256-" -o $k = "gss-curve25519-sha256-" -o \
72514f7
 	    $k = "gss-group14-sha1-" -o $k = "gss-group14-sha256-" -o \
72514f7
 	    $k = "gss-group16-sha512-" ]; then
72514f7
 		continue
72514f7
diff --git a/regress/rekey.sh b/regress/rekey.sh
72514f7
index a2921bef..b118c6c8 100644
72514f7
--- a/regress/rekey.sh
72514f7
+++ b/regress/rekey.sh
72514f7
@@ -39,6 +39,7 @@ increase_datafile_size 300
72514f7
 opts=""
72514f7
 for i in `${SSH} -Q kex`; do
72514f7
 	if [ $i = "gss-gex-sha1-" -o $i = "gss-group1-sha1-" -o \
72514f7
+	    $i = "gss-nistp256-sha256-" -o $i = "gss-curve25519-sha256-" -o \
72514f7
 	    $i = "gss-group14-sha1-" -o $i = "gss-group14-sha256-" -o \
72514f7
 	    $i = "gss-group16-sha512-" ]; then
72514f7
 		continue
72514f7
@@ -62,6 +63,7 @@ if ${SSH} -Q cipher-auth | grep '^.*$' >/dev/null 2>&1 ; then
72514f7
   for c in `${SSH} -Q cipher-auth`; do
72514f7
     for kex in `${SSH} -Q kex`; do
72514f7
 	if [ $kex = "gss-gex-sha1-" -o $kex = "gss-group1-sha1-" -o \
72514f7
+	    $kex = "gss-nistp256-sha256-" -o $kex = "gss-curve25519-sha256-" -o \
72514f7
 	    $kex = "gss-group14-sha1-" -o $kex = "gss-group14-sha256-" -o \
72514f7
 	    $kex = "gss-group16-sha512-" ]; then
72514f7
 		continue
72514f7
diff --git a/ssh-gss.h b/ssh-gss.h
72514f7
index 7bf8d75e..1f73721d 100644
72514f7
--- a/ssh-gss.h
72514f7
+++ b/ssh-gss.h
72514f7
@@ -73,6 +73,8 @@
72514f7
 #define KEX_GSS_GRP14_SHA256_ID			"gss-group14-sha256-"
72514f7
 #define KEX_GSS_GRP16_SHA512_ID			"gss-group16-sha512-"
72514f7
 #define KEX_GSS_GEX_SHA1_ID				"gss-gex-sha1-"
72514f7
+#define KEX_GSS_NISTP256_SHA256_ID			"gss-nistp256-sha256-"
72514f7
+#define KEX_GSS_C25519_SHA256_ID			"gss-curve25519-sha256-"
72514f7
 
72514f7
 #define        GSS_KEX_DEFAULT_KEX \
72514f7
 	KEX_GSS_GEX_SHA1_ID "," \
72514f7
diff --git a/ssh_config.5 b/ssh_config.5
72514f7
index 3d6da510..1dc29bf1 100644
72514f7
--- a/ssh_config.5
72514f7
+++ b/ssh_config.5
72514f7
@@ -762,7 +762,9 @@ gss-gex-sha1-,
72514f7
 gss-group1-sha1-,
72514f7
 gss-group14-sha1-,
72514f7
 gss-group14-sha256-,
72514f7
-gss-group16-sha512-
72514f7
+gss-group16-sha512-,
72514f7
+gss-nistp256-sha256-,
72514f7
+gss-curve25519-sha256-
72514f7
 .Ed
72514f7
 .Pp
72514f7
 The default is
72514f7
diff --git a/sshconnect2.c b/sshconnect2.c
72514f7
index 5d6b8be0..280ae5a6 100644
72514f7
--- a/sshconnect2.c
72514f7
+++ b/sshconnect2.c
72514f7
@@ -256,6 +256,8 @@ ssh_kex2(char *host, struct sockaddr *hostaddr, u_short port)
72514f7
 		kex->kex[KEX_GSS_GRP14_SHA256] = kexgss_client;
72514f7
 		kex->kex[KEX_GSS_GRP16_SHA512] = kexgss_client;
72514f7
 		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_client;
72514f7
+		kex->kex[KEX_GSS_NISTP256_SHA256] = kexecgss_client;
72514f7
+		kex->kex[KEX_GSS_C25519_SHA256] = kexecgss_client;
72514f7
 	}
72514f7
 #endif
72514f7
 	kex->kex[KEX_C25519_SHA256] = kexc25519_client;
72514f7
diff --git a/sshd.c b/sshd.c
72514f7
index e4c879a2..a35735d8 100644
72514f7
--- a/sshd.c
72514f7
+++ b/sshd.c
72514f7
@@ -2247,6 +2247,8 @@ do_ssh2_kex(void)
72514f7
 		kex->kex[KEX_GSS_GRP14_SHA256] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GRP16_SHA512] = kexgss_server;
72514f7
 		kex->kex[KEX_GSS_GEX_SHA1] = kexgss_server;
72514f7
+		kex->kex[KEX_GSS_NISTP256_SHA256] = kexecgss_server;
72514f7
+		kex->kex[KEX_GSS_C25519_SHA256] = kexecgss_server;
72514f7
 	}
72514f7
 #endif
72514f7
 	kex->server = 1;
72514f7
diff --git a/sshd_config.5 b/sshd_config.5
72514f7
index 0793418b..888316bf 100644
72514f7
--- a/sshd_config.5
72514f7
+++ b/sshd_config.5
72514f7
@@ -677,7 +677,9 @@ gss-gex-sha1-,
72514f7
 gss-group1-sha1-,
72514f7
 gss-group14-sha1-,
72514f7
 gss-group14-sha256-,
72514f7
-gss-group16-sha512-
72514f7
+gss-group16-sha512-,
72514f7
+gss-nistp256-sha256-,
72514f7
+gss-curve25519-sha256-
72514f7
 .Ed
72514f7
 .Pp
72514f7
 The default is
72514f7
-- 
72514f7
2.13.5
72514f7
72514f7
72514f7
From 0431695660d5eb1dd1169d42a1624c75a92aa5d2 Mon Sep 17 00:00:00 2001
72514f7
From: Jakub Jelen <jjelen@redhat.com>
72514f7
Date: Wed, 30 Aug 2017 15:30:51 +0200
72514f7
Subject: [PATCH 3/3] Simplify rough edges of GSSAPI Kex
72514f7
72514f7
---
72514f7
 gss-genr.c         | 53 +++++++++++++++++------------------------------------
72514f7
 regress/kextype.sh | 10 ++++------
72514f7
 regress/rekey.sh   | 20 ++++++++------------
72514f7
 3 files changed, 29 insertions(+), 54 deletions(-)
72514f7
72514f7
diff --git a/gss-genr.c b/gss-genr.c
72514f7
index 22040244..c671be31 100644
72514f7
--- a/gss-genr.c
72514f7
+++ b/gss-genr.c
72514f7
@@ -171,47 +171,28 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
72514f7
 gss_OID
72514f7
 ssh_gssapi_id_kex(Gssctxt *ctx, char *name, int kex_type) {
72514f7
 	int i = 0;
72514f7
-	
72514f7
-	switch (kex_type) {
72514f7
-	case KEX_GSS_GRP1_SHA1:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_GRP1_SHA1_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_GRP1_SHA1_ID) - 1;
72514f7
-		break;
72514f7
-	case KEX_GSS_GRP14_SHA1:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA1_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_GRP14_SHA1_ID) - 1;
72514f7
-		break;
72514f7
-	case KEX_GSS_GRP14_SHA256:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_GRP14_SHA256_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_GRP14_SHA256_ID) - 1;
72514f7
-		break;
72514f7
-	case KEX_GSS_GRP16_SHA512:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_GRP16_SHA512_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_GRP16_SHA512_ID) - 1;
72514f7
-		break;
72514f7
-	case KEX_GSS_GEX_SHA1:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_GEX_SHA1_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_GEX_SHA1_ID) - 1;
72514f7
-		break;
72514f7
-	case KEX_GSS_NISTP256_SHA256:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_NISTP256_SHA256_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_NISTP256_SHA256_ID) - 1;
72514f7
-		break;
72514f7
-	case KEX_GSS_C25519_SHA256:
72514f7
-		if (strlen(name) < sizeof(KEX_GSS_C25519_SHA256_ID))
72514f7
-			return GSS_C_NO_OID;
72514f7
-		name += sizeof(KEX_GSS_C25519_SHA256_ID) - 1;
72514f7
+
72514f7
+#define SKIP_KEX_NAME(type) \
72514f7
+	case type: \
72514f7
+		if (strlen(name) < sizeof(type##_ID)) \
72514f7
+			return GSS_C_NO_OID; \
72514f7
+		name += sizeof(type##_ID) - 1; \
72514f7
 		break;
72514f7
+
72514f7
+	switch (kex_type) {
72514f7
+	SKIP_KEX_NAME(KEX_GSS_GRP1_SHA1)
72514f7
+	SKIP_KEX_NAME(KEX_GSS_GRP14_SHA1)
72514f7
+	SKIP_KEX_NAME(KEX_GSS_GRP14_SHA256)
72514f7
+	SKIP_KEX_NAME(KEX_GSS_GRP16_SHA512)
72514f7
+	SKIP_KEX_NAME(KEX_GSS_GEX_SHA1)
72514f7
+	SKIP_KEX_NAME(KEX_GSS_NISTP256_SHA256)
72514f7
+	SKIP_KEX_NAME(KEX_GSS_C25519_SHA256)
72514f7
 	default:
72514f7
 		return GSS_C_NO_OID;
72514f7
 	}
72514f7
 
72514f7
+#undef SKIP_KEX_NAME
72514f7
+
72514f7
 	while (gss_enc2oid[i].encoded != NULL &&
72514f7
 	    strcmp(name, gss_enc2oid[i].encoded) != 0)
72514f7
 		i++;
72514f7
diff --git a/regress/kextype.sh b/regress/kextype.sh
72514f7
index d5b4a713..6b4af28a 100644
72514f7
--- a/regress/kextype.sh
72514f7
+++ b/regress/kextype.sh
72514f7
@@ -14,12 +14,10 @@ echo "KexAlgorithms=$KEXOPT" >> $OBJ/sshd_proxy
72514f7
 
72514f7
 tries="1 2 3 4"
72514f7
 for k in `${SSH} -Q kex`; do
72514f7
-	if [ $k = "gss-gex-sha1-" -o $k = "gss-group1-sha1-" -o \
72514f7
-	    $k = "gss-nistp256-sha256-" -o $k = "gss-curve25519-sha256-" -o \
72514f7
-	    $k = "gss-group14-sha1-" -o $k = "gss-group14-sha256-" -o \
72514f7
-	    $k = "gss-group16-sha512-" ]; then
72514f7
-		continue
72514f7
-	fi
72514f7
+	# ignore GSSAPI key exchange mechanisms (all of them start with gss-)
72514f7
+	case $k in
72514f7
+		gss-* ) continue ;;
72514f7
+	esac
72514f7
 	verbose "kex $k"
72514f7
 	for i in $tries; do
72514f7
 		${SSH} -F $OBJ/ssh_proxy -o KexAlgorithms=$k x true
72514f7
diff --git a/regress/rekey.sh b/regress/rekey.sh
72514f7
index b118c6c8..d6a8742f 100644
72514f7
--- a/regress/rekey.sh
72514f7
+++ b/regress/rekey.sh
72514f7
@@ -38,12 +38,10 @@ increase_datafile_size 300
72514f7
 
72514f7
 opts=""
72514f7
 for i in `${SSH} -Q kex`; do
72514f7
-	if [ $i = "gss-gex-sha1-" -o $i = "gss-group1-sha1-" -o \
72514f7
-	    $i = "gss-nistp256-sha256-" -o $i = "gss-curve25519-sha256-" -o \
72514f7
-	    $i = "gss-group14-sha1-" -o $i = "gss-group14-sha256-" -o \
72514f7
-	    $i = "gss-group16-sha512-" ]; then
72514f7
-		continue
72514f7
-	fi
72514f7
+	# ignore GSSAPI key exchange mechanisms (all of them start with gss-)
72514f7
+	case $i in
72514f7
+		gss-* ) continue ;;
72514f7
+	esac
72514f7
 	opts="$opts KexAlgorithms=$i"
72514f7
 done
72514f7
 for i in `${SSH} -Q cipher`; do
72514f7
@@ -62,12 +60,10 @@ done
72514f7
 if ${SSH} -Q cipher-auth | grep '^.*$' >/dev/null 2>&1 ; then
72514f7
   for c in `${SSH} -Q cipher-auth`; do
72514f7
     for kex in `${SSH} -Q kex`; do
72514f7
-	if [ $kex = "gss-gex-sha1-" -o $kex = "gss-group1-sha1-" -o \
72514f7
-	    $kex = "gss-nistp256-sha256-" -o $kex = "gss-curve25519-sha256-" -o \
72514f7
-	    $kex = "gss-group14-sha1-" -o $kex = "gss-group14-sha256-" -o \
72514f7
-	    $kex = "gss-group16-sha512-" ]; then
72514f7
-		continue
72514f7
-	fi
72514f7
+	# ignore GSSAPI key exchange mechanisms (all of them start with gss-)
72514f7
+	case $kex in
72514f7
+		gss-* ) continue ;;
72514f7
+	esac
72514f7
 	verbose "client rekey $c $kex"
72514f7
 	ssh_data_rekeying "KexAlgorithms=$kex" -oRekeyLimit=256k -oCiphers=$c
72514f7
     done
72514f7
-- 
72514f7
2.13.5
72514f7