Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ pjsip应用程序无法注册帐户,出现无效/不受支持的摘要算法错误_C++_Sip_Pjsip - Fatal编程技术网

C++ pjsip应用程序无法注册帐户,出现无效/不受支持的摘要算法错误

C++ pjsip应用程序无法注册帐户,出现无效/不受支持的摘要算法错误,c++,sip,pjsip,C++,Sip,Pjsip,我尝试使用pjsiplibrary运行,但当我运行应用程序时,遇到了以下错误: 06:56:50.480 sip_auth_client.c ...Unsupported digest algorithm "SHA-256" 06:56:50.480 pjsua_acc.c ....SIP registration error: Invalid/unsupported digest algorithm (PJSIP_EINVALIDALGORITHM) [st

我尝试使用
pjsip
library运行,但当我运行应用程序时,遇到了以下错误:

06:56:50.480      sip_auth_client.c  ...Unsupported digest algorithm "SHA-256"
06:56:50.480            pjsua_acc.c  ....SIP registration error: Invalid/unsupported digest algorithm (PJSIP_EINVALIDALGORITHM) [status=171102]
但是当我检查来自服务器的SIP响应时,我注意到它包含两个
WWW-Authenticate
头:

WWW-Authenticate: Digest realm="sip.linphone.org", nonce="ImEX4gAAAAC73QlWAAC9corBNkwAAAAA", opaque="+GNywA==", algorithm=SHA-256, qop="auth"
WWW-Authenticate: Digest realm="sip.linphone.org", nonce="ImEX4gAAAAC73QlWAAC9corBNkwAAAAA", opaque="+GNywA==", algorithm=MD5, qop="auth"
所以问题是,如果
pjsip
不支持
sha-256
算法,为什么它不使用第二个标题中提到的
md5
算法

示例代码是:

#include <pjsua2.hpp>
#include <iostream>

using namespace pj;

// Subclass to extend the Account and get notifications etc.
class MyAccount : public Account {
public:
    virtual void onRegState(OnRegStateParam &prm) {
        AccountInfo ai = getInfo();
        std::cout << (ai.regIsActive? "*** Register:" : "*** Unregister:")
                  << " code=" << prm.code << std::endl;
    }
};

int main()
{
    Endpoint ep;

    ep.libCreate();

    // Initialize endpoint
    EpConfig ep_cfg;
    ep.libInit( ep_cfg );

    // Create SIP transport. Error handling sample is shown
    TransportConfig tcfg;
    tcfg.port = 5060;
    try {
        ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg);
    } catch (Error &err) {
        std::cout << err.info() << std::endl;
        return 1;
    }

    // Start the library (worker threads etc)
    ep.libStart();
    std::cout << "*** PJSUA2 STARTED ***" << std::endl;

    // Configure an AccountConfig
    AccountConfig acfg;
    acfg.idUri = "sip:test@pjsip.org";
    acfg.regConfig.registrarUri = "sip:pjsip.org";
    AuthCredInfo cred("digest", "*", "test", 0, "secret");
    acfg.sipConfig.authCreds.push_back( cred );

    // Create the account
    MyAccount *acc = new MyAccount;
    acc->create(acfg);

    // Here we don't have anything else to do..
    pj_thread_sleep(10000);

    // Delete the account. This will unregister from server
    delete acc;

    // This will implicitly shutdown the library
    return 0;
}
#包括
#包括
使用名称空间pj;
//子类扩展帐户并获取通知等。
类别MyAccount:公共帐户{
公众:
虚拟void onRegState(onregstatepram&prm){
AccountInfo ai=getInfo();

std::cout我自己也在努力解决这个问题。显然,PJSIP只计算第一个WWW-Authenticate报头,即使服务器提供了多个报头

为了克服这个问题,我在源代码中更改了以下内容:

在文件
/pjsip/src/pjsip/sip_auth_client.c
中找到为WWW Authenticate头生成响应的代码块。它应该在第1220行附近

/* Create authorization header for this challenge, and update
 * authorization session.
 */
status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri,
              tdata, sess, cached_auth, &hauth);
if (status != PJ_SUCCESS)
    return status;

if (pj_pool_get_used_size(cached_auth->pool) >
    PJSIP_AUTH_CACHED_POOL_MAX_SIZE) 
{
    recreate_cached_auth_pool(sess->endpt, cached_auth);
}   

/* Add to the message. */
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth);

/* Process next header. */
hdr = hdr->next;
并将其替换为

/* Create authorization header for this challenge, and update
 * authorization session.
 */
status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri,
              tdata, sess, cached_auth, &hauth);
if (status != PJ_SUCCESS){
    // Previously, pjsip analysed one www-auth header, and if it failed (due to unsupported sha-256 digest for example), it returned and did not consider the next www-auth header.
    PJ_LOG(4,(THIS_FILE, "Invalid response, moving to next"));
    //return status;
    hdr = hdr->next;
}else{
    if (pj_pool_get_used_size(cached_auth->pool) >
        PJSIP_AUTH_CACHED_POOL_MAX_SIZE) 
    {
        recreate_cached_auth_pool(sess->endpt, cached_auth);
    }   

    /* Add to the message. */
    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth);

    /* Process next header. */
    hdr = hdr->next;
}
然后重新编译源代码(按照这些说明)


请注意,尽管这解决了linphone的问题,但我没有在其他情况下测试这一点(例如,当服务器发送多个有效算法或根本没有有效算法时)。

我自己也在努力解决这一问题。显然,PJSIP只评估第一个WWW Authenticate头,即使服务器提供了多个

为了克服这个问题,我在源代码中更改了以下内容:

在文件
/pjsip/src/pjsip/sip_auth_client.c
中找到为WWW Authenticate头生成响应的代码块。它应该在第1220行附近

/* Create authorization header for this challenge, and update
 * authorization session.
 */
status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri,
              tdata, sess, cached_auth, &hauth);
if (status != PJ_SUCCESS)
    return status;

if (pj_pool_get_used_size(cached_auth->pool) >
    PJSIP_AUTH_CACHED_POOL_MAX_SIZE) 
{
    recreate_cached_auth_pool(sess->endpt, cached_auth);
}   

/* Add to the message. */
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth);

/* Process next header. */
hdr = hdr->next;
并将其替换为

/* Create authorization header for this challenge, and update
 * authorization session.
 */
status = process_auth(tdata->pool, hchal, tdata->msg->line.req.uri,
              tdata, sess, cached_auth, &hauth);
if (status != PJ_SUCCESS){
    // Previously, pjsip analysed one www-auth header, and if it failed (due to unsupported sha-256 digest for example), it returned and did not consider the next www-auth header.
    PJ_LOG(4,(THIS_FILE, "Invalid response, moving to next"));
    //return status;
    hdr = hdr->next;
}else{
    if (pj_pool_get_used_size(cached_auth->pool) >
        PJSIP_AUTH_CACHED_POOL_MAX_SIZE) 
    {
        recreate_cached_auth_pool(sess->endpt, cached_auth);
    }   

    /* Add to the message. */
    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)hauth);

    /* Process next header. */
    hdr = hdr->next;
}
然后重新编译源代码(按照这些说明)

请注意,尽管这解决了linphone的问题,但我没有在其他情况下测试这一点(例如,当服务器发送多个有效算法或根本没有算法时)