0

Using this code to connect to OnVif service on my IP Camera in C# .Net 4.5.
Very next to that code, I am trying to get Device information as follows:

string str = client.GetDeviceInformation(out model, out firmware, out serial, out hardwareId);

And encouters this error:

An exception of type 'System.ServiceModel.Security.MessageSecurityException' occurred in mscorlib.dll but was not handled in user code

Additional information: The HTTP request is unauthorized with client authentication scheme 'Digest'. The authentication header received from the server was 'Basic realm="CBBA"'.

I tried this information about Basic realm. By adding an Http header WWW-Authenticate to the request with value Basic realm="Our Site". But no luck.

What the heck is that? How to fix it?

Community
  • 1
  • 1
theGeekster
  • 6,081
  • 12
  • 35
  • 47

2 Answers2

0

You are probably failing to handle the Digest Authentication. To handle things correctly, you should send a request to a not PRE_AUTH ONVIF method without using authentication, neither digest nor ws-usernameToken.

You can get one of the two following answers:

  1. you get a 500 response with env:Sender ter:NoAuthorized which means that the camera does not support HTTP digest (which in fact, for profile S devices is not mandatory). In this case you have to use only WS-UsernameToken

  2. you get a 401 response with the WWW-Authenticate header from the device. In this case you should follow the RFC 2617, evaluate all the necessary elements and resend your requests with the Authorization header.

Remember that an HTTP digest challange is always started by the camera, you can't just add it to the first request.

Check §5.12 of the Core specification, at least to know has a camera handles authentication.

Community
  • 1
  • 1
Ottavio Campana
  • 4,088
  • 5
  • 31
  • 58
0

I had a relevant issue - I had to authenticate with ONVIF cameras for which I did not know the authentication HTTP authentication modes (Basic/Digest). In my answer you can see how to properly iterate through all the HTTP authentication schemes or you can just take the code for Digest, hope it helps.

Community
  • 1
  • 1
Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71