rtsp 用户名、密码登录

在使用rtp看视频时,有时候需要使用用户名和密码登录,那么在用户名密码登录的流程是怎么样的呢?

大致流程:

                   rtsp 客户端发送DESCRIBE指令

                    服务器应答401错误,说明需要用户名密码认证

                    rtsp 客户端再次发送DESCRIBE指令,该指令包含用户名密码等有效信息,其中密码采用MD5算法加密发送

                    服务器应答成功

                    rtsp客户端继续setup、play流程

抓包分析:

DESCRIBE rtsp://192.168.100.123:554/mpeg4cif RTSP/1.0
CSeq: 6
User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)
Accept: application/sdp


RTSP/1.0 401 Unauthorized
CSeq: 6
Date: Fri, Feb 24 2017 07:17:45 GMT
WWW-Authenticate: Digest realm="LIVE555 Streaming Media",nonce="213d8479345cb52cee152187ed8f16d9"


DESCRIBE rtsp://192.168.100.123:554/mpeg4cif RTSP/1.0
CSeq: 7
Authorization: Digest username="admin", realm="LIVE555 Streaming Media", nonce="213d8479345cb52cee152187ed8f16d9", uri="rtsp://192.168.100.123:554/mpeg4cif", response="40c4124a69551684cec093e6ae45af96"
User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)
Accept: application/sdp


RTSP/1.0 200 OK
CSeq: 7
Date: Fri, Feb 24 2017 07:17:45 GMT
Content-Base: rtsp://192.168.100.123/mpeg4cif/
Content-Type: application/sdp
Content-Length: 681

v=0
o=- 187880931531 1 IN IP4 192.168.100.123
s=RTSP/RTP stream from Network Video Server
i=mpeg4cif
t=0 0
a=tool:LIVE555 Streaming Media v2011.05.25
a=type:broadcast
a=control:*
a=range:npt=0-
a=x-qt-text-nam:RTSP/RTP stream from Network Video Server
a=x-qt-text-inf:mpeg4cif
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:384
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=640014;sprop-parameter-sets=Z2QAFK2EAQwgCGEAQwgCGEAQwgCEK1CwS03AQEBQAAADABAAAAMBKEA=,aO48sA==;config=0000000167640014ad84010c20086100430802184010c200842b50b04b4dc040405000000300100000030128

400000000168ee3cb0
a=x-dimensions: 352, 288
a=x-framerate: 8
a=control:track1

response字段计算:

RTSP客户端应该使用username + password并计算response如下:

(1)当password为MD5编码,则

   response = md5(password:nonce:md5(public_method:url));

(2)当password为ANSI字符串,则

    response= md5(md5(username:realm:password):nonce:md5(public_method:url));

客户端在每次发起不同的请求方法时都需要计算response字段,同样在服务器端校验时也默认采取同样的计算方法。


当password为ANSI字符串为例讲解:

step 1:

md5(username:realm:password)
username:admin
realm:LIVE555 Streaming Media  #这个字符在DESCRIBE应答401错误时返回
password:123456
md5(admin:LIVE555 Streaming Media:123456)=b5d76ea8a4c88c4397efbbdbcb8cc725

step 2:

md5(public_method:url)
public_method:DESCRIBE
url:rtsp://192.168.100.123:554/mpeg4cif
md5(DESCRIBE:rtsp://192.168.100.123:554/mpeg4cif)=ec124df220a2c580359ebd8aebff813f


step 3:

response= md5(md5(username:realm:password):nonce:md5(public_method:url))   #nonce字段在DESCRIBE应答401错误时返回

md5(b5d76ea8a4c88c4397efbbdbcb8cc725:213d8479345cb52cee152187ed8f16d9:

ec124df220a2c580359ebd8aebff813f)=40c4124a69551684cec093e6ae45af96


你可能感兴趣的:(Linux,c,视频,Linux系统,rtp,rtsp,用户名密码登录)