码迷,mamicode.com
首页 > 编程语言 > 详细

RTSP C++认证实现

时间:2017-10-29 11:06:31      阅读:652      评论:0      收藏:0      [点我收藏+]

标签:md5   rtsp   认证   

返回的认证报文:

WWW-Authenticate: Digest realm="a4143773bd55", nonce="df9be0ee05ebcb26a4318ea8ba01881b", stale="FALSE"\r\n

在其他的博客中对HTTP进行了认证,指定了其他的一些参数例如md5,auth等参数


int CRtspCommandHandler::HandleUnAuthCommand(char* pszCmdContext, int &nContextLen, const char* pRecvBuffer)

{

std::string strRecvBuf = pRecvBuffer;

std::string strRealm = "realm=\"";

int nRealmLen = strRealm.length();

int nIndexOfRealm = strRecvBuf.find(strRealm, 0);

if (-1 == nIndexOfRealm) return -1;


int nIndexEndOfRealm = strRecvBuf.find("\",", nIndexOfRealm);

if (-1 == nIndexEndOfRealm) return -1;

std::string strRealmValue = strRecvBuf.substr(nIndexOfRealm + nRealmLen, nIndexEndOfRealm - nIndexOfRealm - nRealmLen);


std::string strNonce = "nonce=\"";

int nNonceLen = strNonce.length();

int nIndexOfNonceValueStart = strRecvBuf.find(strNonce, 0);

if (-1 == nIndexOfNonceValueStart) return -1;


int nIndexOfNonceValueEnd = strRecvBuf.find("\",", nIndexOfNonceValueStart);

if (-1 == nIndexOfNonceValueEnd) return -1;

std::string strNonceValue = strRecvBuf.substr(nIndexOfNonceValueStart + nNonceLen, nIndexOfNonceValueEnd - nIndexOfNonceValueStart - nNonceLen);


char* pszAlg = "";

char* pszQop = "";

char* pszNonceCount = NULL;

char* pszCNonce = NULL;


char szNonce[128] = { 0 };

sprintf(szNonce, "%s", strNonceValue.c_str());

char szUserName[128] = { 0 };

sprintf(szUserName, "%s", "admin");

char szRealm[32] = { 0 };

sprintf(szRealm, "%s", strRealmValue.c_str());

char szPassword[32] = { 0 };

sprintf(szPassword, "%s", "admin12345");

char pszMethod[32] = { 0 };

sprintf(pszMethod, "%s", "DESCRIBE");

char pszURI[128] = { 0 };

sprintf(pszURI, "%s", "rtsp://192.168.0.150:554/h264/ch1/main/av_stream");

HASHHEX szHA1;

HASHHEX szHA2 = "";

HASHHEX szResponse;

DigestCalcHA1(pszAlg, szUserName, szRealm, szPassword, szNonce,

pszCNonce, szHA1);

DigestCalcResponse(szHA1, szNonce, pszNonceCount, pszCNonce, pszQop,

pszMethod, pszURI, szHA2, szResponse);

std::string strResponse = szResponse;

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "DESCRIBE " << pszURI << " RTSP/1.0\r\n";

request_stream << "CSeq: " << "4\r\n";

request_stream << "Accept: " << "application/sdp\r\n";

request_stream << "User-Agent: " << "LibVLC/2.1.5 (Live555 Streaming Media v2014.0)\r\n";

request_stream << "Authorization: Digest username=\"" << "admin" << "\","

<< "realm=\"" << strRealmValue << "\","

<< "nonce=\"" << strNonceValue << "\","

<< "uri=\"" << pszURI << "\","

<< "response=\"" << strResponse << "\"\r\n";

request_stream << "\r\n";


request.sgetn(pszCmdContext, request.size());

nContextLen = strlen(pszCmdContext);

}


RTSP C++认证实现

标签:md5   rtsp   认证   

原文地址:http://fengyuzaitu.blog.51cto.com/5218690/1977062

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!