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

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