<h3>Description</h3>
<p>While trying to setup a handoff to a third party SIP trunk with authentication, I ran into some issues with said authentication. I'm using qop auth on the inbound leg (and <code>consume_credentials()</code>), and then UAC to authenticate against the SIP trunk with different credentials. The third party SIP trunk offers qop auth/auth-int.</p>
<p>I manually tried to verify the digest that Kamailio was sending, but couldn't. I added some logging to the <code>auth_alg.c</code> file, and ran the whole thing again. HA1 is calculated correctly, and so is HA2. However, the final step of the algorithm produced an incorrect value.</p>
<p>After further debugging, I realised that the issue comes from <a href="https://github.com/kamailio/kamailio/blob/master/src/modules/uac/auth_alg.c#L151">https://github.com/kamailio/kamailio/blob/master/src/modules/uac/auth_alg.c#L151</a>. More specifically, in my case, the value passed on to <code>MD5Update</code> is <code>auth,auth-int</code>, instead of the simple <code>auth</code> I was expecting (uac doesn't support auth-int).</p>
<h3>Troubleshooting</h3>
<h4>SIP Traffic</h4>
<p>I have PCAPs demonstrating the issue and the hack/fix below. I'd rather not post them publicly, however, I am happy to share them privately with Kamailio devs.</p>
<p>In essence:</p>
<pre><code>-> INVITE sip:12345@someprovider.org:5060;transport=tcp
<- 401 Unauthorized
    WWW-Authenticate: Digest realm="someprovider.org", qop="auth,auth-int", nonce="5BCF48671749b873534dc63e76d5594f3988555f"
-> INVITE sip:12345@someprovider.org:5060;transport=tcp
    Authorization: Digest username="redacted", realm="someprovider.org", nonce="5BCF48671749b873534dc63e76d5594f3988555f", uri="sip:12345@eu.out.didww.com:5060;transport=tcp", qop=auth, nc=00000001, cnonce="2106889321", response="redacted71d4c9ce119dcf3ec56209e", algorithm=MD5
</code></pre>
<h3>Possible Solutions</h3>
<p>The hack I've used for the time being is to replace:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-en">MD5Update</span>(&Md5Ctx, <span class="pl-s"><span class="pl-pds">"</span>:<span class="pl-pds">"</span></span>, <span class="pl-c1">1</span>);
<span class="pl-en">MD5Update</span>(&Md5Ctx, auth->qop.s, auth->qop.len);
<span class="pl-en">MD5Update</span>(&Md5Ctx, <span class="pl-s"><span class="pl-pds">"</span>:<span class="pl-pds">"</span></span>, <span class="pl-c1">1</span>);</pre></div>
<p>with:</p>
<div class="highlight highlight-source-c"><pre><span class="pl-en">MD5Update</span>(&Md5Ctx, <span class="pl-s"><span class="pl-pds">"</span>:auth:<span class="pl-pds">"</span></span>, <span class="pl-c1">6</span>);</pre></div>
<p>Obviously, I realise this is not the correct fix, but I figured I'd let the experts fix the value of <code>auth->qop.len</code>. I can spend more time on this, if required, but I don't know exactly what the "correct" solution is.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.1.6 (x86_64/linux) 
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, 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_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 5.3.1
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<p>Dockerized version of Kamailio on Ubuntu xenial:</p>
<pre><code>kamailio/kamailio:5.1.6-xenial
</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/1684">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZUmca7ApA7EO8oqlG8B0ptXZLP7Kks5uoGyMgaJpZM4X37_6">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZTRrezuPng5TKdUoMXgu0n6YuqJ5ks5uoGyMgaJpZM4X37_6.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":"Wrong QOP value in UAC auth_alg (#1684)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1684"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1684",
"url": "https://github.com/kamailio/kamailio/issues/1684",
"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": "Wrong QOP value in UAC auth_alg (#1684)",
"sections": [
{
"text": "",
"activityTitle": "**Sebastian Lauwers**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@teotwaki",
"facts": [
{
"name": "Repository: ",
"value": "kamailio/kamailio"
},
{
"name": "Issue #: ",
"value": 1684
}
]
}
],
"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\": 1684,\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\": 1684\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1684"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 400539642\n}"
}
],
"themeColor": "26292E"
}
]</script>