Ofek Agmon
Ofek Agmon

Reputation: 5198

pjsua - getting 403 forbidden (bad auth)

I am using the python module for pjsua and trying to register to a PBX.

here is the code:

import sys
import pjsua as pj
import threading


def log_cb(level, str, len)
    print str,

class MyAccountCallback(pj.AccountCallback)
    sem = None

    def __init__(self, account)
        pj.AccountCallback.__init__(self, account)

    def wait(self)
        self.sem = threading.Semaphore(0)
        self.sem.acquire()

    def on_reg_state(self)
        if self.sem
            if self.account.info().reg_status = 200
                self.sem.release()

lib = pj.Lib()

try
    lib.init(log_cfg = pj.LogConfig(level=4, callback=log_cb))
    lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(5060))
    lib.start()

    acc = lib.create_account(pj.AccountConfig("181.21.200.109:5060", "561123", "admin"))

    acc_cb = MyAccountCallback(acc)
    acc.set_callback(acc_cb)
    acc_cb.wait()

    print n
    print Registration complete, status=, acc.info().reg_status, 
          ( + acc.info().reg_reason + )
    print nPress ENTER to quit
    sys.stdin.readline()

    lib.destroy()
    lib = None

except pj.Error, e
    print Exception  + str(e)
    lib.destroy()

the PBX IP is 181.21.200.109, the number I am trying to register is 123456, and as for the password - I just put 123 (I don't think the PBX requires password).

I get from the PBX a sip packet SIP 403 forbidden (bad auth).

To compare, I looked at another register packet from a different sip client that registered successfully. (the PBX sends back OPTIONS Packet).

Here are the packets:

This packet gets FORBIDEN (bad auth) response (failed)

REGISTER sip:181.21.200.109:5060 SIP/2.0

Via: SIP/2.0/UDP 181.21.200.50:51117;rport;branch=z9hG4bKPj36c48c6ff87b47ac86c9036e0acbaed4 (Different)

Route: <sip:181.21.200.109:5060;lr> (Different)

Max-Forwards: 70

From: <sip:[email protected]>;tag=10a3290c7748480c9c0808366ae0c840 (Different)

To: <sip:[email protected]> (Different)

Call-ID: 94f280c9cfcf41539b500ff39582a1ef

CSeq: 21606 REGISTER

User-Agent: pjsip python

Contact: <sip:[email protected]:51117;ob> (Different)

Expires: 300

Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS - (Different Options)

Authorization: Digest username="561123", realm="asterisk", nonce="21f4ad6b", uri="sip:181.21.200.109:5060", response="62a339057d2b4e3fed4d368ff94f6d46", algorithm=MD5

Content-Length:  0

This packet gets OPTIONS response (success)

REGISTER sip:181.21.200.109:5060 SIP/2.0

Via: SIP/2.0/UDP 181.21.200.150;rport;branch=z9hG4bK4H5Z6Z2myFUNr

Max-Forwards: 70

From: <sip:[email protected]:5060>;tag=307m6Zy8cj7pa

To: <sip:[email protected]:5060>

Call-ID: f3ce9234-40e3-1233-a783-5c6b32d1a9b5

CSeq: 3 REGISTER

Contact: <sip:[email protected]>

User-Agent: sofia-sip/1.12.11

Allow: REGISTER, INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, SUBSCRIBE, REFER, UPDATE, INFO

Supported: timer, 100rel, path

Authorization: Digest username="561123", realm="asterisk", nonce="7625cf17", algorithm=MD5, uri="sip:181.21.200.109:5060", response="dca3173b2159f812481ca0c96b10a751"

Content-Length: 0

Does anybody know why am I getting the forbidden response? is there something wrong with my code?

thanks in adcance

Upvotes: 1

Views: 2812

Answers (1)

TMSZ
TMSZ

Reputation: 687

Your PABX does require password for these accounts (otherwise we wouldn't see nonce, response and Authorization header itself) so make sure password is valid. Asterisk may also reject registration with 403 if account is not found (configuration: alwaysauthreject=yes) and your logs don't clarify that as you've tried to register different extension from python and from standalone client.

It would be best to use same extension for comparison (but don't try registering two softphones same time to same extension).

Upvotes: 1

Related Questions