使用ONVIF相机进行身份验证时,Http 400 Bad Request

时间:2015-02-12 22:02:44

标签: soap camera ip onvif usernametoken

我正在尝试通过发送“usernametoken”soap请求来获取设备功能,以便对ONVIF摄像机进行身份验证。但我得到“请求的操作需要授权,发件人未获得授权”错误从相机返回。以下是我发送的“Usernametoken”:

<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"><s:Header><Security s:mustUnderstand="1" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>root</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">PLAolzuaeKGkHrC7uMD52ZAvjDc=</Password><Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">DK81s1X+o0Cp0QfDg7CJ8YSeacg=</Nonce><Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2015-02-12T21:49:39.001Z</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl"><Category>All</Category></GetCapabilities></s:Body></s:Envelope>

创建“nonce”就是这样:

string guid = Guid.NewGuid().ToString();
string nonce = GetSHA1String( guid );

public string GetSHA1String(string phrase)
{
        byte[] hashedDataBytes = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(phrase)); 
        return Convert.ToBase64String(hashedDataBytes);
}

我正在以这种方式创建“Created”:

string created = System.DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");

我正在以这种方式创建PasswordDigest:

string pwd = "admin";
string hashedPassword = CreateHashedPassword(nonce, created, pwd);

 public string CreateHashedPassword(string nonce, string created, string password)
 {
       return GetSHA1String(nonce + created + password);
 }

我不知道我做错了什么。我真的很感激有人可以帮助解决这个问题。

1 个答案:

答案 0 :(得分:0)

当散列时,&#34; nonce + nonce +创建+密码&#34;必须是二进制数据。请参阅此主题以了解类似问题:what's the formula of ONVIF #PasswordDigest