Skip to content

Commit

Permalink
Hash code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhamturakhia committed Apr 22, 2021
1 parent 579d7b4 commit d330130
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions aws_protocol_adaptor/device_client/aws_nvmsgbroker.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,15 @@ bool is_valid_connection_str(char *connection_str)
char *generate_sha256_hash(char *output_str, char *str)
{
unsigned char hashval[SHA256_DIGEST_LENGTH];
int len = SHA256_DIGEST_LENGTH * 2 + 1;
char res[len];
strcpy(res, output_str);
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str, strlen(str));
SHA256_Final(hashval, &sha256);
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
sprintf(res + (i * 2), "%02x", hashval[i]);
sprintf(output_str + (i * 2), "%02x", hashval[i]);

This comment has been minimized.

Copy link
@lummish

lummish Apr 22, 2021

@Shubhamturakhia This logic looks good, but I'm seeing from the API documentation that the connection signature uses the contents of the configuration file as well; the hash needs to reflect all configuration parameters used to create the connection, so we should also hash the configuration file.

We'll need to add in some calls to SHA256_Update to ensure that the contents of the resultant hash incorporate the configuration file as well as the connection string. See here for reference.

}
return res;
return output_str;
}

NvDsMsgApiErrorType nvds_msgapi_connection_signature(char *broker_str, char *cfg, char *output_str, int max_len)
Expand Down

0 comments on commit d330130

Please sign in to comment.