[英]ONVIF Authentication Error?
我正在用C編寫API以使用ONVIF對用戶進行身份驗證。 我編寫一些代碼來制作身份驗證標頭。 但是,當我發送這些標頭時,服務器響應“無法驗證或授權安全令牌”
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);
printf("\nTime in String Format = %s", timestr);
sprintf(sha1_input, "%d+%d+%s", nonce_int, utcTime, password);
SHA1Reset(&sha);
SHA1Input(&sha, (const unsigned char*)sha1_input, strlen(sha1_input));
if(!SHA1Result(&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);
}
之后,我使用POST方法this在HTTP上發送了此請求。
響應:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<SOAP-ENV:Header></SOAP-ENV:Header>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:Code>
<SOAP-ENV:Value>
SOAP-ENV:Sender
</SOAP-ENV:Value>
<SOAP-ENV:Subcode>
<SOAP-ENV:Value>
wsse:FailedAuthentication
</SOAP-ENV:Value>
</SOAP-ENV:Subcode>
</SOAP-ENV:Code>
<SOAP-ENV:Reason>
<SOAP-ENV:Text xml:lang="en">
The security token could not be authenticated or authorized
</SOAP-ENV:Text>
</SOAP-ENV:Reason>
<SOAP-ENV:Node>
http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver
</SOAP-ENV:Node>
<SOAP-ENV:Role>
http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver
</SOAP-ENV:Role>
<SOAP-ENV:Detail></SOAP-ENV:Detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我同步了時間。 我認為問題出在我的身份驗證標頭上。 我找不到任何有用的文檔來指定摘要和其他標頭的確切數據類型和創建方法。 任何幫助將不勝感激。 謝謝
我假設您正在使用ONVIF核心規范 。 看起來它指定使用HTTP摘要式身份驗證 ,這是HTTP級別上的標准身份驗證方法。 您也許可以在某個地方找到該版本的某些C / C ++版本,以檢查其邏輯。
我建議的另一件事是使用Wireshark。 這將准確告訴您在HTTP和SOAP級別發生了什么。 例如,如果它不能弄清您的摘要答復,那么很明顯問題出在您的處理上。
我解決了這個問題。 我使用的是本地時間字符串,而不是utc時間字符串。 這解決了我的問題。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.