From: Amos Jeffries Date: Wed, 31 Dec 2014 02:52:18 +0000 (-0800) Subject: libsspwin32: update to new base64 API X-Git-Tag: merge-candidate-3-v1~399 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dc09715c965c7e8eea7c57dccd34d06348275bb;p=thirdparty%2Fsquid.git libsspwin32: update to new base64 API --- diff --git a/lib/sspwin32.cc b/lib/sspwin32.cc index dd437beb08..b69c4ca6c1 100644 --- a/lib/sspwin32.cc +++ b/lib/sspwin32.cc @@ -462,7 +462,6 @@ const char * WINAPI SSP_MakeChallenge(PVOID PNegotiateBuf, int NegotiateLen) DWORD cbOut = 0; DWORD cbIn = 0; ntlm_challenge * challenge; - const char * encoded = NULL; if (NTLM_asServer.fHaveCtxtHandle) _DeleteSecurityContext(&NTLM_asServer.hctxt); @@ -490,9 +489,17 @@ const char * WINAPI SSP_MakeChallenge(PVOID PNegotiateBuf, int NegotiateLen) challenge = (ntlm_challenge *) fResult; Use_Unicode = NTLM_NEGOTIATE_UNICODE & challenge->flags; NTLM_LocalCall = NTLM_NEGOTIATE_THIS_IS_LOCAL_CALL & challenge->flags; - encoded = base64_encode_bin((char *) fResult, cbOut); + struct base64_encode_ctx ctx; + base64_encode_init(&ctx); + static uint8_t encoded[8192]; + size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast(fResult)); + assert(dstLen < sizeof(encoded)); + dstLen += base64_encode_final(&ctx, encoded+dstLen); + assert(dstLen < sizeof(encoded)); + encoded[dstLen] = '\0'; + return reinterpret_cast(encoded); } - return encoded; + return NULL; } BOOL WINAPI SSP_ValidateNTLMCredentials(PVOID PAutenticateBuf, int AutenticateLen, char * credentials) @@ -524,7 +531,6 @@ const char * WINAPI SSP_MakeNegotiateBlob(PVOID PNegotiateBuf, int NegotiateLen, { DWORD cbOut = 0; DWORD cbIn = 0; - const char * encoded = NULL; if (NTLM_asServer.fHaveCtxtHandle) _DeleteSecurityContext(&NTLM_asServer.hctxt); @@ -548,16 +554,24 @@ const char * WINAPI SSP_MakeNegotiateBlob(PVOID PNegotiateBuf, int NegotiateLen, } *Status = SSP_OK; } while (0); - if (pServerBuf != NULL && cbOut > 0) - encoded = base64_encode_bin((char *) pServerBuf, cbOut); - return encoded; + if (pServerBuf != NULL && cbOut > 0) { + struct base64_encode_ctx ctx; + base64_encode_init(&ctx); + static uint8_t encoded[8192]; + size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast(pServerBuf)); + assert(dstLen < sizeof(encoded)); + dstLen += base64_encode_final(&ctx, encoded+dstLen); + assert(dstLen < sizeof(encoded)); + encoded[dstLen] = '\0'; + return reinterpret_cast(encoded); + } + return NULL; } const char * WINAPI SSP_ValidateNegotiateCredentials(PVOID PAutenticateBuf, int AutenticateLen, PBOOL fDone, int * Status, char * credentials) { DWORD cbOut = 0; DWORD cbIn = 0; - const char * encoded = NULL; memcpy(pClientBuf, PAutenticateBuf, AutenticateLen); ZeroMemory(pServerBuf, cbMaxToken); @@ -575,8 +589,17 @@ const char * WINAPI SSP_ValidateNegotiateCredentials(PVOID PAutenticateBuf, int } *Status = SSP_OK; } while (0); - if (pServerBuf != NULL && cbOut > 0) - encoded = base64_encode_bin((char *) pServerBuf, cbOut); - return encoded; + if (pServerBuf != NULL && cbOut > 0) { + struct base64_encode_ctx ctx; + base64_encode_init(&ctx); + static uint8_t encoded[8192]; + size_t dstLen = base64_encode_update(&ctx, encoded, cbOut, reinterpret_cast(pServerBuf)); + assert(dstLen < sizeof(encoded)); + dstLen += base64_encode_final(&ctx, encoded+dstLen); + assert(dstLen < sizeof(encoded)); + encoded[dstLen] = '\0'; + return reinterpret_cast(encoded); + } + return NULL; }