Skip to content

Commit

Permalink
Better validation/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bretambrose committed Dec 13, 2023
1 parent b220512 commit f8daf8f
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions source/iot/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,10 @@ namespace Aws
{
usernameString = AddToUsernameParameter(usernameString, authorizerName, "x-amz-customauthorizer-name=");
}
if (!authorizerSignature.empty())

if (!authorizerSignature.empty() || !tokenKeyName.empty() || !tokenValue.empty())
{
if (tokenKeyName.empty() || tokenValue.empty())
if (authorizerSignature.empty() || tokenKeyName.empty() || tokenValue.empty())
{
AWS_LOGF_WARN(
AWS_LS_MQTT_CLIENT,
Expand All @@ -382,7 +383,10 @@ namespace Aws
"signed custom authorizer.",
(void *)this);
}
}

if (!authorizerSignature.empty())
{
Crt::String encodedSignature;
if (authorizerSignature.find('%') != authorizerSignature.npos)
{
Expand All @@ -398,17 +402,9 @@ namespace Aws
usernameString =
AddToUsernameParameter(usernameString, encodedSignature, "x-amz-customauthorizer-signature=");
}
if (!tokenKeyName.empty() || !tokenValue.empty())

if (!tokenKeyName.empty() && !tokenValue.empty())
{
if (tokenKeyName.empty() || tokenValue.empty())
{
AWS_LOGF_ERROR(
AWS_LS_MQTT_CLIENT,
"id=%p: Token-based custom authentication requires all token-related properties to be set",
(void *)this);
m_lastError = AWS_ERROR_INVALID_ARGUMENT;
return *this;
}
usernameString = AddToUsernameParameter(usernameString, tokenValue, tokenKeyName + "=");
}

Expand Down

0 comments on commit f8daf8f

Please sign in to comment.