CNAM in PAI but not coming across

I’m running inbound calls through a proxy (for call reputation scoring) before it hits FreePBX.
If a call is rated as being bad, it puts “SPAM” in the P-Asserted-Identity field.
I can see this in the FreePBX logs that it’s being received… but it’s not coming across as the callerID name.
I changed my inbound trunk context to be from-trunk-pai, and set trustrpid to yes… but that didn’t seem to do it.
Looks like the wrong part of PAI is being scrapped… not sure.
Any ideas?

Here is a redacted except from my logs:

[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [+MYPHONENUM@from-trunk-pai:1] NoOp(“SIP/PROXYIN-000063d9”, “Attempting to extract Caller ID from PAI Header”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [+MYPHONENUM@from-trunk-pai:2] Gosub(“SIP/PROXYIN-000063d9”, “trust-pai-as-cid,s,1”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [s@trust-pai-as-cid:1] Set(“SIP/PROXYIN-000063d9”, “CHANTYPE=SIP”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [s@trust-pai-as-cid:2] GotoIf(“SIP/PROXYIN-000063d9”, “1?chansip,1”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx_builtins.c: Goto (trust-pai-as-cid,chansip,1)
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [chansip@trust-pai-as-cid:1] Set(“SIP/PROXYIN-000063d9”, “PAI=”" sip:[email protected]") in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [chansip@trust-pai-as-cid:2] Goto(“SIP/PROXYIN-000063d9”, “setcid,1”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx_builtins.c: Goto (trust-pai-as-cid,setcid,1)
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:1] ExecIf(“SIP/PROXYIN-000063d9”, “0?Return()”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:2] Set(“SIP/PROXYIN-000063d9”, “NAME=”“) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:3] Set(“SIP/PROXYIN-000063d9”, “CALLERID(name)=”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:4] NoOp(“SIP/PROXYIN-000063d9”, “””) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:5] Set(“SIP/PROXYIN-000063d9”, “SIPURI=SPAM>” sip:[email protected]") in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:6] Set(“SIP/PROXYIN-000063d9”, “TYPE=SPAM>” <sip:CALLERNUM") in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:7] Set(“SIP/PROXYIN-000063d9”, “CALLERID(num)=CALLERNUM”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [setcid@trust-pai-as-cid:8] Return(“SIP/PROXYIN-000063d9”, “”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [+MYPHONENUM@from-trunk-pai:3] Goto(“SIP/PROXYIN-000063d9”, “from-trunk,+MYPHONENUM,1”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx_builtins.c: Goto (from-trunk,+MYPHONENUM,1)
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [+MYPHONENUM@from-trunk:1] Set(“SIP/PROXYIN-000063d9”, “__DIRECTION=INBOUND”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [+MYPHONENUM@from-trunk:2] Gosub(“SIP/PROXYIN-000063d9”, “sub-record-check,s,1(in,+MYPHONENUM,yes)”) in new stack
[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [s@sub-record-check:1] GotoIf(“SIP/PROXYIN-000063d9”, “0?initialized”) in new stack

Your header should look something like:
P-Asserted-Identity: "SPAM" <sip:[email protected]>
but it doesn’t.

Either replace the from-trunk-pai context with a similar one of your own, or configure the proxy to set the header in the format that from-trunk-pai is expecting.

If that’s all the proxy is doing, it’s overkill – it’s pretty easy to do the reputation lookup in the FreePBX dialplan.

So the PAI header is coming across correctly (sort-of)… it didn’t paste correctly in my previous message, but in the logs appears as:

[2019-12-26 15:50:48] VERBOSE[30290][C-00001e78] pbx.c: Executing [chansip@trust-pai-as-cid:1] Set("SIP/PROXYIN-000063d9", "PAI="<SPAM>" <sip:[email protected]>") in new stack

but seems like the formatting of "<SPAM>" is throwing things off a bit going through the trust-pai-as-cid context. I need to read up on how to mess with the asterisk dialplan more.

The proxy I’m using will be doing more than reputation lookups… planning on using it for STIR/SHAKEN authentication and other call fraud screening and diverting… but trying to get the call presentation basics down.

The code in from-trunk-pai is dumb and assumes that everything before the first < (other than " characters) is the name.

Perhaps you can configure the proxy to use "(SPAM)" instead of "<SPAM>". Otherwise, create your own version of from-trunk-pai.

1 Like

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