[RESOLVED] Unexplainable password mismatch using pjsua2 to register account on Astericks

#Hello everybody,
I am experiencing a very strange problem when trying to register an account on a new install of Astericks. My configuration is as follows:

  • VMware running Ubuntu 14.04 with Asterisk 11.21.2 install
    -PJSIP 2.4.5 installed (I am working on a client based on it)
    -Python script using PJsua2 python wrapper that tries to register on the Asterisk server.

I have successful ran the helloworld example from a different port on the same machine (4051 instead of 4050) by using Zoiper as a client, validating my installation and setup (I was also able to do the same with Linphone).

I am now trying to do the same with the python script using PJsua2 but I cannot successfully register. The server answers with a 403 message indicating the authentication failed. I can also see from the console that the problem is that the password I provide from PJsua is wrong.

I have checked multiple times that the password in the sip.config file and the one provided with the python script.

#Any help would really be appreciated and will probably save me from going insane.

This is the message I get from Asterisk:

[Mar 16 18:23:32] NOTICE[3993]: chan_sip.c:28360 handle_request_register: Registration from '<sip:192.168.32.173>' failed for '192.168.32.173:5061' - Wrong password

this is what the python script sends and receives:

REGISTER sip:192.168.32.173 SIP/2.0
Via: SIP/2.0/UDP 192.168.32.173:5061;rport;branch=z9hG4bKPj9EEbUpvOiJD3xDrK7OspsPSnu0I9.gdX
Max-Forwards: 70
From: sip:192.168.32.173;tag=9tE8B.rXgmW6GalGNB89S6gNCisXpELk
To: sip:192.168.32.173
Call-ID: Zqr-ljsCUPdzrHqCD8N0y4e4FrpKkS-F
CSeq: 27860 REGISTER
Contact: sip:192.168.32.173:5061;ob
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

–end msg–
18:29:02.307 pjsua_core.c .RX 566 bytes Response msg 401/REGISTER/cseq=27860 (rdata0x91dd794) from UDP 192.168.32.173:5060:
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.32.173:5061;branch=z9hG4bKPj9EEbUpvOiJD3xDrK7OspsPSnu0I9.gdX;received=192.168.32.173;rport=5061
From: sip:192.168.32.173;tag=9tE8B.rXgmW6GalGNB89S6gNCisXpELk
To: sip:192.168.32.173;tag=as1547e23d
Call-ID: Zqr-ljsCUPdzrHqCD8N0y4e4FrpKkS-F
CSeq: 27860 REGISTER
Server: Asterisk PBX 11.21.2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm=“asterisk”, nonce="5cd60f00"
Content-Length: 0

–end msg–
18:29:02.308 pjsua_acc.c …Acc 0: Registration sent
18:29:02.309 pjsua_core.c !Shutting down, flags=0…
18:29:02.309 pjsua_core.c !PJSUA state changed: RUNNING --> CLOSING
18:29:02.309 pjsua_core.c …TX 638 bytes Request msg REGISTER/cseq=27861 (tdta0x91e04f0) to UDP 192.168.32.173:5060:
REGISTER sip:192.168.32.173 SIP/2.0
Via: SIP/2.0/UDP 192.168.32.173:5061;rport;branch=z9hG4bKPjoisgZabhE68D4-6QMwCfiPtd1PUP4e-M
Max-Forwards: 70
From: sip:192.168.32.173;tag=9tE8B.rXgmW6GalGNB89S6gNCisXpELk
To: sip:192.168.32.173
Call-ID: Zqr-ljsCUPdzrHqCD8N0y4e4FrpKkS-F
CSeq: 27861 REGISTER
Contact: sip:192.168.32.173:5061;ob
Expires: 300
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username=“6001”, realm=“asterisk”, nonce=“5cd60f00”, uri=“sip:192.168.32.173”, response=“6cc94c7bf437459f66dbffdfd804c1ad”, algorithm=MD5
Content-Length: 0

–end msg–
18:29:02.310 pjsua_core.c .RX 487 bytes Response msg 403/REGISTER/cseq=27861 (rdata0xb1d01634) from UDP 192.168.32.173:5060:
SIP/2.0 403 Forbidden
Via: SIP/2.0/UDP 192.168.32.173:5061;branch=z9hG4bKPjoisgZabhE68D4-6QMwCfiPtd1PUP4e-M;received=192.168.32.173;rport=5061
From: sip:192.168.32.173;tag=9tE8B.rXgmW6GalGNB89S6gNCisXpELk
To: sip:192.168.32.173;tag=as1547e23d
Call-ID: Zqr-ljsCUPdzrHqCD8N0y4e4FrpKkS-F
CSeq: 27861 REGISTER
Server: Asterisk PBX 11.21.2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0

–end msg–


This the python script I am using

import pjsua2 as pj
import time

class Account(pj.Account):
def onRegState(self, prm):
print "***OnRegState: " + prm.reason

def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)

# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig();
sipTpConfig.port = 5061;
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig);
# Start the library
ep.libStart();

acfg = pj.AccountConfig();
acfg.idUri = "sip:192.168.32.173";
acfg.regConfig.registrarUri = "sip:192.168.32.173";
cred = pj.AuthCredInfo("digest", "asterisk", "6001", 0, "1234");
acfg.sipConfig.authCreds.append(cred);

print "--------------------> got here"
# Create the account
acc = Account();
acc.create(acfg, 1)

# Here we don't have anything else to do..
#time.sleep(10);

# Destroy the library
ep.libDestroy()

if name == “main”:
pjsua2_test()


and finally this is the sip.config file used for enabling the account I am trying to register:

[general]
context=default

[6001]
username=6001
type=friend
context=from-internal
host=dynamic
secret=1234

Thanks!!!

##SOLVED

I didn’t take into account the fact that wrong password could also mean that the username was wrong. This was the case for me, as the idUri in the accoutn configuration int he python script did not include the username ( sip:[ip] instead of sip:[username]@[ip] ).

I was able to solve the problem by changing

to

acfg = pj.AccountConfig(); acfg.idUri = "sip:6001@192.168.32.173"; acfg.regConfig.registrarUri = "sip:192.168.32.173"; cred = pj.AuthCredInfo("digest", "asterisk", "6001", 0, "1234"); acfg.sipConfig.authCreds.append(cred);

Hope this helps anyone experiencing the same (very daft) issue.