Issue adding SIP Trunk UAC Auth

Mark Boyce via sr-users <[email protected]>
Newsgroups gmane.comp.voip.ser
Message-ID <[email protected]>
Hi All

Wondering if anyone here has any thoughts on this issue, before I start trying to reverse engineer the config and randomly update things on this server.

It’s a little out of date but not the worst I’ve seen :-)

Kamailio 5.5.4 
Ubuntu 22.04 LTS

Arrangement is the typical users phones & ITSP Carrier out in the real world, Asterisk on a private network with Kamailio in the middle. The config is broken up in to a mass of include files so not simple to include I’m afraid. 

Issue is -> I’ve been asked to add SIP Auth to the ITSP Trunk as they no longer have IP Auth.  As it arrived I can see the ITSP Auth being relayed through to the asterisk server rather than being caught at the Kamailio level.  I’ve tried to walk through the config and logs but can’t see anything obviously failing or missing.


If I add the code below based on the default config and config from this page, ITSP Auth request is answered by Kamailio, but nothing from the ITSP gets sent to Asterisk. 
https://github.com/kamailio-asterisk/Kamailio-Example/blob/main/Kamailio%20Bytes%20-%20UAC%20INVITE%20Authentication <https://github.com/kamailio-asterisk/Kamailio-Example/blob/main/Kamailio%20Bytes%20-%20UAC%20INVITE%20Authentication>

request_route {
(whole load of security defence stuff)
        # per request initial checks
        route(REQINIT);

        # NAT detection
        route(NATDETECT);

        route(KEEPALIVE);

        # CANCEL processing
        xlog("L_ALERT","FLOWTRACE: Checking for CANCEL ([$rm] From IP:$si:$sp)\n");
        if (is_method("CANCEL")) {
                if (t_check_trans()) {
                        route(RELAY);
                }
                exit;
        }

        # handle retransmissions
        if (!is_method("ACK")) {
                if(t_precheck_trans()) {
                        t_check_trans();
                        exit;
                }
                t_check_trans();
        }

        # handle requests within SIP dialogs
        route(WITHINDLG);

        ### only initial requests (no To tag)

        # authentication
        route(AUTH);

	# Create dialog and record user / ip / etc in dlg_vars 
	# if !is_known_dlg()
        route(MANAGE_DIALOG);

        # record routing for dialog forming requests (in case they are routed)
        # - remove preloaded route headers
        remove_hf("Route");
        if (is_method("INVITE|SUBSCRIBE|REFER")) {
                record_route();
        }

	# account only INVITEs
        if (is_method("INVITE")) {
                route(ACCOUNTING);
        }

        ### requests for my local domains

        # handle presence related requests
        route(PRESENCE);


        # handle registrations
        route(REGISTRAR);

        ### requests for my local domains

        if ($rU==$null) {
                # request with no Username in RURI
                sl_send_reply("484","Address Incomplete");
                exit;
        }

        # dispatch invite to subscriber, PSTN or PBX
        route(ROUTE_INVITE);
}


# Decide who to send the Invite out to
route[ROUTE_INVITE] {
      # We only care about INVITES
      if(!is_method("INVITE")) return;

(source type and destination type identified)

    # now route to destination
    switch ($dlg_var(destination_type)) {
        case "trunk":
            route(TOPSTN);
            break;
       exit;
}  

# PSTN GW 
route[TOPSTN] {
        # check if PSTN GW IP is defined
        if (strempty($sel(cfg_get.pstn.gw_ip))) {
                xlog("SCRIPT: PSTN routing enabled but pstn.gw_ip not defined\n");
                return;
        }

        # normalize target number for pstn gateway
        # - convert leading 00 to +
        if (starts_with("$rU", "00")) {
                strip(2);
                prefix("+");
        }

        if (strempty($sel(cfg_get.pstn.gw_port))) {
                $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
        } else {
                $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":" + $sel(cfg_get.pstn.gw_port);
        }
        t_on_failure("TRUNKAUTH");
        t_relay();
        exit;
}



failure_route[TRUNKAUTH] {
    # Catch if already cancelled
    if (t_is_canceled()) {
        exit;
    }
    if(t_check_status("401|407")) {
        xlog("L_INFO", "TRUNKAUTH: responding to 401/407\n");
        $avp(auser) = “USERNAME";
        $avp(apass) = “PASSWORD";
        uac_auth();
        t_relay();
        exit;
    }
}




What have I missed :-?
Thanks
Mark
-- 
Mark Boyce

​This message contains confidential information. If you received this email by mistake, please let us know and delete it. We ask you to respect any confidential or private information in the email and do not share it unless appropriate to do so. We take precautions to minimise risk but we cannot guarantee the safety, confidentiality and security of the internet. Please carry out your own virus checks on any attachments. We are not liable or bound by the content of this email. 

Dark Origins Limited is a limited company registered in England and Wales. Registered number: 04877988.

__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the sender!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.