Repository navigation
feat: RTSP Digest authentication and keepalive (#8, #11) - #46
Conversation
Digest (fixes #8): - RtspAuth signs requests per RFC 2617: MD5 and MD5-sess, qop=auth with nonce count and client nonce, opaque; SHA-256 challenges are skipped. - Basic is still sent pre-emptively, as before. On 401 the session picks the Digest challenge among all WWW-Authenticate headers and repeats the request once. Wrong credentials fail the attempt instead of looping; a stale nonce is retried. Keepalive (fixes #11): - After PLAY a GET_PARAMETER is sent every half session timeout (from "Session: ...;timeout=N", default 60 s) on the same connection. If the server rejects it, OPTIONS is used. Replies are recognised between interleaved packets; 454 (session gone) triggers a reconnect, 401 refreshes the Digest nonce. Tests: the RFC 2617 example vector, MD5-sess, qop-less Digest, scheme choice, no endless retries, quoted parameters; against the scripted server: Digest-only camera, wrong password, keepalive cadence and the OPTIONS fallback.
PR Summary by QodoAdd RTSP Digest authentication and session keepalive
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
Code Review by Qodo
1.
|
- Keepalives are sent from the watchdog thread, so an idle stream (the reader blocked with no data) still keeps its session; requests are written under the connection lock. - The keepalive interval is half the session timeout with a 250 ms floor, so timeout=1 is refreshed every 500 ms. - Credentials containing control characters (e.g. a percent-encoded CR/LF from a shared link) are rejected; quoted Digest values escape '"' and '\'. - A 401 to a keepalive that cannot be answered ends the session (and reconnects) instead of repeating forever; a stale nonce resends at once. - Digest challenges offering only qop=auth-int are skipped in favour of a later supported one. - MD5-sess sends its cnonce even without qop and keeps one cnonce per server nonce.
Fixes #8, fixes #11.
Digest authentication (#8)
New class
RtspAuth, built per RFC 2617:qop=authwith nonce count (nc) and client nonce (cnonce);opaque;Basic is still sent with the first request, as the app already does with OpenIPC cameras. If the camera replies
401:WWW-Authenticateheaders (a camera may offer both Basic and Digest);stale=true, the request is retried with the new nonce.Keepalive (#11)
GET_PARAMETERwithSessionis sent every half of the session timeout, taken fromSession: …;timeout=N(60 s if absent). It goes over the same TCP connection from the network thread, so no extra thread or lock is needed.GET_PARAMETER(501/405/…),OPTIONSis used from then on.RTSP/prefix:454 Session Not Found→ reconnect;401→ the Digest nonce is refreshed for the next request.README
Digest and keepalive are listed under features. #8, #9 (fixed in #45) and #11 are removed from "Known limitations" in all three languages.
Tests
68 in total; 12 are new.
RtspAuthTest:6629fae49393a05397450978507c4ef1);qop;stalehandling;RtspSessionTest, against the scripted server:timeout=2a keepalive goes out every second while the stream keeps flowing on one connection;OPTIONSfallback;Not tested on a device or with Digest cameras. Hikvision and Dahua cameras use Digest by default.