From 4fa88acbcbae619df5a8be08dd2c715088fb7565 Mon Sep 17 00:00:00 2001
From: Joel Depooter <joel.depooter@safe.com>
Date: Fri, 5 Jun 2015 12:12:12 -0700
Subject: [PATCH] schannel: Add support for optional client certificates

Some servers will request a client certificate, but not require one.
This change allows libcurl to connect to such servers when using
schannel as its ssl/tls backend. When a server requests a client
certificate, libcurl will now continue the handshake without one,
rather than terminating the handshake. The server can then decide
if that is acceptable or not. Prior to this change, libcurl would
terminate the handshake, reporting a SEC_I_INCOMPLETE_CREDENTIALS
error.
---
 lib/vtls/schannel.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c
index b02e42e..a551999 100644
--- a/lib/vtls/schannel.c
+++ b/lib/vtls/schannel.c
@@ -402,6 +402,16 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
       infof(data, "schannel: received incomplete message, need more data\n");
       return CURLE_OK;
     }
+    
+    /* If the server has requested a client certificate, attempt to continue
+       the handshake without one. This will allow connections to servers which
+       request a client certificate but do not require it. */
+    if(sspi_status == SEC_I_INCOMPLETE_CREDENTIALS) {
+       connssl->req_flags |= ISC_REQ_USE_SUPPLIED_CREDS;
+       connssl->connecting_state = ssl_connect_2_writing;
+       infof(data, "schannel: a client certificate has been requested\n");
+       return CURLE_OK;
+    }
 
     /* check if the handshake needs to be continued */
     if(sspi_status == SEC_I_CONTINUE_NEEDED || sspi_status == SEC_E_OK) {
-- 
1.9.4.msysgit.2

