流媒體傳輸協議詳解之---RTSP認證

Rtsp認證主要分爲兩種:

基本認證basic authentication)和摘要認證 digest authentication )。

基本認證是http 1.0提出的認證方案,其消息傳輸不經過加密轉換因此存在嚴重的安全隱患。
摘要認證是http 1.1提出的基本認證的替代方案,其消息經過MD5哈希轉換因此具有更高的安全性。下面主要介紹摘要認證:

1.基本認證 (basic 認證
1.  客戶端發送DESCRIBE請求到服務端,
  1. DESCRIBE  rtsp://192.168.1.55:554/11
  2. RTSP/1.0\r\n
  3. CSeq: 1\r\n
  4. Accept: application/sdp\r\n
  5. User-agent: Realplayer\r\n\r\n

2:RTSP服務端認爲沒有通過認證,發出WWW-Authenticate認證響應

RTSP/1.0 401 Unauthorized\r\n
CSeq: 1\r\n
WWW-Authenticate: Basic realm="RTSPD"\r\n\r\n
 
   此時客戶端程序應該如果彈出密碼認證窗口 ,提示用戶名,輸入認證信息,密碼認證窗口
從響應消息中進行判斷,如果發現是Basic 認證,按如下方式處理

步驟3:客戶端攜帶Authorization串再次發出DESCRIBE請求

DESCRIBE rtsp://192.168.1.55:554/live/1/video.sdp?token=A00453FR805a54C8
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

其中“YWRtaW46YWRtaW4=”是通過對 username:password 進行base64編碼所得

參考代碼:
        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)passwordMD5編碼,

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

(2)passwordANSI字符串,

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


客戶端在每次發起不同的請求方法時都需要計算response字段,同樣在服務器端校驗時也默認採取同樣的計算方法。




本文爲《流媒體開發實戰進階---rtsp視頻播放器》視頻課程,第一章第二節配套講義,

更多內容請收看視頻講解!

http://edu.csdn.net/course/detail/2744

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章