summaryrefslogtreecommitdiff
path: root/lib/http_ntlm.c
diff options
context:
space:
mode:
authorPatrick Monnerat <patrick@monnerat.net>2021-03-17 20:09:55 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-04-22 09:06:07 +0200
commit19ea52da4df3c3ebc399ae25e705c7a8b5d45d95 (patch)
treea24d58a91383624c6fefb1295829b1e3b284feb7 /lib/http_ntlm.c
parent34cf40321c3cfa5160e34a87a816b7c6030c0296 (diff)
downloadcurl-19ea52da4df3c3ebc399ae25e705c7a8b5d45d95.tar.gz
vauth: factor base64 conversions out of authentication procedures
Input challenges and returned messages are now in binary. Conversions from/to base64 are performed by callers (currently curl_sasl.c and http_ntlm.c). Closes #6654
Diffstat (limited to 'lib/http_ntlm.c')
-rw-r--r--lib/http_ntlm.c86
1 files changed, 51 insertions, 35 deletions
diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c
index 4fa38f0b0..4d082aed3 100644
--- a/lib/http_ntlm.c
+++ b/lib/http_ntlm.c
@@ -39,6 +39,7 @@
#include "http_ntlm.h"
#include "curl_ntlm_core.h"
#include "curl_ntlm_wb.h"
+#include "curl_base64.h"
#include "vauth/vauth.h"
#include "url.h"
@@ -80,7 +81,18 @@ CURLcode Curl_input_ntlm(struct Curl_easy *data,
header++;
if(*header) {
- result = Curl_auth_decode_ntlm_type2_message(data, header, ntlm);
+ unsigned char *hdr;
+ size_t hdrlen;
+
+ result = Curl_base64_decode(header, &hdr, &hdrlen);
+ if(!result) {
+ struct bufref hdrbuf;
+
+ Curl_bufref_init(&hdrbuf);
+ Curl_bufref_set(&hdrbuf, hdr, hdrlen, curl_free);
+ result = Curl_auth_decode_ntlm_type2_message(data, &hdrbuf, ntlm);
+ Curl_bufref_free(&hdrbuf);
+ }
if(result)
return result;
@@ -116,7 +128,8 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
{
char *base64 = NULL;
size_t len = 0;
- CURLcode result;
+ CURLcode result = CURLE_OK;
+ struct bufref ntlmmsg;
/* 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 */
@@ -184,50 +197,52 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
#endif
#endif
+ Curl_bufref_init(&ntlmmsg);
switch(*state) {
case NTLMSTATE_TYPE1:
default: /* for the weird cases we (re)start here */
/* Create a type-1 message */
result = Curl_auth_create_ntlm_type1_message(data, userp, passwdp,
service, hostname,
- ntlm, &base64,
- &len);
- if(result)
- return result;
-
- if(base64) {
- free(*allocuserpwd);
- *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
- proxy ? "Proxy-" : "",
- base64);
- free(base64);
- if(!*allocuserpwd)
- return CURLE_OUT_OF_MEMORY;
-
- DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
+ ntlm, &ntlmmsg);
+ if(!result) {
+ DEBUGASSERT(Curl_bufref_len(&ntlmmsg) != 0);
+ result = Curl_base64_encode(data,
+ (const char *) Curl_bufref_ptr(&ntlmmsg),
+ Curl_bufref_len(&ntlmmsg), &base64, &len);
+ if(!result) {
+ free(*allocuserpwd);
+ *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
+ proxy ? "Proxy-" : "",
+ base64);
+ free(base64);
+ if(!*allocuserpwd)
+ result = CURLE_OUT_OF_MEMORY;
+ }
}
break;
case NTLMSTATE_TYPE2:
/* We already received the type-2 message, create a type-3 message */
result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp,
- ntlm, &base64, &len);
- if(result)
- return result;
-
- if(base64) {
- free(*allocuserpwd);
- *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
- proxy ? "Proxy-" : "",
- base64);
- free(base64);
- if(!*allocuserpwd)
- return CURLE_OUT_OF_MEMORY;
-
- DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
-
- *state = NTLMSTATE_TYPE3; /* we send a type-3 */
- authp->done = TRUE;
+ ntlm, &ntlmmsg);
+ if(!result && Curl_bufref_len(&ntlmmsg)) {
+ result = Curl_base64_encode(data,
+ (const char *) Curl_bufref_ptr(&ntlmmsg),
+ Curl_bufref_len(&ntlmmsg), &base64, &len);
+ if(!result) {
+ free(*allocuserpwd);
+ *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
+ proxy ? "Proxy-" : "",
+ base64);
+ free(base64);
+ if(!*allocuserpwd)
+ result = CURLE_OUT_OF_MEMORY;
+ else {
+ *state = NTLMSTATE_TYPE3; /* we send a type-3 */
+ authp->done = TRUE;
+ }
+ }
}
break;
@@ -241,8 +256,9 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
authp->done = TRUE;
break;
}
+ Curl_bufref_free(&ntlmmsg);
- return CURLE_OK;
+ return result;
}
void Curl_http_auth_cleanup_ntlm(struct connectdata *conn)