README.turnserver 45 KB

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