Ошибка регистрации SIP: нет подходящих учетных данных (PJSIP_ENOCREDENTIAL) [status = 171101] Приложение для iOS - PullRequest
0 голосов
/ 26 марта 2019

Я реализую PJSip в приложении для iOS.

Я добавил пользователя sip от сервера, используя этот метод sip_add_account(NSDictionary *account, pjsua_acc_id *acc_id)

Но сервер добавляет к деталям пользователя, а не к Аутентификации, получая эту ошибку:

*07:44:06.880  pjsua_acc.c !....IP address change detected for account 0 (192.168.0.103:5070 --> 103.87.56.179:50721). Updating registration (using method 4)
    07:44:06.880  pjsua_acc.c  ....SIP registration error: No suitable credential (PJSIP_ENOCREDENTIAL) [status=171101]

Я не смог найти связанных вопросов. Когда сервер Добавить все детали, но не аутентифицировать пользователя сервер формы

Как:

Invite Accept 
**##
T 174.67.192.233:64402 -> xxx.xxx.xxx.xxx:5070 [AP]
INVITE sip:19492321401@xxx.xxx.xxx.xxx:5070 SIP/2.0.
Via: SIP/2.0/TCP 192.168.50.107:64402;branch=z9hG4bK254205087;rport;alias.
From: <sip:19494197634@xxx.xxx.xxx.xxx:5070>;tag=1547958148.
To: <sip:19492321401@xxx.xxx.xxx.xxx:5070>.
Call-ID: 80149780-38444-2@BJC.BGI.FA.BAH.
CSeq: 10 INVITE.
Contact: <sip:19494197634@xxx.xxx.xxx.xxx:64402;transport=tcp>.
Max-Forwards: 70.`enter code here`
User-Agent: Grandstream Wave 1.2.9.
Privacy: none.
P-Preferred-Identity: <sip:19494197634@xxx.xxx.xxx.xxx:5070>.
Supported: replaces, path, timer, eventlist.
Allow: INVITE, ACK, OPTIONS, CANCEL, BYE, SUBSCRIBE, NOTIFY, INFO, REFER, UPDATE, MESSAGE.
Content-Type: application/sdp.
Accept: application/sdp, application/dtmf-relay.
Content-Length:   719.**

Но без аутентификации и получения ответа со стороны сервера

///Save & get value From Preference 
 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:

                        [NSNumber numberWithInt:300], @"regTimeout",

                        [NSNumber numberWithBool:YES], @"enableNat",

                        [NSNumber numberWithBool:NO], @"enableMJ",

                        [NSNumber numberWithInt: 5070], @"localPort",

                        [NSNumber numberWithInt: 4000], @"rtpPort",

                        [NSNumber numberWithInt: 30], @"kaInterval",

                        [NSNumber numberWithBool:YES], @"enableEC",

                        [NSNumber numberWithBool:NO], @"disableVad",

                        [NSNumber numberWithInt: 1], @"codec",

                        [NSNumber numberWithBool:YES], @"dtmfWithInfo",

                        [NSNumber numberWithBool:YES],@"removeIntlPrefix",

                        [NSNumber numberWithBool:NO], @"enableICE",

                        [NSNumber numberWithInt: 3], @"logLevel",

                        [NSNumber numberWithBool:YES],  @"enableG711u",

                        [NSNumber numberWithBool:YES],  @"enableG711a",

                        [NSNumber numberWithBool:YES],   @"enableG722",

                        [NSNumber numberWithBool:YES],   @"enableG7221",

                        [NSNumber numberWithBool:YES],   @"enableG729",

                        [NSNumber numberWithBool:YES],  @"enableGSM",

                        [NSNumber numberWithBool:YES], @"keepAwake",

                        [NSNumber numberWithBool:YES], kVoipOverEdge,

                        [[NSUserDefaults standardUserDefaults] objectForKey:UserPhoneNo_Key], @"username",

                        [[NSUserDefaults standardUserDefaults] objectForKey:UserPwd_Key], @"password",

                        kServer, @"server",

                        kStrnServer, @"proxyServer",

                        kStrnServer, @"PJSipServer",

                        //kStrnServer,@"stunServer",

                        nil];




// Code In Objective c 
pj_status_t sip_connect(pj_pool_t *pool, pjsua_acc_id *acc_id)

{

    pj_status_t status;

    pjsua_acc_config acc_cfg;

    const char *uname;

    const char *authname;

    const char *contactname;

    const char *passwd;

    const char *server;



    SiphonApplication *app = (SiphonApplication *)[SiphonApplication sharedApplication];



    // TODO Verify if wifi is connected, if not verify if the user wants edge connection



    uname  = [[[NSUserDefaults standardUserDefaults] stringForKey:

               @"username"] UTF8String]; // 1234567890

    authname  = [[[NSUserDefaults standardUserDefaults] stringForKey:

                  @"authname"] UTF8String]; //1234567890

    contactname  = [[[NSUserDefaults standardUserDefaults] stringForKey:

                     @"contact"] UTF8String]; //1234567890

    passwd = [[[NSUserDefaults standardUserDefaults] stringForKey:

               @"password"] UTF8String]; // 123456

    server = [[[NSUserDefaults standardUserDefaults] stringForKey:

               @"server"] UTF8String]; //xx.xx.xxx.xx





    pjsua_acc_config_default(&acc_cfg);



    // ID

    acc_cfg.id.ptr = (char*) pj_pool_alloc(/*app_config.*/pool, PJSIP_MAX_URL_SIZE);

    if (contactname && strlen(contactname))

        acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,

                                           "\"%s\"<sip:%s@%s>", contactname, uname, server);

    else

        acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,

                                           "sip:%s@%s", uname, server);

     PJ_LOG(1,(THIS_FILE, "'%s'", acc_cfg.id));

    if ((status = pjsua_verify_sip_url(acc_cfg.id.ptr)) != 0)

    {

        PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in local id argument",

                  acc_cfg.id));

        [app displayParameterError: @"Invalid value for username or server."];

        return status;

    }

    // Registrar

    acc_cfg.reg_uri.ptr = (char*) pj_pool_alloc(/*app_config.*/pool,

                                                PJSIP_MAX_URL_SIZE);

    acc_cfg.reg_uri.slen = pj_ansi_snprintf(acc_cfg.reg_uri.ptr,

                                            PJSIP_MAX_URL_SIZE, "sip:%s", server);

    if ((status = pjsua_verify_sip_url(acc_cfg.reg_uri.ptr)) != 0)

    {

        PJ_LOG(1,(THIS_FILE,  "Error: invalid SIP URL '%s' in registrar argument",

                  acc_cfg.reg_uri));

        [app displayParameterError: @"Invalid value for server parameter."];

        return status;

    }



    //acc_cfg.id = pj_str(id);

    //acc_cfg.reg_uri = pj_str(registrar);

    acc_cfg.cred_count = 1;

    acc_cfg.cred_info[0].scheme = pj_str("Digest");

    acc_cfg.cred_info[0].realm = pj_str("*");//pj_str(realm);

    if (authname && strlen(authname))

        acc_cfg.cred_info[0].username = pj_str((char *)authname);

    else

        acc_cfg.cred_info[0].username = pj_str((char *)uname);

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableMJ"])

        acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_DIGEST;

    else

        acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;

    acc_cfg.cred_info[0].data = pj_str((char *)passwd);



    acc_cfg.publish_enabled = PJ_TRUE;

#if defined(MWI) && MWI==1

    acc_cfg.mwi_enabled = PJ_TRUE;

#endif



    acc_cfg.allow_contact_rewrite = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableNat"];



    // FIXME: gestion du message 423 dans pjsip

    acc_cfg.reg_timeout = [[NSUserDefaults standardUserDefaults] integerForKey: @"regTimeout"];

    if (acc_cfg.reg_timeout < 1 || acc_cfg.reg_timeout > 3600)

    {

        PJ_LOG(1,(THIS_FILE,

                  "Error: invalid value for timeout (expecting 1-3600)"));

        [app displayParameterError:

         @"Invalid value for timeout (expecting 1-3600)."];

        return PJ_EINVAL;

    }

    acc_cfg.reg_retry_interval = 300;

    acc_cfg.reg_first_retry_interval = 60;



    // Keep alive interval

    acc_cfg.ka_interval = [[NSUserDefaults standardUserDefaults] integerForKey:@"kaInterval"];



    // proxies server

    NSString *proxies = [[NSUserDefaults standardUserDefaults] stringForKey: @"proxyServer"];

    NSArray *array = [proxies componentsSeparatedByString:@","];

    NSEnumerator *enumerator = [array objectEnumerator];

    NSString *anObject;

    while (anObject = [enumerator nextObject])

    {

        NSMutableString *mutableStr = [anObject mutableCopy];

        CFStringTrimWhitespace((CFMutableStringRef)mutableStr);

        const char *proxy = [mutableStr UTF8String];

        if (proxy && strlen(proxy))

        {

            if (acc_cfg.proxy_cnt==PJ_ARRAY_SIZE(acc_cfg.proxy))

            {

                PJ_LOG(1,(THIS_FILE, "Error: too many proxy servers"));

                break;

            }

            pj_str_t pj_proxy;

            pj_proxy.slen = strlen(proxy) + 20;

            pj_proxy.ptr = (char*) pj_pool_alloc(pool, pj_proxy.slen);

            pj_proxy.slen = pj_ansi_snprintf(pj_proxy.ptr, pj_proxy.slen, "sip:%s", proxy);

            if ((status = pjsua_verify_sip_url(pj_proxy.ptr)) != 0)

            {

                PJ_LOG(1,(THIS_FILE,  "Error: invalid SIP URL '%*.s' in proxy argument (%d)",

                          pj_proxy.slen, pj_proxy.ptr, status));

                [app displayParameterError: @"Invalid value for proxy parameter."];

                continue;

            }

            acc_cfg.proxy[acc_cfg.proxy_cnt++] = pj_proxy;

            acc_cfg.reg_use_proxy=3;

        }

    }



    #if LOCAL_ACCOUNT

        *acc_id = aid;

    #else

        status = pjsua_acc_add(&acc_cfg, PJ_TRUE, acc_id);

        if (status != PJ_SUCCESS)

        {

            pjsua_perror(THIS_FILE, "Error adding new account", status);

            [app displayParameterError: @"Error adding new account."];

        }

    #endif

        return status;

    }
...