README.turnserver 43 KB

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