Skip to content

Commit

Permalink
ntlm: Moved the SSPI based Type-2 message decoding into the SASL module
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-caveman2k committed Nov 16, 2014
1 parent 201d0df commit a3fead9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
14 changes: 2 additions & 12 deletions lib/curl_ntlm_msgs.c
Expand Up @@ -217,8 +217,6 @@ CURLcode Curl_ntlm_decode_type2_target(struct SessionHandle *data,
return CURLE_OK;
}

#endif

/*
NTLM message structure notes:
Expand Down Expand Up @@ -256,9 +254,7 @@ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
const char *header,
struct ntlmdata *ntlm)
{
#ifndef USE_WINDOWS_SSPI
static const char type2_marker[] = { 0x02, 0x00, 0x00, 0x00 };
#endif

/* NTLM type-2 message structure:
Expand All @@ -280,7 +276,7 @@ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
unsigned char *type2 = NULL;
size_t type2_len = 0;

#if defined(CURL_DISABLE_VERBOSE_STRINGS) || defined(USE_WINDOWS_SSPI)
#if defined(CURL_DISABLE_VERBOSE_STRINGS)
(void)data;
#endif

Expand All @@ -297,10 +293,6 @@ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
return CURLE_BAD_CONTENT_ENCODING;
}

#ifdef USE_WINDOWS_SSPI
ntlm->input_token = type2;
ntlm->input_token_len = type2_len;
#else
ntlm->flags = 0;

if((type2_len < 32) ||
Expand Down Expand Up @@ -334,12 +326,10 @@ CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
});

free(type2);
#endif

return result;
}

#ifndef USE_WINDOWS_SSPI
/* copy the source to the destination and fill in zeroes in every
other destination byte! */
static void unicodecpy(unsigned char *dest, const char *src, size_t length)
Expand All @@ -350,7 +340,6 @@ static void unicodecpy(unsigned char *dest, const char *src, size_t length)
dest[2 * i + 1] = '\0';
}
}
#endif

/*
* Curl_ntlm_create_type1_message()
Expand Down Expand Up @@ -472,6 +461,7 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
/* Return with binary blob encoded into base64 */
return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, outlen);
}
#endif

/*
* Curl_ntlm_create_type3_message()
Expand Down
25 changes: 24 additions & 1 deletion lib/curl_sasl_sspi.c
Expand Up @@ -39,6 +39,7 @@
#include "curl_memory.h"
#include "curl_multibyte.h"
#include "curl_ntlm_msgs.h"
#include "sendf.h"
#include "strdup.h"

#define _MPRINTF_REPLACE /* use our functions only */
Expand Down Expand Up @@ -616,7 +617,29 @@ CURLcode Curl_sasl_decode_ntlm_type2_message(struct SessionHandle *data,
const char *type2msg,
struct ntlmdata *ntlm)
{
return Curl_ntlm_decode_type2_message(data, type2msg, ntlm);
CURLcode result = CURLE_OK;
unsigned char *type2 = NULL;
size_t type2_len = 0;

/* Decode the base-64 encoded type-2 message */
if(strlen(type2msg) && *type2msg != '=') {
result = Curl_base64_decode(type2msg, &type2, &type2_len);
if(result)
return result;
}

/* Ensure we have a valid type-2 message */
if(!type2) {
infof(data, "NTLM handshake failure (empty type-2 message)\n");

return CURLE_BAD_CONTENT_ENCODING;
}

/* Simply store the challenge for use later */
ntlm->input_token = type2;
ntlm->input_token_len = type2_len;

return result;
}

/*
Expand Down

0 comments on commit a3fead9

Please sign in to comment.