Ansersion / myRtspClient

A RTSP client based on jrtplib
Apache License 2.0
160 stars 91 forks source link

CheckAuth: error #33

Open mCr86 opened 4 years ago

mCr86 commented 4 years ago

Hi there,

I am triying to connect a TP-Link C200 Camera. Using OpenRTSP I can connect perfectly using ./openRTSP -t -4 -P 10 rtsp://888888:888888@192.168.1.82:554/stream2 With myRtspClient I use ./complete_example rtsp://192.168.1.82:554/stream2, previously I am set username and password in complete_example.cpp. the response is:

Start play rtsp://192.168.1.82:554/stream2
Then put video data into test_packet_recv.h264
RTSP/1.0 200 OK
CSeq: 1
Date: Thu, Jun 25 2020 09:35:01 GMT
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER

CheckAuth: error
DoDESCRIBE error

The error is in line 2000 of rtspClient.cpp:

    if(!IsResponse_200_OK()) {
        return CHECK_ERROR;
    }

If I change return CHECK_ERROR for return CHECK_OK The new response is:

Start play rtsp://192.168.1.82:554/stream2
Then put video data into test_packet_recv.h264 HOLAAAA
RTSP/1.0 200 OK
CSeq: 1
Date: Thu, Jun 25 2020 09:12:23 GMT
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER

RTSP/1.0 401 Unauthorized
CSeq: 3
Date: Thu, Jun 25 2020 09:12:23 GMT
WWW-Authenticate: Digest realm="TP-LINK Streaming Media", nonce="75f8c61d0f9ebdadedb7bb501628d4e7"

DoDESCRIBE error

My RTSP knowledge is null. Could you help me?

Thanks!

mCr86 commented 4 years ago

I think that this info could be usefull: Is a part of the response of a succefully connection using openRSTP:

Sending request: DESCRIBE rtsp://888888:888888@192.168.1.82:554/stream2 RTSP/1.0
CSeq: 3
User-Agent: ./openRTSP (LIVE555 Streaming Media v2020.06.23)
Accept: application/sdp

Received 175 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 401 Unauthorized
CSeq: 3
Date: Thu, Jun 25 2020 10:17:47 GMT
WWW-Authenticate: Digest realm="TP-LINK Streaming Media", nonce="de0cc178e4e28dbd8774b364bafa17b4"

Resending...
Sending request: DESCRIBE rtsp://888888:888888@192.168.1.82:554/stream2 RTSP/1.0
CSeq: 4
Authorization: Digest username="888888", realm="TP-LINK Streaming Media", nonce="de0cc178e4e28dbd8774b364bafa17b4", uri="rtsp://888888:888888@192.168.1.82:554/stream2", response="b64b796d8cddd99c9d632c0ee38078f9"
User-Agent: ./openRTSP (LIVE555 Streaming Media v2020.06.23)
Accept: application/sdp

Received 725 new bytes of response data.
Received a complete DESCRIBE response:
RTSP/1.0 200 OK
CSeq: 4
Date: Thu, Jun 25 2020 10:17:48 GMT
Content-Base: rtsp://192.168.1.82/stream2/
Content-Type: application/sdp
Content-Length: 564
mCr86 commented 4 years ago

more info:

// Note: If a HTTP "GET" command (for RTSP-over-HTTP tunneling) returns "401 Unauthorized", then we resend it
// (with an "Authorization:" header), just as we would for a RTSP command.  However, we do so using a new TCP connection,
// because some servers close the original connection after returning the "401 Unauthorized".
resetTCPSockets();  // forces the opening of a new connection for the resent command

line 1900 RTSPClient.cpp of OpenRTSP.

mCr86 commented 4 years ago

more info:

After the first DESCRIBE, code go to checkAuth(), but do not enter in if(Regex.Regex(RtspResponse.c_str(), PatternDigest.c_str(), &Group)) { Then, do not create the digest authetification response. But I do not know why. I do not understand Regex object.

The parameters of this if() are:

RtspResponse.c_str() =

RTSP/1.0 401 Unauthorized
CSeq: 2
Date: Thu, Jun 25 2020 15:12:29 GMT
WWW-Authenticate: Digest realm="TP-LINK Streaming Media", nonce="61b9e59fd8cd891f95b1c0170ab3aa00"

PatternDigest.c_str() = *Digest +realm="([a-zA-Z_0-9 ]+)", *nonce="([a-zA-Z0-9]+)"

&Group = 0x7ffdd12733a0

mCr86 commented 4 years ago

I found the error: In this pattern: PatternDigest("WWW-Authenticate: *Digest +realm=\"([a-zA-Z_0-9 ]+)\", *nonce=\"([a-zA-Z0-9]+)\""); You don't contemplate hyphen caracter of "TP-LINK". Solution: string PatternDigest("WWW-Authenticate: *Digest +realm=\"([-a-zA-Z_0-9 ]+)\", *nonce=\"([a-zA-Z0-9]+)\"");