1.基本认证 (basic 认证)
- DESCRIBE rtsp://192.168.1.55:554/11
- RTSP/1.0\r\n
- CSeq: 1\r\n
- Accept: application/sdp\r\n
- User-agent: Realplayer\r\n\r\n
2:RTSP服务端认为没有通过认证,发出WWW-Authenticate认证响应
CSeq: 1\r\n
WWW-Authenticate: Basic realm="RTSPD"\r\n\r\n
步骤3:客户端携带Authorization串再次发出DESCRIBE请求
RTSP/1.0\r\n
CSeq: 2\r\n
Accept: application/sdp\r\n
User-Agent: RealMedia Player HelixDNAClient/12.0.1.647 (win32)\r\n
Authorization: Basic YWRtaW46YWRtaW4=\r\n\r\n
- char sztemp[64] = {0};
- sprintf( sztemp, "%s:%s", m_szAuthorName, m_szPwd); //"admin","admin" ); //
- string strOutBase64;
- BaseEncoder::Base64Encode( (BYTE*)sztemp, strlen(sztemp),&strOutBase64 );
2. 摘要认证 Digest authentication
1.客户端发送DESCRIBE请求
DESCRIBE rtsp://192.168.123.158:554/11 RTSP/1.0
CSeq: 2
User-Agent: LibVLC/2.0.5(LIVE555 Streaming Media v2012.09.13)
Accept: application/sdp
服务器端返回401错误,提示未认证并以nonce质询:
RTSP/1.0 401 Unauthorized
Server: HiIpcam/V100R003 VodServer/1.0.0
Cseq: 2
WWW-Authenticate:Digest realm="HipcamRealServer", nonce="3b27a446bfa49b0c48c3edb83139543d"
2.客户端以用户名,密码,nonce,HTTP方法,请求的URI等信息为基础产生response信息进行反馈
DESCRIBE rtsp://192.168.123.158:554/11 RTSP/1.0
CSeq: 3
Authorization: Digest username="admin",realm="Hipcam RealServer", nonce="3b27a446bfa49b0c48c3edb83139543d",uri="rtsp://192.168.123.158:554/11", response="258af9d739589e615f711838a0ff8c58"
User-Agent: LibVLC/2.0.5(LIVE555 Streaming Media v2016.06.13)
Accept: application/sdp
服务器对客户端反馈的response进行校验,通过则返回如下字段:
RTSP/1.0 200 OK
Server: HiIpcam/V100R003 VodServer/1.0.0
Cseq: 3
Content-Type: application/sdp
Cache-Control: must-revalidate
Content-length: 306
Content-Base: rtsp://192.168.123.158:554/11/
v=0
o=StreamingServer 3331435948 1116907222000 IN IP4192.168.123.158
s=\11
c=IN IP4 0.0.0.0
b=AS:1032
t=0 0
a=control:*
m=video 0 RTP/AVP 96
b=AS:1024
a=control:trackID=0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=Z0LgHtoCgPRA,aM4wpIA=
a=framesize:96 640-480
说明:
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字段,同样在服务器端校验时也默认采取同样的计算方法。
本文为《流媒体开发实战进阶---rtsp视频播放器》视频课程,第一章第二节配套讲义,
更多内容请收看视频讲解!