AndyLasers Posted April 15, 2020 Share Posted April 15, 2020 Trying for days to communicate to an IP camera from an apache server using PHP I do get responses from the camera RTSP/1.0 401 Unauthorized CSeq: 1 WWW-Authenticate: Digest realm="Login to 3E072F5PAL00180", nonce="bf2693784e774fb41b569ca02d8abe54" The nonce changes each time I refresh, I guess that is exactly what It should do. I read that I must MD5 the user and password along with some other data and create a string that goes back to the camera to authenticate and once done the camera replies RTSP/1.0 200 OK Somebody has a small bit of code to build the required answer from strings? I am not big in PHP, I did find this on a page but it is way over my head, I do not have anything called $data. $A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]); $A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']); $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2); I get the idea of sending commands with an existing socket. socket_write($socket,$answer); NONCE :62d72a3d3b35bb5440ba29222e3669aa REALM :Login to 3E072F5PAL00180 User : Password : I have assigned directly as strings the password and user. Quote Link to comment Share on other sites More sharing options...
requinix Posted April 15, 2020 Share Posted April 15, 2020 Digest authentication is rather complicated. Do you have any way to change the authentication system it wants to use? Perhaps to "Basic"? Quote Link to comment Share on other sites More sharing options...
AndyLasers Posted April 15, 2020 Author Share Posted April 15, 2020 Hello requinix Sadly no, I cannot connect to the camera with basic auth, or at least I could not find any details on how to do that. It seams that basic auth is out dated. I do see a lot of curl expamples and I tried loads, but none I found work with a camera behind a forwarded port like 554, using curl is quite common but as I understand it is reading via a html connection not rtsp. Of course I could also be wrong. I use delphi mostly so PHP is mind boggling for me. As I understand it, the camera is basically asking me to login. How I send the login data is what I am stuck with. So far I am creating a socket to communicate with the camera then perform a basic request "Describe" to the camera Socket Create result: SuccessSent to the Camera:DESCRIBE rtsp://IP:554 RTSP/1.0 CSeq: 1The Camera Responded with RTSP/1.0 401 Unauthorized CSeq: 1 WWW-Authenticate: Digest realm="Login to 3E072F5PAL00180", nonce="f683e059c7c09ca8511322793dc99d2c" NONCE :f683e059c7c09ca8511322793dc99d2cREALM :Login to 3E072F5PAL00180 I then extract nonce and realm from the camera response into these parts $nonce and $realm, I think then I should combine these with the username, password and send back to the camera as a message to perform the login. It is that message that I am lost how to do. Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 15, 2020 Share Posted April 15, 2020 First question: did you do an rtsp OPTIONS request? OPTIONS rtsp://IP:554 RTSP/1.0 What is the reply? As for Digest authentication, just interpreting this page, I would start with: HA1 = MD5(username:realm:password) HA2 = MD5(method:digestURI) response = MD5(HA1:nonce:HA2) Assuming you have set username and password as variables: $ha1 = md5($username . ':' . $realm . ':' . $password); $ha2 = md5('rtsp://IP:554'); $response = md5($ha1 . ':' $nonce . ':' . $ha2); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.