Search code examples
c++winapintlmsspi

How to authenticate with NTLM with parameters (via HTTP)?


I'm using InitializeSecurityContext function to produce Type 1 and Type 3 messages for NTLM authentication in HTTP. Everything works fine when I'm receiving default header:

WWW-Authenticate: NTLM

But, when I receive header like:

WWW-Authenticate: NTLM realm="SIP Communications Service", targetname="server.domain.com", version=4

It is not going to accept Type 1 message and I'm receiving again all WWW-Authenticate headers. This is the function that I use to produce first response:

result = SSPI()->InitializeSecurityContextW(
    credHandle, // phCredential
    0, // phContext
    0, // *pszTargetName
    ISC_REQ_USE_DCE_STYLE | ISC_REQ_DELEGATE | ISC_REQ_MUTUAL_AUTH
        | ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT
        | ISC_REQ_CONFIDENTIALITY | ISC_REQ_CONNECTION, // fContextReq
    0, // Reserved1
    0, // TargetDataRep
    0, // pInput
    0, // Reserved2
    context, // phNewContext
    bufferDesc, // pOutput
    &outFlags, // pfContextAttr
    &timestamp // ptsExpiry
);

I tried already to set pszTargetName as L"server.domain.com" but it doesn't work too.

Any ideas how I could pass realm, targetname and version parameters (if necessary)? I am communicating with Lync 2013 server.


Solution

  • I was able to authenticate by using MS-SIPAE documentation and NTLM authentication example. Entire process is well described in above link.