More changes to resolve issues brought up during the security
review of the code.
This commit is contained in:
@@ -43,7 +43,7 @@ AuthTokenIf_GetAuthToken(
|
||||
IN const char *pHostName,
|
||||
IN void *pCredStoreScope,
|
||||
INOUT char *pTokenBuf,
|
||||
INOUT int *pTokenBufLen)
|
||||
INOUT uint32_t *pTokenBufLen)
|
||||
//
|
||||
// Arguments:
|
||||
// pIfInstance -
|
||||
@@ -131,6 +131,9 @@ AuthTokenIf_GetAuthToken(
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- Memory allocation failure\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_INSUFFICIENT_RESOURCES);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@@ -180,40 +183,55 @@ AuthTokenIf_GetAuthToken(
|
||||
&expiry);
|
||||
if (secStatus == SEC_E_OK)
|
||||
{
|
||||
char *pEncodedToken;
|
||||
int encodedTokenLen;
|
||||
|
||||
// The security context was initialized, now return it to the caller after base64 encoding it.
|
||||
retStatus = EncodeData(sendTok.pvBuffer,
|
||||
(const int) sendTok.cbBuffer,
|
||||
&pEncodedToken,
|
||||
&encodedTokenLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
// Make sure that the token is not too large
|
||||
if (sendTok.cbBuffer <= UINT32_MAX)
|
||||
{
|
||||
// Verify that the caller provided a buffer that is big enough
|
||||
if (encodedTokenLen > *pTokenBufLen)
|
||||
uint32_t encodedTokenLen;
|
||||
char *pEncodedToken;
|
||||
|
||||
// The security context was initialized, now return it to the caller after base64 encoding it.
|
||||
retStatus = EncodeData(sendTok.pvBuffer,
|
||||
(const uint32_t) sendTok.cbBuffer,
|
||||
&pEncodedToken,
|
||||
&encodedTokenLen);
|
||||
if (CASA_SUCCESS(retStatus))
|
||||
{
|
||||
// The buffer is not big enough
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_BUFFER_OVERFLOW);
|
||||
// Verify that the caller provided a buffer that is big enough
|
||||
if (encodedTokenLen > *pTokenBufLen)
|
||||
{
|
||||
// The buffer is not big enough
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_BUFFER_OVERFLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The buffer provided is large enough, copy the data.
|
||||
memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Return the actual size or the size required
|
||||
*pTokenBufLen = encodedTokenLen;
|
||||
|
||||
// Free the buffer containing the encoded token after clearing
|
||||
// its memory to avoid leaking sensitive information.
|
||||
memset(pEncodedToken, 0, strlen(pEncodedToken));
|
||||
free(pEncodedToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The buffer provided is large enough, copy the data.
|
||||
memcpy((void*) pTokenBuf, pEncodedToken, encodedTokenLen);
|
||||
|
||||
// Success
|
||||
retStatus = CASA_STATUS_SUCCESS;
|
||||
DbgTrace(1, "-AuthTokenIf_GetAuthToken- Encoding failed\n", 0);
|
||||
}
|
||||
|
||||
// Return the actual size or the size required
|
||||
*pTokenBufLen = encodedTokenLen;
|
||||
|
||||
// Free the buffer containing the encoded token after clearing
|
||||
// its memory to avoid leaking sensitive information.
|
||||
memset(pEncodedToken, 0, strlen(pEncodedToken));
|
||||
free(pEncodedToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
DbgTrace(0, "-AuthTokenIf_GetAuthToken- GSS Token too large\n", 0);
|
||||
retStatus = CasaStatusBuild(CASA_SEVERITY_ERROR,
|
||||
CASA_FACILITY_KRB5TOKEN,
|
||||
CASA_STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
// Delete the security context
|
||||
|
||||
Reference in New Issue
Block a user