]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
libsspwin32: update to new base64 API
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 31 Dec 2014 02:52:18 +0000 (18:52 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 31 Dec 2014 02:52:18 +0000 (18:52 -0800)
lib/sspwin32.cc

index dd437beb08639e9c04c80649da1bc778a727f288..b69c4ca6c1b265b5339304d380d9450873f440e5 100644 (file)
@@ -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<const uint8_t*>(fResult));
+        assert(dstLen < sizeof(encoded));
+        dstLen += base64_encode_final(&ctx, encoded+dstLen);
+        assert(dstLen < sizeof(encoded));
+        encoded[dstLen] = '\0';
+        return reinterpret_cast<char *>(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<const uint8_t*>(pServerBuf));
+        assert(dstLen < sizeof(encoded));
+        dstLen += base64_encode_final(&ctx, encoded+dstLen);
+        assert(dstLen < sizeof(encoded));
+        encoded[dstLen] = '\0';
+        return reinterpret_cast<char *>(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<const uint8_t*>(pServerBuf));
+        assert(dstLen < sizeof(encoded));
+        dstLen += base64_encode_final(&ctx, encoded+dstLen);
+        assert(dstLen < sizeof(encoded));
+        encoded[dstLen] = '\0';
+        return reinterpret_cast<char *>(encoded);
+    }
+    return NULL;
 }