README.turnserver 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. GENERAL INFORMATION
  2. The TURN Server project contains the source code of a TURN server and TURN client
  3. messaging library. Also, some extra programs provided, for testing-only
  4. purposes.
  5. See the INSTALL file for the building instructions.
  6. After the build, you will have the following binary images:
  7. 1. turnserver: TURN Server relay.
  8. The compiled binary image of the TURN Server program is located in bin/ sub-directory.
  9. 2. turnadmin: TURN administration tool. See README.turnadmin and turnadmin man page.
  10. 3. turnutils_uclient. See README.turnutils and turnutils man page.
  11. 4. turnutils_peer. See README.turnutils and turnutils man page.
  12. 5. turnutils_stunclient. See README.turnutils and turnutils man page.
  13. 6. turnutils_rfc5769check. See README.turnutils and turnutils man page.
  14. In the "examples/scripts" sub-directory, you will find the examples of command lines to be used
  15. to run the programs. The scripts are meant to be run from examples/ sub-directory, for example:
  16. $ cd examples
  17. $ ./scripts/secure_relay.sh
  18. RUNNING THE TURN SERVER
  19. Options note: turnserver has long and short option names, for most options.
  20. Some options have only long form, some options have only short form. Their syntax
  21. somewhat different, if an argument is required:
  22. The short form must be used as this (for example):
  23. $ turnserver -L 12.34.56.78
  24. The long form equivalent must use the "=" character:
  25. $ turnserver --listening-ip=12.34.56.78
  26. If this is a flag option (no argument required) then their usage are the same, for example:
  27. $ turnserver -a
  28. is equivalent to:
  29. $ turnserver --lt-cred-mech
  30. =====================================
  31. NAME
  32. turnserver - a TURN relay server implementation.
  33. SYNOPSIS
  34. $ turnserver [-n | -c <config-file> ] [flags] [ --userdb=<userdb-file> | --psql-userdb=<db-conn-string> | --mysql-userdb=<db-conn-string> | --mongo-userdb=<db-conn-string> | --redis-userdb=<db-conn-string> ] [-z | --no-auth | -a | --lt-cred-mech ] [options]
  35. $ turnserver -h
  36. DESCRIPTION
  37. Config file settings:
  38. -n Do not use configuration file, use only command line parameters.
  39. -c Configuration file name (default - turnserver.conf).
  40. The format of config file can be seen in
  41. the supplied examples/etc/turnserver.conf example file. Long
  42. names of the options are used as the configuration
  43. items names in the file. If not an absolute path is supplied,
  44. then the file is searched in the following directories:
  45. * current directory
  46. * current directory etc/ sub-directory
  47. * upper directory level etc/
  48. * /etc/
  49. * /usr/local/etc/
  50. * installation directory /etc
  51. User database settings:
  52. -b, --db, --userdb SQLite user database file name (default - /var/db/turndb or
  53. /usr/local/var/db/turndb or /var/lib/turn/turndb).
  54. -e, --psql-userdb User database connection string for PostgreSQL.
  55. This database can be used for long-term credentials mechanism,
  56. and it can store the secret value
  57. for secret-based timed authentication in TURN RESP API.
  58. The connection string format is like that:
  59. "host=<host> dbname=<dbname> user=<db-user> password=<db-user-password> connect_timeout=<seconds>"
  60. (for 8.x or newer Postgres).
  61. Or:
  62. "postgresql://username:password@hostname:port/databasename"
  63. (for 9.x or newer Postgres).
  64. See the INSTALL file for more explanations and examples.
  65. Also, see http://www.PostgreSQL.org for full PostgreSQL documentation.
  66. -M, --mysql-userdb User database connection string for MySQL or MariaDB.
  67. This database can be used for long-term credentials mechanism,
  68. and it can store the secret value for
  69. secret-based timed authentication in TURN RESP API.
  70. The connection string format is like that:
  71. "host=<host> dbname=<dbname> user=<db-user> password=<db-user-password> connect_timeout=<seconds> read_timeout=<seconds>"
  72. See the INSTALL file for more explanations and examples.
  73. Also, see http://www.mysql.org or http://mariadb.org
  74. for full MySQL documentation.
  75. Optional connection string parameters for the secure communications (SSL):
  76. ca, capath, cert, key, cipher
  77. (see http://dev.mysql.com/doc/refman/5.1/en/ssl-options.html for the
  78. command options description).
  79. --secret-key-file This is the file path which contain secret key of aes encryption while using MySQL password encryption.
  80. If you want to use in the MySQL connection string the password in encrypted format,
  81. then set in this option the file path of the secret key. The key which is used to encrypt MySQL password.
  82. Warning: If this option is set, then MySQL password must be set in "mysql-userdb" option in encrypted format!
  83. If you want to use cleartext password then do not set this option!
  84. -J, --mongo-userdb User database connection string for MongoDB.
  85. This database can be used for long-term credentials mechanism,
  86. and it can store the secret value
  87. for secret-based timed authentication in TURN RESP API.
  88. The connection string format is like that:
  89. "mongodb://username:password@host:port/database?options"
  90. See the INSTALL file for more explanations and examples.
  91. Also, see http://docs.mongodb.org/manual/
  92. for full MongoDB documentation.
  93. -N, --redis-userdb User database connection string for Redis.
  94. This database can be used for long-term credentials mechanism,
  95. and it can store the secret
  96. value for secret-based timed authentication in TURN RESP API.
  97. The connection string format is like that:
  98. "ip=<ip-addr> dbname=<db-number> password=<db-password> connect_timeout=<seconds>"
  99. See the INSTALL file for more explanations and examples.
  100. Also, see http://redis.io for full Redis documentation.
  101. Flags:
  102. -v, --verbose Moderate verbose mode.
  103. -V, --Verbose Extra verbose mode, very annoying and not recommended.
  104. -o, --daemon Run server as daemon.
  105. --prod Production mode: hide the software version.
  106. -f, --fingerprint Use fingerprints in the TURN messages. If an incoming request
  107. contains a fingerprint, then TURN server will always add
  108. fingerprints to the messages in this session, regardless of the
  109. per-server setting.
  110. -a, --lt-cred-mech Use long-term credentials mechanism (this one you need for WebRTC usage).
  111. -z, --no-auth Do not use any credentials mechanism, allow anonymous access.
  112. Opposite to -a and -A options. This is default option when no
  113. authentication-related options are set.
  114. By default, no credential mechanism is used -
  115. any user is allowed.
  116. --use-auth-secret TURN REST API flag.
  117. Flag that sets a special WebRTC authorization option
  118. that is based upon authentication secret. The feature purpose
  119. is to support "TURN Server REST API" as described in
  120. the TURN REST API section below.
  121. This option uses timestamp as part of combined username:
  122. usercombo -> "timestamp:username",
  123. turn user -> usercombo,
  124. turn password -> base64(hmac(input_buffer = usercombo, key = shared-secret)).
  125. This allows TURN credentials to be accounted for a specific user id.
  126. If you don't have a suitable id, the timestamp alone can be used.
  127. This option is just turns on secret-based authentication.
  128. The actual value of the secret is defined either by option static-auth-secret,
  129. or can be found in the turn_secret table in the database.
  130. --oauth Support oAuth authentication, as in the third-party STUN/TURN RFC 7635.
  131. --dh566 Use 566 bits predefined DH TLS key. Default size of the key is 1066.
  132. --dh2066 Use 2066 bits predefined DH TLS key. Default size of the key is 1066.
  133. --no-tlsv1 Do not allow TLSv1/DTLSv1 protocol.
  134. --no-tlsv1_1 Do not allow TLSv1.1 protocol.
  135. --no-tlsv1_2 Do not allow TLSv1.2/DTLSv1.2 protocol.
  136. --no-udp Do not start UDP client listeners.
  137. --no-tcp Do not start TCP client listeners.
  138. --no-tls Do not start TLS client listeners.
  139. --no-dtls Do not start DTLS client listeners.
  140. --no-udp-relay Do not allow UDP relay endpoints defined in RFC 5766,
  141. use only TCP relay endpoints as defined in RFC 6062.
  142. --no-tcp-relay Do not allow TCP relay endpoints defined in RFC 6062,
  143. use only UDP relay endpoints as defined in RFC 5766.
  144. --no-stdout-log Flag to prevent stdout log messages.
  145. By default, all log messages are going to both stdout and to
  146. the configured log file. With this option everything will be going to
  147. the log file only (unless the log file itself is stdout).
  148. --syslog With this flag, all log will be redirected to the system log (syslog).
  149. --simple-log This flag means that no log file rollover will be used, and the log file
  150. name will be constructed as-is, without PID and date appendage.
  151. This option can be used, for example, together with the logrotate tool.
  152. --secure-stun Require authentication of the STUN Binding request.
  153. By default, the clients are allowed anonymous access to the STUN Binding functionality.
  154. -S, --stun-only Run as STUN server only, all TURN requests will be ignored.
  155. Option to suppress TURN functionality, only STUN requests will be processed.
  156. --no-stun Run as TURN server only, all STUN requests will be ignored.
  157. Option to suppress STUN functionality, only TURN requests will be processed.
  158. --allow-loopback-peers Allow peers on the loopback addresses (127.x.x.x and ::1).
  159. --no-multicast-peers Disallow peers on well-known broadcast addresses
  160. (224.0.0.0 and above, and FFXX:*).
  161. --mobility Mobility with ICE (MICE) specs support.
  162. --no-cli Turn OFF the CLI support. By default it is always ON.
  163. See also options --cli-ip and --cli-port.
  164. --server-relay Server relay. NON-STANDARD AND DANGEROUS OPTION.
  165. Only for those applications when we want to run
  166. server applications on the relay endpoints.
  167. This option eliminates the IP permissions check
  168. on the packets incoming to the relay endpoints.
  169. See http://tools.ietf.org/search/rfc5766#section-17.2.3 .
  170. --udp-self-balance (recommended for older Linuxes only)
  171. Automatically balance UDP traffic over auxiliary servers
  172. (if configured). The load balancing is using the
  173. ALTERNATE-SERVER mechanism. The TURN client must support
  174. 300 ALTERNATE-SERVER response for this functionality.
  175. --check-origin-consistency The flag that sets the origin consistency
  176. check: across the session, all requests must have the same
  177. main ORIGIN attribute value (if the ORIGIN was
  178. initially used by the session).
  179. -h Help.
  180. Options with values:
  181. --stale-nonce[=<value>] Use extra security with nonce value having
  182. limited lifetime, in seconds (default 600 secs).
  183. --max-allocate-lifetime Set the maximum value for the allocation lifetime.
  184. Default to 3600 secs.
  185. --channel-lifetime Set the lifetime for channel binding, default to 600 secs.
  186. This value MUST not be changed for production purposes.
  187. --permission-lifetime Set the value for the lifetime of the permission.
  188. Default to 300 secs.
  189. This MUST not be changed for production purposes.
  190. -d, --listening-device Listener interface device.
  191. (NOT RECOMMENDED. Optional functionality, Linux only).
  192. The turnserver process must have root privileges to bind the
  193. listening endpoint to a device. If turnserver must run as a
  194. process without root privileges, then just do not use this setting.
  195. -L, --listening-ip Listener IP address of relay server.
  196. Multiple listeners can be specified, for example:
  197. -L ip1 -L ip2 -L ip3
  198. If no IP(s) specified, then all IPv4 and
  199. IPv6 system IPs will be used for listening.
  200. The same ip(s) can be used as both listening and relay ip(s).
  201. -p, --listening-port TURN listener port for UDP and TCP listeners (Default: 3478).
  202. Note: actually, TLS & DTLS sessions can connect to the "plain" TCP & UDP
  203. port(s), too - if allowed by configuration.
  204. --tls-listening-port TURN listener port for TLS and DTLS listeners (Default: 5349).
  205. Note: actually, "plain" TCP & UDP sessions can connect to the TLS & DTLS
  206. port(s), too - if allowed by configuration. The TURN server
  207. "automatically" recognizes the type of traffic. Actually, two listening
  208. endpoints (the "plain" one and the "tls" one) are equivalent in terms of
  209. functionality; but we keep both endpoints to satisfy the RFC 5766 specs.
  210. For secure TCP connections, we currently support SSL version 3 and
  211. TLS versions 1.0, 1.1, 1.2.
  212. For secure UDP connections, we support DTLS version 1.
  213. --alt-listening-port Alternative listening port for UDP and TCP listeners;
  214. default (or zero) value means "listening port plus one".
  215. This is needed for STUN CHANGE_REQUEST - in RFC 5780 sense
  216. or in old RFC 3489 sense - for NAT behavior discovery). The TURN Server
  217. supports CHANGE_REQUEST only if it is started with more than one
  218. listening IP address of the same family (IPv4 or IPv6). The CHANGE_REQUEST
  219. is only supported by UDP protocol, other protocols are listening
  220. on that endpoint only for "symmetry".
  221. --alt-tls-listening-port Alternative listening port for TLS and DTLS protocols.
  222. Default (or zero) value means "TLS listening port plus one".
  223. --aux-server Auxiliary STUN/TURN server listening endpoint.
  224. Aux servers have almost full TURN and STUN functionality.
  225. The (minor) limitations are:
  226. 1) Auxiliary servers do not have alternative ports and
  227. they do not support STUN RFC 5780 functionality (CHANGE REQUEST).
  228. 2) Auxiliary servers also are never returning ALTERNATIVE-SERVER reply.
  229. Valid formats are 1.2.3.4:5555 for IPv4 and [1:2::3:4]:5555 for IPv6.
  230. There may be multiple aux-server options, each will be used for listening
  231. to client requests.
  232. -i, --relay-device Relay interface device for relay sockets
  233. (NOT RECOMMENDED. Optional, Linux only).
  234. -E, --relay-ip Relay address (the local IP address that
  235. will be used to relay the packets to the
  236. peer). Multiple relay addresses may be used:
  237. -E ip1 -E ip2 -E ip3
  238. The same IP(s) can be used as both listening IP(s) and relay IP(s).
  239. If no relay IP(s) specified, then the turnserver will apply the
  240. default policy: it will decide itself which relay addresses to be
  241. used, and it will always be using the client socket IP address as
  242. the relay IP address of the TURN session (if the requested relay
  243. address family is the same as the family of the client socket).
  244. -X, --external-ip TURN Server public/private address mapping, if the server is behind NAT.
  245. In that situation, if a -X is used in form "-X <ip>" then that ip will be reported
  246. as relay IP address of all allocations. This scenario works only in a simple case
  247. when one single relay address is be used, and no CHANGE_REQUEST functionality is
  248. required. That single relay address must be mapped by NAT to the 'external' IP.
  249. The "external-ip" value, if not empty, is returned in XOR-RELAYED-ADDRESS field.
  250. For that 'external' IP, NAT must forward ports directly (relayed port 12345
  251. must be always mapped to the same 'external' port 12345).
  252. In more complex case when more than one IP address is involved,
  253. that option must be used several times, each entry must
  254. have form "-X <public-ip/private-ip>", to map all involved addresses.
  255. CHANGE_REQUEST (RFC5780 or RFC3489) NAT discovery STUN functionality will work
  256. correctly, if the addresses are mapped properly, even when the TURN server itself
  257. is behind A NAT.
  258. By default, this value is empty, and no address mapping is used.
  259. -m, --relay-threads Number of the relay threads to handle the established connections
  260. (in addition to authentication thread and the listener thread).
  261. If explicitly set to 0 then application runs relay process in a single thread,
  262. in the same thread with the listener process (the authentication thread will
  263. still be a separate thread). If not set, then a default optimal algorithm
  264. will be employed (OS-dependent). In the older Linux systems
  265. (before Linux kernel 3.9), the number of UDP threads is always one threads
  266. per network listening endpoint - unless "-m 0" or "-m 1" is set.
  267. --min-port Lower bound of the UDP port range for relay
  268. endpoints allocation.
  269. Default value is 49152, according to RFC 5766.
  270. --max-port Upper bound of the UDP port range for relay
  271. endpoints allocation.
  272. Default value is 65535, according to RFC 5766.
  273. -u, --user Long-term security mechanism credentials user account,
  274. in the column-separated form username:key.
  275. Multiple user accounts may be used in the command line.
  276. The key is either the user password, or
  277. the key is generated
  278. by turnadmin command. In the second case,
  279. the key must be prepended with 0x symbols.
  280. The key is calculated over the user name,
  281. the user realm, and the user password.
  282. This setting may not be used with TURN REST API.
  283. -r, --realm The default realm to be used for the users when no explicit
  284. origin/realm relationship was found in the database, or if the TURN
  285. server is not using any database (just the commands-line settings
  286. and the userdb file). Must be used with long-term credentials
  287. mechanism or with TURN REST API.
  288. -C, --rest-api-separator This is the timestamp/username separator symbol
  289. (character) in TURN REST API. The default value is :.
  290. -q, --user-quota Per-user allocations quota: how many concurrent
  291. allocations a user can create. This option can also be set
  292. through the database, for a particular realm.
  293. -Q, --total-quota Total allocations quota: global limit on concurrent allocations.
  294. This option can also be set through the database, for a particular realm.
  295. -s, --max-bps Max bytes-per-second bandwidth a TURN session is allowed to handle
  296. (input and output network streams are treated separately). Anything above
  297. that limit will be dropped or temporary suppressed (within the
  298. available buffer limits). This option can also be set through the
  299. database, for a particular realm.
  300. -B, --bps-capacity Maximum server capacity.
  301. Total bytes-per-second bandwidth the TURN server is allowed to allocate
  302. for the sessions, combined (input and output network streams are treated
  303. separately).
  304. --static-auth-secret Static authentication secret value (a string) for TURN REST API only.
  305. If not set, then the turn server will try to use the dynamic value
  306. in turn_secret table in user database (if present). The database-stored
  307. value can be changed on-the-fly by a separate program, so this is why
  308. that other mode is dynamic. Multiple shared secrets can be used
  309. (both in the database and in the "static" fashion).
  310. --server-name Server name used for
  311. the oAuth authentication purposes.
  312. The default value is the realm name.
  313. --cert Certificate file, PEM format. Same file
  314. search rules applied as for the configuration
  315. file. If both --no-tls and --no-dtls options
  316. are specified, then this parameter is not needed.
  317. Default value is turn_server_cert.pem.
  318. --pkey Private key file, PEM format. Same file
  319. search rules applied as for the configuration
  320. file. If both --no-tls and --no-dtls options
  321. are specified, then this parameter is not needed.
  322. Default value is turn_server_pkey.pem.
  323. --pkey-pwd If the private key file is encrypted, then this password to be used.
  324. --cipher-list Allowed OpenSSL cipher list for TLS/DTLS connections.
  325. Default value is "DEFAULT".
  326. --CA-file CA file in OpenSSL format.
  327. Forces TURN server to verify the client SSL certificates.
  328. By default, no CA is set and no client certificate check is performed.
  329. --ec-curve-name Curve name for EC ciphers, if supported by OpenSSL
  330. library (TLS and DTLS). The default value is prime256v1,
  331. if pre-OpenSSL 1.0.2 is used. With OpenSSL 1.0.2+,
  332. an optimal curve will be automatically calculated, if not defined
  333. by this option.
  334. --dh-file Use custom DH TLS key, stored in PEM format in the file.
  335. Flags --dh566 and --dh2066 are ignored when the DH key is taken from a file.
  336. -l, --log-file Option to set the full path name of the log file.
  337. By default, the turnserver tries to open a log file in
  338. /var/log/turnserver, /var/log, /var/tmp, /tmp and . (current)
  339. directories (which file open operation succeeds
  340. first that file will be used). With this option you can set the
  341. definite log file name.
  342. The special names are "stdout" and "-" - they will force everything
  343. to the stdout. Also, "syslog" name will redirect everything into
  344. the system log (syslog), as if the option "--syslog" was set.
  345. In the runtime, the logfile can be reset with the SIGHUP signal
  346. to the turnserver process.
  347. --alternate-server Option to set the "redirection" mode. The value of this option
  348. will be the address of the alternate server for UDP & TCP service in form of
  349. <ip>[:<port>]. The server will send this value in the attribute
  350. ALTERNATE-SERVER, with error 300, on ALLOCATE request, to the client.
  351. Client will receive only values with the same address family
  352. as the client network endpoint address family.
  353. See RFC 5389 and RFC 5766 for ALTERNATE-SERVER functionality description.
  354. The client must use the obtained value for subsequent TURN communications.
  355. If more than one --alternate-server options are provided, then the functionality
  356. can be more accurately described as "load-balancing" than a mere "redirection".
  357. If the port number is omitted, then the default port
  358. number 3478 for the UDP/TCP protocols will be used.
  359. Colon (:) characters in IPv6 addresses may conflict with the syntax of
  360. the option. To alleviate this conflict, literal IPv6 addresses are enclosed
  361. in square brackets in such resource identifiers, for example:
  362. [2001:db8:85a3:8d3:1319:8a2e:370:7348]:3478 .
  363. Multiple alternate servers can be set. They will be used in the
  364. round-robin manner. All servers in the pool are considered of equal weight and
  365. the load will be distributed equally. For example, if we have 4 alternate servers,
  366. then each server will receive 25% of ALLOCATE requests. An alternate TURN server
  367. address can be used more than one time with the alternate-server option, so this
  368. can emulate "weighting" of the servers.
  369. --tls-alternate-server Option to set alternative server for TLS & DTLS services in form of
  370. <ip>:<port>. If the port number is omitted, then the default port
  371. number 5349 for the TLS/DTLS protocols will be used. See the
  372. previous option for the functionality description.
  373. -O, --redis-statsdb Redis status and statistics database connection string, if used (default - empty,
  374. no Redis stats DB used). This database keeps allocations status information, and it can
  375. be also used for publishing and delivering traffic and allocation event notifications.
  376. This database option can be used independently of --redis-userdb option,
  377. and actually Redis can be used for status/statistics and SQLite or MySQL or MongoDB or
  378. PostgreSQL can be used for the user database.
  379. The connection string has the same parameters as redis-userdb connection string.
  380. --max-allocate-timeout Max time, in seconds, allowed for full allocation establishment.
  381. Default is 60 seconds.
  382. --denied-peer-ip=<IPaddr[-IPaddr]>
  383. --allowed-peer-ip=<IPaddr[-IPaddr]> Options to ban or allow specific ip addresses or ranges
  384. of ip addresses. If an ip address is specified as both allowed and denied, then
  385. the ip address is considered to be allowed. This is useful when you wish to ban
  386. a range of ip addresses, except for a few specific ips within that range.
  387. This can be used when you do not want users of the turn server to be able to access
  388. machines reachable by the turn server, but would otherwise be unreachable from the
  389. internet (e.g. when the turn server is sitting behind a NAT). The 'white" and "black" peer
  390. IP ranges can also be dynamically changed in the database.
  391. The allowed/denied addresses (white/black lists) rules are very simple:
  392. 1) If there is no rule for an address, then it is allowed;
  393. 2) If there is an "allowed" rule that fits the address then it is allowed - no matter what;
  394. 3) If there is no "allowed" rule that fits the address, and if there is a "denied" rule that
  395. fits the address, then it is denied.
  396. --pidfile File name to store the pid of the process.
  397. Default is /var/run/turnserver.pid (if superuser account is used) or
  398. /var/tmp/turnserver.pid .
  399. --proc-user User name to run the process. After the initialization, the turnserver process
  400. will make an attempt to change the current user ID to that user.
  401. --proc-group Group name to run the process. After the initialization, the turnserver process
  402. will make an attempt to change the current group ID to that group.
  403. -K, --keep-address-family TURN server allocates address family according TURN
  404. Client <=> Server communication address family.
  405. !! It breaks RFC6156 section-4.2 (violates default IPv4) !!
  406. --cli-ip Local system IP address to be used for CLI management interface.
  407. The turnserver process can be accessed for management with telnet,
  408. at this IP address and on the CLI port (see the next parameter).
  409. Default value is 127.0.0.1. You can use telnet or putty (in telnet mode)
  410. to access the CLI management interface.
  411. --cli-port CLI management interface listening port. Default is 5766.
  412. --cli-password CLI access password. Default is empty (no password).
  413. For the security reasons, it is recommended to use the encrypted
  414. form of the password (see the -P command in the turnadmin
  415. utility). The dollar signs in the encrypted form must be escaped.
  416. --cli-max-output-sessions Maximum number of output sessions in ps CLI command.
  417. This value can be changed on-the-fly in CLI. The default value is 256.
  418. --ne=[1|2|3] Set network engine type for the process (for internal purposes).
  419. ==================================
  420. LOAD BALANCE AND PERFORMANCE TUNING
  421. This topic is covered in the wiki page:
  422. https://github.com/coturn/coturn/wiki/turn_performance_and_load_balance
  423. ===================================
  424. WEBRTC USAGE
  425. This is a set of notes for the WebRTC users:
  426. 1) WebRTC uses long-term authentication mechanism, so you have to use -a
  427. option (or --lt-cred-mech). WebRTC relaying will not work with anonymous
  428. access. With -a option, do not forget to set the
  429. default realm (-r option). You will also have to set up the user accounts,
  430. for that you have a number of options:
  431. a) command-line options (-u).
  432. b) a database table (SQLite or PostgreSQL or MySQL or MongoDB). You will have to
  433. set keys with turnadmin utility (see docs and wiki for turnadmin).
  434. You cannot use open passwords in the database.
  435. c) Redis key/value pair(s), if Redis is used. You key use either keys or
  436. open passwords with Redis; see turndb/testredisdbsetup.sh file.
  437. d) You also can use the TURN REST API. You will need shared secret(s) set
  438. either through the command line option, or through the config file, or through
  439. the database table or Redis key/value pairs.
  440. 2) Usually WebRTC uses fingerprinting (-f).
  441. 3) -v option may be nice to see the connected clients.
  442. 4) -X is needed if you are running your TURN server behind a NAT.
  443. 5) --min-port and --max-port may be needed if you want to limit the relay endpoints ports
  444. number range.
  445. ===================================
  446. TURN REST API
  447. In WebRTC, the browser obtains the TURN connection information from the web
  448. server. This information is a secure information - because it contains the
  449. necessary TURN credentials. As these credentials are transmitted over the
  450. public networks, we have a potential security breach.
  451. If we have to transmit a valuable information over the public network,
  452. then this information has to have a limited lifetime. Then the guy who
  453. obtains this information without permission will be able to perform
  454. only limited damage.
  455. This is how the idea of TURN REST API - time-limited TURN credentials -
  456. appeared. This security mechanism is based upon the long-term credentials
  457. mechanism. The main idea of the REST API is that the web server provides
  458. the credentials to the client, but those credentials can be used only
  459. limited time by an application that has to create a TURN server connection.
  460. The "classic" long-term credentials mechanism (LTCM) is described here:
  461. http://tools.ietf.org/html/rfc5389#section-10.2
  462. http://tools.ietf.org/html/rfc5389#section-15.4
  463. For authentication, each user must know two things: the username and the
  464. password. Optionally, the user must supply the ORIGIN value, so that the
  465. server can figure out the realm to be used for the user. The nonce and
  466. the realm values are supplied by the TURN server. But LTCM is not saying
  467. anything about the nature and about the persistence of the username and
  468. of the password; and this is used by the REST API.
  469. In the TURN REST API, there is no persistent passwords for users. A user has
  470. just the username. The password is always temporary, and it is generated by
  471. the web server on-demand, when the user accesses the WebRTC page. And,
  472. actually, a temporary one-time session only, username is provided to the user,
  473. too.
  474. The temporary user is generated as:
  475. temporary-username="timestamp" + ":" + "username"
  476. where username is the persistent user name, and the timestamp format is just
  477. seconds sinse 1970 - the same value as time(NULL) function returns.
  478. The temporary password is obtained as HMAC-SHA1 function over the temporary
  479. username, with shared secret as the HMAC key, and then the result is encoded:
  480. temporary-password = base64_encode(hmac-sha1(shared-secret, temporary-username))
  481. Both the TURN server and the web server know the same shared secret. How the
  482. shared secret is distributed among the involved entities is left to the WebRTC
  483. deployment details - this is beyond the scope of the TURN REST API.
  484. So, a timestamp is used for the temporary password calculation, and this
  485. timestamp can be retrieved from the temporary username. This information
  486. is valuable, but only temporary, while the timestamp is not expired. Without
  487. knowledge of the shared secret, a new temporary password cannot be generated.
  488. This is all formally described in Justin's Uberti TURN REST API document
  489. that can be obtained following the link "TURN REST API" in the TURN Server
  490. project's page https://github.com/coturn/coturn/.
  491. Once the temporary username and password are obtained by the client (browser)
  492. application, then the rest is just 'classic" long-term credentials mechanism.
  493. For developers, we are going to describe it step-by-step below:
  494. - a new TURN client sends a request command to the TURN server. Optionally,
  495. it adds the ORIGIN field to it.
  496. - TURN server sees that this is a new client and the message is not
  497. authenticated.
  498. - the TURN server generates a random nonce string, and return the
  499. error 401 to the client, with nonce and realm included. If the ORIGIN
  500. field was present in the client request, it may affect the realm value
  501. that the server chooses for the client.
  502. - the client sees the 401 error and it extracts two values from
  503. the error response: the nonce and the realm.
  504. - the client uses username, realm and password to produce a key:
  505. key = MD5(username ":" realm ":" SASLprep(password))
  506. (SASLprep is described here: http://tools.ietf.org/html/rfc4013)
  507. - the client forms a new request, adds username, realm and nonce to the
  508. request. Then, the client calculates and adds the integrity field to
  509. the request. This is the trickiest part of the process, and it is
  510. described in the end of section 15.4:
  511. http://tools.ietf.org/html/rfc5389#section-15.4
  512. - the client, optionally, adds the fingerprint field. This may be also
  513. a tricky procedure, described in section 15.5 of the same document.
  514. WebRTC usually uses fingerprinted TURN messages.
  515. - the TURN server receives the request, reads the username.
  516. - then the TURN server checks that the nonce and the realm in the request
  517. are the valid ones.
  518. - then the TURN server calculates the key.
  519. - then the TURN server calculates the integrity field.
  520. - then the TURN server compares the calculated integrity field with the
  521. received one - they must be the same. If the integrity fields differ,
  522. then the request is rejected.
  523. In subsequent communications, the client may go with exactly the same
  524. sequence, but for optimization usually the client, having already
  525. information about realm and nonce, pre-calculates the integrity string
  526. for each request, so that the 401 error response becomes unnecessary.
  527. The TURN server may use "--stale-nonce" option for extra security: in
  528. some time, the nonce expires and the client will obtain 438 error response
  529. with the new nonce, and the client will have to start using the new nonce.
  530. In subsequent communications, the sever and the client will always assume
  531. the same password - the original password becomes the session parameter and
  532. is never expiring. So the password is not changing while the session is valid
  533. and unexpired. So, if the session is properly maintained, it may go forever,
  534. even if the user password has been already changed (in the database). The
  535. session simply is using the old password. Once the session got disconnected,
  536. the client will have to use the new password to re-connect (if the password
  537. has been changed).
  538. An example when a new shared secret is generated every hour by the TURN server
  539. box and then supplied to the web server, remotely, is provided in the script
  540. examples/scripts/restapi/shared_secret_maintainer.pl .
  541. A very important thing is that the nonce must be totally random and it must be
  542. different for different clients and different sessions.
  543. ===================================
  544. DATABASES
  545. For the user database, the turnserver has the following options:
  546. 1) Users can be set in the command line, with multiple -u or --user options.
  547. Obviously, only a few users can be set that way, and their credentials are fixed
  548. for the turnserver process lifetime.
  549. 2) Users can be stored in SQLite DB. The default SQLite database file is /var/db/turndb
  550. or /usr/local/var/db/turndb or /var/lib/turn/turndb.
  551. 3) Users can be stored in PostgreSQL database, if the turnserver was compiled with PostgreSQL
  552. support. Each time turnserver checks user credentials, it reads the database (asynchronously,
  553. of course, so that the current flow of packets is not delayed in any way), so any change in the
  554. database content is immediately visible by the turnserver. This is the way if you need the
  555. best scalability. The schema for the database can be found in schema.sql file.
  556. For long-term credentials, you have to set the "keys" for the users; the "keys" are generated
  557. by the turnadmin utility. For the key generation, you need username, password and the realm.
  558. All users in the database must use the same realm value; if down the road you will decide
  559. to change the realm name, then you will have to re-generate all user keys (that can be done
  560. in a batch script). See the file turndb/testsqldbsetup.sql as an example.
  561. 4) The same is true for MySQL database. The same schema file is applicable.
  562. The same considerations are applicable.
  563. 5) The same is true for the Redis database, but the Redis database has aa different schema -
  564. it can be found (in the form of explanation) in schema.userdb.redis.
  565. Also, in Redis you can store both "keys" and open passwords (for long term credentials) -
  566. the "open password" option is less secure but more convenient for low-security environments.
  567. See the file turndb/testredisdbsetup.sh as an example.
  568. 6) If a database is used, then users can be divided into multiple independent realms. Each realm
  569. can be administered separately, and each realm can have its own set of users and its own
  570. performance options (max-bps, user-quota, total-quota).
  571. 7) If you use MongoDB, the database will be setup for you automatically.
  572. 8) Of course, the turnserver can be used in non-secure mode, when users are allowed to establish
  573. sessions anonymously. But in most cases (like WebRTC) that will not work.
  574. For the status and statistics database, there are two choices:
  575. 1) The simplest choice is not to use it. Do not set --redis-statsdb option, and this functionality
  576. will be simply ignored.
  577. 2) If you choose to use it, then set the --redis-statsdb option. This may be the same database
  578. as in --redis-userdb option, or it may be a different database. You may want to use different
  579. database for security or convenience reasons. Also, you can use different database management
  580. systems for the user database and for the ststus and statistics database. For example, you can use
  581. MySQL as the user database, and you can use redis for the statistics. Or you can use Redis for both.
  582. So, we have 6 choices for the user management, and 2 choices for the statistics management. These
  583. two are totally independent. So, you have overall 6*2=12 ways to handle persistent information,
  584. choose any for your convenience.
  585. You do not have to handle the database information "manually" - the turnadmin program can handle
  586. everything for you. For PostgreSQL and MySQL you will just have to create an empty database
  587. with schema.sql SQL script. With Redis, you do not have to do even that - just run turnadmin and
  588. it will set the users for you (see the turnadmin manuals). If you are using SQLite, then the
  589. turnserver or turnadmin will initialize the empty database, for you, when started. The
  590. TURN server installation process creates an empty initialized SQLite database in the default
  591. location (/var/db/turndb or /usr/local/var/db/turndb or /var/lib/turn/turndb, depending on the system).
  592. =================================
  593. ALPN
  594. The server supports ALPNs "stun.turn" and "stun.nat-discovery", when
  595. compiled with OpenSSL 1.0.2 or newer. If the server receives a TLS/DTLS
  596. ClientHello message that contains one or both of those ALPNs, then the
  597. server chooses the first stun.* label and sends it back (in the ServerHello)
  598. in the ALPN extension field. If no stun.* label is found, then the server
  599. does not include the ALPN information into the ServerHello.
  600. =================================
  601. LIBRARIES
  602. In the lib/ sub-directory the build process will create TURN client messaging library.
  603. In the include/ sub-directory, the necessary include files will be placed.
  604. The C++ wrapper for the messaging functionality is located in TurnMsgLib.h header.
  605. An example of C++ code can be found in stunclient.c file.
  606. =================================
  607. DOCS
  608. After installation, run the command:
  609. $ man turnserver
  610. or in the project root directory:
  611. $ man -M man turnserver
  612. to see the man page.
  613. In the docs/html subdirectory of the original archive tree, you will find the client library
  614. reference. After the installation, it will be placed in PREFIX/share/doc/turnserver/html.
  615. =================================
  616. LOGS
  617. When the TURN Server starts, it makes efforts to create a log file turn_<pid>.log
  618. in the following directories:
  619. * /var/log
  620. * /log/
  621. * /var/tmp
  622. * /tmp
  623. * current directory
  624. If all efforts failed (due to the system permission settings) then all
  625. log messages are sent only to the standard output of the process.
  626. This behavior can be controlled by --log-file, --syslog and --no-stdout-log
  627. options.
  628. =================================
  629. HTTPS MANAGEMENT INTERFACE
  630. The turnserver process provides an HTTPS Web access as statistics and basic
  631. management interface. The turnserver listens to incoming HTTPS admin
  632. connections on the same ports as the main TURN/STUN listener. The Web admin
  633. pages are basic and self-explanatory.
  634. To make the HTTPS interface active, the database table admin_user must be
  635. populated with the admin user account(s). An admin user can be a superuser
  636. (if not assigned to a particular realm) or a restricted user (if assigned to
  637. a realm). The restricted admin users can perform only limited actions, within
  638. their corresponding realms.
  639. =================================
  640. TELNET CLI
  641. The turnserver process provides a telnet CLI access as statistics and basic management
  642. interface. By default, the turnserver starts a telnet CLI listener on IP 127.0.0.1 and
  643. port 5766. That can be changed by the command-cline options of the turnserver process
  644. (see --cli-ip and --cli-port options). The full list of telnet CLI commands is provided
  645. in "help" command output in the telnet CLI.
  646. =================================
  647. CLUSTERS
  648. TURN Server can be a part of the cluster installation. But, to support the "even port" functionality
  649. (RTP/RTCP streams pairs) the client requests from a particular IP must be delivered to the same
  650. TURN Server instance, so it requires some networking setup massaging for the cluster. The reason is that
  651. the RTP and RTCP relaying endpoints must be allocated on the same relay IP. It would be possible
  652. to design a scheme with the application-level requests forwarding (and we may do that later) but
  653. it would affect the performance.
  654. =================================
  655. FILES
  656. /etc/turnserver.conf
  657. /var/db/turndb
  658. /usr/local/var/db/turndb
  659. /var/lib/turn/turndb
  660. /usr/local/etc/turnserver.conf
  661. =================================
  662. DIRECTORIES
  663. /usr/local/share/turnserver
  664. /usr/local/share/doc/turnserver
  665. /usr/local/share/examples/turnserver
  666. =================================
  667. STANDARDS
  668. obsolete STUN RFC 3489
  669. new STUN RFC 5389
  670. TURN RFC 5766
  671. TURN-TCP extension RFC 6062
  672. TURN IPv6 extension RFC 6156
  673. STUN/TURN test vectors RFC 5769
  674. STUN NAT behavior discovery RFC 5780
  675. =================================
  676. SEE ALSO
  677. turnadmin, turnutils
  678. ======================================
  679. WEB RESOURCES
  680. project page:
  681. https://github.com/coturn/coturn/
  682. Wiki page:
  683. https://github.com/coturn/coturn/wiki
  684. forum:
  685. https://groups.google.com/forum/?fromgroups=#!forum/turn-server-project-rfc5766-turn-server
  686. ======================================
  687. AUTHORS
  688. Oleg Moskalenko <[email protected]>
  689. Gabor Kovesdan http://kovesdan.org/
  690. Daniel Pocock http://danielpocock.com/
  691. John Selbie ([email protected])
  692. Lee Sylvester <[email protected]>
  693. Erik Johnston <[email protected]>
  694. Roman Lisagor <[email protected]>
  695. Vladimir Tsanev <[email protected]>
  696. Po-sheng Lin <[email protected]>
  697. Peter Dunkley <[email protected]>
  698. Mutsutoshi Yoshimoto <[email protected]>
  699. Federico Pinna <[email protected]>
  700. Bradley T. Hughes <[email protected]>
  701. Mihaly Meszaros <[email protected]>