Blame SOURCES/Pass-channel-bindings-through-SPNEGO.patch

287c72
From 6265b0fbc59e13756364b97a5e3e8672514f8302 Mon Sep 17 00:00:00 2001
31ace6
From: Isaac Boukris <iboukris@gmail.com>
31ace6
Date: Tue, 28 Apr 2020 18:15:55 +0200
31ace6
Subject: [PATCH] Pass channel bindings through SPNEGO
31ace6
31ace6
ticket: 8907 (new)
31ace6
(cherry picked from commit d16325a24c34ec9a5f6fb4910987f162e0d4d9cd)
31ace6
(cherry picked from commit ee79bd43005245d3e5a2d3ec6d61146945e77717)
31ace6
---
31ace6
 src/lib/gssapi/spnego/gssapiP_negoex.h |  8 ++---
31ace6
 src/lib/gssapi/spnego/negoex_ctx.c     | 34 +++++++++++----------
31ace6
 src/lib/gssapi/spnego/spnego_mech.c    | 41 +++++++++++++-------------
31ace6
 3 files changed, 43 insertions(+), 40 deletions(-)
31ace6
31ace6
diff --git a/src/lib/gssapi/spnego/gssapiP_negoex.h b/src/lib/gssapi/spnego/gssapiP_negoex.h
31ace6
index 44b08f523..489ab7c42 100644
31ace6
--- a/src/lib/gssapi/spnego/gssapiP_negoex.h
31ace6
+++ b/src/lib/gssapi/spnego/gssapiP_negoex.h
31ace6
@@ -201,10 +201,10 @@ negoex_restrict_auth_schemes(spnego_gss_ctx_id_t ctx,
31ace6
 OM_uint32
31ace6
 negoex_init(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
             gss_name_t target_name, OM_uint32 req_flags, OM_uint32 time_req,
31ace6
-            gss_buffer_t input_token, gss_buffer_t output_token,
31ace6
-            OM_uint32 *time_rec);
31ace6
+            gss_buffer_t input_token, gss_channel_bindings_t bindings,
31ace6
+            gss_buffer_t output_token, OM_uint32 *time_rec);
31ace6
 
31ace6
 OM_uint32
31ace6
 negoex_accept(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
-              gss_buffer_t input_token, gss_buffer_t output_token,
31ace6
-              OM_uint32 *time_rec);
31ace6
+              gss_buffer_t input_token, gss_channel_bindings_t bindings,
31ace6
+              gss_buffer_t output_token, OM_uint32 *time_rec);
31ace6
diff --git a/src/lib/gssapi/spnego/negoex_ctx.c b/src/lib/gssapi/spnego/negoex_ctx.c
31ace6
index 18d9d4147..8848ee4db 100644
31ace6
--- a/src/lib/gssapi/spnego/negoex_ctx.c
31ace6
+++ b/src/lib/gssapi/spnego/negoex_ctx.c
31ace6
@@ -276,7 +276,8 @@ static OM_uint32
31ace6
 mech_init(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
           gss_name_t target, OM_uint32 req_flags, OM_uint32 time_req,
31ace6
           struct negoex_message *messages, size_t nmessages,
31ace6
-          gss_buffer_t output_token, OM_uint32 *time_rec)
31ace6
+          gss_channel_bindings_t bindings, gss_buffer_t output_token,
31ace6
+          OM_uint32 *time_rec)
31ace6
 {
31ace6
     OM_uint32 major, first_major = 0, first_minor = 0;
31ace6
     struct negoex_auth_mech *mech = NULL;
31ace6
@@ -316,10 +317,9 @@ mech_init(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
         mech = K5_TAILQ_FIRST(&ctx->negoex_mechs);
31ace6
 
31ace6
         major = gss_init_sec_context(minor, cred, &mech->mech_context, target,
31ace6
-                                     mech->oid, req_flags, time_req,
31ace6
-                                     GSS_C_NO_CHANNEL_BINDINGS, input_token,
31ace6
-                                     &ctx->actual_mech, output_token,
31ace6
-                                     &ctx->ctx_flags, time_rec);
31ace6
+                                     mech->oid, req_flags, time_req, bindings,
31ace6
+                                     input_token, &ctx->actual_mech,
31ace6
+                                     output_token, &ctx->ctx_flags, time_rec);
31ace6
 
31ace6
         if (major == GSS_S_COMPLETE)
31ace6
             mech->complete = 1;
31ace6
@@ -351,7 +351,8 @@ mech_init(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
 static OM_uint32
31ace6
 mech_accept(OM_uint32 *minor, spnego_gss_ctx_id_t ctx,
31ace6
             gss_cred_id_t cred, struct negoex_message *messages,
31ace6
-            size_t nmessages, gss_buffer_t output_token, OM_uint32 *time_rec)
31ace6
+            size_t nmessages, gss_channel_bindings_t bindings,
31ace6
+            gss_buffer_t output_token, OM_uint32 *time_rec)
31ace6
 {
31ace6
     OM_uint32 major, tmpmin;
31ace6
     struct negoex_auth_mech *mech;
31ace6
@@ -395,10 +396,10 @@ mech_accept(OM_uint32 *minor, spnego_gss_ctx_id_t ctx,
31ace6
         gss_release_cred(&tmpmin, &ctx->deleg_cred);
31ace6
 
31ace6
     major = gss_accept_sec_context(minor, &mech->mech_context, cred,
31ace6
-                                   &msg->token, GSS_C_NO_CHANNEL_BINDINGS,
31ace6
-                                   &ctx->internal_name, &ctx->actual_mech,
31ace6
-                                   output_token, &ctx->ctx_flags,
31ace6
-                                   time_rec, &ctx->deleg_cred);
31ace6
+                                   &msg->token, bindings, &ctx->internal_name,
31ace6
+                                   &ctx->actual_mech, output_token,
31ace6
+                                   &ctx->ctx_flags, time_rec,
31ace6
+                                   &ctx->deleg_cred);
31ace6
 
31ace6
     if (major == GSS_S_COMPLETE)
31ace6
         mech->complete = 1;
31ace6
@@ -609,8 +610,8 @@ make_output_token(OM_uint32 *minor, spnego_gss_ctx_id_t ctx,
31ace6
 OM_uint32
31ace6
 negoex_init(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
             gss_name_t target_name, OM_uint32 req_flags, OM_uint32 time_req,
31ace6
-            gss_buffer_t input_token, gss_buffer_t output_token,
31ace6
-            OM_uint32 *time_rec)
31ace6
+            gss_buffer_t input_token, gss_channel_bindings_t bindings,
31ace6
+            gss_buffer_t output_token, OM_uint32 *time_rec)
31ace6
 {
31ace6
     OM_uint32 major, tmpmin;
31ace6
     gss_buffer_desc mech_output_token = GSS_C_EMPTY_BUFFER;
31ace6
@@ -663,7 +664,8 @@ negoex_init(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
     /* Process the input token and/or produce an output token.  This may prune
31ace6
      * the mech list, but on success there will be at least one mech entry. */
31ace6
     major = mech_init(minor, ctx, cred, target_name, req_flags, time_req,
31ace6
-                      messages, nmessages, &mech_output_token, time_rec);
31ace6
+                      messages, nmessages, bindings, &mech_output_token,
31ace6
+                      time_rec);
31ace6
     if (major != GSS_S_COMPLETE)
31ace6
         goto cleanup;
31ace6
     assert(!K5_TAILQ_EMPTY(&ctx->negoex_mechs));
31ace6
@@ -701,8 +703,8 @@ cleanup:
31ace6
 
31ace6
 OM_uint32
31ace6
 negoex_accept(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
-              gss_buffer_t input_token, gss_buffer_t output_token,
31ace6
-              OM_uint32 *time_rec)
31ace6
+              gss_buffer_t input_token, gss_channel_bindings_t bindings,
31ace6
+              gss_buffer_t output_token, OM_uint32 *time_rec)
31ace6
 {
31ace6
     OM_uint32 major, tmpmin;
31ace6
     gss_buffer_desc mech_output_token = GSS_C_EMPTY_BUFFER;
31ace6
@@ -754,7 +756,7 @@ negoex_accept(OM_uint32 *minor, spnego_gss_ctx_id_t ctx, gss_cred_id_t cred,
31ace6
      * prune the list to a single mech.  Continue on error if an output token
31ace6
      * is generated, so that we send the token to the initiator.
31ace6
      */
31ace6
-    major = mech_accept(minor, ctx, cred, messages, nmessages,
31ace6
+    major = mech_accept(minor, ctx, cred, messages, nmessages, bindings,
31ace6
                         &mech_output_token, time_rec);
31ace6
     if (major != GSS_S_COMPLETE && mech_output_token.length == 0)
31ace6
         goto cleanup;
31ace6
diff --git a/src/lib/gssapi/spnego/spnego_mech.c b/src/lib/gssapi/spnego/spnego_mech.c
31ace6
index 594fc5894..4cf011143 100644
31ace6
--- a/src/lib/gssapi/spnego/spnego_mech.c
31ace6
+++ b/src/lib/gssapi/spnego/spnego_mech.c
31ace6
@@ -130,6 +130,7 @@ init_ctx_reselect(OM_uint32 *, spnego_gss_ctx_id_t, OM_uint32,
31ace6
 static OM_uint32
31ace6
 init_ctx_call_init(OM_uint32 *, spnego_gss_ctx_id_t, spnego_gss_cred_id_t,
31ace6
 		   OM_uint32, gss_name_t, OM_uint32, OM_uint32, gss_buffer_t,
31ace6
+		   gss_channel_bindings_t,
31ace6
 		   gss_buffer_t, OM_uint32 *, send_token_flag *);
31ace6
 
31ace6
 static OM_uint32
31ace6
@@ -144,8 +145,8 @@ acc_ctx_vfy_oid(OM_uint32 *, spnego_gss_ctx_id_t, gss_OID,
31ace6
 		OM_uint32 *, send_token_flag *);
31ace6
 static OM_uint32
31ace6
 acc_ctx_call_acc(OM_uint32 *, spnego_gss_ctx_id_t, spnego_gss_cred_id_t,
31ace6
-		 gss_buffer_t, gss_buffer_t, OM_uint32 *, OM_uint32 *,
31ace6
-		 send_token_flag *);
31ace6
+		 gss_buffer_t, gss_channel_bindings_t, gss_buffer_t,
31ace6
+		 OM_uint32 *, OM_uint32 *, send_token_flag *);
31ace6
 
31ace6
 static gss_OID
31ace6
 negotiate_mech(spnego_gss_ctx_id_t, gss_OID_set, OM_uint32 *);
31ace6
@@ -905,6 +906,7 @@ init_ctx_call_init(OM_uint32 *minor_status,
31ace6
 		   OM_uint32 req_flags,
31ace6
 		   OM_uint32 time_req,
31ace6
 		   gss_buffer_t mechtok_in,
31ace6
+		   gss_channel_bindings_t bindings,
31ace6
 		   gss_buffer_t mechtok_out,
31ace6
 		   OM_uint32 *time_rec,
31ace6
 		   send_token_flag *send_token)
31ace6
@@ -921,15 +923,14 @@ init_ctx_call_init(OM_uint32 *minor_status,
31ace6
 	if (gss_oid_equal(sc->internal_mech, &negoex_mech)) {
31ace6
 		ret = negoex_init(minor_status, sc, mcred, target_name,
31ace6
 				  mech_req_flags, time_req, mechtok_in,
31ace6
-				  mechtok_out, time_rec);
31ace6
+				  bindings, mechtok_out, time_rec);
31ace6
 	} else {
31ace6
 		ret = gss_init_sec_context(minor_status, mcred,
31ace6
 					   &sc->ctx_handle, target_name,
31ace6
 					   sc->internal_mech, mech_req_flags,
31ace6
-					   time_req, GSS_C_NO_CHANNEL_BINDINGS,
31ace6
-					   mechtok_in, &sc->actual_mech,
31ace6
-					   mechtok_out, &sc->ctx_flags,
31ace6
-					   time_rec);
31ace6
+					   time_req, bindings, mechtok_in,
31ace6
+					   &sc->actual_mech, mechtok_out,
31ace6
+					   &sc->ctx_flags, time_rec);
31ace6
 	}
31ace6
 
31ace6
 	/* Bail out if the acceptor gave us an error token but the mech didn't
31ace6
@@ -981,8 +982,8 @@ init_ctx_call_init(OM_uint32 *minor_status,
31ace6
 	gss_delete_sec_context(&tmpmin, &sc->ctx_handle, GSS_C_NO_BUFFER);
31ace6
 	tmpret = init_ctx_call_init(&tmpmin, sc, spcred, acc_negState,
31ace6
 				    target_name, req_flags, time_req,
31ace6
-				    mechtok_in, mechtok_out, time_rec,
31ace6
-				    send_token);
31ace6
+				    mechtok_in, bindings, mechtok_out,
31ace6
+				    time_rec, send_token);
31ace6
 	if (HARD_ERROR(tmpret))
31ace6
 		goto fail;
31ace6
 	*minor_status = tmpmin;
31ace6
@@ -1004,7 +1005,7 @@ spnego_gss_init_sec_context(
31ace6
 			gss_OID mech_type,
31ace6
 			OM_uint32 req_flags,
31ace6
 			OM_uint32 time_req,
31ace6
-			gss_channel_bindings_t input_chan_bindings,
31ace6
+			gss_channel_bindings_t bindings,
31ace6
 			gss_buffer_t input_token,
31ace6
 			gss_OID *actual_mech,
31ace6
 			gss_buffer_t output_token,
31ace6
@@ -1084,8 +1085,8 @@ spnego_gss_init_sec_context(
31ace6
 	if (!spnego_ctx->mech_complete) {
31ace6
 		ret = init_ctx_call_init(minor_status, spnego_ctx, spcred,
31ace6
 					 acc_negState, target_name, req_flags,
31ace6
-					 time_req, mechtok_in, &mechtok_out,
31ace6
-					 time_rec, &send_token);
31ace6
+					 time_req, mechtok_in, bindings,
31ace6
+					 &mechtok_out, time_rec, &send_token);
31ace6
 		if (ret != GSS_S_COMPLETE)
31ace6
 			goto cleanup;
31ace6
 
31ace6
@@ -1542,8 +1543,9 @@ cleanup:
31ace6
 static OM_uint32
31ace6
 acc_ctx_call_acc(OM_uint32 *minor_status, spnego_gss_ctx_id_t sc,
31ace6
 		 spnego_gss_cred_id_t spcred, gss_buffer_t mechtok_in,
31ace6
-		 gss_buffer_t mechtok_out, OM_uint32 *time_rec,
31ace6
-		 OM_uint32 *negState, send_token_flag *tokflag)
31ace6
+		 gss_channel_bindings_t bindings, gss_buffer_t mechtok_out,
31ace6
+		 OM_uint32 *time_rec, OM_uint32 *negState,
31ace6
+		 send_token_flag *tokflag)
31ace6
 {
31ace6
 	OM_uint32 ret, tmpmin;
31ace6
 	gss_OID_desc mechoid;
31ace6
@@ -1568,13 +1570,12 @@ acc_ctx_call_acc(OM_uint32 *minor_status, spnego_gss_ctx_id_t sc,
31ace6
 	mcred = (spcred == NULL) ? GSS_C_NO_CREDENTIAL : spcred->mcred;
31ace6
 	if (negoex) {
31ace6
 		ret = negoex_accept(minor_status, sc, mcred, mechtok_in,
31ace6
-				    mechtok_out, time_rec);
31ace6
+				    bindings, mechtok_out, time_rec);
31ace6
 	} else {
31ace6
 		(void) gss_release_name(&tmpmin, &sc->internal_name);
31ace6
 		(void) gss_release_cred(&tmpmin, &sc->deleg_cred);
31ace6
 		ret = gss_accept_sec_context(minor_status, &sc->ctx_handle,
31ace6
-					     mcred, mechtok_in,
31ace6
-					     GSS_C_NO_CHANNEL_BINDINGS,
31ace6
+					     mcred, mechtok_in, bindings,
31ace6
 					     &sc->internal_name,
31ace6
 					     &sc->actual_mech, mechtok_out,
31ace6
 					     &sc->ctx_flags, time_rec,
31ace6
@@ -1620,7 +1621,7 @@ spnego_gss_accept_sec_context(
31ace6
 			    gss_ctx_id_t *context_handle,
31ace6
 			    gss_cred_id_t verifier_cred_handle,
31ace6
 			    gss_buffer_t input_token,
31ace6
-			    gss_channel_bindings_t input_chan_bindings,
31ace6
+			    gss_channel_bindings_t bindings,
31ace6
 			    gss_name_t *src_name,
31ace6
 			    gss_OID *mech_type,
31ace6
 			    gss_buffer_t output_token,
31ace6
@@ -1734,8 +1735,8 @@ spnego_gss_accept_sec_context(
31ace6
 	 */
31ace6
 	if (negState != REQUEST_MIC && mechtok_in != GSS_C_NO_BUFFER) {
31ace6
 		ret = acc_ctx_call_acc(minor_status, sc, spcred, mechtok_in,
31ace6
-				       &mechtok_out, time_rec, &negState,
31ace6
-				       &return_token);
31ace6
+				       bindings, &mechtok_out, time_rec,
31ace6
+				       &negState, &return_token);
31ace6
 	}
31ace6
 
31ace6
 	/* Step 3: process or generate the MIC, if the negotiated mech is