INSTALL 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. I. TURN Server as a standard OS package
  2. At the present time, several operation systems have this project pre-packaged:
  3. 1) New Linuxes in Debian family have package "coturn":
  4. http://packages.qa.debian.org/r/coturn.html
  5. If you are using the Debian package from the project download site,
  6. then follow these instructions:
  7. Unpack the archive:
  8. $ tar xvfz turnserver-<...>.tar.gz
  9. Read the INSTALl file:
  10. $ cat INSTALL
  11. Install the *.deb file:
  12. $ sudo apt-get update
  13. $ sudo apt-get install gdebi-core
  14. $ sudo gdebi coturn*.deb
  15. (to install the bare package without any dependencies, type:
  16. $ sudo dpkg -i coturn_*_*.deb)
  17. After the install, read the documentation in /usr/share/doc/coturn directory.
  18. All binaries will be installed in /usr/bin/ directory.
  19. The turn*.conf config files are in /etc directory.
  20. The service start-up control scripts will be in /etc/init.d/coturn and
  21. in /etc/defaults/coturn files.
  22. 2) ArchLinux has this TURN server package:
  23. https://aur.archlinux.org/packages/coturn/
  24. 3) FreeBSD and OpenSUSE have the predecessor of this project packaged
  25. (rfc5766-turn-server).
  26. II. DOWNLOAD
  27. You have to download the archive file turnserver-*.tar.gz and unpack it:
  28. $ tar xfz turnserver-*.tgz
  29. it will create the directory 'turnserver-*' with all sources, build files,
  30. examples and documentation.
  31. III. BUILD
  32. If you are sure that you system is ready for the build (see the section
  33. "Extra libraries and Utilities" below) then you can build the system.
  34. First, you have to run the configure script:
  35. $ cd turnserver-*
  36. $ ./configure
  37. It will create a Makefile customized for your system.
  38. By default, the generated Makefile will install everything to:
  39. - /usr on Solaris.
  40. - /usr/pkg on NetBSD.
  41. - /usr/local everywhere else.
  42. The binaries will be copied to the bin subdirectory of the installation
  43. destination, config files copied to etc subdirectory. The default SQLite database
  44. will be created in var/db/turndb. There will be
  45. also documents, examples and some other files, in separate directories.
  46. You can change the root configured destination directory by
  47. setting PREFIX variable in the
  48. configure command line. For example:
  49. $ PREFIX=/opt ./configure
  50. Or:
  51. $ ./configure --prefix=/opt
  52. You can change the auxiliary configured destination sub-directories by
  53. setting BINDIR, CONFDIR, MANPREFIX, EXAMPLESDIR, DOCSDIR, LIBDIR, SCHEMADIR,
  54. LOCALSTATEDIR, TURNDBDIR and TURNINCLUDEDIR variables in the
  55. configure command line. For example:
  56. $ PREFIX=/opt BINDIR=/opt/bin64 CONFDIR=/opt/conf ./configure
  57. Or:
  58. $ ./configure --prefix=/opt --bindir=/opt/bin64 --confdir=/opt/conf
  59. You also can change the compilation and link options by
  60. setting common build variables in the
  61. configure command line. For example:
  62. $ CC=clang CFLAGS=-D_CAURIB LDFLAGS=-lshanka ./configure --prefix=/opt/shy
  63. See below a separate INSTALL section for more details.
  64. The script "configure" is a proprietary script. It will create a Makefile
  65. that you can use to build the project:
  66. $ make
  67. The make command without options will do the following:
  68. - compile the code.
  69. - create bin/ sub-directory and put the TURN server, TURN admin and
  70. "utility" programs there.
  71. - create lib/ sub-directory and put the client library there.
  72. - create include/turn/ sub-directory and put include files there.
  73. - create sqlite/turndb default empty database that will be copied to
  74. var/db/ during the installation.
  75. The TURN programs can be either called directly, or a shell scripts can be used.
  76. The script examples are located in examples/scripts directory. These scripts
  77. are just examples: you can run them successfully for the tests, but
  78. you will have to change the script parameters for your real environment.
  79. The command:
  80. $ sudo make install
  81. will install everything into the system file structure (see below).
  82. (NOTE: On NetBSD, use "su root -c").
  83. The command:
  84. $ sudo make deinstall
  85. will remove all installed TURN Server files from your system.
  86. The command:
  87. $ make clean
  88. will clean all results of the build and configuration actions.
  89. Do not run "make clean" before "make deinstall". The "clean" command will
  90. remove the Makefile and you will not be able to "deinstall" then. If that
  91. has happened, then run ./configure and make again, then deinstall and then
  92. clean.
  93. NOTE: On most modern systems, the build will produce dynamically linked
  94. executables. If you want statically linked executables, you have to modify,
  95. accordingly, the Makefile.in template file.
  96. IV. OPENSSL
  97. If you are using the OpenSSL that is coming with your system, and you are
  98. OK with it, then you do not have to read this chapter. If your system has
  99. an outdated OpenSSL version, or if you need some very fresh OpenSSL features
  100. that are not present in the current usual stable version, then you may have
  101. to compile (and run) your TURN server with a different OpenSSL version.
  102. For example, if you need ALPN feature, or DTLS1.2, and your system comes with
  103. OpenSSL 1.0.1, you will not be able to use those features unless you install
  104. OpenSSL 1.0.2 and compile and run the TURN server with the newer version.
  105. The problem is, it is usually not safe to replace the system's OpenSSL with
  106. a different version. Some systems are "bound" to its "native" OpenSSL
  107. installations, and their behavior may become unpredictable with the newer
  108. versions.
  109. So you want to preserve your system's OpenSSL but you want to compile and to
  110. run the TURN server with newer OpenSSL version. There are different ways to
  111. do that. We are suggesting the following:
  112. 1) Download the OpenSSL version from openssl.org.
  113. 2) Let's assume that we want to install the "custom" OpenSSL into /opt.
  114. Configure and build OpenSSL as:
  115. $ ./config --prefix=/opt
  116. $ make
  117. $ make install
  118. Those commands will install OpenSSL into /opt, with static libraries (no
  119. dynamic libraries).
  120. 3) Build the TURN server:
  121. $ ./configure --prefix=/opt
  122. $ make
  123. Those commands will build the TURN server binaries, statically linked
  124. against the newer OpenSSL.
  125. 4) Then you can run the TURN server without setting the dynamic
  126. libraries paths - because it has been linked statically against the newer
  127. OpenSSL libraries.
  128. One potential problem is that libevent2 is using the OpenSSL, too. So, ideally,
  129. to be 100% safe of all potential discrepancies in the runtime, we'd suggesting
  130. rebuilding libevent2 with the newer OpenSSL, too.
  131. V. INSTALL
  132. This step is optional. You can run the turnserver from the original build
  133. directory, successfully, without installing the TURN server into your system.
  134. You have to install the turnserver only if you want to integrate the
  135. turnserver in your system.
  136. Run the command:
  137. $ make install
  138. It will install turnserver in /usr/local/ directory (or to whatever directory
  139. was set in the PREFIX variable). You will have to copy
  140. /usr/local/etc/turnserver.conf.default to /usr/local/etc/turnserver.conf file
  141. and adjust your runtime configuration.
  142. This command will also:
  143. - copy the content of examples subdirectory into
  144. PREFIX/share/examples/turnserver/ directory;
  145. - copy the generated default empty SQLite database from sqlite/turndb
  146. to /usr/local/var/db or to /var/db/turndb;
  147. - copy the content of include/turn subdirectory into
  148. PREFIX/include/turn/ directory;
  149. - copy the database schema file turndb/schema.sql into
  150. PREFIX/share/turnserver/
  151. directory;
  152. - copy all docs into PREFIX/share/doc/turnserver/ directory.
  153. The installation destination of "make install" can be changed by
  154. using DESTDIR variable, for example:
  155. $ ./configure --prefix=/usr
  156. $ make
  157. $ make DESTDIR=/opt install
  158. In this example, the root installation directory will be /opt/usr.
  159. The "configure" script by default generates a Makefile with "rpath" option
  160. set for the dynamic libraries linking (if your system and your compiler
  161. allow that option). If that is not desirable (like in some OS packaging
  162. procedures), then run the "configure" script with --disable-rpath option.
  163. If you are not using the rpath linking option, then after the installation,
  164. you may have to adjust the system-wide shared library search path with
  165. "ldconfig -n <libdirname>" (Linux), "ldconfig -m <libdirname>" (BSD) or
  166. "crle -u -l <libdirname>" (Solaris). Your system must be able to find the
  167. libevent2, openssl and (optionally) SQLite and/or PostgreSQL and/or MySQL
  168. (MariaDB) and/or MongoDB and/or Redis shared libraries, either with the
  169. help of the system-wide library search configuration or by using
  170. LD_LIBRARY_PATH. "make install" will make a non-guaranteed effort to add
  171. automatically PREFIX/lib and /usr/local/lib to the libraries search path,
  172. but if you have some libraries in different non-default directories then
  173. you will have to add them manually to the search path, or you will have
  174. to adjust LD_LIBRARY_PATH.
  175. VI. PLATFORMS
  176. The TURN Server is using generic *NIX system APIs and is supposed to be
  177. usable on wide range of *NIX systems.
  178. The following platforms are supported
  179. (both i386 and x86_64 variants when applicable):
  180. - Linux,
  181. - BSD family (Mac OS X, FreeBSD, NetBSD, OpenBSD),
  182. - Solaris 11,
  183. - Cygwin
  184. It must work on other *NIXes, as well. The configure script and/or
  185. Makefile may need adjustments for other *NIXes not mentioned above.
  186. The code of the client messaging library can be compiled and used on
  187. Windows, too, but it is not supported for now.
  188. VI. COMPILERS
  189. The TURN Server is written in C programming language, for portability
  190. and for the performance reasons.
  191. The tested C compilers are:
  192. - gcc 3.4.4 thru 4.8.x
  193. - clang 3.0 or better
  194. - Solaris Studio 12 C compiler
  195. It may be compiled with other compilers, too.
  196. The code is compatible with C++ compiler, and a C++ compiler
  197. (like g++) can be used for the compilation, too:
  198. $ CC=g++ ./configure
  199. $ make
  200. VIII. WHICH EXTRA LIBRARIES AND UTILITIES YOU NEED
  201. In addition to common *NIX OS services and libraries, to compile this code,
  202. OpenSSL (version 1.0.0a or better recommended) and libevent2 (version 2.0.5
  203. or better) are required, SQLite C development library and header is optional,
  204. the PostgreSQL C client development setup is optional,
  205. the MySQL (MariaDB) C client development setup is optional,
  206. the MongoDB C Driver and the Hiredis development files for Redis database
  207. access are all optional. For development build, the development headers and
  208. the libraries to link with, are to be installed. For the runtime, only the
  209. runtime setup is required. If the build is modified for
  210. static linking, then even runtime installation is not needed.
  211. OpenSSL, SQLite, libevent2, PostgreSQL, MySQL (or MariaDB) and Hiredis
  212. libraries can be downloaded from their web sites:
  213. - http://www.openssl.org (required);
  214. - http://www.libevent.org (required);
  215. - http://www.sqlite.org (optional);
  216. - http://www.postgresql.org (optional);
  217. - http://www.mysql.org (or http://mariadb.org) (optional);
  218. - https://github.com/mongodb/mongo-c-driver (optional);
  219. - http://redis.io (optional).
  220. The installations are pretty straightforward - the usual
  221. "./configure" and "make install" commands. Install them into their default
  222. locations - the configure script and the Makefile are assuming that they are
  223. installed in their default locations. If not, then you will have to modify
  224. those.
  225. Most modern popular systems (FreeBSD, Linux Ubuntu/Debian/Mint, Amazon Linux, Fedora)
  226. have a simpler way of the third party tools installation:
  227. *) FreeBSD (the FRESH ports database is assumed to be installed, with
  228. the turnserver port included):
  229. $ cd /usr/ports/net/turnserver
  230. $ sudo make install clear
  231. That's it - that command will install the TURN server with all necesary
  232. thrid-party tools.
  233. If you system have no fresh ports repository:
  234. $ cd /usr/ports/security/openssl/
  235. $ sudo make install clean
  236. $ cd /usr/ports/databases/sqlite3/
  237. $ sudo make install clean
  238. $ cd /usr/ports/devel/libevent2/
  239. $ sudo make install clean
  240. $ cd /usr/ports/databases/postgresql84-client/ (or any other version)
  241. $ sudo make install clean
  242. $ cd /usr/ports/databases/mysql51-client/ (or any other version)
  243. $ sudo make install clean
  244. $ cd /usr/ports/databases/hiredis/
  245. $ sudo make install clean
  246. **) Linux Ubuntu, Debian, Mint:
  247. $ sudo apt-get install libssl-dev
  248. $ sudo apt-get install libsqlite3 (or sqlite3)
  249. $ sudo apt-get install libsqlite3-dev (or sqlite3-dev)
  250. $ sudo apt-get install libevent-dev
  251. $ sudo apt-get install libpq-dev
  252. $ sudo apt-get install mysql-client
  253. $ sudo apt-get install libmysqlclient-dev
  254. $ sudo apt-get install libhiredis-dev
  255. or you can use Synaptic or other software center.
  256. ***) Fedora:
  257. $ sudo yum install openssl-devel
  258. $ sudo yum install sqlite
  259. $ sudo yum install sqlite-devel
  260. $ sudo yum install libevent
  261. $ sudo yum install libevent-devel
  262. $ sudo yum install postgresql-devel
  263. $ sudo yum install postgresql-server
  264. $ sudo yum install mysql-devel
  265. $ sudo yum install mysql-server
  266. $ sudo yum install hiredis
  267. $ sudo yum install hiredis-devel
  268. ****) Amazon Linux is similar to Fedora, but:
  269. - you have to install gcc first:
  270. $ sudo yum install gcc
  271. - mongo-c-driver packages are not available "automatically".
  272. MongoDB support will not be compiled, unless you install it "manually"
  273. before the TURN server compilation. Refer to
  274. https://github.com/mongodb/mongo-c-driver for installation instructions
  275. of the driver.
  276. - hiredis packages are not available, so do not issue the
  277. hiredis installation commands. Redis support will not be
  278. compiled, unless you install it "manually" before the TURN
  279. server compilation. For Amazon EC2 AMIs, we install the
  280. redis manually in the system. But the TURN server can be
  281. perfectly installed without redis support - if you do not
  282. need it.
  283. *****) Older Debian family Linuxes are using some packages
  284. with different names.
  285. ******) On some CentOS / RedHat 6.x systems you have to install
  286. libevent2 "manually", and optionally you have to download and
  287. install Hiredis, but everything else can be found in the software
  288. repository. Also, if you would like to make an RPM for CentOS,
  289. check the directory rpm/ with the instructions.
  290. NOTE: If your tools are installed in non-standard locations, you will
  291. have to adjust CFLAGS and LDFLAGS environment variables for TURN
  292. server ./configure script. For example, to configure the TURN server
  293. with Solaris 11 PostgreSQL 32-bits setup, you may use a command
  294. like this:
  295. $ CFLAGS="${CFLAGS} -I/usr/postgres/9.2-pgdg/include/" LDFLAGS="${LDFLAGS} -L/usr/postgres/9.2-pgdg/lib/" ./configure
  296. Dynamic library paths:
  297. You may also have to adjust the turn server start script, add all the dynamic runtime
  298. library paths to LD_LIBRARY_PATH. Or you may find that it would be more convenient to adjust the
  299. system-wide shared library search path by using commands:
  300. on Linux:
  301. $ ldconfig -n <libdirname>
  302. or on BSD:
  303. $ ldconfig -m <libdirname>
  304. or on Solaris:
  305. $ crle -u -l <libdirname>
  306. On Mac OS X, you have three different choices for dynamic libraries handling:
  307. 1) Use DYLD_LIBRARY_PATH environment variable in runtime; OR
  308. 2) Before the compilation, check the dynamic libraries and adjust their identification names,
  309. if necessary, to the absolute library path or to @rpath/<library-file-name>.
  310. For example, the MySQL dynamic library may need that adjustment. You will have to use
  311. "adjust_name_tool" with -id option for that; OR
  312. 3) After the compilation, you can use the same tool, "adjust_name_tool",
  313. with option -change, to adjust the library paths values in the binary,
  314. where necessary. All library paths must be absolute paths or @rpath/... .
  315. See also the next section.
  316. NOTE: See "SQLite setup" and "PostgreSQL setup" and "MySQL setup" and
  317. "MongoDB setup" and "Redis setup" sections below for more database setup
  318. information.
  319. NOTE: If you do not install SQLite or PostgreSQL or MySQL or MongoDB or Redis,
  320. then you will be limited to the command-line options for user database.
  321. It will work great for development setup, but for real runtime systems you
  322. will need SQLite or PostgreSQL or MySQL or MongoDB or Redis.
  323. NOTE: To run PostgreSQL or MySQL or MongoDB or Redis server on the same system,
  324. you will also have to install a corresponding PostgreSQL or MySQL or
  325. MongoDB or Redis server package. The DB C development packages only provide
  326. development libraries, and client libraries only provide client
  327. access utilities and runtime libraries. The server packages may
  328. include everything - client, C development and server runtime.
  329. NOTE: OpenSSL to be installed before libevent2. When libevent2 is building,
  330. it is checking whether OpenSSL has been already installed, and which version
  331. of OpenSSL. If the OpenSSL is missed, or too old, then libevent_openssl
  332. library is not being created during the build, and you will not be able to
  333. compile the TURN Server with TLS support.
  334. NOTE: An older libevent version, version 1.x.x, is often included in some *NIX
  335. distributions. That version has its deficiencies and is inferior to the newer
  336. libevent2, especially in the performance department. This is why we are
  337. not providing backward compatibility with the older libevent 1.x version.
  338. If you have a system with older libevent, then you have to install the new
  339. libevent2 from their web site. It was tested with older *NIXes
  340. (like FreeBSD 6.x) and it works just fine.
  341. NOTE: SQLite must be of version 3.x.
  342. NOTE: For extra security features (like DTLS)
  343. support, OpenSSL version 1.0.0a or newer is recommended. Older versions do
  344. not support DTLS, reliably, in some cases. For example, the Debian 'Squeeze'
  345. Linux supplies 0.9.8 version of OpenSSL, that does not work correctly with
  346. DTLS over IPv6. If your system already has an older version of OpenSSL
  347. installed (usually in directory /usr) then you may want to install your
  348. newer OpenSSL "over" the old one (because it will most probably will not allow
  349. removal of the old one). When installing the newer OpenSSL, run the OpenSSL's
  350. configure command like this:
  351. $ ./config --prefix=/usr
  352. that will set the installation prefix to /usr (without "--prefix=/usr"
  353. by default it would be installed to /usr/local). This is necessary if you
  354. want to overwrite your existing older OpenSSL installation.
  355. IX. BUILDING WITH NON-DEFAULT PREFIX DIRECTORY
  356. Say, you have an older system with old openssl and old libevent
  357. library and you do not want to change that, but you still want
  358. to build the turnserver.
  359. Do the following steps:
  360. 1) Download new openssl from openssl.org.
  361. 2) Configure and build new openssl and install it into /opt:
  362. $ ./config --prefix=/opt
  363. $ make
  364. $ make install
  365. 3) Download the latest libevent2 from libevent.org, configure and install
  366. it into /opt:
  367. $ ./configure --prefix=/opt
  368. $ make
  369. $ make install
  370. 4) Change directory to coturn and build it:
  371. $ ./configure --prefix=/opt
  372. $ make
  373. After that, you can either use it locally, or install it into /opt.
  374. But remember that to run it, you have to adjust your LD_LIBRARY_PATH,
  375. like that:
  376. $ LD_LIBRARY_PATH=/opt/lib ./bin/turnserver
  377. An alternative would be adjusting the system-wide shared library search path
  378. by using
  379. $ ldconfig -n <libdirname> (Linux)
  380. $ ldconfig -m <libdirname> (BSD)
  381. $ crle -u -l <libdirname> (Solaris)
  382. X. TEST SCRIPTS
  383. First of all, you can use the test vectors from RFC 5769 to double-check that the
  384. STUN/TURN message encoding algorithms work properly. Run the utility:
  385. $ cd examples
  386. $ ./scripts/rfc5769.sh
  387. It will perform several protocol checks and print the results on the output.
  388. If anything has compiled wrongly (TURN Server, or OpenSSL libraries)
  389. then you will see some errors.
  390. Now, you can perform the TURN functionality test (bare minimum TURN example).
  391. If everything compiled properly, then the following programs must run
  392. together successfully, simulating TURN network routing in local loopback
  393. networking environment:
  394. Open two shell screens or consoles:
  395. In shell number 1, run TURN server application:
  396. $ cd examples
  397. $ ./scripts/basic/relay.sh
  398. In shell number 2, run test client application:
  399. $ cd examples
  400. $ ./scripts/basic/udp_c2c_client.sh
  401. If the client application produces output and in approximately 22 seconds
  402. prints the jitter, loss and round-trip-delay statistics, then everything is
  403. fine.
  404. There is another more complex test:
  405. In shell number 1, run TURN server application:
  406. $ cd examples
  407. $ ./scripts/basic/relay.sh
  408. In shell number 2, run "peer" application:
  409. $ cd examples
  410. $ ./scripts/peer.sh
  411. In shell number 3, run test client application:
  412. $ cd examples
  413. $ ./scripts/basic/udp_client.sh (or ./scripts/basic/tcp_client.sh)
  414. There is a similar set of examples/scripts/longtermsecure/* scripts for
  415. TURN environment with long-term authentication mechanism. This set of
  416. scripts is more complex, and checking the scripts options is useful for
  417. understanding how the TURN Server works:
  418. In shell number 1, run secure TURN server application:
  419. $ cd examples
  420. $ ./scripts/longtermsecure/secure_relay.sh
  421. In shell number 2, run "peer" application:
  422. $ cd examples
  423. $ ./scripts/peer.sh
  424. In shell number 3, run secure test client application:
  425. $ cd examples
  426. $ ./scripts/longtermsecure/secure_udp_client.sh
  427. (or ./scripts/longtermsecure/secure_tcp_client.sh)
  428. (or ./scripts/longtermsecure/secure_tls_client.sh)
  429. (or ./scripts/longtermsecure/secure_dtls_client.sh)
  430. (or ./scripts/longtermsecure/secure_sctp_client.sh)
  431. (or ./scripts/longtermsecure/secure_udp_c2c.sh for "peerless"
  432. client-to-client communications)
  433. The provided scripts are set for the local loopback communications,
  434. as an example and as a test environment. Real networking IPs must be
  435. used in real work environments.
  436. Try wireshark to check the communications between client, turnserver
  437. and the peer.
  438. Check the README.* files and the comments in the scripts relay.sh and
  439. secure_relay.sh as a guidance how to run the TURN server.
  440. XI. OS X compilation notes
  441. OS X usually has an older version of openssl supplied, with some Apple
  442. additions. The the "native" openssl will work, within its limitations,
  443. but the best option is to install a good fresh openssl development
  444. library, from http://www.openssl.org. You will have
  445. to handle the dynamic linking of the generated binaries, or use the
  446. static linking (see the section OPENSSL).
  447. XII. MS Windows and Cygwin support
  448. Currently, this project cannot be compiled under MS Windows.
  449. As the project is using fairly straightforward *NIX API, it is supported
  450. under Cygwin environment in MS Windows.
  451. One note for Cygwin users: we recommended libevent2 installation from the cygwin
  452. "ports" site: http://sourceware.org/cygwinports/ . You will have to install
  453. libevent2 runtime and libevent-devel packages. "Manual" libevent2 compilation
  454. and installation in Cygwin is not recommended and does not garantee a good
  455. outcome.
  456. XIII. CLIENT API LIBRARY.
  457. The compilation process will create lib/ sub-directory with libturnclient.a
  458. library. The header files for this library are located in include/turn/client/
  459. sub-directory. The C++ wrapper for the messaging functionality is located in
  460. TurnMsgLib.h header. An example of C++ code can be found in stunclient.c file.
  461. This file is compiled as a C++ program if C++ compiler is used, and as a C
  462. program if C compiler is used.
  463. XIV. DOCS
  464. After installation, the man page turnserver(1) must be available. The man page
  465. is located in man/man1 subdirectory. If you want to see the man page without
  466. installation, run the command:
  467. $ man -M man turnserver
  468. HTML-formatted client library functions reference is located in docs/html
  469. subdirectory of the original archive tree. After the installation, it will
  470. be placed in PREFIX/share/doc/turnserver/html.
  471. XV. SQLite setup
  472. The site http://www.sqlite.org site has excellent extensive documentation.
  473. The default SQLite database location for the TURN Server is
  474. /usr/local/var/db/turndb or /var/db/turndb (depending on the platform).
  475. The database schema for the TURN server is very minimalistic and is located
  476. in project's turndb/schema.sql file, or in the system's
  477. PREFIX/share/turnserver/schema.sql file after the turnserver installation:
  478. If you would like to created a new fresh SQLite TURN database:
  479. $ sqlite3 <your-db-file-name> < turndb/schema.sql
  480. The schema description:
  481. # Table for long-term credentials mechanism authorization:
  482. #
  483. CREATE TABLE turnusers_lt (
  484. realm varchar(127) default '',
  485. name varchar(512),
  486. hmackey char(128),
  487. PRIMARY KEY (realm,name)
  488. );
  489. The field hmackey contains HEX string representation of the key.
  490. We do not store the user open passwords for long-term credentials, for
  491. security reasons. Storing only the HMAC key has its own implications -
  492. if you change the realm, you will have to update the HMAC keys of all
  493. users, because the realm is used for the HMAC key generation.
  494. The key must be up to 32 characters (HEX representation of 16 bytes) for SHA1:
  495. # Table holding shared secrets for secret-based authorization
  496. # (REST API). Shared secret can be stored either in unsecure open
  497. # plain form, or in encrypted form (see turnadmin docs).
  498. # It can only be used together with the long-term
  499. # mechanism:
  500. #
  501. CREATE TABLE turn_secret (
  502. realm varchar(127) default '',
  503. value varchar(127),
  504. primary key (realm,value)
  505. );
  506. # Table holding "white" allowed peer IP ranges.
  507. #
  508. CREATE TABLE allowed_peer_ip (
  509. realm varchar(127) default '',
  510. ip_range varchar(256),
  511. primary key (realm,ip_range)
  512. );
  513. # Table holding "black" denied peer IP ranges.
  514. #
  515. CREATE TABLE denied_peer_ip (
  516. realm varchar(127) default '',
  517. ip_range varchar(256),
  518. primary key (realm,ip_range)
  519. );
  520. # Table to match origin to realm.
  521. # Multiple origins may have the same realm.
  522. # If no realm is found or the origin is absent
  523. # then the default realm is used.
  524. #
  525. CREATE TABLE turn_origin_to_realm (
  526. origin varchar(127),
  527. realm varchar(127),
  528. primary key (origin,realm)
  529. );
  530. # Realm options.
  531. # Valid options are 'max-bps',
  532. # 'total-quota' and 'user-quota'.
  533. # Values for them are integers (in text form).
  534. #
  535. CREATE TABLE turn_realm_option (
  536. realm varchar(127) default '',
  537. opt varchar(32),
  538. value varchar(128),
  539. primary key (realm,opt)
  540. );
  541. # oAuth key storage table.
  542. #
  543. CREATE TABLE oauth_key (
  544. kid varchar(128),
  545. ikm_key varchar(256),
  546. timestamp bigint default 0,
  547. lifetime integer default 0,
  548. as_rs_alg varchar(64) default '',
  549. realm varchar(127) default '',
  550. primary key (kid)
  551. );
  552. The oauth_key table fields meanings are:
  553. kid: the kid of the key;
  554. ikm_key - base64-encoded key ("input keying material");
  555. timestamp - (optional) the timestamp (in seconds) when the key
  556. lifetime starts;
  557. lifetime - (optional) the key lifetime in seconds; the default value
  558. is 0 - unlimited lifetime.
  559. as_rs_alg - oAuth token encryption algorithm; the valid values are
  560. "A256GCM", "A128GCM" (see
  561. http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40#section-5.1).
  562. The default value is "A256GCM";
  563. realm - (optional) can be used to set the user realm (if the field is not empty).
  564. # Https access admin users.
  565. # Leave this table empty if you do not want
  566. # remote https access to the admin functions.
  567. # Web user password can be stored either in unsecure open
  568. # plain form, or in encrypted form (see turnadmin docs).
  569. #
  570. CREATE TABLE admin_user (
  571. name varchar(32),
  572. realm varchar(127),
  573. password varchar(127),
  574. primary key (name)
  575. );
  576. You can use turnadmin program to manage the database - you can either use
  577. turnadmin to add/modify/delete users, or you can use turnadmin to produce
  578. the hmac keys and modify the database with your favorite tools.
  579. When starting the turnserver, the --db parameter will be, for example:
  580. turnserver ... --db="/var/db/turndb"
  581. You will have to use the program turnadmin to fill the
  582. database, or you can do that manually with psql.
  583. Fill in users, for example:
  584. Shared secret for the TURN REST API (realm north.gov):
  585. $ bin/turnadmin -s logen -r north.gov -b "/var/db/turndb"
  586. Long-term credentials mechanism:
  587. $ bin/turnadmin -a -b "/var/db/turndb" -u gorst -r north.gov -p hero
  588. $ bin/turnadmin -a -b "/var/db/turndb" -u ninefingers -r north.gov -p youhavetoberealistic
  589. Admin users:
  590. $ bin/turnadmin -A -b "/var/db/turndb" -u gorst -p hero
  591. $ bin/turnadmin -A -b "/var/db/turndb" -u ninefingers -p youhavetoberealistic -r north.gov
  592. XVI. PostgreSQL setup
  593. The site http://www.postgresql.org site has excellent extensive documentation.
  594. For a quick-start guide, you can take a look into this page:
  595. http://www.freebsddiary.org/postgresql.php. That page is written for
  596. FreeBSD users, but it has lots of generic information applicable to other
  597. *NIXes, too.
  598. For the psql-userdb TURN server parameter, you can either set a PostgreSQL
  599. connection string, or a PostgreSQL URI, see the link:
  600. For 8.4 PostgreSQL version:
  601. http://www.postgresql.org/docs/8.4/static/libpq-connect.html
  602. For newer 9.x versions:
  603. http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-CONNSTRING.
  604. In the PostgreSQL connection string or URI, you can set the host, the
  605. access port, the database name, the user, and the user password
  606. (if the access is secured). Numerous other parameters can be set,
  607. see the links above. The TURN server will blindly use that connection
  608. string without any modifications. You are responsible for the right
  609. connection string format.
  610. Below are the steps to setup the PostgreSQL database server from scratch:
  611. 1) Install PostgreSQL server. After the installation, do not forget to
  612. initialize the postgres root database directory:
  613. $ sudo bash
  614. $ su -l pgsql
  615. $ initdb -D /usr/local/pgsql/data
  616. 2) Find and edit Postgres' pg_hba.conf file to set the access options
  617. (see docs). On different systems, it may be located in different places.
  618. Set the lines for local access as "trust" for now (you can change it later),
  619. for TCP/IP access set the value as "md5".
  620. To set TCP/IP access from any host, use "0.0.0.0/0" for IPv4, and "::/0"
  621. for IPv6.
  622. 3) Edit postgresql.conf file to allow TCP/IP access - uncomment and edit
  623. the "listen_addresses" option (see docs). On different systems, this file
  624. may be located in different places.
  625. 4) Restart your system or restart the postgresql server, for example:
  626. $ sudo /etc/init.d/postgresql stop
  627. $ sudo /etc/init.d/postgresql start
  628. The scripts may also be in /usr/local/etc/init.d, or in /etc/rc.d/, or
  629. in /usr/local/etc/rc.d/ .
  630. 5) Check /etc/passwd file to find out which user account is used for the
  631. PostgreSQL admin access on your system (it may be "pgsql", or "postgres",
  632. or "postgresql"). Let's assume that this is "postgres" account.
  633. 6) Create a database for the TURN purposes, with name, say, "turn":
  634. $ createdb -U postgres coturn
  635. 7) Create a user for the TURN with name, say, "turn":
  636. $ psql -U postgres coturn
  637. turn=# create user turn with password 'turn';
  638. turn=#
  639. Ctrl-D
  640. 8) Create the TURN users database schema.
  641. The database schema for the TURN server is very minimalistic and is located
  642. in project's turndb/schema.sql file, or in the system's
  643. PREFIX/share/turnserver/schema.sql file after the turnserver installation:
  644. $ cat turndb/schema.sql | psql -U turn -d coturn
  645. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "turnusers_lt_pkey" for table "turnusers_lt"
  646. CREATE TABLE
  647. CREATE TABLE
  648. See the SQLite section for the detailed database schema explanation.
  649. To fill the database with test data:
  650. cat turndb/testsqldbsetup.sql | psql -U turn -d coturn
  651. You can use turnadmin program to manage the database - you can either use
  652. turnadmin to add/modify/delete users, or you can use turnadmin to produce
  653. the hmac keys and modify the database with your favorite tools.
  654. More examples of database schema creation:
  655. psql -h <host> -U <db-user> -d <database-name> < turndb/schema.sql
  656. (old style for 8.4)
  657. psql postgresql://username:password@/databasename < turndb/schema.sql
  658. (newer style for 9.x, UNIX domain local sockets)
  659. Or:
  660. psql postgresql://username:password@hostname:port/databasename < turndb/schema.sql
  661. (newer style for 9.x, TCP/IP access)
  662. Below, the string "postgresql://turn:turn@/turn" is the connection URI.
  663. Of course, the administrators can play with the connection string as they want.
  664. When starting the turnserver, the psql-userdb parameter will be, for example:
  665. turnserver ... --psql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30"
  666. Or, for 9.x PostgreSQL versions:
  667. turnserver ... --psql-userdb=postgresql://username:password@/databasename ...
  668. 9) You are ready to use the TURN database. The database name is "turn",
  669. the user name is "turn", the user password is "turn". Of course, you can
  670. choose your own names. Now, you will have to use the program turnadmin to fill the
  671. database, or you can do that manually with psql.
  672. Fill in users, for example:
  673. Shared secret for the TURN REST API (realm north.gov):
  674. $ bin/turnadmin -s logen -r north.gov -e "host=localhost dbname=coturn user=turn password=turn"
  675. Long-term credentials mechanism:
  676. $ bin/turnadmin -a -e "host=localhost dbname=coturn user=turn password=turn" -u gorst -r north.gov -p hero
  677. $ bin/turnadmin -a -e "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic
  678. Admin users:
  679. $ bin/turnadmin -A -e "host=localhost dbname=coturn user=turn password=turn" -u gorst -p hero
  680. $ bin/turnadmin -A -e "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -p youhavetoberealistic -r north.gov
  681. XVII. MySQL (MariaDB) setup
  682. The MySQL setup is similar to PostgreSQL (the same idea), and is well documented
  683. on their site http://www.mysql.org. The TURN Server database schema is the
  684. same as for PostgreSQL and you can find it in turndb/schema.sql file, or
  685. in the system's PREFIX/share/turnserver/schema.sql file after the turnserver
  686. installation.
  687. The general setup is similar to PostgreSQL setup procedure:
  688. 1) Check that the mysql server access is OK. Immediately after the MySQL server
  689. installation, it must be accessible, at the very minimum, at the localhost with
  690. the root account.
  691. 2) Login into mysql console from root account:
  692. $ sudo bash
  693. # mysql mysql
  694. (or mysql -p mysql if mysql account password set)
  695. 3) Add 'turn' user with 'turn' password (for example):
  696. > create user 'turn'@'localhost' identified by 'turn';
  697. 4) Create database 'coturn' (for example) and grant privileges to user 'turn':
  698. > create database coturn;
  699. > grant all on coturn.* to 'turn'@'localhost';
  700. > flush privileges;
  701. Ctrl-D
  702. 5) Create database schema:
  703. $ mysql -p -u turn coturn < turndb/schema.sql
  704. Enter password: turn
  705. $
  706. Fill in test database data, if this is a test database
  707. (not a production database):
  708. $ mysql -p -u turn coturn < turndb/testsqldbsetup.sql
  709. 6) Fill in users, for example:
  710. Shared secret for the TURN REST API (realm north.gov):
  711. $ bin/turnadmin -s logen -r north.gov -M "host=localhost dbname=coturn user=turn password=turn"
  712. Long-term credentials mechanism:
  713. $ bin/turnadmin -a -M "host=localhost dbname=coturn user=turn password=turn" -u gorst -r north.gov -p hero
  714. $ bin/turnadmin -a -M "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic
  715. Admin users:
  716. $ bin/turnadmin -A -M "host=localhost dbname=coturn user=turn password=turn" -u gorst -p hero
  717. $ bin/turnadmin -A -M "host=localhost dbname=coturn user=turn password=turn" -u ninefingers -p youhavetoberealistic -r north.gov
  718. 7) Now we can use mysql in the turnserver.
  719. If the TURN server was compiled with MySQL support, then we can use the
  720. TURN server database parameter --mysql-userdb. The value of this parameter
  721. is a connection string for the MySQL database. As "native" MySQL does not
  722. have such a feature as "connection string", the TURN server parses the
  723. connection string and converts it into MySQL database connection parameter.
  724. The format of the MySQL connection string is:
  725. "host=<host> dbname=<database-name> user=<database-user> password=<database-user-password> port=<port> connect_timeout=<seconds> read_timeout=<seconds>"
  726. (all parameters are optional)
  727. So, an example of the MySQL database parameter in the TURN server command
  728. line would be:
  729. --mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30"
  730. Or in the turnserver.conf file:
  731. mysql-userdb="host=localhost dbname=coturn user=turn password=turn connect_timeout=30 read_timeout=30"
  732. If you have to use a secure MySQL connection (SSL) then you have to use also
  733. the optional connection string parameters for the secure communications:
  734. ca, capath, cert, key, cipher (see
  735. http://dev.mysql.com/doc/refman/5.1/en/ssl-options.html for the
  736. command options description).
  737. XVIII. MongoDB setup
  738. The MongoDB setup is well documented on their site http://docs.mongodb.org/manual/.
  739. Note: if your system has a "standard" plain vanilla UNIX "make" utility
  740. (that is not a GNU make) then you will have to use the GNU make to compile
  741. the Mongo driver, because the Mongo compilation process was written with
  742. the "proprietary" GNU extensions. For example, in FreeBSD in will have to use
  743. "gmake" command.
  744. If the TURN server was compiled with MongoDB support (mongo-c-driver is the C client
  745. library for MongoDB), then we can use the TURN server database parameter
  746. --mongo-userdb. The value of this parameter is a connection string
  747. for the MongoDB database. The format of the connection string is described at
  748. http://hergert.me/docs/mongo-c-driver/mongoc_uri.html:
  749. "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
  750. So, an example of the MongoDB database parameter in the TURN server command
  751. line would be:
  752. --mongo-userdb="mongodb://localhost:27017/coturn"
  753. Or in the turnserver.conf file:
  754. mongo-userdb="mongodb://localhost:27017/coturn"
  755. The meanings of the MongoDB keys are the same as for the other databases, see the
  756. explanations for the Postgres, for example.
  757. See the file testmongosetup.sh for the database structure examples.
  758. XIX. Redis setup
  759. The Redis setup is well documented on their site http://redis.io.
  760. The TURN Server Redis database schema description can be found
  761. in schema.userdb.redis and schema.stats.redis files. Those files are located
  762. either in the turndb subdirectory of the main source code directory,
  763. or in /usr/local/share/turnserver/ after the installation, or somewhere in /usr/share/
  764. directory, depending on the OS and on the instalation package.
  765. If the TURN server was compiled with Hiredis support (Hiredis is the C client
  766. library for Redis), then we can use the TURN server database parameter
  767. --redis-userdb. The value of this parameter is a connection string
  768. for the Redis database. As "native" Redis does not have such a feature as
  769. "connection string", the TURN server parses the connection string and
  770. converts it into Redis database access parameter. The format of the Redis
  771. connection string is:
  772. "ip=<ip-addr> dbname=<database-number> password=<database-password> port=<port> connect_timeout=<seconds>"
  773. (all parameters are optional)
  774. So, an example of the Redis database parameter in the TURN server command
  775. line would be:
  776. --redis-userdb="ip=127.0.0.1 dbname=2 password=turn connect_timeout=30"
  777. Or in the turnserver.conf file:
  778. redis-userdb="ip=127.0.0.1 dbname=2 password=turn connect_timeout=30"
  779. Redis can be also used for the TURN allocation status check and for status and
  780. traffic notifications.
  781. See the explanation in the turndb/schema.stats.redis file, and an example in
  782. turndb/testredisdbsetup.sh file. One special thing about TURN Redis security
  783. setup is that you can store open passwords for long-term credentials in Redis.
  784. You cannot set open passwords for long-term credentials in SQLite or MySQL or
  785. PostgreSQL - with those DBs, you have to use the keys only. With Redis, you
  786. have a choice - keys or open passwords.
  787. You also have to take care about Redis connection parameters, the timeout and the
  788. keepalive. The following settings must be in your Redis config file
  789. (/etc/redis.conf or /usr/local/etc/redis.conf):
  790. ..........
  791. timeout 0
  792. ..........
  793. tcp-keepalive 60
  794. ..........
  795. Redis TURN admin commands:
  796. Shared secret for the TURN REST API (realm north.gov):
  797. $ bin/turnadmin -s logen -r north.gov -N "host=localhost dbname=2 user=turn password=turn"
  798. Long-term credentials mechanism:
  799. $ bin/turnadmin -a -N "host=localhost dbname=2 user=turn password=turn" -u gorst -r north.gov -p hero
  800. $ bin/turnadmin -a -N "host=localhost dbname=2 user=turn password=turn" -u ninefingers -r north.gov -p youhavetoberealistic
  801. Admin users:
  802. $ bin/turnadmin -A -N "host=localhost dbname=2 user=turn password=turn" -u gorst -p hero
  803. $ bin/turnadmin -A -N "host=localhost dbname=2 user=turn password=turn" -u ninefingers -p youhavetoberealistic -r north.gov
  804. See the file testredisdbsetup.sh for the data structure examples.
  805. XX. Performance tuning
  806. This topic is covered in the wiki page:
  807. https://github.com/coturn/coturn/wiki/TURN-Performance-and-Load-Balance
  808. XXI. TURN Server setup
  809. Read the project wiki pages: https://github.com/coturn/coturn/wiki
  810. Also, check the project from page links to the TURN/WebRTC configuration examples.
  811. It may give you an idea how it can be done.
  812. XXII. HTTPS Management Interface
  813. The turnserver process provides an HTTPS Web access as statistics and basic management
  814. interface. The turnserver listens to incoming HTTPS admin connections on the same ports
  815. as the main TURN/STUN listener. The Web admin pages are basic and self-explanatory.
  816. To make the HTTPS interface active, the database table admin_user must be
  817. populated with the admin user account(s). An admin user can be a superuser
  818. (if not assigned to a particular realm) or a restricted user (if assigned to
  819. a realm). The restricted admin users can perform only limited actions, within
  820. their corresponding realms.
  821. XXIII. Telnet CLI management interface
  822. You have a telnet interface (enabled by default) to access the turnserver process,
  823. to view its state, to gather some statistical information, and to make some changes
  824. on-the-fly.
  825. You can access that CLI interface with telnet or putty program (in telnet mode).
  826. The process by default listens to port 5766 on IP address 127.0.0.1 for the telnet
  827. connections.
  828. WARNING: all telnet communications are going unencrypted over the network. For
  829. security reasons, we advise using the loopback IP addresses for CLI (127.0.0.1
  830. or ::1). The CLI may have a password configured, but that password is
  831. transferred over the network unencrypted, too. So sticking to the local system
  832. CLI access, and accessing the turnserver system terminal with ssh only, would
  833. be a wise decision.
  834. XXIV. ALPN support.
  835. Starting with version 4.3.2.1, the TURN server supports the ALPN STUN
  836. specifications (http://tools.ietf.org/html/draft-ietf-tram-alpn-08).
  837. If the ALPN functionality is needed, then OpenSSL version 1.0.2 or
  838. newer has to be used. See OPENSSL section for the OpenSSL upgrade hints.
  839. XXV. SCTP support
  840. Starting with version 4.4.3.1, the TURN server supports 'native' SCTP.
  841. On the client side, the TURN server, additionally, supports SCTP and
  842. TLS-over-SCTP.
  843. The relay side is not changing - the relay communications will still be UDP
  844. or TCP.