⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipcommand.cxx

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 CXX
📖 第 1 页 / 共 3 页
字号:
    if (proxyAuth->getAuthScheme() != AUTH_BASIC)    {        cpLog(LOG_DEBUG_STACK, "SCHEME IS NOT BASIC");        return false;    }    if (pwd.length())    {        SipBasic basic;        cookie = basic.formSIPBasic(data, pwd);    }    else    {        cookie = data;    }    //get cookie from proxy auth and compare    const Data& recvdcookie = proxyAuth->getBasicCookie();    if (recvdcookie == cookie)    {        cpLog(LOG_DEBUG_STACK, " basic authentication successful");        return true;    }    cpLog(LOG_DEBUG_STACK, " basic authentication failed");    return false;}bool SipCommand::checkAuthBasic(const Data& data, const Data& pwd){    Sptr<SipAuthorization> authorization;    myHeaderList.getParsedHeader(authorization, SIP_AUTHORIZATION_HDR);    Data cookie;    Data authScheme = authorization->getAuthScheme();    if ( isEqualNoCase(authScheme, AUTH_BASIC ) == false )    {        cpLog(LOG_DEBUG_STACK, "Tag %s scheme is not Basic", authScheme.logData() );        return false;    }    if (pwd.length())    {        SipBasic basic;        cookie = basic.formSIPBasic(data, pwd);    }    else    {        cookie = data;    }    //get cookie from proxyAuth, and compare    Data recvdcookie = authorization->getBasicCookie();    if (recvdcookie == cookie)    {        cpLog(LOG_DEBUG_STACK, "Basic authentication successful");        return true;    }    // -ctam    cpLog(LOG_DEBUG_STACK, "cookie (msg) = %s", cookie.logData() );    cpLog(LOG_DEBUG_STACK, "data   (ms)  = %s", data.logData() );    cpLog(LOG_DEBUG_STACK, "Basic authentication failed");    return false;}voidSipCommand::setProxyAuthDigest(const Data& nonce, const Data& user,                               const Data& pwd, const Data& method,                               const Data& realm, const Data& requestURI,                               const Data& qop, const Data& cnonce,                               const Data& alg, const Data& noncecount,                               const Data& opaque){    Sptr<SipProxyAuthorization> authorization;    myHeaderList.getParsedHeader(authorization, SIP_PROXY_AUTHORIZATION_HDR);    SipDigest sipDigest;    Data response = sipDigest.form_SIPdigest(nonce, user, pwd, method,                    requestURI, realm, qop, cnonce, alg, noncecount);    cpLog(LOG_DEBUG_STACK, "setAuthDigest::Response = %s\n", 	  response.logData());        //set this as response in authorization.        authorization->setAuthScheme(AUTH_DIGEST);    if(user != "")    {        authorization->setTokenDetails("username", user); //1    }    if(realm != "")    {        authorization->setTokenDetails("realm", realm);  //2    }    if(nonce != "")    {        authorization->setTokenDetails("nonce", nonce);  //3    }    if(response != "")    {        authorization->setTokenDetails("response", response); //4    }    if(qop != "")    {        authorization->setTokenDetails("qop", qop); //5    }    if(requestURI != "")    {        authorization->setTokenDetails("uri", requestURI); //6    }    if(cnonce != "")    {        authorization->setTokenDetails("cnonce", cnonce); //7    }    if(noncecount != "")    {        authorization->setTokenDetails("nc", noncecount); //8    }    if(opaque != "")    {        authorization->setTokenDetails("opaque", opaque); //9    }    if(alg != "")    {        authorization->setTokenDetails("algorithm", alg); // 10    }}voidSipCommand::setAuthDigest(const Data& nonce, const Data& user,                          const Data& pwd, const Data& method,                          const Data& realm, const Data& requestURI,                          const Data& qop, const Data& cnonce,                          const Data& alg, const Data& noncecount,                          const Data& opaque){    Sptr<SipAuthorization> authorization;    myHeaderList.getParsedHeader(authorization, SIP_AUTHORIZATION_HDR);    SipDigest sipDigest;    Data response = sipDigest.form_SIPdigest(nonce, user, pwd, method,                    requestURI, realm, qop, cnonce, alg, noncecount);    cpLog(LOG_DEBUG_STACK, "setAuthDigest::Response = %s\n", 	  response.logData());        //set this as response in authorization.        authorization->setAuthScheme(AUTH_DIGEST);        if(user != "")    {        authorization->setTokenDetails("username", user); //1    }    if(realm != "")    {        authorization->setTokenDetails("realm", realm);  //2    }    if(nonce != "")    {        authorization->setTokenDetails("nonce", nonce);  //3    }    if(response != "")    {        authorization->setTokenDetails("response", response); //4    }    if(qop != "")    {        authorization->setTokenDetails("qop", qop); //5    }    if(requestURI != "")    {        authorization->setTokenDetails("uri", requestURI); //6    }    if(cnonce != "")    {        authorization->setTokenDetails("cnonce", cnonce); //7    }    if(noncecount != "")    {        authorization->setTokenDetails("nc", noncecount); //8    }    if(opaque != "")    {        authorization->setTokenDetails("opaque", opaque); //9    }    if(alg != "")    {        authorization->setTokenDetails("algorithm", alg); // 10    }}boolSipCommand::checkAuthDigest(const Data& nonce,                             const Data& user,                            const Data& pwd,                             const Data& realm,                            const Data& requestURI,                            const bool authReg /* default value */){    Sptr<SipAuthorization> authorization;    myHeaderList.getParsedHeader(authorization, SIP_AUTHORIZATION_HDR);    Sptr<SipProxyAuthorization> proxyAuth;    myHeaderList.getParsedHeader(proxyAuth, SIP_PROXY_AUTHORIZATION_HDR);    Data authScheme;    if (authReg)    {        cpLog( LOG_DEBUG_STACK,                "using Authorization: header for digest check");        authScheme = authorization->getAuthScheme();    }    else    {        cpLog( LOG_DEBUG_STACK,                "using Proxy-Authorization: header for digest check");        authScheme = proxyAuth->getAuthScheme();    }        Data method;    method = myRequestLine.getMethod();    // xxx need to test this    if ( isEqualNoCase( authScheme, AUTH_DIGEST ) == false   )    {        cpLog(LOG_DEBUG_STACK, "AUTH_DIGEST: %s", AUTH_DIGEST.logData());        cpLog(LOG_DEBUG_STACK, "authScheme: %s", authScheme.logData());        cpLog(LOG_DEBUG_STACK, "Tag %s Not a DIGEST scheme", authScheme.logData() );        return false;    }    else    {        Data checksum;        Data algorithm;        Data msgNonce;        if (authReg)        {            checksum  = authorization->getTokenValue("response");            algorithm = authorization->getTokenValue("algorithm");            msgNonce  = authorization->getTokenValue("nonce");        }        else        {            checksum  = proxyAuth->getTokenValue("response");            algorithm = proxyAuth->getTokenValue("algorithm");            msgNonce  = proxyAuth->getTokenValue("nonce");        }        if(!isEqualNoCase(nonce, msgNonce))        {            cpLog(LOG_DEBUG_STACK, "passed nonce != msg nonce");            cpLog(LOG_DEBUG_STACK, "passed nonce == %s", nonce.logData());            cpLog(LOG_DEBUG_STACK, "msg nonce    == %s", msgNonce.logData());            return false;        }        if (checksum.length() == 0)        {            cpLog(LOG_DEBUG_STACK, "zero length digest data");            return false;        }        cpLog( LOG_DEBUG_STACK, "Calling form_SIPdigest with:" );        cpLog( LOG_DEBUG_STACK, "  nonce    = %s", nonce.logData() );        cpLog( LOG_DEBUG_STACK, "  user     = %s", user.logData() );        cpLog( LOG_DEBUG_STACK, "  pswd     = %s", pwd.logData() );        cpLog( LOG_DEBUG_STACK, "  method   = %s", method.logData() );        cpLog( LOG_DEBUG_STACK, "  uri      = %s", requestURI.logData());        cpLog( LOG_DEBUG_STACK, "  realm    = %s", realm.logData());        cpLog( LOG_DEBUG_STACK, "  algorithm= %s", algorithm.logData());        SipDigest sipDigest;        Data response = sipDigest.form_SIPdigest(nonce,                                                  user,                                                  pwd,                                                  method,                                                 requestURI,                                                  realm,                                                  Data(""),                                                 Data(""),                                                  algorithm,                                                 Data(""));        cpLog(LOG_DEBUG_STACK, "Message digest    == %s",               checksum.logData());        cpLog(LOG_DEBUG_STACK, "Calculated digest == %s\n",               response.logData());        if (checksum == response)        {            cpLog(LOG_DEBUG_STACK, " Digest authentication successful");            return true;        }        else        {            cpLog(LOG_DEBUG_STACK, " Digest authentication failed");            return false;        }    }    return false;}Data SipCommand::computeBranch(Data hashBranch /* default value */) const{    Sptr <BaseUrl> toBaseUrl = getTo().getUrl();    if (toBaseUrl.getPtr() != 0)    {	if (toBaseUrl->getType() == SIP_URL)	{	    Sptr <SipUrl> sipUrl;	    sipUrl.dynamicCast(toBaseUrl);	    hashBranch += sipUrl->getNameAddr();	}    }        Sptr <BaseUrl> fromBaseUrl = getFrom().getUrl();    if (fromBaseUrl.getPtr() != 0)    {	if (fromBaseUrl->getType() == SIP_URL)	{	    Sptr <SipUrl> sipUrl;	    sipUrl.dynamicCast(fromBaseUrl);    	    hashBranch+= sipUrl->getNameAddr();	}    }    hashBranch+= getCallId().encode();        Sptr <BaseUrl> reqBaseUrl = getRequestLine().getUrl();    if (reqBaseUrl.getPtr() != 0)    {	if (reqBaseUrl->getType() == SIP_URL)	{	    Sptr <SipUrl> sipUrl;	    sipUrl.dynamicCast(reqBaseUrl);	    hashBranch+= sipUrl->getNameAddr();	}    }    hashBranch+= getCSeq().getCSeqData();        unsigned len = (unsigned int)(hashBranch.length());        //form MD5 out of hashBranch, and return.    MD5Context ctx;    MD5Init(&ctx);    LocalScopeAllocator lo;     MD5Update(&ctx, (unsigned char*)(hashBranch.getData(lo)), len);            unsigned char hashDigest[16];        MD5Final(hashDigest, &ctx);        hashBranch = convertToHex(hashDigest, 16);        return hashBranch;}    DataSipCommand::computeUniqueBranch(){    return RandomHex::get(4);}DataSipCommand::computeProxyBranch() const{    Data result("z9hG4bK"); // magic cookie per rfc2543bis-09        result += computeStatelessProxyBranch();    result += ".";    result += computeUniqueBranch();    return result;}DataSipCommand::computeStatelessProxyBranch() const{    return computeBranch();}boolSipCommand::detectLoop() const{    SipViaList viaList = getViaList();    Data checkBranch = computeBranch();    for( SipViaList::iterator i = viaList.begin();i != viaList.end(); i++ )    {        Data pb;        if (((*i)->getBranch().match(".", &pb) == FOUND) &&             ( pb == checkBranch) )        {            return true;        }    }    return false;}Data SipCommand::computeBranch2() const{    return computeBranch(Data(theSystem.gethostAddress())                          + Data(theSystem.getSystemPort()));}DataSipCommand::encode() const{    Data data;    data = myRequestLine.encode();    encodeBody(&data);    return data;}bool SipCommand::toBeRetransmitted() const{    if(getType() != SIP_ACK) return true;    return false;}// see section 16.6 and 16.7 of bis09 draft - !jf!Sptr<SipUrl>SipCommand::postProcessRouteAndGetNextHop() {    Sptr<SipUrl> url;    Sptr<BaseUrl> burl;#if 1    burl = getRequestLine().getUrl();#else     // loose routing not working !jf!    if (routeEmpty()) // send to value in req-uri    {        burl = getRequestLine().getUrl();    }    else if (!routeFront().getUrl()->isLooseRouterPresent())    {        SipRoute route;        route.setUrl(getRequestLine().getUrl());        routePushBack(route);        burl = routeFront().getUrl();        getMutableRequestLine().setUrl(burl);        routePopFront();    }    else   // send it to first entry in route if it exists    {        burl = routeFront().getUrl();    }#endif    url.dynamicCast(burl);            return url;}/* Local Variables: *//* c-file-style: "stroustrup" *//* indent-tabs-mode: nil *//* c-file-offsets: ((access-label . -) (inclass . ++)) *//* c-basic-offset: 4 *//* End: */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -