I am writing an API for ONVIF authentication in C. I create WS-UsernameToken, But it is not working. Is there any problem with this WS-UsernameToken.
unsigned int nonce_int = 0, i = 0;
time_t utcTime = 0;
struct tm *timeInfo = NULL;
char sha1_input[100] = { 0 };
SHA1Context sha = { 0 };
nonce_int = GetRandomNumber();
encode_base64(sizeof(nonce_int), (char*)&nonce_int, nonceLen, noncestr);
utcTime = time(NULL);
timeInfo = localtime(&utcTime);
strftime(timestr, timeLen, "%Y-%m-%dT%H:%M:%SZ", timeInfo);
sprintf(sha1_input, "%d%s%s", nonce_int, timestr, password);
SHA1Reset(&sha);
SHA1Input(&sha, (const unsigned char*)sha1_input, strlen(sha1_input));
if(!SHA1Result(&sha))
{
printf("\nERROR-- could not compute message digest");
}
else
{
int i = 0;
memset(sha1_input, 0x00, sizeof(sha1_input));
for(i = 0; i < 5; i++)
{
sha.Message_Digest[i] = ntohl(sha.Message_Digest[i]);
}
encode_base64(sizeof(sha.Message_Digest), (unsigned char*)sha.Message_Digest, digestLen, digeststr);
}
return 0;
But when I use these values and send ONVIF request. It replies that "The security token could not be authenticated or authorized". I was wondering where I am making mistakes.Thanks
I figured out the problem. I was using local time string rather than utc time string. this solved my problem. thanks