The returned authentication message:
Www-authenticate:digest realm= "A4143773bd55", nonce= "df9be0ee05ebcb26a4318ea8ba01881b", stale= "FALSE" \ r \ n
HTTP is authenticated in other blogs, and other parameters such as Md5,auth are specified.
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 + + Certification implementation