mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
http NTLM: refactoring followup
Output of Curl_ntlm_create_type1_message() and Curl_ntlm_create_type3_message() functions is now already base64 encoded.
This commit is contained in:
parent
f5ad192d23
commit
d535cff775
@ -684,28 +684,25 @@ static void unicodecpy(unsigned char *dest,
|
|||||||
/*
|
/*
|
||||||
* Curl_ntlm_create_type1_message()
|
* Curl_ntlm_create_type1_message()
|
||||||
*
|
*
|
||||||
* This is used to generate a ntlm type-1 message ready for encoding
|
* This is used to generate an already encoded NTLM type-1 message ready
|
||||||
* and sending to the recipient, be it a: HTTP, SMTP or POP3 server,
|
* for sending to the recipient, be it a: HTTP, SMTP or POP3 server,
|
||||||
* using the appropriate compile time crypo API.
|
* using the appropriate compile time crypo API.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
*
|
*
|
||||||
* userp [in] - The user name in the format User or Domain\User.
|
* userp [in] - The user name in the format User or Domain\User.
|
||||||
* passdwp [in] - The user's password.
|
* passdwp [in] - The user's password.
|
||||||
* ntlm [in] - The ntlm data struct being used and modified.
|
* ntlm [in/out] - The ntlm data struct being used and modified.
|
||||||
* ntlmbuf [in] - Pointer to preallocated buffer to receive message.
|
* outptr [in/out] - The adress where a pointer to newly allocated memory
|
||||||
* sizep [out] - Size of message written into output buffer.
|
* holding the result will be stored upon completion.
|
||||||
*
|
*
|
||||||
* Returns CURLE_OK on success.
|
* Returns CURLE_OK on success.
|
||||||
*/
|
*/
|
||||||
CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
||||||
const char *passwdp,
|
const char *passwdp,
|
||||||
struct ntlmdata *ntlm,
|
struct ntlmdata *ntlm,
|
||||||
unsigned char *ntlmbuf,
|
char **outptr)
|
||||||
size_t *sizep)
|
|
||||||
{
|
{
|
||||||
size_t size;
|
|
||||||
|
|
||||||
/* NTLM type-1 message structure:
|
/* NTLM type-1 message structure:
|
||||||
|
|
||||||
Index Description Content
|
Index Description Content
|
||||||
@ -720,6 +717,10 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
|||||||
(*) -> Optional
|
(*) -> Optional
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
unsigned char ntlmbuf[NTLM_BUFSIZE];
|
||||||
|
size_t base64_sz = 0;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_SSPI
|
#ifdef USE_WINDOWS_SSPI
|
||||||
|
|
||||||
SecBuffer buf;
|
SecBuffer buf;
|
||||||
@ -895,17 +896,15 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
|||||||
fprintf(stderr, "\n****\n");
|
fprintf(stderr, "\n****\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Return the message size */
|
/* Return with binary blob encoded into base64 */
|
||||||
*sizep = size;
|
return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, &base64_sz);
|
||||||
|
|
||||||
return CURLE_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Curl_ntlm_create_type3_message()
|
* Curl_ntlm_create_type3_message()
|
||||||
*
|
*
|
||||||
* This is used to generate a ntlm type-3 message ready for encoding
|
* This is used to generate an already encoded NTLM type-3 message ready
|
||||||
* and sending to the recipient, be it a: HTTP, SMTP or POP3 server,
|
* for sending to the recipient, be it a: HTTP, SMTP or POP3 server,
|
||||||
* using the appropriate compile time crypo API.
|
* using the appropriate compile time crypo API.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
@ -913,9 +912,9 @@ CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
|||||||
* data [in] - The session handle.
|
* data [in] - The session handle.
|
||||||
* userp [in] - The user name in the format User or Domain\User.
|
* userp [in] - The user name in the format User or Domain\User.
|
||||||
* passdwp [in] - The user's password.
|
* passdwp [in] - The user's password.
|
||||||
* ntlm [in] - The ntlm data struct being used and modified.
|
* ntlm [in/out] - The ntlm data struct being used and modified.
|
||||||
* ntlmbuf [in] - Pointer to preallocated buffer to receive message.
|
* outptr [in/out] - The adress where a pointer to newly allocated memory
|
||||||
* sizep [out] - Size of message written into output buffer.
|
* holding the result will be stored upon completion.
|
||||||
*
|
*
|
||||||
* Returns CURLE_OK on success.
|
* Returns CURLE_OK on success.
|
||||||
*/
|
*/
|
||||||
@ -923,8 +922,7 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data,
|
|||||||
const char *userp,
|
const char *userp,
|
||||||
const char *passwdp,
|
const char *passwdp,
|
||||||
struct ntlmdata *ntlm,
|
struct ntlmdata *ntlm,
|
||||||
unsigned char *ntlmbuf,
|
char **outptr)
|
||||||
size_t *sizep)
|
|
||||||
{
|
{
|
||||||
/* NTLM type-3 message structure:
|
/* NTLM type-3 message structure:
|
||||||
|
|
||||||
@ -944,7 +942,8 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data,
|
|||||||
(*) -> Optional
|
(*) -> Optional
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
unsigned char ntlmbuf[NTLM_BUFSIZE];
|
||||||
|
size_t base64_sz = 0;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_SSPI
|
#ifdef USE_WINDOWS_SSPI
|
||||||
@ -1294,10 +1293,8 @@ CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data,
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Return the message size */
|
/* Return with binary blob encoded into base64 */
|
||||||
*sizep = size;
|
return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, &base64_sz);
|
||||||
|
|
||||||
return CURLE_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* USE_NTLM */
|
#endif /* USE_NTLM */
|
||||||
|
@ -24,22 +24,20 @@
|
|||||||
|
|
||||||
#ifdef USE_NTLM
|
#ifdef USE_NTLM
|
||||||
|
|
||||||
/* This is to generate a ntlm type-1 message */
|
/* This is to generate a base64 encoded NTLM type-1 message */
|
||||||
CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
CURLcode Curl_ntlm_create_type1_message(const char *userp,
|
||||||
const char *passwdp,
|
const char *passwdp,
|
||||||
struct ntlmdata *ntlm,
|
struct ntlmdata *ntlm,
|
||||||
unsigned char *ntlmbuf,
|
char **outptr);
|
||||||
size_t *size);
|
|
||||||
|
|
||||||
/* This is to generate a ntlm type-3 message */
|
/* This is to generate a base64 encoded NTLM type-3 message */
|
||||||
CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data,
|
CURLcode Curl_ntlm_create_type3_message(struct SessionHandle *data,
|
||||||
const char *userp,
|
const char *userp,
|
||||||
const char *passwdp,
|
const char *passwdp,
|
||||||
struct ntlmdata *ntlm,
|
struct ntlmdata *ntlm,
|
||||||
unsigned char *ntlmbuf,
|
char **outptr);
|
||||||
size_t *size);
|
|
||||||
|
|
||||||
/* This is to decode a ntlm type-2 message */
|
/* This is to decode a NTLM type-2 message */
|
||||||
CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
|
CURLcode Curl_ntlm_decode_type2_message(struct SessionHandle *data,
|
||||||
const char* header,
|
const char* header,
|
||||||
struct ntlmdata* ntlm);
|
struct ntlmdata* ntlm);
|
||||||
|
@ -453,13 +453,10 @@ CURLcode Curl_output_ntlm_sso(struct connectdata *conn,
|
|||||||
CURLcode Curl_output_ntlm(struct connectdata *conn,
|
CURLcode Curl_output_ntlm(struct connectdata *conn,
|
||||||
bool proxy)
|
bool proxy)
|
||||||
{
|
{
|
||||||
size_t size = 0;
|
|
||||||
char *base64 = NULL;
|
char *base64 = NULL;
|
||||||
size_t base64_sz = 0;
|
|
||||||
unsigned char ntlmbuf[NTLM_BUFSIZE];
|
|
||||||
CURLcode error;
|
CURLcode error;
|
||||||
|
|
||||||
/* point to the address of the pointer that holds the string to sent to the
|
/* point to the address of the pointer that holds the string to send to the
|
||||||
server, which is for a plain host or for a HTTP proxy */
|
server, which is for a plain host or for a HTTP proxy */
|
||||||
char **allocuserpwd;
|
char **allocuserpwd;
|
||||||
|
|
||||||
@ -514,22 +511,12 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
|
|||||||
switch(ntlm->state) {
|
switch(ntlm->state) {
|
||||||
case NTLMSTATE_TYPE1:
|
case NTLMSTATE_TYPE1:
|
||||||
default: /* for the weird cases we (re)start here */
|
default: /* for the weird cases we (re)start here */
|
||||||
|
|
||||||
/* Create a type-1 message */
|
/* Create a type-1 message */
|
||||||
|
error = Curl_ntlm_create_type1_message(userp, passwdp, ntlm, &base64);
|
||||||
error = Curl_ntlm_create_type1_message(userp, passwdp,
|
|
||||||
ntlm, ntlmbuf, &size);
|
|
||||||
if(error)
|
if(error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if(size > 0) {
|
if(base64) {
|
||||||
/* convert the binary blob into base64 */
|
|
||||||
error = Curl_base64_encode(NULL, (char *)ntlmbuf, size,
|
|
||||||
&base64, &base64_sz);
|
|
||||||
if(error)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
if(base64_sz > 0) {
|
|
||||||
Curl_safefree(*allocuserpwd);
|
Curl_safefree(*allocuserpwd);
|
||||||
*allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
|
*allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
|
||||||
proxy ? "Proxy-" : "",
|
proxy ? "Proxy-" : "",
|
||||||
@ -537,26 +524,16 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
|
|||||||
DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
|
DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
|
||||||
free(base64);
|
free(base64);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NTLMSTATE_TYPE2:
|
case NTLMSTATE_TYPE2:
|
||||||
/* We already received the type-2 message, create a type-3 message */
|
/* We already received the type-2 message, create a type-3 message */
|
||||||
|
|
||||||
error = Curl_ntlm_create_type3_message(conn->data, userp, passwdp,
|
error = Curl_ntlm_create_type3_message(conn->data, userp, passwdp,
|
||||||
ntlm, ntlmbuf, &size);
|
ntlm, &base64);
|
||||||
if(error)
|
if(error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if(size > 0) {
|
if(base64) {
|
||||||
/* convert the binary blob into base64 */
|
|
||||||
error = Curl_base64_encode(NULL, (char *)ntlmbuf, size,
|
|
||||||
&base64, &base64_sz);
|
|
||||||
if(error)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
if(base64_sz > 0) {
|
|
||||||
Curl_safefree(*allocuserpwd);
|
Curl_safefree(*allocuserpwd);
|
||||||
*allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
|
*allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
|
||||||
proxy ? "Proxy-" : "",
|
proxy ? "Proxy-" : "",
|
||||||
@ -564,11 +541,9 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
|
|||||||
DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
|
DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
|
||||||
free(base64);
|
free(base64);
|
||||||
|
|
||||||
ntlm->state = NTLMSTATE_TYPE3; /* we sent a type-3 */
|
ntlm->state = NTLMSTATE_TYPE3; /* we send a type-3 */
|
||||||
authp->done = TRUE;
|
authp->done = TRUE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NTLMSTATE_TYPE3:
|
case NTLMSTATE_TYPE3:
|
||||||
|
Loading…
Reference in New Issue
Block a user