auth_functions.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="auth.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <title>Functions</title>
  6. <section id="auth.f.consume_credentials">
  7. <title><function>consume_credentials()</function></title>
  8. <para>
  9. This function removes previously authorized credential headers from the
  10. message being processed by the server. That means that the
  11. downstream message will not contain credentials there were used by
  12. this server. This ensures that the proxy will not reveal
  13. information about credentials used to downstream elements and also
  14. the message will be a little bit shorter. The function must be
  15. called after <function>www_authorize</function>,
  16. <function>proxy_authorize</function>,
  17. <function>www_authenticate</function> or
  18. <function>proxy_authenticate</function>.
  19. </para>
  20. <example>
  21. <title>consume_credentials example</title>
  22. <programlisting>
  23. ...
  24. if (www_authenticate("realm", "subscriber")) {
  25. consume_credentials();
  26. };
  27. ...
  28. </programlisting>
  29. </example>
  30. </section>
  31. <section id="auth.f.has_credentials">
  32. <title><function>has_credentials(realm)</function></title>
  33. <para>
  34. This function returns true of the request has Autorization or
  35. Proxy-Authorization header with provided realm. The parameter
  36. can be string with pseudo-variables.
  37. </para>
  38. <example>
  39. <title>consume_credentials example</title>
  40. <programlisting>
  41. ...
  42. if (has_credentials("myrealm")) {
  43. ...
  44. }
  45. ...
  46. </programlisting>
  47. </example>
  48. </section>
  49. <section id="auth.f.www_challenge">
  50. <title>
  51. <function moreinfo="none">www_challenge(realm, flags)</function>
  52. </title>
  53. <para>
  54. The function challenges a user agent. It will generate a
  55. WWW-Authorize header field containing a digest challenge, it will
  56. put the header field into a response generated from the request the
  57. server is processing and send the reply. Upon reception of such a
  58. reply the user agent should compute credentials and retry the
  59. request. For more information regarding digest authentication
  60. see RFC2617. See module parameter force_stateless_reply
  61. regarding sending of the reply.
  62. </para>
  63. <para>Meaning of the parameters is as follows:</para>
  64. <itemizedlist>
  65. <listitem>
  66. <para><emphasis>realm</emphasis> - Realm is a opaque string that
  67. the user agent should present to the user so he can decide what
  68. username and password to use. Usually this is domain of the host
  69. the server is running on.
  70. </para>
  71. <para>
  72. It must not be empty string <quote></quote>. In case of REGISTER
  73. requests, the To header field domain (e.g., variable $td) can be used
  74. (because this header field represents the user being registered),
  75. for all other messages From header field domain can be used
  76. (e.g., variable $fd).
  77. </para>
  78. <para>
  79. The string may contain pseudo variables.
  80. </para>
  81. </listitem>
  82. <listitem>
  83. <para><emphasis>flags</emphasis> - Value of this parameter can be
  84. a bitmask of following:</para>
  85. <itemizedlist>
  86. <listitem>
  87. <para><emphasis>1</emphasis> - build challenge header with
  88. qop=auth</para>
  89. </listitem>
  90. <listitem>
  91. <para><emphasis>2</emphasis> - build challenge header with
  92. qop=auth-int</para>
  93. </listitem>
  94. <listitem>
  95. <para><emphasis>4</emphasis> - do not send '500 Internal
  96. Server Error' reply automatically in failure cases
  97. (error code is returned to config)</para>
  98. </listitem>
  99. <listitem>
  100. <para><emphasis>16</emphasis> - build challenge header with
  101. stale=true</para>
  102. </listitem>
  103. </itemizedlist>
  104. </listitem>
  105. </itemizedlist>
  106. <para>
  107. This function can be used from REQUEST_ROUTE.
  108. </para>
  109. <example>
  110. <title>www_challenge usage</title>
  111. <programlisting format="linespecific">
  112. ...
  113. if (!www_authenticate("$td", "subscriber")) {
  114. www_challenge("$td", "1");
  115. }
  116. ...
  117. </programlisting>
  118. </example>
  119. </section>
  120. <section id="auth.f.proxy_challenge">
  121. <title>
  122. <function moreinfo="none">proxy_challenge(realm, flags)</function>
  123. </title>
  124. <para>
  125. The function challenges a user agent. It will generate a
  126. Proxy-Authorize header field containing a digest challenge, it will
  127. put the header field into a response generated from the request the
  128. server is processing and send the reply. Upon reception of such a
  129. reply the user agent should compute credentials and retry the request.
  130. For more information regarding digest authentication see RFC2617.
  131. See module parameter force_stateless_reply regarding sending of the reply.
  132. </para>
  133. <para>Meaning of the parameters is the same as for function
  134. www_challenge(realm, flags)</para>
  135. <para>
  136. This function can be used from REQUEST_ROUTE.
  137. </para>
  138. <example>
  139. <title>proxy_challenge usage</title>
  140. <programlisting format="linespecific">
  141. ...
  142. if (!proxy_authenticate("$fd", "subscriber")) {
  143. proxy_challenge("$fd", "1");
  144. };
  145. ...
  146. </programlisting>
  147. </example>
  148. </section>
  149. <section id="auth.f.auth_challenge">
  150. <title>
  151. <function moreinfo="none">auth_challenge(realm, flags)</function>
  152. </title>
  153. <para>
  154. The function challenges a user agent for authentication. It combines
  155. the functions www_challenge() and proxy_challenge(), by calling
  156. internally the first one for REGISTER requests and the second one for
  157. the rest of other request types.
  158. </para>
  159. <para>Meaning of the parameters the same as for function
  160. www_challenge(realm, flags)</para>
  161. <para>
  162. This function can be used from REQUEST_ROUTE.
  163. </para>
  164. <example>
  165. <title>auth_challenge usage</title>
  166. <programlisting format="linespecific">
  167. ...
  168. if (!auth_check("$fd", "subscriber", "1")) {
  169. auth_challenge("$fd", "1");
  170. };
  171. ...
  172. </programlisting>
  173. </example>
  174. </section>
  175. <section id="auth.f.pv_www_authenticate">
  176. <title>
  177. <function moreinfo="none">pv_www_authenticate(realm, passwd, flags [, method])</function>
  178. </title>
  179. <para>
  180. The function verifies credentials according to
  181. <ulink url="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</ulink>.
  182. If the credentials are verified successfully then the function
  183. will succeed and mark the credentials as authorized (marked
  184. credentials can be later used by some other functions). If the
  185. function was unable to verify the credentials for some reason
  186. then it will fail and the script should
  187. call <function moreinfo="none">www_challenge</function> which will
  188. challenge the user again.
  189. </para>
  190. <para>Negative codes may be interpreted as follows:</para>
  191. <itemizedlist>
  192. <listitem><para>
  193. <emphasis>-1 (generic error)</emphasis> - some generic error
  194. occurred and no reply was sent out
  195. </para></listitem>
  196. <listitem><para>
  197. <emphasis>-2 (invalid password)</emphasis> - wrong password
  198. </para></listitem>
  199. <listitem><para>
  200. <emphasis>-3 (invalid user)</emphasis> - authentication user does
  201. not exist
  202. </para></listitem>
  203. <listitem><para>
  204. <emphasis>-4 (nonce expired)</emphasis> - the nonce has expired
  205. </para></listitem>
  206. <listitem><para>
  207. <emphasis>-5 (no credentials)</emphasis> - request does not contain
  208. an Authorization header with the correct realm
  209. </para></listitem>
  210. <listitem><para>
  211. <emphasis>-6 (nonce reused)</emphasis> - the nonce has already been
  212. used to authenticate a previous request
  213. </para></listitem>
  214. <listitem><para>
  215. <emphasis>-8 (auth user mismatch)</emphasis> - the auth user is different
  216. then the From/To user
  217. </para></listitem>
  218. </itemizedlist>
  219. <para>Meaning of the parameters is as follows:</para>
  220. <itemizedlist>
  221. <listitem>
  222. <para><emphasis>realm</emphasis> - Realm is a opaque string that
  223. the user agent should present to the user so he can decide what
  224. username and password to use. Usually this is domain of the host
  225. the server is running on.
  226. </para>
  227. <para>
  228. It must not be empty string <quote></quote>. In case of REGISTER
  229. requests To header field domain (e.g., varibale $td) can be used
  230. (because this header field represents a user being registered),
  231. for all other messages From header field domain can be used
  232. (e.g., varibale $fd).
  233. </para>
  234. <para>
  235. The string may contain pseudo variables.
  236. </para>
  237. </listitem>
  238. <listitem>
  239. <para><emphasis>passwd</emphasis> - the password to be used
  240. for authentication. Can contain config variables. The Username is
  241. taken from Auth header.</para>
  242. </listitem>
  243. <listitem>
  244. <para><emphasis>flags</emphasis> - the value of this parameter
  245. can be a bitmask of following:</para>
  246. <itemizedlist>
  247. <listitem>
  248. <para><emphasis>1</emphasis> - the value of password
  249. parameter is HA1 format</para>
  250. </listitem>
  251. <listitem>
  252. <para><emphasis>2</emphasis> - build challenge header with
  253. no qop and add it to avp</para>
  254. </listitem>
  255. <listitem>
  256. <para><emphasis>4</emphasis> - build challenge header with
  257. qop=auth and add it to avp</para>
  258. </listitem>
  259. <listitem>
  260. <para><emphasis>8</emphasis> - build challenge header with
  261. qop=auth-int and add it to avp</para>
  262. </listitem>
  263. <listitem>
  264. <para><emphasis>16</emphasis> - build challenge header with
  265. stale=true</para>
  266. </listitem>
  267. </itemizedlist>
  268. </listitem>
  269. <listitem>
  270. <para><emphasis>method</emphasis> - the method to be used for
  271. authentication. This parameter is optional and if not set
  272. is the first "word" on the request-line.</para>
  273. </listitem>
  274. </itemizedlist>
  275. <para>
  276. When challenge header is built and stored in avp,
  277. append_to_reply() and the sl reply functions can be used to send
  278. appropriate SIP reply to challenge for authentication.
  279. </para>
  280. <para>
  281. This function can be used from REQUEST_ROUTE.
  282. </para>
  283. <example>
  284. <title><function moreinfo="none">pv_www_authenticate</function>
  285. usage</title>
  286. <programlisting format="linespecific">
  287. ...
  288. if (!pv_www_authenticate("$td", "123abc", "0")) {
  289. www_challenge("$td", "1");
  290. };
  291. ...
  292. </programlisting>
  293. </example>
  294. </section>
  295. <section id="auth.f.pv_proxy_authenticate">
  296. <title>
  297. <function moreinfo="none">pv_proxy_authenticate(realm, passwd, flags)</function>
  298. </title>
  299. <para>
  300. The function verifies credentials according to
  301. <ulink url="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</ulink>. If
  302. the credentials are verified successfully then the function will
  303. succeed and mark the credentials as authorized (marked credentials can
  304. be later used by some other functions). If the function was unable to
  305. verify the credentials for some reason then it will fail and
  306. the script should call
  307. <function moreinfo="none">proxy_challenge</function> which will
  308. challenge the user again. For more about the negative return codes,
  309. see the above function.
  310. </para>
  311. <para>Meaning of the parameters is the same as for
  312. pv_www_authenticate(realm, passwd, flags)</para>
  313. <para>
  314. This function can be used from REQUEST_ROUTE.
  315. </para>
  316. <example>
  317. <title>pv_proxy_authenticate usage</title>
  318. <programlisting format="linespecific">
  319. ...
  320. $avp(password)="xyz";
  321. if (!pv_proxy_authenticate("$fd", "$avp(password)", "0")) {
  322. proxy_challenge("$fd", "1");
  323. };
  324. ...
  325. </programlisting>
  326. </example>
  327. </section>
  328. <section id="auth.f.pv_auth_check">
  329. <title>
  330. <function moreinfo="none">pv_auth_check(realm, passwd, flags, checks)</function>
  331. </title>
  332. <para>
  333. The function combines the functionalities of
  334. <function moreinfo="none">pv_www_authenticate</function> and
  335. <function moreinfo="none">pv_proxy_authenticate</function>, first being
  336. exectuted if the SIP request is a REGISTER, the second for the rest.
  337. </para>
  338. <para>
  339. Meaning of the first three parameters is the same as for
  340. pv_www_authenticate(realm, passwd, flags).
  341. </para>
  342. <para>
  343. Parameter <emphasis>checks</emphasis> can be used to control the
  344. behaviour of the function. If it is 1, then the function will
  345. check to see if the authentication username matches either To or
  346. From header username, a matter of whether it is for a REGISTER
  347. request or not. The parameter may be a pseudo variable.
  348. </para>
  349. <para>
  350. This function can be used from REQUEST_ROUTE.
  351. </para>
  352. <example>
  353. <title>pv_auth_check usage</title>
  354. <programlisting format="linespecific">
  355. ...
  356. $avp(password)="xyz";
  357. if (!pv_auth_check("$fd", "$avp(password)", "0", "1")) {
  358. proxy_challenge("$fd", "1");
  359. };
  360. ...
  361. </programlisting>
  362. </example>
  363. </section>
  364. <section id="auth.f.auth_get_www_authenticate">
  365. <title>
  366. <function moreinfo="none">auth_get_www_authenticate(realm, flags, pvdest)</function>
  367. </title>
  368. <para>
  369. Build WWW-Authentication header and set the resulting value in 'pvdest' pseudo-variable parameter.
  370. </para>
  371. <para>Meaning of the realm and flags parameters is the same as for
  372. pv_www_authenticate(realm, passwd, flags)</para>
  373. <para>
  374. This function can be used from ANY_ROUTE.
  375. </para>
  376. <example>
  377. <title>auth_get_www_authenticate</title>
  378. <programlisting format="linespecific">
  379. ...
  380. if (auth_get_www_authenticate("$fd", "0", "$var(wauth)")) {
  381. xlog("www authenticate header is [$var(wauth)]\n");
  382. }
  383. ...
  384. </programlisting>
  385. </example>
  386. </section>
  387. </section>