2012-05-29 63 views
5

我們有支持ONVIF協議的網絡IP攝像機。當我試圖獲得它的PTZ配置時,它會給出Auth錯誤。我正在C中執行此操作。以下是請求和響應。如何在ONVIF中驗證用戶?

請求:

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
    "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"" 
    "xmlns:tds=\"http://www.onvif.org/ver20/ptz/wsdl\">" 
    "<soap:Body>" 
    "<tds:GetNodes/>" 
    "</soap:Body>" 
    "</soap:Envelope>" 

響應:

<?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:Body> 
    <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: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> 
      The action requested requires authorization and the sender is not authorized 
     </SOAP-ENV:Detail> 
    </SOAP-ENV:Fault> 
</SOAP-ENV:Body> 

我如何驗證用戶?由於

+0

問:你是否手工編寫你的SOAP?問:相機型號和製造商是什麼?他們是否支持一個接口庫?或者任何規格(除了WSDL)?你有沒有嘗試聯繫他們(至少對於示例代碼)? – paulsm4

+0

它是佳能相機,VB-M40。這種認證方法在ONVIF程序員指南中給出。 「http://www.onvif.org/Portals/0/documents/WhitePapers/ONVIF_WG-APG-Application_Programmer%27s_Guide.pdf」 –

回答

2

需要認證的那些命令。他們的驗證頭可以像這樣添加。

snprintf(postData, sizeof(postData), 
      "<?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/ver20/ptz/wsdl\">" 
      "<SOAP-ENV:Header><wsse:Security><wsse:UsernameToken>" 
      "<wsse:Username>%s</wsse:Username>" 
      "<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-" 
      "200401-wss-username-token-profile-1.0#PasswordDigest\">" 
       "%s</wsse:Password><wsse:Nonce>%s</wsse:Nonce>" 
      "<wsu:Created>%s</wsu:Created></wsse:UsernameToken>" 
      "</wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body>" 
      "<tds:GetNodes>" 
      "</SOAP-ENV:Body></SOAP-ENV:Envelope>", 
      username, base64EncDigest, nonce_char, time_char); 
+0

如何生成密碼摘要?我正在瀏覽ONVIF程序員API,它看起來像是通過執行'Digest = B64ENCODE(SHA1(B64DECODE(Nonce)+ Date + Password))'生成的,但日期和密碼都是已轉換爲二進制文件。將字符串轉換爲二進制文件意味着什麼?你是如何生成摘要的? – CadentOrange

+0

nonce_char應該是base64編碼的?什麼是time_char?是時間戳還是現在時間,比如2014-01-02T12:47:08Z – kashifmehmood

1

您可以使用gSOAP的與WSSE插件生成的,你需要ONVIF WDSL C++客戶端代理。

這樣做是否大大簡化了我的工作。以下是調用GetVideoEncoderConfiguration並讀取響應的示例。

_media__GetVideoEncoderConfigurations query; 
_media__GetVideoEncoderConfigurationsResponse response; 

soap_wsse_add_Security(&mediaProxy); 
soap_wsse_add_UsernameTokenDigest(&mediaProxy, NULL, m_username.c_str(), m_password.c_str()); 

if(mediaProxy.GetVideoEncoderConfigurations(&query, &response) == SOAP_OK) 
{ 
    LogSuccess("GetVideoEncoderConfigurations"); 
    for(auto it = response.Configurations.begin(); it != response.Configurations.end(); ++it) 
    { 
     onvif__VideoEncoderConfiguration* videoConf = *it; 
     log(I3) << "Name= " << videoConf->Name << ", Encoding=" << videoConf->Encoding << ", Resolution=" << videoConf->Resolution->Width << "x" << videoConf->Resolution->Height; 
    } 
} 
else 
    LogError("GetVideoEncoderConfigurations", soap_faultdetail(&mediaProxy)); 

所以沒有手動創建肥皂消息。 gSOAP生成的代碼會在較低層處理此問題。當然,需要2天才能生成wsse支持的工作代碼,但仍然可以快10倍。如果您有興趣瞭解更多信息,請聯繫我。