mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-12-07 10:41:34 +03:00
Refactor Base64 functions, encode/decode using OpenSSL's EVP interface
Our own implementation works fine, however we should use OpenSSL's one since we already link to the library. Base64Decode() and Base64Encode() return the required buffer size when "dst" is NULL. This allows to efficiently allocate a buffer, without wasting memory or risking an overflow. Base64FromBin() and Base64ToBin() perform all steps, returning a heap-allocated buffer with the data in it.
This commit is contained in:
@ -939,30 +939,26 @@ bool HttpParseBasicAuthHeader(HTTP_HEADER *h, char *username, UINT username_size
|
||||
{
|
||||
if (StrCmpi(key, "Basic") == 0 && IsEmptyStr(value) == false)
|
||||
{
|
||||
UINT b64_dest_size = StrSize(value) * 2 + 256;
|
||||
char *b64_dest = ZeroMalloc(b64_dest_size);
|
||||
|
||||
Decode64(b64_dest, value);
|
||||
|
||||
if (IsEmptyStr(b64_dest) == false)
|
||||
char *str = Base64ToBin(NULL, value, StrLen(value));
|
||||
if (str != NULL)
|
||||
{
|
||||
if (b64_dest[0] == ':')
|
||||
if (str[0] == ':')
|
||||
{
|
||||
// Empty username
|
||||
StrCpy(username, username_size, "");
|
||||
StrCpy(password, password_size, b64_dest + 1);
|
||||
StrCpy(password, password_size, str + 1);
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetKeyAndValue(b64_dest, username, username_size, password, password_size, ":"))
|
||||
if (GetKeyAndValue(str, username, username_size, password, password_size, ":"))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Free(b64_dest);
|
||||
Free(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user