Help configuring PJSIP to receive SMS

Asterisk v16.2.1 on Ubuntu 20.04
SIP trunk provider: voip.ms

voip.ms allows you to enable the sending and receiving of SMS messages over an SMS trunk. I have followed their Wikis and my configurations (below) are taken from them. I am unable to receive SMSs (have not tried sending yet). I have verified I can receive voice calls at the DID.

When I turn on the PJSIP logger, I see the following messages for an incoming SMS. This makes me suspect I have mis-configured somehow:

<--- Received SIP request (463 bytes) from UDP:208.100.60.19:5060 --->
MESSAGE sip:s@MY_PUBLIC_IP:5060 SIP/2.0
Via: SIP/2.0/UDP 208.100.60.19:5060;branch=z9hG4bK0a7c3c97
Max-Forwards: 70
From: "7087777777" <sip:7087777777@montreal1.voip.ms>;tag=as42b4a878
To: <sip:s@MY_PUBLIC_IP:5060>
Contact: <sip:7087777777@208.100.60.19:5060>
Call-ID: 7a61845a427d07c2747a8e3a4718b360@208.100.60.19:5060
CSeq: 102 MESSAGE
User-Agent: voip.ms
X-SMS-To: 7088888888
Content-Type: text/plain;charset=UTF-8
Content-Length: 8

xyzqwert
<--- Transmitting SIP response (530 bytes) to UDP:208.100.60.19:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 208.100.60.19:5060;rport=5060;received=208.100.60.19;branch=z9hG4bK0a7c3c97
Call-ID: 7a61845a427d07c2747a8e3a4718b360@208.100.60.19:5060
From: "7087777777" <sip:7087777777@montreal1.voip.ms>;tag=as42b4a878
To: <sip:s@MY_PUBLIC_IP>;tag=z9hG4bK0a7c3c97
CSeq: 102 MESSAGE
WWW-Authenticate: Digest realm="asterisk",nonce="1645928808/a2be835389fdb86df7c89cf0812de647",opaque="7a2fc105514c62f0",algorithm=md5,qop="auth"
Server: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Content-Length:  0

Here is the relevant portions of extensions.conf:

[voipms-sms-in]
exten => _!,1,NoOp(Inbound SMS dialplan invoked)
  same => n,NoOp(To ${MESSAGE(to)})
  same => n,NoOp(From ${MESSAGE(from)})
  same => n,NoOp(Body ${MESSAGE(body)})
  same => n,Hangup()

And my pjsip.conf:

[voipms]
type = endpoint
transport = transport-udp
context = voipms-inbound
message_context = voipms-sms-in
disallow = all
allow = ulaw
from_user = 123456
auth = voipms
outbound_auth = voipms
aors = voipms
; NAT parameters:
rtp_symmetric = yes
rewrite_contact = yes
send_rpid = yes

This is both inbound and outbound authentication. I’m not aware of any ITSP that supports inbound authentication, however your log is incomplete, and doesn’t show whether or not voip.ms acts on Asterisk’s challenge for inbound authentication.

Surely voip.ms is not sufficiently broken to require rtp_symmetric, and rewrite_contact. These deliberately violate SIP and SDP in order to cope with broken NAT implementations, at the far end.

I also don’t see an identify section, which is also likely to result in a (faked) challenge for inbound authentication. (Faked so as not to give away to an attacker that the user name is invalid.)

David: Thanks for the response. I had only posted a snippet of my pjsip.conf, but can see that was not helpful. Below is the full config. Note that I modified the NAT parameters as per your suggestion and verified voice calling still works.

pjsip.conf

[transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0

[voipms]
type = registration
transport = transport-udp
outbound_auth = voipms
client_uri = sip:USERNAME@montreal1.voip.ms:5060
server_uri = sip:montreal1.voip.ms:5060

[voipms]
type = auth
auth_type = userpass
username = USERNAME
password = PASSWORD

[voipms]
type = aor
contact = sip:USERNAME@montreal1.voip.ms

[voipms]
type = endpoint
transport = transport-udp
context = voipms-inbound
message_context = voipms-sms-in
disallow = all
allow = ulaw
from_user = USERNAME
auth = voipms
outbound_auth = voipms
aors = voipms

[voipms]
type = identify
endpoint = voipms
match = montreal1.voip.ms

Below is the logs for an incoming SMS message… hopefully more complete:

<--- Received SIP request (468 bytes) from UDP:208.100.60.19:5060 --->
MESSAGE sip:s@PUBLICIP:5060 SIP/2.0
Via: SIP/2.0/UDP 208.100.60.19:5060;branch=z9hG4bK3a7c01a1
Max-Forwards: 70
From: "MYMOBILE" <sip:MYMOBILE@montreal1.voip.ms>;tag=as7a52a0a3
To: <sip:s@PUBLICIP:5060>
Contact: <sip:MYMOBILE@208.100.60.19:5060>
Call-ID: 120222bb5169d6460afc36a44e280770@208.100.60.19:5060
CSeq: 102 MESSAGE
User-Agent: voip.ms
X-SMS-To: MYDID
Content-Type: text/plain;charset=UTF-8
Content-Length: 12

Hello world!
<--- Transmitting SIP response (530 bytes) to UDP:208.100.60.19:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 208.100.60.19:5060;rport=5060;received=208.100.60.19;branch=z9hG4bK3a7c01a1
Call-ID: 120222bb5169d6460afc36a44e280770@208.100.60.19:5060
From: "MYMOBILE" <sip:MYMOBILE@montreal1.voip.ms>;tag=as7a52a0a3
To: <sip:s@PUBLICIP>;tag=z9hG4bK3a7c01a1
CSeq: 102 MESSAGE
WWW-Authenticate: Digest realm="asterisk",nonce="1646012328/f83b6a8b35d01af3b102329464c9a612",opaque="235054815e1f62de",algorithm=md5,qop="auth"
Server: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Content-Length:  0


<--- Received SIP request (722 bytes) from UDP:208.100.60.19:5060 --->
MESSAGE sip:s@PUBLICIP:5060 SIP/2.0
Via: SIP/2.0/UDP 208.100.60.19:5060;branch=z9hG4bK78cd6887
Max-Forwards: 70
From: "MYMOBILE" <sip:MYMOBILE@montreal1.voip.ms>;tag=as7a52a0a3
To: <sip:s@PUBLICIP:5060>;tag=z9hG4bK3a7c01a1
Call-ID: 120222bb5169d6460afc36a44e280770@208.100.60.19:5060
CSeq: 103 MESSAGE
User-Agent: voip.ms
Proxy-Authorization: Digest username="SIPUSERNAME", realm="asterisk", algorithm=MD5, uri="sip:s@PUBLICIP:5060", nonce="1646032328/f83b6a8b35d01affe102329464c9a612", response="2fe9024f456a2d84b70462a47fd2ede5", opaque="235804815e1f62de", qop=auth, cnonce="51cdb933", nc=00000002
X-SMS-To: MYDID
Content-Type: text/plain;charset=UTF-8
Content-Length: 12

Hello world!
<--- Transmitting SIP response (403 bytes) to UDP:208.100.60.19:5060 --->
SIP/2.0 481 Call/Transaction Does Not Exist
Via: SIP/2.0/UDP 208.100.60.19:5060;rport=5060;received=208.100.60.19;branch=z9hG4bK78cd6887
Call-ID: 120222bb5169d6460afc36a44e280770@208.100.60.19:5060
From: "MYMOBILE" <sip:MYMOBILE@montreal1.voip.ms>;tag=as7a52a0a3
To: <sip:s@PUBLICIP>;tag=z9hG4bK3a7c01a1
CSeq: 103 MESSAGE
Server: Asterisk PBX 16.2.1~dfsg-2ubuntu1
Content-Length:  0

You still haven’t removed the auth= line.;

That did the trick… thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.