Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
tutorials:openser-modular-install [2009/02/14 21:34] – 86.121.129.39 | tutorials:openser-modular-install [2009/02/14 21:36] (current) – 86.121.129.39 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | This tutorial is designed to help relative newbies (like myself) who wish to understand how exactly to install Kamailio (OpenSER) in a slightly unconventional way, as well as understand the basics of Kamailio (OpenSER). The goal of this exercise is to install Kamailio (OpenSER) on two PCs, each with a specific task, and have them interact with a MySQL server on another machine. The design here is academic: one of the Kamailio PC’s will act as a simple stateful proxy, and the other will only act as a registrar: | ||
+ | On a side-note: all the information here is inferred from the scattered documentation and my own use of Kamailio. So it may not be accurate. If I got it wrong somewhere, feel free to tell me. **The version this tutorial was based on is 1.1.0**, with earlier and later versions of Kamailio there may be variations. | ||
+ | |||
+ | Most of the information in this document can be found elsewhere, but you’ll need to read several documents to put it all together: [[http:// | ||
+ | |||
+ | The pages on the website that explain how to [[http:// | ||
+ | |||
+ | |||
+ | ====== How does Kamailio (OpenSER) work? ====== | ||
+ | |||
+ | If you want to do operations that differ from the usual, you might want to broadly understand the structure of Kamailio (OpenSER). Not the workings of the code (unless you want to do something REALLY special), but how it works once compiled. There’s basically two parts to Kamailio (OpenSER): | ||
+ | the //core//, which is the working executable part, and the // | ||
+ | |||
+ | The modules are by far the most important component that give Kamailio the ability to perform a specific task. The working part of the modules can be divided in two parts: the exported parameters, and the exported functions. These will both be important when it comes to setting up Kamailio with it’s configuration file: '' | ||
+ | |||
+ | The core provides the framework for Kamailio (OpenSER). Whatever else you will find in the configuration file is part of the core (which has parameters, functions, and more – see [[http:// | ||
+ | |||
+ | ====== Setting up the network ====== | ||
+ | |||
+ | For the network we would like to build here’s what we absolutely need: | ||
+ | |||
+ | *Proxy: Kamailio (OpenSER) core, Transaction module (TM) for stateful transactions, | ||
+ | |||
+ | *Registrar: Kamailio (OpenSER) core, Stateless replier module (SL), User location implementation module (USRLOC), SIP Registrar implementation module (REGISTRAR) and MySQL-backend for database API module (MYSQL). | ||
+ | |||
+ | *Location service: MySQL server. | ||
+ | |||
+ | I’ll assume that you took my advice and downloaded Kamailio (OpenSER) from the SVN. If you used binary packages and managed to get them to work, never fear, it won’t be a problem. Just skip the part about the Kamailio (OpenSER) installation. If you really want to follow the rest of the tutorial, go to the directory where the modules are installed (.so files, they should be in ''/ | ||
+ | |||
+ | |||
+ | ===== Modular Kamailio (OpenSER) servers installation ===== | ||
+ | |||
+ | To fully understand what is happening, we’ll only install the strict minimum. In order to do this, we will only install those modules that we need and that I mentioned earlier. There’s several ways to achieve this, and here’s what I find the simplest: | ||
+ | |||
+ | Edit the Makefile, and at line 304 change this instruction: | ||
+ | |||
+ | < | ||
+ | Install: all mk-install-dirs install-cfg install-bin install-modules \ | ||
+ | | ||
+ | </ | ||
+ | |||
+ | To | ||
+ | < | ||
+ | Install: kamailio mk-install-dirs install-cfg install-bin install-modules \ | ||
+ | | ||
+ | </ | ||
+ | Now, making sure that you have super-user privileges, execute: | ||
+ | < | ||
+ | > make install | ||
+ | </ | ||
+ | Now we have only the core installed, we’ll add the modules that we want to the installation. First, however, we’ll need to build them (make sure that you have the appropriate libraries installed): | ||
+ | < | ||
+ | > make include_module=”mysql” modules | ||
+ | </ | ||
+ | Now you simply need to copy the modules you want to the appropriate directory. If you followed my instructions up to here, it should be ''/ | ||
+ | |||
+ | |||
+ | ===== Setting up MySQL ===== | ||
+ | |||
+ | I’ll assume that you managed to install MySQL on the PC destined to be a location server. You now need to install the necessary Kamailio (OpenSER) database using: '' | ||
+ | |||
+ | *read-only : user: openser password: openserro | ||
+ | *read-write: | ||
+ | |||
+ | These users can be either a local or a remote user (fortunately), | ||
+ | |||
+ | One final thing remains to be done before you can use the MySQL location service, and that’s to make it accessible remotely. You’ll need to change a line in ''/ | ||
+ | < | ||
+ | Bind-address = localhost | ||
+ | </ | ||
+ | to | ||
+ | < | ||
+ | Bind-address = | ||
+ | </ | ||
+ | |||
+ | ===== Setting up Kamailio (OpenSER) ===== | ||
+ | |||
+ | To set up Kamailio (OpenSER) you will need to modify two files: '' | ||
+ | < | ||
+ | |||
+ | # | ||
+ | # openser control tool resource file | ||
+ | # | ||
+ | # here you can set variables used in the kamctl | ||
+ | |||
+ | ## your SIP domain | ||
+ | SIP_DOMAIN= '' | ||
+ | |||
+ | ## database type: MYSQL or PGSQL, by defaulte none is loaded | ||
+ | DBENGINE=MYSQL | ||
+ | |||
+ | ## database host | ||
+ | DBHOST= '' | ||
+ | |||
+ | ## database name | ||
+ | DBNAME=openser | ||
+ | |||
+ | ## database read/write user | ||
+ | DBRWUSER=openser | ||
+ | |||
+ | ## database read only user | ||
+ | DBROUSER=openserro | ||
+ | |||
+ | ## password for database read only user | ||
+ | DBROPW=openserro | ||
+ | |||
+ | ## database super user | ||
+ | DBROOTUSER=" | ||
+ | |||
+ | ## type of aliases used: DB - database aliases; UL - usrloc aliases | ||
+ | ## - default: none | ||
+ | ALIASES_TYPE=" | ||
+ | |||
+ | ## control engine: FIFO or UNIXSOCK | ||
+ | ## - default FIFO | ||
+ | CTLENGINE=" | ||
+ | |||
+ | ## path to FIFO file | ||
+ | OSER_FIFO=" | ||
+ | |||
+ | ## check ACL names; default on (1); off (0) | ||
+ | VERIFY_ACL=1 | ||
+ | |||
+ | ## ACL names - if VERIFY_ACL is set, only the ACL names from below list | ||
+ | ## are accepted | ||
+ | ACL_GROUPS=" | ||
+ | |||
+ | ## verbose - debug purposes - default ' | ||
+ | VERBOSE=1 | ||
+ | </ | ||
+ | This file is used by the '' | ||
+ | |||
+ | A side note about '' | ||
+ | < | ||
+ | > kamctl | ||
+ | </ | ||
+ | For '' | ||
+ | |||
+ | ===== Setting up the Kamailio (OpenSER) proxy ===== | ||
+ | |||
+ | The first part of the '' | ||
+ | < | ||
+ | # | ||
+ | # | ||
+ | # simple quick-start config script | ||
+ | # | ||
+ | |||
+ | # ----------- global configuration parameters ------------------------ | ||
+ | | ||
+ | #Uncomment these lines to enter debugging mode | ||
+ | debug=9 | ||
+ | Fork=no | ||
+ | Log_stderror=yes | ||
+ | | ||
+ | |||
+ | check_via=no | ||
+ | dns=no | ||
+ | rev_dns=no | ||
+ | listen= ip this pc will listen on | ||
+ | port=5060 | ||
+ | children=4 | ||
+ | fifo="/ | ||
+ | fifo_db_url=" | ||
+ | </ | ||
+ | It gets interesting once we load the modules and set their parameters. | ||
+ | < | ||
+ | # ------------------ module loading ---------------------------------- | ||
+ | |||
+ | # Uncomment this if you want to use SQL database | ||
+ | loadmodule "/ | ||
+ | |||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | |||
+ | loadmodule "/ | ||
+ | |||
+ | # ----------------- setting module-specific parameters --------------- | ||
+ | # -- usrloc params -- | ||
+ | |||
+ | modparam(" | ||
+ | |||
+ | # Uncomment this if you want to use SQL database | ||
+ | # for persistent storage and comment the previous line | ||
+ | modparam(" | ||
+ | |||
+ | # -- rr params -- | ||
+ | # add value to ;lr param to make some broken UAs happy | ||
+ | modparam(" | ||
+ | </ | ||
+ | You may have been wondering why we use '' | ||
+ | |||
+ | As for the parameters, we tell usrloc where the database is situated, and that we do not want to keep a local table for the addresses, only the remote database '' | ||
+ | < | ||
+ | # ------------------------- | ||
+ | |||
+ | # main routing logic | ||
+ | |||
+ | route{ | ||
+ | |||
+ | # initial sanity checks -- messages with | ||
+ | # max_forwards==0, | ||
+ | if (!mf_process_maxfwd_header(" | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | if (msg:len >= 2048 ) { | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | # we record-route all messages -- to make sure that | ||
+ | # subsequent messages will go through our proxy; that's | ||
+ | # particularly good if upstream and downstream entities | ||
+ | # use different transport protocol | ||
+ | if (!method==" | ||
+ | | ||
+ | |||
+ | # subsequent messages withing a dialog should take the | ||
+ | # path determined by record-routing | ||
+ | if (loose_route()){ | ||
+ | | ||
+ | }; | ||
+ | |||
+ | if (!uri==myself) { | ||
+ | | ||
+ | }; | ||
+ | |||
+ | # if the request is for other domain use UsrLoc | ||
+ | #(in case, it does not work, use the following command | ||
+ | # with proper names and addresses in it) | ||
+ | if (uri==myself) { | ||
+ | |||
+ | if (method==" | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | | ||
+ | if (!uri==myself) { | ||
+ | | ||
+ | }; | ||
+ | |||
+ | # | ||
+ | if (!lookup(" | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | }; | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | route[1] { | ||
+ | # send it out now; use stateful forwarding as it works reliably | ||
+ | # even for UDP2TCP | ||
+ | if (!t_relay()) { | ||
+ | | ||
+ | }; | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | # route[2] will route REGISTER messages towards the registrar | ||
+ | # No database connectivity is required here, as the registrar then sends the messages to the location server | ||
+ | route[2] { | ||
+ | # | ||
+ | | ||
+ | | ||
+ | | ||
+ | }; | ||
+ | exit; | ||
+ | } | ||
+ | </ | ||
+ | Basically, the proxy merely routes (relays) the messages to the appropriate location, checking against the database if necessary. As you can see, the proxy also makes a few checks (and modifications) on the message and sends an error message if necessary. | ||
+ | |||
+ | ===== Setting up the Kamailio (OpenSER) registrar ===== | ||
+ | |||
+ | |||
+ | The registrar is obviously simpler then the proxy server, as the only thing that needs to be done is accept the REGISTER request and record it in the database. As the beginning of the code is essentially the same, we’ll only check it from the addition of the modules: | ||
+ | < | ||
+ | # ------------------ module loading ---------------------------------- | ||
+ | |||
+ | # Uncomment this if you want to use SQL database | ||
+ | loadmodule "/ | ||
+ | |||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | |||
+ | # ----------------- setting module-specific parameters --------------- | ||
+ | |||
+ | # -- usrloc params -- | ||
+ | |||
+ | modparam(" | ||
+ | |||
+ | # Uncomment this if you want to use SQL database | ||
+ | # for persistent storage and comment the previous line | ||
+ | modparam(" | ||
+ | |||
+ | # ------------------------- | ||
+ | |||
+ | # main routing logic | ||
+ | |||
+ | route{ | ||
+ | |||
+ | # initial sanity checks -- too long messages | ||
+ | if (msg:len >= 2048 ) { | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | if (!uri==myself) { | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | # the only valid message for the registrar is the register message | ||
+ | # other messages are answered with an error message | ||
+ | if (uri==myself) { | ||
+ | |||
+ | if (method==" | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | }; | ||
+ | exit; | ||
+ | } else { | ||
+ | | ||
+ | exit; | ||
+ | }; | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== Adding minimal security ====== | ||
+ | |||
+ | |||
+ | We now have a fully functional but extremely insecure network. We will add security so that messages will not be accepted from just any machine. In order to do so, we will add a few modules to each server: | ||
+ | < | ||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | loadmodule "/ | ||
+ | |||
+ | modparam(" | ||
+ | |||
+ | #this line tells auth_db the name of the password column | ||
+ | #(for the ha1 calculation) | ||
+ | modparam(" | ||
+ | </ | ||
+ | For the proxy we’ll want to modify the way INVITE messages are handled (this code replaces the '' | ||
+ | < | ||
+ | if (method==" | ||
+ | route(1); | ||
+ | exit; | ||
+ | } if (method==" | ||
+ | route(3); | ||
+ | exit; | ||
+ | } else if (method==" | ||
+ | route(2); | ||
+ | exit; | ||
+ | }; | ||
+ | </ | ||
+ | And add the corresponding route at the end of the code: | ||
+ | < | ||
+ | route[3] { | ||
+ | # ----------------------------------------------------------------- | ||
+ | # INVITE Message Handler | ||
+ | # ----------------------------------------------------------------- | ||
+ | if (!proxy_authorize("/ | ||
+ | proxy_challenge("/ | ||
+ | exit; | ||
+ | } else if (!check_from()) { | ||
+ | sl_send_reply(" | ||
+ | break; | ||
+ | }; | ||
+ | consume_credentials(); | ||
+ | lookup(" | ||
+ | if (uri!=myself) { | ||
+ | route(1); | ||
+ | exit; | ||
+ | }; | ||
+ | if (!lookup(" | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | }; | ||
+ | route(1); | ||
+ | } | ||
+ | </ | ||
+ | And for the registrar you only need to add the following lines before the '' | ||
+ | < | ||
+ | if (!www_authorize("/ | ||
+ | www_challenge("/ | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | if (!check_to()) { | ||
+ | sl_send_reply(" | ||
+ | exit; | ||
+ | }; | ||
+ | |||
+ | consume_credentials(); | ||
+ | </ | ||
+ | |||
+ | The last step is to add your users in the database as suscribers. In order to do so you'll need to have the MySQL client (as mentioned earlier) installed on one of your Kamailio (OpenSER) servers. The instruction is : | ||
+ | |||
+ | < | ||
+ | > kamctl add '' | ||
+ | </ | ||
+ | |||
+ | It would of course also be useful to add tls support for greater security, but fortunately there’s already a good guide for that in the [[http:// | ||
+ | |||
+ | tutorial by: | ||
+ | Alistair Doswald | ||
+ | Project VaDeSe - VoIP security and video on demand - www.vadese.org | ||
+ | Institute for Information and Communication Technologies(IICT) - www.iict.ch | ||
+ | [[http:// |