Blame SOURCES/Implement-KERB_AP_OPTIONS_CBT-server-side.patch

31ace6
From 7aea9fc73fb508e3168581990eb2e2ff7a1aea31 Mon Sep 17 00:00:00 2001
31ace6
From: Isaac Boukris <iboukris@gmail.com>
31ace6
Date: Mon, 9 Mar 2020 16:04:21 +0100
31ace6
Subject: [PATCH] Implement KERB_AP_OPTIONS_CBT (server side)
31ace6
31ace6
Add server support for Microsoft's KERB_AP_OPTIONS_CBT as described in
31ace6
MS-KILE.  If the client includes the AP option in the authenticator
31ace6
authdata and the server passed channel bindings, require the bindings
31ace6
to match.
31ace6
31ace6
[ghudson@mit.edu: refactored to put more logic in the helper function;
31ace6
added a comment; clarified commit message]
31ace6
31ace6
ticket: 8900 (new)
31ace6
(cherry picked from commit 4f7c77b64a048ca5e3199b26b31493698c777a9c)
31ace6
(cherry picked from commit 6407bf087fe53088d91efd09df736e979cd4e8db)
31ace6
---
31ace6
 src/include/krb5/krb5.hin                |  1 +
31ace6
 src/lib/gssapi/krb5/accept_sec_context.c | 45 +++++++++++++++++++++++-
31ace6
 2 files changed, 45 insertions(+), 1 deletion(-)
31ace6
31ace6
diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin
31ace6
index f8269fb17..9264bede1 100644
31ace6
--- a/src/include/krb5/krb5.hin
31ace6
+++ b/src/include/krb5/krb5.hin
31ace6
@@ -1915,6 +1915,7 @@ krb5_verify_checksum(krb5_context context, krb5_cksumtype ctype,
31ace6
 #define KRB5_AUTHDATA_SIGNTICKET        512     /**< formerly 142 in krb5 1.8 */
31ace6
 #define KRB5_AUTHDATA_FX_ARMOR 71
31ace6
 #define KRB5_AUTHDATA_AUTH_INDICATOR 97
31ace6
+#define KRB5_AUTHDATA_AP_OPTIONS 143
31ace6
 /** @} */ /* end of KRB5_AUTHDATA group */
31ace6
 
31ace6
 /* password change constants */
31ace6
diff --git a/src/lib/gssapi/krb5/accept_sec_context.c b/src/lib/gssapi/krb5/accept_sec_context.c
31ace6
index 9d3e2f4fe..175a24c4e 100644
31ace6
--- a/src/lib/gssapi/krb5/accept_sec_context.c
31ace6
+++ b/src/lib/gssapi/krb5/accept_sec_context.c
31ace6
@@ -430,6 +430,32 @@ kg_process_extension(krb5_context context,
31ace6
 /* A zero-value channel binding, for comparison */
31ace6
 static const uint8_t null_cb[CB_MD5_LEN];
31ace6
 
31ace6
+/* Look for AP_OPTIONS in authdata.  If present and the options include
31ace6
+ * KERB_AP_OPTIONS_CBT, set *cbt_out to true. */
31ace6
+static krb5_error_code
31ace6
+check_cbt(krb5_context context, krb5_authdata **authdata,
31ace6
+          krb5_boolean *cbt_out)
31ace6
+{
31ace6
+    krb5_error_code code;
31ace6
+    uint32_t ad_ap_options;
31ace6
+    const uint32_t KERB_AP_OPTIONS_CBT = 0x4000;
31ace6
+
31ace6
+    *cbt_out = FALSE;
31ace6
+
31ace6
+    code = krb5_find_authdata(context, NULL, authdata,
31ace6
+                              KRB5_AUTHDATA_AP_OPTIONS, &authdata);
31ace6
+    if (code || authdata == NULL)
31ace6
+        return code;
31ace6
+    if (authdata[1] != NULL || authdata[0]->length != 4)
31ace6
+        return KRB5KRB_AP_ERR_MSG_TYPE;
31ace6
+
31ace6
+    ad_ap_options = load_32_le(authdata[0]->contents);
31ace6
+    if (ad_ap_options & KERB_AP_OPTIONS_CBT)
31ace6
+        *cbt_out = TRUE;
31ace6
+
31ace6
+    return 0;
31ace6
+}
31ace6
+
31ace6
 /*
31ace6
  * The krb5 GSS mech appropriates the authenticator checksum field from RFC
31ace6
  * 4120 to store structured data instead of a checksum, indicated with checksum
31ace6
@@ -454,7 +480,7 @@ process_checksum(OM_uint32 *minor_status, krb5_context context,
31ace6
     krb5_error_code code = 0;
31ace6
     OM_uint32 status, option_id, token_flags;
31ace6
     size_t cb_len, option_len;
31ace6
-    krb5_boolean valid, token_cb_present = FALSE, cb_match = FALSE;
31ace6
+    krb5_boolean valid, client_cbt, token_cb_present = FALSE, cb_match = FALSE;
31ace6
     krb5_key subkey;
31ace6
     krb5_data option, empty = empty_data();
31ace6
     krb5_checksum cb_cksum;
31ace6
@@ -582,6 +608,23 @@ process_checksum(OM_uint32 *minor_status, krb5_context context,
31ace6
         }
31ace6
     }
31ace6
 
31ace6
+    /*
31ace6
+     * If the client asserts the KERB_AP_OPTIONS_CBT flag (from MS-KILE) in the
31ace6
+     * authenticator authdata, and the acceptor passed channel bindings,
31ace6
+     * require matching channel bindings from the client.  The intent is to
31ace6
+     * prevent an authenticator generated for use outside of a TLS channel from
31ace6
+     * being used inside of one.
31ace6
+     */
31ace6
+    code = check_cbt(context, authenticator->authorization_data, &client_cbt);
31ace6
+    if (code) {
31ace6
+        status = GSS_S_FAILURE;
31ace6
+        goto fail;
31ace6
+    }
31ace6
+    if (client_cbt && acceptor_cb != GSS_C_NO_CHANNEL_BINDINGS && !cb_match) {
31ace6
+        status = GSS_S_BAD_BINDINGS;
31ace6
+        goto fail;
31ace6
+    }
31ace6
+
31ace6
     status = GSS_S_COMPLETE;
31ace6
 
31ace6
 fail: