C 如何在ONVIF中对用户进行身份验证?

C 如何在ONVIF中对用户进行身份验证?,c,authentication,soap,onvif,C,Authentication,Soap,Onvif,我们有支持ONVIF协议的网络IP摄像机。当我试图获取它的PTZ配置时,它给出了Auth错误。我在C中实现了这一点。以下是请求和响应 _media__GetVideoEncoderConfigurations query; _media__GetVideoEncoderConfigurationsResponse response; soap_wsse_add_Security(&mediaProxy); soap_wsse_add_UsernameTokenDigest(&m

我们有支持ONVIF协议的网络IP摄像机。当我试图获取它的PTZ配置时,它给出了Auth错误。我在C中实现了这一点。以下是请求和响应

_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));
请求:

"<?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>

SOAP-ENV:发送方
三:未授权
发件人未经授权
http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver
http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver
请求的操作需要授权,而发件人未经授权


如何对用户进行身份验证?感谢那些需要验证的命令。它们的身份验证头可以这样添加

 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);
snprintf(postData,sizeof(postData),
"" 
"" 
"" 
%s
""
%s%s
%s
"" 
"" 
"", 
用户名、Base645、摘要、当前字符、时间字符);

<代码> > p>您可以使用WSOSE插件的GSOAP来生成您需要的OnvIWDSL的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));
\u媒体\u获取视频编码器配置查询;
_媒体获取视频编码器配置响应;
soap\u wsse\u添加\u安全性(&mediaProxy);
soap_wsse_add_usernametokedigest(&mediaProxy,NULL,m_username.c_str(),m_password.c_str());
if(mediaProxy.GetVideoEncoderConfigurations(&query,&response)==SOAP\u OK)
{
LogSuccess(“GetVideoEncoderConfiguration”);
对于(自动it=response.Configurations.begin();it!=response.Configurations.end();++it)
{
onvif_uu视频编码器配置*videoConf=*它;

日志(I3)Q:您是否手工编写SOAP?Q:相机型号和制造商是什么?他们是否支持接口库?或任何规范(除WSDL外)?您是否尝试联系过他们(至少是示例代码)?这是一款佳能相机,VB-M40。此验证方法在ONVIF程序员指南中给出。“”如何生成密码摘要?我正在浏览ONVIF程序员API,它看起来像是通过执行
digest=B64ENCODE(SHA1(B64DECODE(Nonce)+日期+密码)生成的密码摘要
但日期和密码都是已转换为二进制的字符串。将字符串转换为二进制意味着什么?您是如何生成摘要的?nonce_字符应该是base64编码的?什么是time_字符?它是时间戳还是像2014-01-02T12:47:08Z这样的当前时间