Skip to content

Commit 46c642f

Browse files
committed
Completely omit CBs AV pairs when no CB provided
Although the MS-NLMP Spec says zero CBs should be equivalent to no CBs, Windows apparently fails validation when CBs are optional and an all zero CB is presented. So avoid sending any CBs if we have none. Also make sure to deal with missing CBs on the accpetor by ignoreing missing CBs and setting the new GSS_C_CHANNEL_BOUND_FLAG in gss flags if the CBs are present and matching. Signed-off-by: Simo Sorce <[email protected]>
1 parent 9377d90 commit 46c642f

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/gss_sec_ctx.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ uint32_t gssntlm_accept_sec_context(uint32_t *minor_status,
942942
}
943943

944944
if (input_chan_bindings != GSS_C_NO_CHANNEL_BINDINGS) {
945+
uint8_t zero_cb[16] = { 0 };
945946
if (input_chan_bindings->initiator_addrtype != 0 ||
946947
input_chan_bindings->initiator_address.length != 0 ||
947948
input_chan_bindings->acceptor_addrtype != 0 ||
@@ -953,12 +954,23 @@ uint32_t gssntlm_accept_sec_context(uint32_t *minor_status,
953954
unhashed_cb.length = input_chan_bindings->application_data.length;
954955
unhashed_cb.data = input_chan_bindings->application_data.value;
955956

956-
/* TODO: optionally allow to ignore CBT if av_cb is null ? */
957-
retmin = ntlm_verify_channel_bindings(&unhashed_cb, &av_cb);
958-
if (retmin) {
957+
if (av_cb.length && (av_cb.length != 16)) {
959958
set_GSSERRS(retmin, GSS_S_DEFECTIVE_TOKEN);
960959
goto done;
961960
}
961+
if (av_cb.length &&
962+
(memcmp(av_cb.data, zero_cb, 16) != 0)) {
963+
retmin = ntlm_verify_channel_bindings(&unhashed_cb, &av_cb);
964+
if (retmin) {
965+
set_GSSERRS(retmin, GSS_S_DEFECTIVE_TOKEN);
966+
goto done;
967+
/* This flag has been introduced only recently in MIT krb5 */
968+
#ifdef GSS_C_CHANNEL_BOUND_FLAG
969+
} else {
970+
ctx->gss_flags |= GSS_C_CHANNEL_BOUND_FLAG;
971+
#endif /* GSS_C_CHANNEL_BOUND_FLAG */
972+
}
973+
}
962974
}
963975

964976
if (ctx->neg_flags & (NTLMSSP_NEGOTIATE_SIGN |

src/ntlm.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ struct wire_single_host_data {
6868
};
6969
#pragma pack(pop)
7070

71-
#pragma pack(push, 1)
72-
struct wire_channel_binding {
73-
uint8_t md5_hash[16];
74-
};
75-
#pragma pack(pop)
76-
7771
#pragma pack(push, 1)
7872
struct wire_ntlm_cli_chal {
7973
uint8_t resp_type;
@@ -560,7 +554,7 @@ int ntlm_encode_target_info(struct ntlm_ctx *ctx, char *nb_computer_name,
560554
av_target_name_len = strlen(av_target_name);
561555
max_size += 4 + av_target_name_len * 2;
562556
}
563-
if (av_cb) {
557+
if (av_cb && av_cb->length > 0) {
564558
max_size += 4 + av_cb->length;
565559
}
566560

@@ -632,7 +626,7 @@ int ntlm_encode_target_info(struct ntlm_ctx *ctx, char *nb_computer_name,
632626
av_target_name_len);
633627
if (ret) goto done;
634628
}
635-
if (av_cb) {
629+
if (av_cb && av_cb->length > 0) {
636630
ret = ntlm_encode_av_pair_value(&buffer, &data_offs,
637631
MSV_AV_CHANNEL_BINDINGS, av_cb);
638632
if (ret) goto done;
@@ -791,7 +785,7 @@ int ntlm_process_target_info(struct ntlm_ctx *ctx, bool protect,
791785
uint32_t av_flags = 0;
792786
uint64_t srv_time = 0;
793787
uint8_t cb[16] = { 0 };
794-
struct ntlm_buffer av_cb = { cb, 16 };
788+
struct ntlm_buffer av_cb = { NULL, 0 };
795789
int ret = 0;
796790

797791
/* TODO: check that returned netbios/dns names match ? */
@@ -824,6 +818,8 @@ int ntlm_process_target_info(struct ntlm_ctx *ctx, bool protect,
824818
}
825819

826820
if (unhashed_cb->length > 0) {
821+
av_cb.data = cb;
822+
av_cb.length = 16;
827823
ret = ntlm_hash_channel_bindings(unhashed_cb, &av_cb);
828824
if (ret) goto done;
829825
}

0 commit comments

Comments
 (0)