According to my test, the only WRONG thing you did is forget to RESET context.handle
once initialized during handshaking.
c
isc_status = InitializeSecurityContextW(
&creds,
context.initialized ? &context.handle : nullptr,
nullptr,
context_reqs,
0,
SECURITY_NATIVE_DREP,
isc_input_buffers,
0,
&context.handle, // HERE
&out_buffer_desc,
&context.attrs,
&context.expiry
);
asc_status = AcceptSecurityContext(
&creds,
context.initialized ? &context.handle : nullptr,
&in_buffer_desc,
context_reqs,
SECURITY_NATIVE_DREP,
&context.handle, // HERE
&out_buffer_desc,
&context.attrs,
&context.expiry
);
BTW, you don't need to call DeleteSecurityContext
on the old CtxtHandle because it's been invalid after the call.