Asterisk 13 PJSIP : "Contact" field in SIP is randomized

Hello,

We are using Asterisk 13.1-cert2 and PJSIP, with Nextiva as the SIP Trunk provider.
Incoming calls are working, but dialing out is not working. The carrier says that there are 2 reasons why dialing out is not working :

  1. If you look at the SIP trace below, the carrier is indicating that the reason for not working is because the “Contact:” line has a cryptic-randomized number in there, instead of the actual contact.

Right now it sends: Contact: sip:ec89dc3e-90df-4fbd-99bd-f5b225f8da3d@107.207.90.90:5060
But it should be sending: Contact: sip:7143861212@107.207.90.90:5060

  1. We are unable to send the X-P-Asserted-Identity, because while the dialplan runs PJSIP_HEADER without error, the option doesn’t make it into the SIP packet.

Thanks a lot in advance for your help !!

(hackers: don’t waste time, private information have been changed)

******** SIP TRACE FOR OUTBOUND CALL **********

<— Transmitting SIP request (891 bytes) to UDP:208.73.140.70:5060 —>
INVITE sip:9492345566@208.73.140.70:5060 SIP/2.0
Via: SIP/2.0/UDP 107.207.90.90:5060;rport;branch=z9hG4bKPja-5qMYTknEobutnWKzOTPpSrCg3swCz
From: "Manager Office"
sip:7143861212@107.207.90.90;tag=slIrplpaQV6S.tpB64u4BEbK-.7HBEis
To: sip:9492345566@208.73.140.70
Contact: sip:ec89dc3e-90df-4fbd-99bd-f5b225f8da3d@107.207.90.90:5060
Call-ID: QmF69h0tpNPtZhE6IrwYqtoQ67kcJ5pn
CSeq: 9147 INVITE
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE,
PRACK, REFER, REGISTER, MESSAGE
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800
Min-SE: 90
Content-Type: application/sdp
Content-Length: 237
v=0
o=- 455864548 455864548 IN IP4 107.207.90.90
s=Asterisk
c=IN IP4 107.207.90.90
t=0 0
m=audio 19628 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

******** DIALPLAN FOR OUTBOUND CALL *********************

[dial-out]
exten => _X.,1,NoOp()
same => n,Set(PJSIP_HEADER(add,X-P-Asserted-Identity)=sip:7147890101)
same => n,Set(CALLERID(num)=7143861212)
same => n,Dial(PJSIP/${EXTEN}@nextiva1,45,r)
same => n,Hangup()

******** PJSIP CONFIGURATION FOR SIP TRUNK ***********

[nextiva1]
type=endpoint
transport=transport-udp
context=from-nextiva
disallow=all
allow=ulaw
aors=nextiva1-aor

[nextiva1-auth]
type=auth
auth_type=userpass
username=7143861212
password=NotMyRealPassword

[nextiva1-reg]
type=registration
outbound_auth=nextiva1-auth
server_uri=sip:bt.voipdnsservers.com
client_uri=sip:7143861212@bt.voipdnsservers.com

[nextiva1]
type=identify
endpoint=nextiva1
match=208.73.140.70

[nextiva1-aor]
type=aor
contact=sip:bt.voipdnsservers.com:5060

Unfortunately the string does not show up under this new platform. As for your PJSIP_HEADER problem you need to use a pre-dial handler to run it on the dialed channel[1].

[1] https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers

What the ITSP was incorrectly insisting on was that the Contact header should contain a user part matching the phone number by which they know the client, whereas it is a completely opaque string that is only relevant to the system that is sending it. Asterisk was sending some sort of GUUID string. They should not be using it for any identification or authentication purpose. The ITSP is broken.

Whilst I don’t know the PJSIP side of the second question, the X- prefix seems questionable. chan_sip could natively handle P-Asserted-Identity and I suspect PJSIP can. Also the SIP URI is semantically invalid, as it seems to be using user part as though it was a domain part.

Indeed! I forgot about that. P-Asserted-Identity is enabled using the “send_pai” option on the endpoint. There is also a trust option “trust_id_outbound” to control whether private identification details should be sent or not.

Hello Jcolp and David!

Thanks a lot for your responses!!!
I tried both your suggestions:

*** On attempting to add the SIP header, i transformed the dialplan from:

[dial-out-nextiva]
exten => _X.,1,NoOp()
same => n,Set(CALLERID(num)=7143861234)
same => n,Set(PJSIP_HEADER(add,X-Nextiva-SayHello)=Hello)
same => n,Dial(PJSIP/${EXTEN}@nextiva1,30,r)
same => n,NoOp(Status: ${DIALSTATUS})
same => n,Hangup()

*** to:

[dial-out-nextiva]
exten => _X.,1,NoOp()
same => n,Set(CALLERID(num)=7143861234)
same => n,Dial(PJSIP/${EXTEN}@nextiva1,B(addh^1^1))
same => n,NoOp(Status: ${DIALSTATUS})
same => n,Hangup()

[addh]
exten => 1,1,NoOp()
same => n,Verbose(0, In caller pre-dial handler!)
same => n,Set(PJSIP_HEADER(add,X-Nextiva-SayHello)=Hello)
same => n,Return()

And when attempting to dial a number, I am getting the very same result: the dialplan executes everything including the PJSIP_HEADER, but no header is inserted into the INVITE…

-- Executing [9497951234@dial-out-nextiva:3] Set("PJSIP/100-00000025", "CALLERID(num)=7143861234") in new stack
-- Executing [9497951234@dial-out-nextiva:4] Dial("PJSIP/100-00000025", "PJSIP/9497951234@nextiva1,,B(addh^1^1)") in new stack
-- PJSIP/100-00000025 Internal Gosub(addh,1,1) start
-- Executing [1@addh:1] NoOp("PJSIP/100-00000025", "") in new stack
-- Executing [1@addh:2] Verbose("PJSIP/100-00000025", "0, In caller pre-dial handler!") in new stack

In caller pre-dial handler!
– Executing [1@addh:3] Set(“PJSIP/100-00000025”, “PJSIP_HEADER(add,X-Nextiva-SayHello)=Hello”) in new stack
– Executing [1@addh:4] Return(“PJSIP/100-00000025”, “”) in new stack
== Spawn extension (dial-out-nextiva, 9497951234, 4) exited non-zero on ‘PJSIP/100-00000025’
– PJSIP/100-00000025 Internal Gosub(addh,1,1) complete GOSUB_RETVAL=
– Called PJSIP/9497951234@nextiva1

**************** Trace:

<— Transmitting SIP request (901 bytes) to UDP:208.73.123.45:5060 —>
INVITE sip:9497951234@bt.voipdnsservers.com:5060 SIP/2.0
Via: SIP/2.0/UDP 107.207.12.34:5060;rport;branch=z9hG4bKPjRXQkKMQGIZtMGkCMdxtYGPZ-JPsPVj0n
From: “Desk” sip:7143861234@107.207.12.34;tag=17Huzx1HCGrq-cMOeuldTY
To: sip:9497951234@bt.voipdnsservers.com
Contact: sip:be429d2d-d6d9-4ee0-8883-ca1f40e2dac7@107.207.12.34:5060
Call-ID: RMn2GlpyVFPyxPZ5VCn.ZJrjE9vm
CSeq: 16525 INVITE
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REFER, REGISTER, MESSAGE
Supported: 100rel, timer, replaces, norefersub
Session-Expires: 1800
Min-SE: 90
Content-Type: application/sdp
Content-Length: 237

v=0
o=- 453472723 453472723 IN IP4 107.207.12.34
s=Asterisk
c=IN IP4 107.207.12.34
t=0 0
m=audio 15224 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

With regards to attempting to disable the obfuscation of the from in the “Contact Field”, I attempted to put the “trust_id_outbound=yes” option in the carrier section and/or the desk phone section of pjsip.conf, and it is still sending as you can see above in the form of what looks like a UUID… Is there a way to disable that and make it show up just like any other version of Asterisk with just the clear number like the From: field ?

Thanks a lot again !!!