我已經從Sony索尼攝像機SNC-CH110。默認用戶是'admin',密碼也是'admin'。我的大問題是驗證。ONVIF:使用ONVIF協議的SNC-CH110驗證失敗
<SOAP-ENV:Fault>
<SOAP-ENV:Code>
<SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value>
<SOAP-ENV:Subcode>
<SOAP-ENV:Value>ter:NotAuthorized</SOAP-ENV:Value>
</SOAP-ENV:Subcode>
</SOAP-ENV:Code>
<SOAP-ENV:Reason>
<SOAP-ENV:Text xml:lang="en">Sender not Authorized</SOAP-ENV:Text>
</SOAP-ENV:Reason>
<SOAP-ENV:Detail>
<SOAP-ENV:Text xml:lang="en">The action requested requires authorization and the sender is not authorized
</SOAP-ENV:Text>
</SOAP-ENV:Detail>
</SOAP-ENV:Fault>
根據ONVIF規範1.02,我使用的「用戶名標記配置文件」爲這是在說明書http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0.pdf或http://www.onvif.org/Portals/0/documents/WhitePapers/ONVIF_WG-APG-Application_Programmer%27s_Guide.pdf
下面是我使用以形成皁請求腳本記載的認證:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<SOAP-ENV:Header>
<Security SOAP-ENV:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>admin</Username>
<wsse:Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-token-profile-1.0#PasswordDigest"">" + hashBase64 + @"</wsse:Password>
<wsse:Nonce >" + Convert.ToBase64String(_nonce) + @"</wsse:Nonce>
<Created>" + dt + @"</Created>
</UsernameToken>
</Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tds:GetCapabilities>
<tds:Category>All</tds:Category>
</tds:GetCapabilities>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"
這裏是我的發送請求代碼:
byte[] _nonce = new byte[16];
RandomNumberGenerator rndGenerator = new RNGCryptoServiceProvider();
rndGenerator.GetBytes(_nonce);
// get other operands to the right format
string dt = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ss.fffZ");
byte[] time = Encoding.UTF8.GetBytes(dt);
byte[] pwd = Encoding.UTF8.GetBytes("admin");
byte[] operand = new byte[_nonce.Length + time.Length + pwd.Length];
Array.Copy(_nonce, operand, _nonce.Length);
Array.Copy(time, 0, operand, _nonce.Length, time.Length);
Array.Copy(pwd, 0, operand, _nonce.Length + time.Length, pwd.Length);
// create the hash
SHA1 sha1 = SHA1.Create();
string hashBase64 = Convert.ToBase64String(sha1.ComputeHash(operand));
XmlDocument xml = new XmlDocument();
xml.Load("../../../xml/GetCapabilities.xml");
Communication.SendTcpXml(xml.InnerXml, new Uri("http://192.168.1.25/onvif/device_service"));
我真的很困惑,因爲我找不到一個錯誤。非常有趣的是,當我使用程序ONVIF Device Manager(我通過Wireshark獲取)的日期,密碼,隨機數和用戶名時,我很成功。但我不明白這個程序如何哈希密碼,因爲我完全按照規範來做,而且當我使用相同的日期,隨機數和密碼時,我無法得到與此程序相同的散列密碼。我會很感激任何幫助,謝謝。
我前段時間做了一個小小的Java函數來計算和顯示Header部分(只是一個小測試)。我使用SoapUI和海康威視相機測試了結果,並且完美地工作;我希望它有幫助:http://pastebin.com/x16Prr2J – pparescasellas 2014-09-05 09:52:51