Skip to content

Keep Alive (NTLM) #362

Closed
Closed
@terrancesnyder

Description

@terrancesnyder

I am trying to proxy content and the target server is running NTLM auth. The NTLM spec requires a certain handshake where the first 401 is sent, and the client responds.

http://www.innovation.ch/personal/ronald/ntlm.html

...this manifests itself in that the network connection 
must be kept alive during the second part of the 
handshake, i.e. between the receiving of the type-2 
message from the server (step 4) and the sending of the 
type-3 message (step 5). Each time the connection is closed 
this second part (steps 3 through 6) must be repeated over 
the new connection (i.e. it's not enough to just keep sending 
the last type-3 message). Also, once the connection is 
authenticated, the Authorization header need not be sent 
anymore while the connection stays open, no matter what 
resource is accessed.

For implementations wishing to work with M$'s software 
this means that they must make sure they use either HTTP/1.0 
keep-alive's or HTTP/1.1 persistent connections....

I've run wireshark and fiddler and I can see that the connection is NOT being re-used even though the req and res object include the required connection = 'keep-alive'.

I've attached screenshots of wireshark showing different ports being used during the multiple stages of NTLM authentication. Doing some research I got conflicting stories on if keep-alive actually does work, and if it does / does not work in node-http-proxy.

so far, running through squid-proxy, fiddler, and other proxies wireshark reports the correct re-using of the connection. The only one that does not show this is node-http-proxy (and it's also the only one that isn't able to auth the user correctly).

In addition it seems like the headers for www-authenticate are being mangled when there are multiple ones so I had to put in a patch... Without this Firefox, Chrome, IE were not prompting for NTLM authentication because there was only ONE www-authenticate header being returned rather than two separate ones.

    // WWW-Authenticate
    if (response.headers['www-authenticate']) {
      var l = [];
      for (var i=0; i<response.headers['www-authenticate'].split(',').length;i++) {
        l.push(response.headers['www-authenticate'].split(',')[i].trim());
      }
      response.headers['www-authenticate'] = l;
    }

Bad (through node-http-proxy)

Capture2

As shown above you can see for each request we grab a new socket (which destroys NTLM auth and proves that it is not doing keep-alive).

Good (through fiddler, squid, etc)

Capture

The above capture shows that with a proxy running (fiddler, squid, etc) we get the re-use one would expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions