ser_radius.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <section id="ser_radius" xmlns:xi="http://www.w3.org/2001/XInclude">
  9. <sectioninfo>
  10. <authorgroup>
  11. <author>
  12. <firstname>Jan</firstname>
  13. <surname>Janak</surname>
  14. <email>[email protected]</email>
  15. </author>
  16. </authorgroup>
  17. <copyright>
  18. <year>2003</year>
  19. <holder>FhG FOKUS</holder>
  20. </copyright>
  21. <revhistory>
  22. <revision>
  23. <revnumber>$Revision$</revnumber>
  24. <date>$Date$</date>
  25. </revision>
  26. </revhistory>
  27. </sectioninfo>
  28. <title>SIP-router RADIUS Howto</title>
  29. <section id="radius_intro">
  30. <title>Introduction</title>
  31. <simpara>
  32. SIP-router can be configured to use RADIUS server for authentication,
  33. accounting, and group membership checking. Since configuration of
  34. RADIUS seems to be a common source of problems, we decided to put
  35. together this HOWTO.
  36. </simpara>
  37. <simpara>
  38. The HOWTO covers installation and configuration of FreeRADIUS
  39. server only. There are other RADIUS servers available and as
  40. long as they support digest authentication, they should work
  41. too. Any volunteers willing to describe setup of other RADIUS
  42. servers are encouraged to contact the author.
  43. </simpara>
  44. <section id="prerequisities">
  45. <title>Prerequisites</title>
  46. <simpara>
  47. To set up RADIUS support in SIP-router you will need the following:
  48. </simpara>
  49. <itemizedlist>
  50. <listitem>
  51. <simpara>
  52. FreeRADIUS server, you can get it from <ulink
  53. url="http://www.freeradius.org">FreeRADIUS
  54. website</ulink>. The HOWTO describes installation
  55. and setup of release 0.9.1.
  56. </simpara>
  57. </listitem>
  58. <listitem>
  59. <simpara>
  60. Radiusclient library. In version 0.8.14 we started to
  61. use the new version of radiusclient library developed
  62. by Maxim Sobolev called radiusclient-ng. The homepage
  63. of the library is <ulink
  64. url="http://developer.berlios.de/projects/radiusclient-ng/">http://developer.berlios.de/projects/radiusclient-ng/</ulink>
  65. </simpara>
  66. </listitem>
  67. <listitem>
  68. <simpara>
  69. SIP-router, get it from <ulink url="&serhome;">&serhome;</ulink>
  70. </simpara>
  71. </listitem>
  72. <listitem>
  73. <simpara>
  74. You should also have some experience in configuring
  75. SIP-router. Before you enable RADIUS authentication or
  76. accounting make sure that the basic server is running
  77. and that you know how to customize it to your taste.
  78. </simpara>
  79. </listitem>
  80. <listitem>
  81. <simpara>
  82. If you want to use RADIUS accounting then you will have
  83. to compile SIP-router from sources so you should know how to
  84. do it.
  85. </simpara>
  86. </listitem>
  87. </itemizedlist>
  88. <simpara>
  89. Various Unix/Linux distributions might include binary packages
  90. of the mentioned applications. In that case you can safely use
  91. the packages, there shouldn't be any problem. Location of some
  92. files may be different, though. We will describe how to install
  93. the software from sources only.
  94. </simpara>
  95. <warning>
  96. <simpara>
  97. Configuration of FreeRADIUS server described in the
  98. document is in no way exhaustive. This document is a sort
  99. of quick-start-guide, it shows how to get things running,
  100. but you should definitely read FreeRADIUS documentation and
  101. configure the server properly ! You have been warned.
  102. </simpara>
  103. </warning>
  104. </section>
  105. </section>
  106. <section id="radiusclient">
  107. <title>Radiusclient Library</title>
  108. <simpara>
  109. Untar the source tarball.
  110. </simpara>
  111. <screen>
  112. root@localhost:/usr/local/src# tar xvfz radiusclient-0.4.3.tar.gz
  113. </screen>
  114. <simpara>
  115. Compile and install the library.
  116. </simpara>
  117. <screen>
  118. root@localhost:/usr/local/src# cd radiusclient-0.3.2
  119. root@localhost:/usr/local/src/radiusclient-0.3.2# ./configure
  120. root@localhost:/usr/local/src/radiusclient-0.3.2# make
  121. root@localhost:/usr/local/src/radiusclient-0.3.2# make install
  122. </screen>
  123. <simpara>
  124. By default all the configuration files of the radiusclient library
  125. will be in <filename>/usr/local/etc/radiusclient</filename>
  126. directory.
  127. </simpara>
  128. <simpara>
  129. If you use binary packages then the configuration files will be
  130. probably in <filename>/etc/radiusclient</filename>.
  131. </simpara>
  132. <section>
  133. <title>File <filename>radiusclient.conf</filename></title>
  134. <simpara>
  135. The main configuration file of the library is
  136. <filename>/usr/local/etc/radiusclient/radiusclient.conf</filename>,
  137. open the file in your favorite text editor and find lines
  138. containing the following:
  139. </simpara>
  140. <programlisting>
  141. authserver localhost
  142. </programlisting>
  143. <simpara>
  144. This is the hostname or IP address of the RADIUS server used
  145. for authentication. You will have to change this unless the
  146. server is running on the same host as your SIP proxy.
  147. </simpara>
  148. <programlisting>
  149. acctserver localhost
  150. </programlisting>
  151. <simpara>
  152. This is the hostname or IP address of the RADIUS server used
  153. for accounting. You will have to change this unless the server
  154. is running on the same host as your SIP proxy.
  155. </simpara>
  156. </section>
  157. <section id="servers">
  158. <title>File <filename>servers</filename></title>
  159. <simpara>
  160. RADIUS protocol uses simple access control mechanism based on
  161. shared secrets that allows RADIUS servers to limit access from
  162. RADIUS clients. A RADIUS server is configured with a secret
  163. string and only RADIUS clients that have the same secret will
  164. be accepted.
  165. </simpara>
  166. <simpara>
  167. You need to configure a shared secret for each server you have
  168. configured in <filename>radiusclient.conf</filename> file in
  169. the previous step. The shared secrets are stored in
  170. <filename>/usr/local/etc/radiusclient/servers</filename> file.
  171. </simpara>
  172. <simpara>
  173. Each line contains hostname of a RADIUS server and shared
  174. secret used in communication with that server. The two values
  175. are separated by whitespaces. Configure shared secrets for
  176. every RADIUS server you are going to use.
  177. </simpara>
  178. <warning>
  179. <simpara>
  180. RADIUS servers and clients must be configured with the same
  181. shared secret, otherwise they will not accept RADIUS
  182. messages from each other and neither authentication nor
  183. accounting will work !
  184. </simpara>
  185. </warning>
  186. </section>
  187. <section id="dictionary_client">
  188. <title>File <filename>dictionary</filename></title>
  189. <simpara>
  190. Radiusclient library contains file called
  191. <filename>dictionary.ser</filename>. That file includes all the
  192. attributes that are needed by SIP-router. Include the file in the
  193. main <filename>dictionary</filename> file. To
  194. include the file, put the following line at the end of
  195. <filename>dictionary</filename> file:
  196. </simpara>
  197. <screen>
  198. $INCLUDE /usr/local/etc/radiuclient/dictionary.ser
  199. </screen>
  200. </section>
  201. </section>
  202. <section id="freeradius">
  203. <title>FreeRADIUS Server</title>
  204. <simpara>
  205. Untar, configure, build, and install the server:
  206. </simpara>
  207. <screen>
  208. root@localhost:/usr/local/src# tar xvfz freeradius-0.9.1.tar.gz
  209. root@localhost:/usr/local/src# cd freeradius-0.9.1
  210. root@localhost"/usr/local/src/freeradius-0.9.1# ./configure
  211. root@localhost"/usr/local/src/freeradius-0.9.1# make
  212. root@localhost"/usr/local/src/freeradius-0.9.1# make install
  213. </screen>
  214. <simpara>
  215. All the configuration files of FreeRADIUS server will be in
  216. <filename>/usr/local/etc/raddb</filename> directory. If you install
  217. a binary package then you will probably find them in
  218. <filename>/etc/raddb</filename>.
  219. </simpara>
  220. <simpara>
  221. The following sections describe how to configure freeradius
  222. server. First we describe the common configuration that must be
  223. done in any case. Configuration specific for authentication,
  224. accounting, and group membership checking will be described in
  225. separate sections.
  226. </simpara>
  227. <section id="common_configuration">
  228. <title>Common configuration</title>
  229. <section>
  230. <title>File <filename>clients.conf</filename></title>
  231. <simpara>
  232. File <filename>/usr/local/etc/raddb/clients.conf</filename>
  233. contains description of RADIUS clients that are allowed to
  234. use the server. For each of the clients you need to specify
  235. its hostname or IP address and also a shared secret. The
  236. shared secret must be the same string you configured in
  237. radiusclient library.
  238. </simpara>
  239. <simpara>
  240. Suppose that your SIP server is running on host
  241. proxy.foo.bar and radiusclient library on that machine has
  242. been configure with "foobarsecret" as the shared
  243. secret. You need to put the following section into the
  244. file:
  245. </simpara>
  246. <programlisting>
  247. client proxy.foo.bar {
  248. secret = foobarsecret
  249. shortname = foo
  250. }
  251. </programlisting>
  252. <simpara>
  253. This fragment allows access from RADIUS clients on
  254. proxy.foo.bar if they use "foobarsecret" as the shared
  255. secret.
  256. </simpara>
  257. <note>
  258. <simpara>
  259. The file already contains an entry for localhost (127.0.0.1), so if you are
  260. running the RADIUS server on the same host as your SIP server, then modify
  261. the existing entry instead. By default it contains shared secret
  262. "testing123".
  263. </simpara>
  264. </note>
  265. </section>
  266. <section id="dictionary_server">
  267. <title>File <filename>dictionary</filename></title>
  268. <simpara>
  269. File <filename>/usr/local/etc/raddb/dictionary</filename>
  270. contains the dictionary of FreeRADIUS server. You have to
  271. add the same dictionary file
  272. (<filename>dictionary.ser</filename>), which you added to
  273. the dictionary of radiusclient library, also here. In this
  274. case you don't have to append the contents of the file, you
  275. can include it into the main file. Add the following line
  276. at the end of
  277. <filename>/usr/local/etc/raddb/dictionary</filename>:
  278. </simpara>
  279. <programlisting>
  280. $INCLUDE /usr/local/etc/radiusclient/dictionary.ser
  281. </programlisting>
  282. <simpara>
  283. That will include the same attribute definitions that are
  284. used in radiusclient library so the client and server will
  285. understand each other.
  286. </simpara>
  287. </section>
  288. <section id="radiusd.conf">
  289. <title>File <filename>radiusd.conf</filename></title>
  290. <simpara>
  291. Digest authentication is disabled by default and you must
  292. enable it in this file. There are two sections, "authorize"
  293. and "authenticate". Both sections contain line containing
  294. word "digest". Both of them are commented and you must
  295. un-comment them to enable digest authentication.
  296. </simpara>
  297. <note>
  298. <simpara>
  299. There is also another line containing word "digest"
  300. followed by curly braces and it is enabled by
  301. default. The section is supposed to contain digest
  302. module parameters but because digest module has no
  303. parameters, it is empty. This is not the line you are
  304. supposed to uncomment ! There are two more.
  305. </simpara>
  306. </note>
  307. </section>
  308. <section id="users">
  309. <title>File <filename>users</filename></title>
  310. <simpara>
  311. This file contains authentication information for each
  312. user. For testing purposes we will create user "test". Put
  313. the following into the file:
  314. </simpara>
  315. <programlisting>
  316. test Auth-Type := Digest, User-Password == "test"
  317. Reply-Message = "Hello, test with digest"
  318. </programlisting>
  319. <simpara>
  320. The username and password is for testing only, you can
  321. safely remove the entry once your RADIUS server works and
  322. you are able to authenticate.
  323. </simpara>
  324. </section>
  325. </section>
  326. <section id="test">
  327. <title>Test The Server</title>
  328. <note>
  329. <simpara>
  330. This step is optional.
  331. </simpara>
  332. </note>
  333. <simpara>
  334. The basic configuration of FreeRADIUS server is done it now we
  335. are going to test if it really works. Start the server with
  336. parameter -X. That will cause the server to stay in the
  337. foreground (it will not turn into daemon) and produce a lot of
  338. debugging information on the standard output:
  339. </simpara>
  340. <screen>
  341. root@/usr/local/src# radiusd -X
  342. </screen>
  343. <simpara>
  344. Create file <filename>digest</filename> and put the following
  345. into the file:
  346. </simpara>
  347. <programlisting>
  348. User-Name = "test", Digest-Response = "631d6d73147add2f9e437f59bbc3aeb7",
  349. Digest-Realm = "testrealm", Digest-Nonce = "1234abcd" ,
  350. Digest-Method = "INVITE", Digest-URI = "sip:[email protected]",
  351. Digest-Algorithm = "MD5", Digest-User-Name = "test"
  352. </programlisting>
  353. <simpara>
  354. All the attributes must be on a single line.
  355. </simpara>
  356. <simpara>
  357. Run <command>radclient</command> to test the server:
  358. </simpara>
  359. <screen>
  360. root@/usr/local/src# radclient -f digest localhost auth &lt;shared_secret&gt;
  361. </screen>
  362. <note>
  363. <simpara>
  364. I suppose that you run the test utility directly on the
  365. RADIUS server since it comes with the FreeRADIUS server
  366. package. That also means that you have to enable access
  367. from localhost in your <filename>clients.conf</filename>
  368. file. Don't forget to replace &lt;shared_secret&gt; with
  369. the shared secret configured for localhost clients in
  370. <filename>clients.conf</filename>.
  371. </simpara>
  372. </note>
  373. <simpara>
  374. If your server works properly then you should see the following response:
  375. </simpara>
  376. <screen>
  377. Received response ID 224, code 2, length = 45
  378. Reply-Message = "Hello, test with digest"
  379. </screen>
  380. </section>
  381. <section id="auth_configuration">
  382. <title>Authentication Configuration</title>
  383. <simpara>
  384. To create user "joe" in domain "sip-router.org" with password
  385. "heslo" put the following into file
  386. <filename>/usr/local/etc/raddb/users</filename>:
  387. </simpara>
  388. <programlisting>
  389. [email protected] Auth-Type := Digest, User-Password == "heslo"
  390. Reply-Message = "Authenticated",
  391. Sip-Rpid = "1234"
  392. </programlisting>
  393. <simpara>
  394. Attribute "Sip-Rpid" is optional. The attribute
  395. contains a phone number associated to the user. SIP-router can be
  396. configured to put the phone number into Remote-Party-ID header
  397. field of the SIP message. The header field can be then used
  398. by PSTN gateways to display the number as the number of the
  399. caller on regular phones. You can omit the attribute if you
  400. don't need it.
  401. </simpara>
  402. </section>
  403. <section id="accounting_configuration_server">
  404. <title>Accounting Configuration</title>
  405. <simpara>
  406. By default the FreeRADIUS server will log all accounting requests
  407. into <filename>/usr/local/var/log/radius/radacct</filename>
  408. directory in form of plain text files. The server will
  409. create one file for each hostname in the directory. The
  410. following example shows how the log files look like.
  411. </simpara>
  412. <example>
  413. <title>Example of Accounting Report</title>
  414. <programlisting>
  415. Tue Jun 24 00:20:55 2003
  416. Acct-Status-Type = Start
  417. Service-Type = 15
  418. Sip-Response-Code = 200
  419. Sip-Method = 1
  420. User-Name = "[email protected]"
  421. Calling-Station-Id = "sip:[email protected]"
  422. Called-Station-Id = "sip:[email protected]"
  423. Sip-Translated-Request-URI = "sip:[email protected]"
  424. Acct-Session-Id = "[email protected]"
  425. Sip-To-Tag = "cb2cfe2e-3659-28c7-a8cc-ab0b8cbd3012"
  426. Sip-From-Tag = "a783bd2f-bb8d-46fd-84a9-00a9833f189e"
  427. Sip-CSeq = "1"
  428. NAS-IP-Address = 192.168.2.16
  429. NAS-Port = 5060
  430. Acct-Delay-Time = 0
  431. Client-IP-Address = 127.0.0.1
  432. Acct-Unique-Session-Id = "9b323e6b2f5b0f33"
  433. Timestamp = 1056406855
  434. Tue Jun 24 00:20:56 2003
  435. Acct-Status-Type = Stop
  436. Service-Type = 15
  437. Sip-Response-Code = 200
  438. Sip-Method = 8
  439. User-Name = "[email protected]"
  440. Calling-Station-Id = "sip:[email protected]"
  441. Called-Station-Id = "sip:[email protected]"
  442. Sip-Translated-Request-URI = "sip:192.168.2.32:9576"
  443. Acct-Session-Id = "[email protected]"
  444. Sip-To-Tag = "a783bd2f-bb8d-46fd-84a9-00a9833f189e"
  445. Sip-From-Tag = "cb2cfe2e-3659-28c7-a8cc-ab0b8cbd3012"
  446. Sip-CSeq = "4580"
  447. NAS-IP-Address = 192.168.2.16
  448. NAS-Port = 5060
  449. Acct-Delay-Time = 0
  450. Client-IP-Address = 127.0.0.1
  451. Acct-Unique-Session-Id = "b2c2479a07b17c95"
  452. Timestamp = 1056406856
  453. </programlisting>
  454. </example>
  455. </section>
  456. <section id="group_checking">
  457. <title>Group Checking Configuration</title>
  458. <simpara>
  459. If you want to make user "joe" in domain "sip-router.org" member of
  460. group "pstn" then add the following to your
  461. <filename>/usr/local/etc/raddb/users</filename> file:
  462. </simpara>
  463. <programlisting>
  464. [email protected] Sip-Group == "pstn", Auth-Type := Accept
  465. Reply-Message = "Authorized"
  466. </programlisting>
  467. </section>
  468. </section>
  469. <section id="ser_config">
  470. <title>SIP-router Configuration</title>
  471. <simpara>
  472. We will describe installation from sources here. If you use binary
  473. packages then there is an additional package containing RADIUS
  474. related modules. You will need to install the package.
  475. </simpara>
  476. <simpara>
  477. RADIUS-related modules are not compiled by default. To compile
  478. them, edit <filename>Makefile</filename>, find variable
  479. <varname>exclude_modules</varname> and you should see
  480. "auth_radius", "acc_radius", and "misc_radius" among excluded
  481. modules. Simply remove the three modules from the list.
  482. </simpara>
  483. <simpara>
  484. If you need RADIUS accounting then edit also sip_router/modules/acc/Makefile and
  485. uncomment lines containing:
  486. </simpara>
  487. <programlisting>
  488. DEFS+=-DRAD_ACC
  489. LIBS=-L$(LOCALBASE)/lib -lradiusclient
  490. </programlisting>
  491. <simpara>
  492. Then recompile and re-install SIP-router:
  493. </simpara>
  494. <screen>
  495. root@localhost:/usr/local/src/sip_router# make proper
  496. root@localhost:/usr/local/src/sip_router# make all
  497. root@localhost:/usr/local/src/sip_router# make install
  498. </screen>
  499. <section id="auth_configuration_client">
  500. <title>Authentication Configuration</title>
  501. <simpara>
  502. Edit configuration file of SIP-router and instead of
  503. <filename>auth_db.so</filename> load
  504. <filename>auth_radius.so</filename> and also replace
  505. <function>www_authorize</function> with
  506. <function>radius_www_authorize</function>.
  507. </simpara>
  508. <note>
  509. <simpara>
  510. <function>radius_www_authorize</function> takes just one
  511. parameter (as opposed to <function>www_authorize</function>
  512. which takes 2).
  513. </simpara>
  514. </note>
  515. </section>
  516. <section id="acc_configuration">
  517. <title>Accounting Configuration</title>
  518. <simpara>
  519. To enable RADIUS accounting simply use
  520. <varname>radius_log_flag</varname> and
  521. <varname>radius_log_missed_flag</varname> parameters instead of
  522. <varname>log_flag</varname> and
  523. <varname>log_missed_flag</varname>. Mark transactions that
  524. should be logged with flags configured in the parameters.
  525. </simpara>
  526. </section>
  527. <section id="group_membership_checking">
  528. <title>Group Membership Checking</title>
  529. <simpara>
  530. Instead of <filename>group.so</filename> load
  531. <filename>group_radius.so</filename>. The module exports the
  532. same functions as <filename>group.so</filename>, the only
  533. difference is that all the function names exported by
  534. <filename>group_radius.so</filename> have "radius_" prefix.
  535. </simpara>
  536. </section>
  537. </section>
  538. <section id="faq">
  539. <title>Frequently Asked Questions</title>
  540. <qandaset>
  541. <qandaentry>
  542. <question>
  543. <simpara>
  544. I compiled SIP-router RADIUS modules and installed
  545. radiusclient library, but when I try to start the server I get
  546. the following error message:
  547. </simpara>
  548. <programlisting>
  549. libradiusclient.so.0: cannot open shared object file: No such file or directory
  550. </programlisting>
  551. </question>
  552. <answer>
  553. <simpara>
  554. Make sure that the directory which contains the library
  555. (usually <filename>/usr/local/lib</filename>) is listed
  556. in <filename>/etc/ld.so.conf</filename> and run
  557. <command>ldconfig -v</command> (as root).
  558. </simpara>
  559. </answer>
  560. </qandaentry>
  561. <qandaentry>
  562. <question>
  563. <simpara>
  564. I configured everything as described in this HOWTO, but
  565. I get the following message from radiusclient library
  566. "check_radius_reply: received invalid reply digest from
  567. RADIUS server". What does that mean ?
  568. </simpara>
  569. </question>
  570. <answer>
  571. <simpara>
  572. That means that radiusclient library was unable to
  573. verify digest of the RADIUS message (it is not related
  574. to SIP digest) because shared secret of the client
  575. and server do not match.
  576. </simpara>
  577. <note>
  578. <simpara>
  579. FreeRADIUS server has two files that can contain
  580. definitions of clients and corresponding shared
  581. secrets--<filename>clients</filename> and
  582. <filename>clients.conf</filename>.
  583. </simpara>
  584. <simpara>
  585. If you have proper shared secret in one file and you still get the
  586. mentioned error message then check also the other file. This can easily
  587. happen to clients running on the same host (127.0.0.1 or localhost),
  588. because <filename>clients.conf</filename> contains
  589. definition for localhost by default with secret "testing123".
  590. </simpara>
  591. </note>
  592. </answer>
  593. </qandaentry>
  594. </qandaset>
  595. </section>
  596. </section>