返回的认证报文:
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);
}