日期:2014-05-16  浏览次数:21032 次

Linux设备上的Onvif实现17:实现RTSP摘要认证

1 RTSP协议中定义了两种认证方法,基本认证(basic authentication),摘要认证(digest authentication)。基本认证是http1.0提出的认证方案,其密码传输的加密算法(base64)是可逆算法,很容易被截获破解。摘要认证是http1.1提出的替代方案,其密码经过MD5哈希转换因此具有更高的安全性。 本文只介绍摘要认证。

2 网络上有一篇文章介绍RTSP摘要认证协议,http://www.360doc.com/content/13/0827/17/13084517_310297107.shtml,这篇内容比较完整准确,但是对于如何计算出摘要确语焉不详,无法正确计算出摘要。对此经过多番尝试,终于试验出了正确的计算方法。本文将给出详细的计算步骤。

3 先看一段抓包下来的正确的摘要认证消息。示例中的用户名是“admin”,密码是“admin”。

//默认无认证----------------------------
DESCRIBE rtsp://192.168.0.112:540/live/h264_ulaw/VGA RTSP/1.0
CSeq: 6
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Accept: application/sdp

RTSP/1.0 401 Unauthorized
CSeq: 6
WWW-Authenticate: Basic realm="Server"
WWW-Authenticate: Digest realm="Server", nonce="52bb051ecad61e78d67664700e67407ad865c429bde208b7ea1e6e22aa7d8ccf"

//使用摘要认证----------------------------
DESCRIBE rtsp://192.168.0.112:540/live/h264_ulaw/VGA RTSP/1.0
CSeq: 7
Authorization: Digest username="admin", realm="Server", nonce="52bb051ecad61e78d67664700e67407ad865c429bde208b7ea1e6e22aa7d8ccf", uri="rtsp://192.168.0.112:540/live/h264_ulaw/VGA", response="1ac6f141f4c740ba54088914941f094f"
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Accept: application/sdp

RTSP/1.0 200 OK
CSeq: 7
Content-Base: rtsp://192.168.0.112:540/live/h264_ulaw/VGA/
Content-Type: application/sdp
Cache-Control: must-revalidate
x-Accept-Dynamic-Rate: 1
Content-Length: 305
sdp内容略过

//建立视频通道连接----------------------------
SETUP rtsp://192.168.0.112:540/live/h264_ulaw/VGA/track1 RTSP/1.0
CSeq: 8
Authorization: Digest username="admin", realm="Server", nonce="52bb051ecad61e78d67664700e67407ad865c429bde208b7ea1e6e22aa7d8ccf", uri="rtsp://192.168.0.112:540/live/h264_ulaw/VGA/", response="ff71e2de4489997fa2fd058462ca48df"
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Transport: RTP/AVP;unicast;client_port=57704-57705

RTSP/1.0 200 OK
CSeq: 8
Transport: RTP/AVP;unicast;client_port=57704-57705;server_port=59024-59025
x-dynamic-rate: 1
Session: D694FB02673D8FFC816E78EB384E09

//建立音频通道连接----------------------------
SETUP rtsp://192.168.0.112:540/live/h264_ulaw/VGA/track3 RTSP/1.0
CSeq: 9
Authorization: Digest username="admin", realm="Server", nonce="52bb051ecad61e78d67664700e67407ad865c429bde208b7ea1e6e22aa7d8ccf", uri="rtsp://192.168.0.112:540/live/h264_ulaw/VGA/", response="ff71e2de4489997fa2fd058462ca48df"
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Transport: RTP/AVP;unicast;client_port=57706-57707
Session: D694FB02673D8FFC816E78EB384E09

RTSP/1.0 200 OK
CSeq: 9
Transport: RTP/AVP;unicast;client_port=57706-57707;server_port=53570-53571
x-dynamic-rate: 1
Session: D694FB02673D8FFC816E78EB384E09

//----------------------------
PLAY rtsp://192.168.0.112:540/live/h264_ulaw/VGA/ RTSP/1.0
CSeq: 10
Authorization: Digest username="admin", realm="Server", nonce="52bb051ecad61e78d67664700e67407ad865c429bde208b7ea1e6e22aa7d8ccf", uri="rtsp://192.168.0.112:540/live/h264_ulaw/VGA/", response="a0187b5bb73d8cfaedab47365b0b8848"
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Session: D694FB02673D8FFC816E78EB384E09
Range: npt=0.000-

RTSP/1.0 200 OK
CSeq: 10
Session: D694FB02673D8FFC816E78EB384E09
Range: npt=now-
RTP-Info: url=rtsp://192.168.0.112:540/live/h264_ulaw/VGA//track1;seq=52039;rtptime=3232015484,url=rtsp://192.168.0.112:540/live/h264_ulaw/VGA//track3;seq=36501;rtptime=34449408


//----------------------------
TEARDOWN rts