RTSP C + + Certification implementation

Source: Internet
Author: User
Tags sprintf

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.