This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Get Snapshot from Hikvision Camera
#16
(15.03.2023, 10:55)admin Wrote: Thanks, here's a couple of things you can try:

1. Remove space between items in the Authorization header.
Replace:
Code:
return 'Digest ' .. table.concat(digest, ', ')
With:
Code:
return 'Digest ' .. table.concat(digest, ',')

2. Modify the items and their order in the header.
Replace:
Code:
local auth = {
  { 'username', user },
  { 'realm', ht.realm },
  { 'nonce', ht.nonce },
  { 'uri', uri },
  { 'cnonce', cnonce },
  { 'nc', nc, unquote = true },
  { 'qop', 'auth' },
  { 'algorithm', 'MD5' },
  { 'response', response },
}
With:
Code:
local auth = {
  { 'username', user },
  { 'realm', ht.realm },
  { 'nonce', ht.nonce },
  { 'uri', uri },
  { 'cnonce', cnonce },
  { 'nc', nc, unquote = true },
  -- { 'algorithm', 'MD5' },
  { 'response', response },
  { 'qop', 'auth' },
}

3. Make the cnonce longer.
Replace:
Code:
local cnonce = string.format('%08x', os.time())
With:
Code:
local cnonce = md5sum(string.format('%08x', os.time()))

When setting cnonce manually I get the same header as curl does by applying change 1 and 2.

It doesn´t work.

Code:
* arg: 1
  * string: <!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error</p>
</body>
</html>
<!DOCTYPE html>
<html><head><title>Document Error: Unauthorized</title></head>
<body><h2>Access Error: 401 -- Unauthorized</h2>
<p>Authentication Error</p>
</body>
</html>

I´ve found in the camera manual (Hikvision HWI-B140H (https://www.hi-watch.eu/en-us/product/15...let-camera))
The autentification mode is:

Code:
9.17 Security
You can improve system security by setting security parameters.
9.17.1 Authentication
You can improve network access security by setting RTSP and WEB authentication.
Go to Configuration → System → Security → Authentication to choose authentication protocol
and method according to your needs.
RTSP Authentication
Digest and digest/basic are supported, which means authentication information is needed when
RTSP request is sent to the device. If you select digest/basic, it means the device supports
digest or basic authentication. If you select digest, the device only supports digest
authentication.
RTSP Digest Algorithm
MD5, SHA256 and MD5/SHA256 encrypted algorithm in RTSP authentication. If you enable the
digest algorithm except for MD5, the third-party platform might not be able to log in to the
device or enable live view because of compatibility. The encrypted algorithm with high strength
Network Camera User Manual
79
is recommended.
WEB Authentication
Digest and digest/basic are supported, which means authentication information is needed when
WEB request is sent to the device. If you select digest/basic, it means the device supports digest
or basic authentication. If you select digest, the device only supports digest authentication.
WEB Digest Algorithm
MD5, SHA256 and MD5/SHA256 encrypted algorithm in WEB authentication. If you enable the
digest algorithm except for MD5, the third-party platform might not be able to log in to the
device or enable live view because of compatibility. The encrypted algorithm with high strength
is recommended.
Reply


Messages In This Thread
RE: Get Snapshot from Hikvision Camera - by DGrandes - 16.03.2023, 10:37

Forum Jump: