title: ONVIF Authentication Error?
body: <p>I am writing an API in C for authenticating user using ONVIF. I write some code to make authentication header. But when I sent these headers the server respond that "The security token could not be authenticated or authorized"</p>
  
  <pre><code>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*)&amp;nonce_int, nonceLen, noncestr);
  
    utcTime = time(NULL);
    timeInfo = localtime(&amp;utcTime);
    strftime(timestr, timeLen, "%Y-%m-%dT%H:%M:%SZ", timeInfo);
    printf("\nTime in String Format = %s", timestr);
  
    sprintf(sha1_input, "%d+%d+%s", nonce_int, utcTime, password);
  
    SHA1Reset(&amp;sha);
    SHA1Input(&amp;sha, (const unsigned char*)sha1_input, strlen(sha1_input));
  
    if(!SHA1Result(&amp;sha))
    {
      printf("\nERROR-- could not compute message digest");
    }
    else
    {
      memset(sha1_input, 0x00, sizeof(sha1_input));
      /*sprintf(sha1_input, "%X%X%X%X%X", sha.Message_Digest[0], sha.Message_Digest[1],
        sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]);*/
  
      sprintf(sha1_input, "%u%u%u%u%u", sha.Message_Digest[0], sha.Message_Digest[1],
        sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]);
  
      printf("\nSHA1 Digest = %s", sha1_input);
      encode_base64(strlen(sha1_input), sha1_input, digestLen, digeststr);
      printf("\nSHA1 Digest Base64 Encoded = %s", digeststr);
    }
  </code></pre>
  
  <p>after that I sent this request on HTTP using POST method this.</p>
  
  <p>Response:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
                      xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" 
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                      xmlns:wsa5="http://www.w3.org/2005/08/addressing" 
                      xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" 
                      xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
                      xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
                      xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
                      xmlns:ptzimg2="http://www.onvif.org/ver10/schema" 
                      xmlns:ptzimg3="http://www.w3.org/2005/05/xmlmime" 
                      xmlns:ptzimg4="http://docs.oasis-open.org/wsn/b-2" 
                      xmlns:ptzimg5="http://docs.oasis-open.org/wsrf/bf-2" 
                      xmlns:ptzimg6="http://docs.oasis-open.org/wsn/t-1" 
                      xmlns:ptzimg1="http://www.onvif.org/ver20/ptz/wsdl" 
                      xmlns:ptzimg7="http://www.onvif.org/ver20/imaging/wsdl" 
                      xmlns:ter="http://www.onvif.org/ver10/error"&gt;
  
      &lt;SOAP-ENV:Header&gt;&lt;/SOAP-ENV:Header&gt;
      &lt;SOAP-ENV:Body&gt;
          &lt;SOAP-ENV:Fault&gt;
              &lt;SOAP-ENV:Code&gt;
                  &lt;SOAP-ENV:Value&gt;
                      SOAP-ENV:Sender
                  &lt;/SOAP-ENV:Value&gt;
                  &lt;SOAP-ENV:Subcode&gt;
                      &lt;SOAP-ENV:Value&gt;
                          wsse:FailedAuthentication
                      &lt;/SOAP-ENV:Value&gt;
                  &lt;/SOAP-ENV:Subcode&gt;
              &lt;/SOAP-ENV:Code&gt;
              &lt;SOAP-ENV:Reason&gt;
                  &lt;SOAP-ENV:Text xml:lang="en"&gt;
                      The security token could not be authenticated or authorized
                  &lt;/SOAP-ENV:Text&gt;
              &lt;/SOAP-ENV:Reason&gt;
              &lt;SOAP-ENV:Node&gt;
                  http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver
              &lt;/SOAP-ENV:Node&gt;
              &lt;SOAP-ENV:Role&gt;
                  http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver
              &lt;/SOAP-ENV:Role&gt;
              &lt;SOAP-ENV:Detail&gt;&lt;/SOAP-ENV:Detail&gt;
          &lt;/SOAP-ENV:Fault&gt;
      &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>I synchronized the time. I think the problem is with my authentication headers. I did not find any useful documentation that specifies the exact data type and creation method for digest and other headers. any help will be appreciated. Thanks</p>