<h3>Description</h3>
<p>Following this scenario:</p>
<p>Softphone <-> Kamailio <-> Asterisk</p>
<p>1- Softphone registers with kamailio (REGISTER)<br>
2- Kamailio challenges... (401)<br>
3- Softphone registers with kamailio (REGISTER + Auth info)<br>
4- Kamailio accepts (200)<br>
5- If Kamailio accepted, it sends a REGISTER to asterisk (REGISTER)<br>
6- Asterisk challenges... (401)<br>
7- Kamailio authenticates (REGISTER + Auth info)<br>
8- Asterisk accepts (200)</p>
<p>(NOTE: I know you can avoid Asterisk re-requesting for authentication, but in this case it's mandatory.)</p>
<p>kamailio.cfg has this:</p>
<pre><code>        $var(rip) = $(avp(s:dsp_uri_list){uri.host});
        $var(rip_port) = $(avp(s:dsp_uri_list){uri.port});
        $uac_req(method)="REGISTER";
        $uac_req(auser)=$avp(customer_user);
        $uac_req(apasswd)=$avp(customer_pass);
        $uac_req(ruri)="sip:" + $var(rip) + ":" + $var(rip_port);
        $uac_req(furi)="sip:" + $au + "@" + $var(rip);
        $uac_req(turi)="sip:" + $au + "@" + $var(rip);
        $uac_req(hdrs)="Contact: <sip:" + $au + "@X.X.X.X:5060>\r\n";
        $uac_req(evroute)=1;
        if ($sel(contact.expires) != $null) {
            $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
        } else {
            $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
        }
        uac_req_send();
</code></pre>
<p>and this:</p>
<pre><code># Log replies from uac_req_send()
event_route[uac:reply] {
    xlog("L_NOTICE", "[UAC] - $uac_req(method) request from user $uac_req(auser) to $uac_req(ruri) completed with code: $uac_req(evcode)\n");
}
</code></pre>
<p>The result:</p>
<p><a target="_blank" href="https://user-images.githubusercontent.com/16212586/43027222-0a32bd48-8c2e-11e8-8038-16d0dba00dec.png"><img src="https://user-images.githubusercontent.com/16212586/43027222-0a32bd48-8c2e-11e8-8038-16d0dba00dec.png" alt="image" style="max-width:100%;"></a></p>
<pre><code>Jul 20 16:49:42 sbc01 sbc[5236]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401
Jul 20 16:51:05 sbc01 sbc[5240]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401
Jul 20 16:51:49 sbc01 sbc[5241]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401
Jul 20 17:00:06 sbc01 sbc[5239]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401
Jul 20 17:09:06 sbc01 sbc[5240]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401
</code></pre>
<p>I was expecting for <code>$uac_req(evcode)</code> to be 200, but it's 401.</p>
<h4>Reproduction</h4>
<p>Generate a REGISTER using uaq_send_req() with <code>auser</code> and <code>apasswd</code> set, and then print the <code>$uac_req(evcode)</code> from the corresponding <code>event_route[]</code>.</p>
<h3>Possible Solutions</h3>
<p>Not sure if the 401 is expected because it was the <em>first</em> final response, period.</p>
<p>Or, (when using authentication), it should be updated to 200 or whatever the reply is after sending the REGISTER with auth info.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code># kamailio -v
version: kamailio 5.1.4 (x86_64/linux)
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 6.3.0
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>OS: Debian stretch 9.4

Kernel: Linux kamailio 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1598">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZfJH--MAedrTGG1xrsXV2yaZV0quks5uIlbVgaJpZM4VZVoE">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZfHfV6tNUiyjcvNPyKUR6aeW_Mu2ks5uIlbVgaJpZM4VZVoE.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"Reply code in $uac_req(evcode) remains 401 instead of 200 when using uac_req_send() with authentication (#1598)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1598"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1598",
"url": "https://github.com/kamailio/kamailio/issues/1598",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Reply code in $uac_req(evcode) remains 401 instead of 200 when using uac_req_send() with authentication (#1598)",
"sections": [
{
"text": "",
"activityTitle": "**Joel Serrano**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@joelsdc",
"facts": [
{
"name": "Repository: ",
"value": "kamailio/kamailio"
},
{
"name": "Issue #: ",
"value": 1598
}
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1598,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1598\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1598"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 358963716\n}"
}
],
"themeColor": "26292E"
}
]</script>