<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hello,</p>
    <p>iirc, the auth header related variables (like $ar) are set when
      some authentication functions are used, but that is for requests.
      For replies, I am not sure if it is done at all, being also a
      different header name.</p>
    <p>Unless you want to dig a bit in the code and see what happens
      there, for now a solution here would be using transformations to
      extract fields from the header Proxy-Authenticate or
      WWW-Authenticate.</p>
    <p>If you want to have these variables set in other cases than it is
      now, you can open a new feature request on github issue tracker.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 20.01.19 12:58, Mack Hendricks
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:08A3BD57-52FE-4013-BD77-2039B2040CEF@dopensource.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      Hey All,
      <div class=""><br class="">
      </div>
      <div class="">So, I want to use the UAC module to handle Digest
        Auth to upstream carriers.  But, I don’t know which carrier will
        be selected until another module (dRouting in this case) tells
        the logic which carrier to use.</div>
      <div class=""><br class="">
      </div>
      <div class="">I can see in the logs that the uac_auth function can
        capture the Auth Realm.  But, I need to access it from the
        Kamailio script so that I can lookup the credentials for that
        realm and then call uac_auth.  I’ve tried getting the info from
        $ar, but that gives me the realm of the inbound request versus
        the realm of the upstream carrier.  Also, I’ve tried
        using $T_rpl($ar), but that returns 0.  Here’s my logic from the
        Kamailio file:</div>
      <div class=""><br class="">
      </div>
      <div class="">
        <div class=""><br class="">
        </div>
        <div class="">        if(t_check_status("401|407")) {</div>
        <div class="">                $var(reply_realm) = $T_rpl($ar);</div>
        <div class="">                $var(query)="select
          auth_username,auth_password from uacreg where realm='" +
          $var(reply_realm) + "'";</div>
        <div class="">               
          sql_xquery("cb","$var(query)","rb");</div>
        <div class="">                xlog("L_DEBUG","[MANAGE_FAILURE:
          Proxy Auth]: The query is $var(query) auth realm is
          $var(reply_realm) and the user name is
          $xavp(rb=>auth_username)");</div>
        <div class="">                $avp(auser) =
          $xavp(rb=>auth_username);</div>
        <div class="">                $avp(apass) =
          $xavp(rb=>auth_password);</div>
        <div class="">                uac_auth();</div>
        <div class="">                t_relay();</div>
        <div class="">                exit;`</div>
        <div class="">        }</div>
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class="">A snippet of the log file is below:</div>
      <div class="">
        <div class=""><br class="">
        </div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: exec: ***
          cfgtrace:failure_route=[DEFAULT_ROUTE]
          c=[/etc/kamailio/kamailio.cfg] l=1616 a=63 n=assign</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: exec: ***
          cfgtrace:failure_route=[DEFAULT_ROUTE]
          c=[/etc/kamailio/kamailio.cfg] l=1617 a=63 n=assign</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: exec: ***
          cfgtrace:failure_route=[DEFAULT_ROUTE]
          c=[/etc/kamailio/kamailio.cfg] l=1618 a=24 n=uac_auth</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: DEBUG: uac [auth.c:409]: uac_auth():
          picked reply is 0x7f900cb7eaf0, code 407</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: DEBUG: uac [auth.c:225]:
          get_autenticate_hdr(): looking for header "Proxy-Authenticate"</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: DEBUG: uac [auth.c:429]: uac_auth():
          header found; body=<Digest realm="<a
            href="http://sip.flowroute.com" class=""
            moz-do-not-send="true">sip.flowroute.com</a>",
          nonce="XERJMlxESAbDNCK3INmBfoET1GGxpcyr", qop="auth"></div>
        <div class=""><span style="background-color: rgb(255, 251, 0);"
            class="">Jan 20 10:05:58 dsiprouter
            /usr/sbin/kamailio[2871]: DEBUG: uac [auth_hdr.c:209]:
            parse_authenticate_body(): <realm>="<a
              href="http://sip.flowroute.com" class=""
              moz-do-not-send="true">sip.flowroute.com</a>" state=2</span></div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: DEBUG: uac [auth_hdr.c:209]:
          parse_authenticate_body():
          <nonce>="XERJMlxESAbDNCK3INmBfoET1GGxpcyr" state=3</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: DEBUG: uac [auth_hdr.c:209]:
          parse_authenticate_body(): <qop>="auth" state=1</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: DEBUG: uac [auth.c:449]: uac_auth():
          no credential for realm "<a href="http://sip.flowroute.com"
            class="" moz-do-not-send="true">sip.flowroute.com</a>"</div>
        <div class="">Jan 20 10:05:58 dsiprouter
          /usr/sbin/kamailio[2871]: exec: ***
          cfgtrace:failure_route=[DEFAULT_ROUTE]
          c=[/etc/kamailio/kamailio.cfg] l=1619 a=24 n=t_relay</div>
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class="">Thanks in advance for any help</div>
      <div class=""><br class="">
      </div>
      <div class="">Mack Hendricks</div>
      <div class="">dSIPRouter</div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Kamailio World Conference - May 6-8, 2019 -- <a class="moz-txt-link-abbreviated" href="http://www.kamailioworld.com">www.kamailioworld.com</a>
Kamailio Advanced Training - Mar 4-6, 2019 in Berlin; Mar 25-27, 2019, in Washington, DC, USA -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a></pre>
  </body>
</html>