vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Jakub Jelen 6666c1
From bc74944ce7a2eabd228d47051f277ce108914c96 Mon Sep 17 00:00:00 2001
Jakub Jelen 6666c1
From: Jakub Jelen <jjelen@redhat.com>
Jakub Jelen 6666c1
Date: Tue, 16 Oct 2018 16:44:40 +0200
Jakub Jelen 6666c1
Subject: [PATCH] Unbreak authentication using gssapi-keyex (#1625366)
Jakub Jelen 6666c1
Jakub Jelen 6666c1
---
Jakub Jelen 6666c1
 auth2-gss.c    |  6 +++---
Jakub Jelen 6666c1
 gss-serv.c     |  4 +++-
Jakub Jelen 6666c1
 monitor.c      | 13 ++++++++++---
Jakub Jelen 6666c1
 monitor_wrap.c |  4 +++-
Jakub Jelen 6666c1
 monitor_wrap.h |  2 +-
Jakub Jelen 6666c1
 ssh-gss.h      |  2 +-
Jakub Jelen 6666c1
 6 files changed, 21 insertions(+), 10 deletions(-)
Jakub Jelen 6666c1
Jakub Jelen 6666c1
diff --git a/auth2-gss.c b/auth2-gss.c
Jakub Jelen 6666c1
index 3f2ad21d..a61ac089 100644
Jakub Jelen 6666c1
--- a/auth2-gss.c
Jakub Jelen 6666c1
+++ b/auth2-gss.c
Jakub Jelen 6666c1
@@ -84,7 +84,7 @@ userauth_gsskeyex(Authctxt *authctxt)
Jakub Jelen 6666c1
 	if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gss_kex_context, 
Jakub Jelen 6666c1
 	    &gssbuf, &mic))))
Jakub Jelen 6666c1
 		authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
Jakub Jelen 6666c1
-		    authctxt->pw));
Jakub Jelen 6666c1
+		    authctxt->pw, 1));
Jakub Jelen 6666c1
 	
Jakub Jelen 6666c1
 	sshbuf_free(b);
Jakub Jelen 6666c1
 	free(mic.value);
Jakub Jelen 6666c1
@@ -299,7 +299,7 @@ input_gssapi_exchange_complete(int type, u_int32_t plen, struct ssh *ssh)
Jakub Jelen 6666c1
 		fatal("%s: %s", __func__, ssh_err(r));
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	authenticated = PRIVSEP(ssh_gssapi_userok(authctxt->user,
Jakub Jelen 6666c1
-	    authctxt->pw));
Jakub Jelen 6666c1
+	    authctxt->pw, 1));
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	if ((!use_privsep || mm_is_monitor()) &&
Jakub Jelen 6666c1
 	    (displayname = ssh_gssapi_displayname()) != NULL)
Jakub Jelen 6666c1
@@ -347,7 +347,7 @@ input_gssapi_mic(int type, u_int32_t plen, struct ssh *ssh)
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	if (!GSS_ERROR(PRIVSEP(ssh_gssapi_checkmic(gssctxt, &gssbuf, &mic))))
Jakub Jelen 6666c1
 		authenticated = 
Jakub Jelen 6666c1
-		    PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw));
Jakub Jelen 6666c1
+		    PRIVSEP(ssh_gssapi_userok(authctxt->user, authctxt->pw, 0));
Jakub Jelen 6666c1
 	else
Jakub Jelen 6666c1
 		logit("GSSAPI MIC check failed");
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
diff --git a/gss-serv.c b/gss-serv.c
Jakub Jelen 6666c1
index 786ac95c..87de2baa 100644
Jakub Jelen 6666c1
--- a/gss-serv.c
Jakub Jelen 6666c1
+++ b/gss-serv.c
Jakub Jelen 6666c1
@@ -493,10 +493,12 @@ verify_authentication_indicators(Gssctxt *gssctxt)
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 /* Privileged */
Jakub Jelen 6666c1
 int
Jakub Jelen 6666c1
-ssh_gssapi_userok(char *user, struct passwd *pw)
Jakub Jelen 6666c1
+ssh_gssapi_userok(char *user, struct passwd *pw, int kex)
Jakub Jelen 6666c1
 {
Jakub Jelen 6666c1
 	OM_uint32 lmin;
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
+	(void) kex; /* used in privilege separation */
Jakub Jelen 6666c1
+
Jakub Jelen 6666c1
 	if (gssapi_client.exportedname.length == 0 ||
Jakub Jelen 6666c1
 	    gssapi_client.exportedname.value == NULL) {
Jakub Jelen 6666c1
 		debug("No suitable client data");
Jakub Jelen 6666c1
diff --git a/monitor.c b/monitor.c
Jakub Jelen 6666c1
index 9bbe8cc4..7b1903af 100644
Jakub Jelen 6666c1
--- a/monitor.c
Jakub Jelen 6666c1
+++ b/monitor.c
Jakub Jelen 6666c1
@@ -1877,14 +1877,17 @@ mm_answer_gss_checkmic(int sock, struct sshbuf *m)
Jakub Jelen 6666c1
 int
Jakub Jelen 6666c1
 mm_answer_gss_userok(int sock, struct sshbuf *m)
Jakub Jelen 6666c1
 {
Jakub Jelen 6666c1
-	int r, authenticated;
Jakub Jelen 6666c1
+	int r, authenticated, kex;
Jakub Jelen 6666c1
 	const char *displayname;
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	if (!options.gss_authentication && !options.gss_keyex)
Jakub Jelen 6666c1
 		fatal("%s: GSSAPI authentication not enabled", __func__);
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
+	if ((r = sshbuf_get_u32(m, &kex)) != 0)
Jakub Jelen 6666c1
+		fatal("%s: buffer error: %s", __func__, ssh_err(r));
Jakub Jelen 6666c1
+
Jakub Jelen 6666c1
 	authenticated = authctxt->valid &&
Jakub Jelen 6666c1
-	    ssh_gssapi_userok(authctxt->user, authctxt->pw);
Jakub Jelen 6666c1
+	    ssh_gssapi_userok(authctxt->user, authctxt->pw, kex);
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	sshbuf_reset(m);
Jakub Jelen 6666c1
 	if ((r = sshbuf_put_u32(m, authenticated)) != 0)
Jakub Jelen 6666c1
@@ -1893,7 +1896,11 @@ mm_answer_gss_userok(int sock, struct sshbuf *m)
Jakub Jelen 6666c1
 	debug3("%s: sending result %d", __func__, authenticated);
Jakub Jelen 6666c1
 	mm_request_send(sock, MONITOR_ANS_GSSUSEROK, m);
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
-	auth_method = "gssapi-with-mic";
Jakub Jelen 6666c1
+	if (kex) {
Jakub Jelen 6666c1
+		auth_method = "gssapi-keyex";
Jakub Jelen 6666c1
+	} else {
Jakub Jelen 6666c1
+		auth_method = "gssapi-with-mic";
Jakub Jelen 6666c1
+	}
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	if ((displayname = ssh_gssapi_displayname()) != NULL)
Jakub Jelen 6666c1
 		auth2_record_info(authctxt, "%s", displayname);
Jakub Jelen 6666c1
diff --git a/monitor_wrap.c b/monitor_wrap.c
Jakub Jelen 6666c1
index fb52a530..508d926d 100644
Jakub Jelen 6666c1
--- a/monitor_wrap.c
Jakub Jelen 6666c1
+++ b/monitor_wrap.c
Jakub Jelen 6666c1
@@ -984,13 +984,15 @@ mm_ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
Jakub Jelen 6666c1
 }
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 int
Jakub Jelen 6666c1
-mm_ssh_gssapi_userok(char *user, struct passwd *pw)
Jakub Jelen 6666c1
+mm_ssh_gssapi_userok(char *user, struct passwd *pw, int kex)
Jakub Jelen 6666c1
 {
Jakub Jelen 6666c1
 	struct sshbuf *m;
Jakub Jelen 6666c1
 	int r, authenticated = 0;
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	if ((m = sshbuf_new()) == NULL)
Jakub Jelen 6666c1
 		fatal("%s: sshbuf_new failed", __func__);
Jakub Jelen 6666c1
+	if ((r = sshbuf_put_u32(m, kex)) != 0)
Jakub Jelen 6666c1
+		fatal("%s: buffer error: %s", __func__, ssh_err(r));
Jakub Jelen 6666c1
 
Jakub Jelen 6666c1
 	mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_GSSUSEROK, m);
Jakub Jelen 6666c1
 	mm_request_receive_expect(pmonitor->m_recvfd,
Jakub Jelen 6666c1
diff --git a/monitor_wrap.h b/monitor_wrap.h
Jakub Jelen 6666c1
index 494760dd..5eba5ecc 100644
Jakub Jelen 6666c1
--- a/monitor_wrap.h
Jakub Jelen 6666c1
+++ b/monitor_wrap.h
Jakub Jelen 6666c1
@@ -60,7 +60,7 @@ int mm_sshkey_verify(const struct sshkey *, const u_char *, size_t,
Jakub Jelen 6666c1
 OM_uint32 mm_ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
Jakub Jelen 6666c1
 OM_uint32 mm_ssh_gssapi_accept_ctx(Gssctxt *,
Jakub Jelen 6666c1
    gss_buffer_desc *, gss_buffer_desc *, OM_uint32 *);
Jakub Jelen 6666c1
-int mm_ssh_gssapi_userok(char *user, struct passwd *);
Jakub Jelen 6666c1
+int mm_ssh_gssapi_userok(char *user, struct passwd *, int kex);
Jakub Jelen 6666c1
 OM_uint32 mm_ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jakub Jelen 6666c1
 OM_uint32 mm_ssh_gssapi_sign(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jakub Jelen 6666c1
 int mm_ssh_gssapi_update_creds(ssh_gssapi_ccache *);
Jakub Jelen 6666c1
diff --git a/ssh-gss.h b/ssh-gss.h
Jakub Jelen 6666c1
index 39b6ce69..98262837 100644
Jakub Jelen 6666c1
--- a/ssh-gss.h
Jakub Jelen 6666c1
+++ b/ssh-gss.h
Jakub Jelen 6666c1
@@ -162,7 +162,7 @@ gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
Jakub Jelen 6666c1
 int ssh_gssapi_server_check_mech(Gssctxt **,gss_OID, const char *, 
Jakub Jelen 6666c1
     const char *);
Jakub Jelen 6666c1
 OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
Jakub Jelen 6666c1
-int ssh_gssapi_userok(char *name, struct passwd *);
Jakub Jelen 6666c1
+int ssh_gssapi_userok(char *name, struct passwd *, int kex);
Jakub Jelen 6666c1
 OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
Jakub Jelen 6666c1
 void ssh_gssapi_do_child(char ***, u_int *);
Jakub Jelen 6666c1
 void ssh_gssapi_cleanup_creds(void);
Jakub Jelen 6666c1
-- 
Jakub Jelen 6666c1
2.17.2
Jakub Jelen 6666c1