RTSP C++認證實現

來源:互聯網
上載者:User

標籤: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++認證實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.