I’ve run into an odd issue trying to get my client that is using PJSIP to talk to Asterisk. The first time it tries to REGISTER with my Asterisk server it get’s back a 401 Unauthorized. Which is expected. However the next attempt, PJSIP should send the Authorization Header in it’s REGISTER request. But it’s not doing this. See below for a snippet of a packet capture I’ve done.
10.200.0.72 is my Asterisk server. And 10.200.154.118 is my client. For reference, it’s an iOS project I’m working on and I’m trying to get my device to register as extension 100.
Here’s the really confusing part. This wasn’t working 2 days ago, and then suddenly yesterday it started working fine. Now today, it’s not working again. It’s almost as if it all of sudden starts working and PJSIP finally sends the Authorization Header. Other devices such as my LinkSys PCAP device are able to register without issue. So I know it must be something I’m doing wrong with PJSIP? I’ve been wrestling with this for over a week and I know it must be something simple but it escapes me. Welcome any thoughts anyone might have?
Also, apologies for the length of this message. I wanted to include as much info as possible. I tried to trim down as much as possible. Via: SIP/2.0/UDP 10.200.154.118:5080;rport;branch=z9hG4bKPjKy2xO6UVBMvX6oiWCt9UrWdclNlhvh31 Call-ID: 6ddWjvyiBuGGfEW7vq2AvF-PF8SSpUxZ Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Via: SIP/2.0/UDP 10.200.154.118:5080;branch=z9hG4bKPjKy2xO6UVBMvX6oiWCt9UrWdclNlhvh31;received=174.0.50.116;rport=15923 Call-ID: 6ddWjvyiBuGGfEW7vq2AvF-PF8SSpUxZ Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE Supported: replaces, timer WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="5d4f67d0" Via: SIP/2.0/UDP 10.200.154.118:5080;rport;branch=z9hG4bKPjKy2xO6UVBMvX6oiWCt9UrWdclNlhvh31 Call-ID: 6ddWjvyiBuGGfEW7vq2AvF-PF8SSpUxZ Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Via: SIP/2.0/UDP 10.200.154.118:5080;rport;branch=z9hG4bKPjKy2xO6UVBMvX6oiWCt9UrWdclNlhvh31 Call-ID: 6ddWjvyiBuGGfEW7vq2AvF-PF8SSpUxZ Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS Via: SIP/2.0/UDP 10.200.154.118:5080;branch=z9hG4bKPjKy2xO6UVBMvX6oiWCt9UrWdclNlhvh31;received=174.0.50.116;rport=15923 Call-ID: 6ddWjvyiBuGGfEW7vq2AvF-PF8SSpUxZ Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE Supported: replaces, timer WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="5d4f67d0"
It’s not any firewall issue obviously as the packets are getting through and I don’t have any restrictions on which IPs can connect to that extension…
For those who are familiar with ObjC.. Here’s my start and register function…
- (void) startAndRegisterOnServer:(NSString *)sipDomain withUserName:(NSString *)sipUser andPassword:(NSString *)password success:(void (^)(void))success failure:(void (^)(int errorCode, NSString *errorMessage))failure if (status != PJ_SUCCESS) failure (status, @"Error in pjsua_create"); // Setup Config and Initialize pjsua_config_default (&config); config.cb.on_incoming_call = &on_incoming_call; config.cb.on_call_media_state = &on_call_media_state; config.cb.on_call_state = &on_call_state; config.cb.on_reg_state2 = &on_reg_state2; pjsua_logging_config logConfig; pjsua_logging_config_default(&logConfig); logConfig.console_level = 3; status = pjsua_init(&config, &logConfig, NULL); if (status != PJ_SUCCESS) failure (status, @"Error in pjsua_init"); pjsua_transport_config udpTransportConfig; pjsua_transport_config_default(&udpTransportConfig); udpTransportConfig.port = 5080; status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &udpTransportConfig, NULL); if (status != PJ_SUCCESS) failure (status, @"Error adding UDP transport"); pjsua_transport_config tcpTransportConfig; pjsua_transport_config_default(&tcpTransportConfig); tcpTransportConfig.port = 5080; status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &tcpTransportConfig, NULL); if (status != PJ_SUCCESS) failure (status, @"Error adding TCP transport"); if (status != PJ_SUCCESS) failure (status, @"Error starting PJSUA"); // UnRegister with SIP Server First if (pjsua_acc_get_count() > 0) [self unregisterAccount]; // Register with SIP Server pjsua_acc_config accountConfig; pjsua_acc_config_default(&accountConfig); char sipAccount [MAX_SIP_ACCOUNT_LENGTH]; sprintf (sipAccount, " sip:%s@%s", [sipUser UTF8String], [sipDomain UTF8String]); accountConfig.id = pj_str(sipAccount); char regUri[MAX_SIP_REGISTER_URI_LENGTH]; sprintf(regUri, " sip:%s", [sipDomain UTF8String]); accountConfig.reg_uri = pj_str(regUri); // Set the accountConfig with the credentials. accountConfig.cred_count = 1; accountConfig.cred_info[0].scheme = pj_str("digest"); accountConfig.cred_info[0].realm = pj_str("asterisk"); accountConfig.cred_info[0].username = pj_str((char *)[sipUser UTF8String]); accountConfig.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; accountConfig.cred_info[0].data = pj_str((char *)[password UTF8String]); status = pjsua_acc_add(&accountConfig, PJ_TRUE, &accID); [PJSIPInterfaceManager sharedInstance].accountID = accID; if (status != PJ_SUCCESS) failure (status, @"Error registering account with server"); // Shutdown audio for PJSIP since we are using CallKit.
Also I know this isn’t related to PJSIP directly but I’ve included my config settings here on Asterisk for reference…
SIP Settings
UDP Bindaddress: 0.0.0.0:5060 TCP SIP Bindaddress: 0.0.0.0:5060 TLS SIP Bindaddress: Disabled Ignore SDP sess. ver.: No Allow unknown access: Yes Allow overlap dialing: Yes Use domains as realms: No Call to non-local dom.: Yes SDP Session Name: Asterisk PBX 13.7.2 Legacy userfield parse: No Auth. Failure Events: Off T.38 MaxDtgrm: 4294967295 --------------------------- --------------------------- SIP address remapping: Enabled using externaddr Localnet: 10.200.0.72/255.255.0.0 Global Signalling Settings: --------------------------- Codecs: (ulaw|alaw|gsm|g726|g723|g729|speex|g722|g719) RTP Keepalive: 0 (Disabled) MWI NOTIFY mime type: application/simple-message-summary Pedantic SIP support: Yes Reg. min duration 60 secs Reg. max duration: 3600 secs Reg. default duration: 3600 secs Sub. min duration 60 secs Sub. max duration: 3600 secs Outbound reg. timeout: 120 secs Outbound reg. attempts: 0 Outbound reg. retry 403:0 Notify ringing state: Yes Max Call Bitrate: 384 kbps Session Expires: 1800 secs Context: from-sip-external Record on feature: automon Record off feature: automon Voice Mail Extension: *97
Here is the config for sip peer 100…
Record On feature : automon Record Off feature : automon CallingPres : Presentation Allowed, Not Screened LastMsgsSent : 32767/65535 T.38 MaxDtgrm: 4294967295 Codecs : (ulaw|alaw|gsm|g726|g723|g729|speex|g722|g719)
I’ve REDACTED any external IP’s for security reasons.
Again, appreciate any thoughts or insights anyone might have. Much appreciated.
Regards,
Peter |