Authentication patterns for China-made IoT devices

Most Chinese surveillance and industrial IoT devices share a small set of authentication models. Knowing which one a device uses saves hours of trial and error, because the same username and password can be correct for the web interface and useless for the API.

This guide documents the four models that appear on this site repeatedly, plus the failure signals that separate an authentication problem from a permission problem. It is written from vendor documentation, not from a lab test.

Activate first, then authenticate

A new device usually refuses service until it has been activated: the first login sets the admin password, and some models also require a security question or a bound phone number. Until that step is done, every API call fails with the same 401 that a wrong password produces.

Two consequences follow. First, a device cannot be integrated by whoever holds only the network diagram; someone has to complete activation once. Second, the "default password" step is a security boundary, not a convenience: a device that still accepts a well-known default is a device that has not been configured.

Model 1: HTTP Digest

Hikvision ISAPI and Dahua CGI both accept Digest authentication over HTTP or HTTPS. The exchange is a challenge-response:

  1. The client sends the request without credentials.
  2. The device answers 401 with a WWW-Authenticate header carrying a realm and a nonce.
  3. The client hashes the password with the nonce and resends.

The password itself is never transmitted, which is why Digest is better than Basic on an isolated LAN. It does not encrypt the payload, so a camera configured over plain HTTP still exposes stream URLs, snapshots and configuration in transit. Use HTTPS when the device supports it, and use Digest anyway.

Most HTTP clients implement the handshake already:

curl --digest -u admin:PASSWORD "http://192.168.1.64/ISAPI/System/deviceInfo"

A common mistake is sending a pre-hashed credential header copied from another device. The nonce is per challenge; a stale response fails even with the right password.

Model 2: Session token

Dahua's CGI layer often expects a session rather than digest-per-request. The client calls the login method, receives a session identifier, then appends it to later calls. The token expires, and the device may allow only a limited number of concurrent sessions, so a long-running integration has to handle re-login instead of assuming the first token lasts.

SDKs hide this. Hand-written scripts usually do not, and a script that works for an hour and then returns 401 is showing an expiry, not a credentials problem.

Model 3: Proprietary SDK over TCP

Hikvision's device network SDK uses port 8000 and Dahua's NetSDK uses port 37777 in the documented default configuration. Neither is HTTP: the login is a binary exchange inside a vendor protocol, and Digest never appears.

This path is the most capable one, and the least portable:

For server-side recording, playback search and alarm subscription, the SDK is usually the reliable route. For a single snapshot or a stream URL, HTTP and RTSP are enough.

Model 4: ONVIF with WS-Security

ONVIF is the cross-vendor option, and its authentication is neither Digest nor a session cookie. Requests carry a WS-Security UsernameToken: the password is sent as a digest computed from a nonce and a creation timestamp.

Two practical consequences:

ONVIF profile support is per model, not per brand, so the profile row in the datasheet is the claim to check before designing around it.

Token and key models on the IoT side

Gateways, modules and cloud connectors replace the password with a token:

Pattern Where it appears What breaks it
Username and password on MQTT Local brokers, Zigbee2MQTT bridges Broker restart with new credentials
Long-lived API key HTTP APIs, webhook receivers Key rotation, scope changes
Short-lived token with refresh Cloud platforms, vendor APIs Clock skew, refresh race
Per-device certificate TLS mutual auth Expiry, wrong CA bundle

The common failure is not cryptography but configuration drift: a rotated broker password left in a config file, or an API key scoped to one project reused in another.

Reading the failure signal

Response Meaning Next check
401 on every call Credentials not accepted or device not activated Complete activation, re-enter password
401 after a working period Session or token expired Add re-login
403 with valid credentials Authenticated but not permitted User role, ONVIF user list, IP allowlist
404 with valid credentials Wrong path or wrong API version Model manual
Connection reset or timeout Port closed, wrong protocol, or lockout Firewall, SDK port, device lock

A device that returns 401 to correct credentials is often in a lockout window after repeated failures. Waiting is part of the diagnosis.

Credential hygiene that survives a project

Related reading