From 886f45584ca2ce2641e46c19ffdd5a49104b821a Mon Sep 17 00:00:00 2001 From: Viktor Ivanov Date: Tue, 13 May 2014 15:14:08 +0300 Subject: [PATCH] Fix bug with xmpp chat not connecting The facebook suddenly stopped connecting on my dev machine. I still cannot explain what caused this change in behaviour, but I was finally able to diagnose and fix the problem. Chat was not connecting due to an error in tls_start. The windows function InitializeSecurityContext was returning a SEC_E_INCOMPLETE_MESSAGE status which was being treated as an error. However, the documentation states that this is not an error. This status simply indicates that more data needs to be read. This commit does precisely that -- when SEC_E_INCOMPLETE_MESSAGE we read more data from the socket and call InitializeSecurityContext again. --- src/tls_schannel.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tls_schannel.c b/src/tls_schannel.c index b63d2ac..e6aea18 100644 --- a/src/tls_schannel.c +++ b/src/tls_schannel.c @@ -255,10 +255,18 @@ int tls_start(tls_t *tls) NULL, 0, &(tls->hctxt), &sbdout, &ctxtattr, NULL); + unsigned char *p = sbin[0].pvBuffer; + int len = 0; + while (ret == SEC_I_CONTINUE_NEEDED - || ret == SEC_I_INCOMPLETE_CREDENTIALS) { - unsigned char *p = sbin[0].pvBuffer; - int len = 0, inbytes = 0; + || ret == SEC_I_INCOMPLETE_CREDENTIALS + || ret == SEC_E_INCOMPLETE_MESSAGE) { + int inbytes = 0; + + if (ret != SEC_E_INCOMPLETE_MESSAGE) { + len = 0; + p = sbin[0].pvBuffer; + } if (sbdout.pBuffers[0].cbBuffer) { unsigned char *writebuff = sbdout.pBuffers[0].pvBuffer;