Subject: [PATCH] curl_ntlm_msgs.c: Remove ISC_REQ_* flags from
call to InitializeSecurityContext to fix bug in NTLM handshake
for HTTP proxy authentication using Windows SSPI

NTLM handshake for HTTP proxy authentication failed with error
SEC_E_INVALID_TOKEN from InitializeSecurityContext for certain proxy
servers on generating the NTLM Type-3 message.
The flag ISC_REQ_CONFIDENTIALITY seems to cause the problem according
to the observations and suggestions made in a bug report for the
QT project (https://bugreports.qt-project.org/browse/QTBUG-17322).
Removing all flags solved the problem.

Bug: curl-library mailing list http://curl.haxx.se/mail/lib-2014-08/0273.html
Reported-by: Ulrich Telle
Helpers: Steve Holme, Daniel Stenberg
---
 lib/curl_ntlm_msgs.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-) 
 
diff U3 curl-7.38.0/lib/curl_ntlm_msgs.c curl-7.38.0-patched/lib/curl_ntlm_msgs.c
--- curl-7.38.0/lib/curl_ntlm_msgs.c	Wed Sep 03 15:22:36 2014
+++ curl-7.38.0-patched/lib/curl_ntlm_msgs.c	Fri Sep 12 11:29:17 2014
@@ -476,9 +476,7 @@
   /* Generate our type-1 message */
   status = s_pSecFn->InitializeSecurityContext(&ntlm->handle, NULL,
                                                (TCHAR *) TEXT(""),
-                                               ISC_REQ_CONFIDENTIALITY |
-                                               ISC_REQ_REPLAY_DETECT |
-                                               ISC_REQ_CONNECTION,
+                                               0,
                                                0, SECURITY_NETWORK_DREP,
                                                NULL, 0,
                                                &ntlm->c_handle, &type_1_desc,
@@ -641,7 +639,6 @@
 
   (void)passwdp;
   (void)userp;
-  (void)data;
 
   /* Setup the type-2 "input" security buffer */
   type_2_desc.ulVersion = SECBUFFER_VERSION;
@@ -663,16 +660,16 @@
   status = s_pSecFn->InitializeSecurityContext(&ntlm->handle,
                                                &ntlm->c_handle,
                                                (TCHAR *) TEXT(""),
-                                               ISC_REQ_CONFIDENTIALITY |
-                                               ISC_REQ_REPLAY_DETECT |
-                                               ISC_REQ_CONNECTION,
+                                               0,
                                                0, SECURITY_NETWORK_DREP,
                                                &type_2_desc,
                                                0, &ntlm->c_handle,
                                                &type_3_desc,
                                                &attrs, &tsDummy);
-  if(status != SEC_E_OK)
+  if(status != SEC_E_OK) {
+    infof(data, "NTLM handshake failure (type-3 message): InitializeSecurityContext status=%x\n", status); 
     return CURLE_RECV_ERROR;
+  }
 
   size = type_3_buf.cbBuffer;
 
 --
 

