Commit Graph

244 Commits

Author SHA1 Message Date
Michael Jones
da332ed9e7
Add the InsertBraces command for clang-format to ensure that all conditionals always have braces (#1408)
- Why? Because code where conditionals lack braces is much harder to read, and prone to indentation confusion.
- How? Just added an extra flag to .clang-format and re-ran clang-format on all the files.

I also moved .clang-format up to the top level of the repo so that it can be applied to the fuzz targets as well.
2024-01-27 16:38:40 -08:00
Pavel Punsky
0afbc6204d
Replace HeapAlloc with malloc (#1378)
Use malloc/free instead of HeapAlloc/HeapFree
2024-01-18 21:08:28 -08:00
Dave Lambley
20c8d86a34
Return a 400 response to HTTP requests (#1231)
For our deployment, it is useful if coturn returns a valid HTTP response to an HTTP request. To do this on the same port as STUN/TURN and without enabling the admin site, I have extended `read_client_connection()` to return a canned HTTP response, in response to an HTTP request, rather than immediately closing the connection.
2023-11-05 17:25:12 -08:00
Gustavo Garcia
88ced47138
Replace srand/rand with srandom/random (#1279)
- srandom/random provide stronger randomness characteristics than
srand/rand in some operating systems.
- usage of srand/rand is not very consistent in coturn.

There is room for more refactoring and use apputils helper functions in
ns_turn_msg.c too but i'm not sure that dependency from "client" module
to "apps" module is a good idea yet.

Thx @0xdea

Co-authored-by: Gustavo Garcia <gustavogb@mail.com>
2023-10-02 16:19:57 +02:00
Alexander Udovichenko
2a695ea855
Add warning and disable web admin if no-tls option used (#1256)
Fixes https://github.com/coturn/coturn/issues/1239

https to web ui freeze in browser if no_tls option used, because no tls
stuff initialized.
This PR add warning about this and comment aboute this in default config
2023-08-27 16:27:37 -07:00
rim
7bc932a905
Fix build with libressl 3.6+ (#1198)
Tested on FreeBSD 13/stable
2023-05-14 16:38:58 -07:00
Stefan Sundin
43f8b873a7
Fix typo in mainrelay.c (#1169) 2023-03-12 17:29:39 -07:00
Molly Miller
902cb99849
Add configuration option for TLS 1.3 ciphersuites (#1118)
There are two different API's in OpenSSL for configuring TLS ciphers,
one for TLS 1.2 and below, and another for TLS 1.3. coturn only calls
the TLS 1.2 API when handling the `--cipher-list` configuration option,
which means that it's not possible to use non-default ciphersuites with
TLS 1.3 connections.

This PR calls appropriate OpenSSL API to allow TLS 1.3 ciphersuites to be configured.
2022-12-16 15:53:36 -08:00
Molly Miller
82646a9023
Add explicit SIGTERM and SIGINT handlers. (#1106)
coturn running inside a docker container runs as PID 1, however PID 1
has special signal handling semantics (see the note at the bottom of the
section
[here](https://docs.docker.com/engine/reference/run/#foreground)).
coturn relies on the default behaviour of SIGTERM to terminate the
process, however as no signal handler is explicitly installed, it
doesn't respond to SIGTERM when running inside a container. This PR
fixes this problem by installing explicit signal handlers for SIGINT and
SIGTERM, which trigger the same termination mechanism as the admin
interface "halt" command.

This is a port of wireapp#6 for upstream.
2022-12-06 17:06:51 -08:00
Molly Miller
af4f190a94
Fix inverted logic in TLS configuration options (#1105)
This PR fixes some errata from #996 and #989:

- Some DTLS code was left over in the common path for allocating and
initialising `SSL_CTX`'s, and the DTLS-specific configuration code was
erroneously operating on the TLS context instead of the DTLS context.

- In both the TLS and DTLS codepaths, the previous refactoring inverted
the logic for the `--no-tlsv1`/`--no-tlsv1_1`/etc command line options,
so that these options would instead *enable* the respective (D)TLS
versions, instead of disabling this. This would mean that by default
coturn would only support TLS 1.3 and DTLS 1.2, and no earlier versions.

I've also regenerated the manual pages (with the `make-man.sh` script)
to match the documentation in the README files.
2022-12-06 17:03:23 -08:00
Pavel Punsky
95373d3e2a
Cleanup logs on turnserver start (#1088)
Reformatting and removing some duplications:
- Some lines have WARNING WARNING: cleaned up.
- Lines printed using perror: only LOG_ mechanism should be used.
- Printing IO mechanism (epoll for example) for each thread: selected
mechanism logged once
- Duplicate lines (perror and also LOG): duplication removed
- Duplicates: clean up (because calling function multiple times -
configuration load)
2022-11-14 17:45:20 -08:00
Gustavo Garcia
d9108a4b54
Add clang format rules and checks (#935)
I would like to get feedback on this and see if people is confortable
with these clang rules.

Right now is using the "llvm" style increasing the line length from 80
to 120 given that coturn is using long lines often.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2022-11-06 22:05:17 +01:00
Gregor Jasny
83b8ddb744
Check and fix format string for turn_log_func_default (#1064) 2022-10-31 11:07:04 -07:00
Pavel Punsky
4995b64453
Fix warnings (unused arguments, undeclared function) (#1057) 2022-10-29 20:13:55 -07:00
Emil Ljungdahl
c4f670fa24
WINDOWS: unsigned long should not be used to store pointers (#1055)
On LLP64 systems (read Windows) unsigned long is only 4 bytes wide,
which makes it very unsuitable for storing pointers.
-----
Additional comments:
uintptr_t since c99 or uintptr_t since C++11
see: https://cplusplus.com/reference/cstdint/,
https://en.cppreference.com/w/c/types/integer,
https://en.cppreference.com/w/cpp/types/integer

C11 re-enabled in #1056
2022-10-29 20:13:25 -07:00
Pavel Punsky
6ff98239f4
Reduce usage of TURN_NO_HIREDIS macros (#1022)
`TURN_NO_HIREDIS` is defined when hiredis library is not present and any
redis functionality must be disabled

While all above is correct, it does not require ifdef-ing out all
related code.
For example, redis related fields in `turn_params` do not need to be
compiled out. Same for certain function parameters.

This PR reduces amount of places in code where `TURN_NO_HIREDIS` is used
to make code simpler by moving as much usage of this define into
dbd_redis.h/c files and compiling them unconditionally.

- Always compile/link `dbd_redis.c`
- Move many `TURN_NO_HIREDIS` decisions into `dbd_redis.c`
- Delete empty function redis_async_init
2022-10-29 18:17:12 -07:00
Pavel Punsky
181216e9f1
Reduce usage of TURN_NO_PROMETHEUS (#1023)
`TURN_NO_PROMETHEUS` is defined when prometheus libraries are not
present and any prometheus functionality must be disabled

While all above is correct, it does not require ifdef-ing out all
related code.
For example, prometheus related fields in turn_params do not need to be
compiled out. Same for certain function parameters.

This PR reduces amount of places in code where `TURN_NO_PROMETHEUS` is
used to make code simpler by moving as much usage of this define into
prom_server.h/c files and compiling them unconditionally.

- Always compile/link prom_server.c
- Move many TURN_NO_PROMETHEUS decisions into prom_server.c
2022-10-28 20:22:50 -07:00
Kang Lin
40c99db6ba
Support Windows MSVC (#855)
The following changes have been made:
1. Replace deprecated functions with new standard functions
2. Add corresponding MSVC functions for non-standard functions 
3. Remove warnings about unsafe functions
4. CMAKE: modify find pack Libevent and openssl 
5. Modify include files
6. Use pthread4W
7. Modify socket in windows
8. Add CI - github action
8.1. msvc
8.2. mingw
10. The database:
9.1. sqlite, pgsql, hiredis, mongo  is test compiled.
9.2. mysql, isnot test compiled.
11. The applications、server can be compiled and run successfully! 
12. Add vcpkg manifest mode in cmake.
2022-10-28 19:32:23 -07:00
Pavel Punsky
d72a2a8920
Cleanup openssl initialization (#1012)
Rewriting openssl initialization code (threading support to make it
cleaner

- Regroup functions so that there is one ifdef (for old code and new
code)
- Modern openssl (>1.0.2) does not need any synchornization routines so
they are empty
- Old openssl (<=1.0.2) now require `OPENSSL_THREADS` which allows
running multiple threads in turnserver. Not having turnserver
multi-threaded is a huge waste. `OPENSSL_THREADS` is now a requirement.


Test Plan:
- CI builds pass for openssl versions 1.0.2, 1.1.1, 3.0, including tests
2022-10-24 22:06:35 +02:00
Pavel Punsky
af9bc12055
Sanitize DB connection string before printing to log (#1020)
Store sanitized version of DB connection string with password masked
(replace all chars with * which exposes its length)
Use sanitized version when logging connection string

Fixes #1017 and #272
2022-10-17 08:44:30 +02:00
Pavel Punsky
ae2673959b
Use single SSL_CTX for DTLS support (#996)
Similar to #989, use a single SSL context for all versions of DTLS
protocol

- Add support for modern API (protocol version independent APIs)
- Add DTLS test to the CI test
- Removing calls to `SSL_CTX_set_read_ahead` in DTLS context (does
nothing as DTLS is datagram protocol - we always get the whole datagram
so this call has no impact)

Fixes #924
2022-10-05 10:26:46 +02:00
Pavel Punsky
a3d338e2c1
Silence warnings by converting STRCPY to strncpy calls (#995)
STRCPY macro makes pointer comparison which creates a warning

In those places, replace the macro with `strncpy` with careful review of
destination buffer size

With this change I do not get compiler warnings at all
2022-09-30 08:17:46 -07:00
Pavel Punsky
73c14d6b10
Replace references to non-existent pdf file with links (#1002)
Fixes #800
2022-09-29 11:09:10 -07:00
Pavel Punsky
4bab2adba4
Use a single SSL context object (#989)
openssl allows multiple TLS version support through a single SSL_CTX
object.

This PR replaces 4 per-version SSL_CTX objects with a single object
(DTLS is not yet changed).
SSL context initialization code for openssl with modern API (>=1.1.0)
uses `TLS_server_method` and `SSL_CTX_set_min_proto_version` instead of
enabling specific TLS version. Byproduct of this is TLSv1_3 support when
used with openssl-1.1.1 and above

TLS 1.2 and TLS 1.3 cannot be disabled (as before)

Test plan:
- run_tests.sh script now runs turnserver with SSL certificate (which
enables TLS support)
- run_tests.sh now has one more basic test that uses TLS protocol

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-28 09:50:25 +02:00
Pavel Punsky
ae259637eb
Replace bzero with memset (#986)
Replace all instances of `bzero` with memset by find-replace-edit.
This is straightforward replacement which is suboptimal in a few cases
(for example we could use calloc instead of malloc+memset(0))

Inspired by #855
2022-09-17 08:36:28 +02:00
Pavel Punsky
98d19fc441
Fix small issues reported by cppcheck (#967)
- Redundant checks for variable values
- Potential nullptr dereference
- Double check for the same variable

Run with:
```
cppcheck --inline-suppr --language=c --enable=warning,performance --force .
```

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-08 11:25:38 +02:00
Pavel Punsky
83bd4e23e7
Print turnserver version with --version (#973)
Print number version of the build

```
$ turnserver --version
4.5.2
```


Closes #843

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-07 07:06:31 +02:00
Pavel Punsky
41a8aa09ff Document dependency between new-log-timestamp-format and new-log-timestamp 2022-08-27 20:34:35 -07:00
Gustavo Garcia
38c4055cb0
Merge pull request #789 from korayvt/syslog_facility
Add syslog facility configuration
2022-08-10 11:40:43 +02:00
KORAY VATANSEVER
2b91f0ad8b Function renamed for the consistency. Incomplete coding completed.
Tested for the empty and invalid values.  Parameter is ignored in those cases.
2022-08-09 13:06:45 +03:00
Gustavo Garcia
bf54410bc7
Merge branch 'sysvinit/toggle-username-labels-upstream' of github.com:wireapp/coturn into wireapp-sysvinit/toggle-username-labels-upstream 2022-07-29 09:47:17 +02:00
Molly Miller
6fd08bac3b Invert logic for handling username metrics labels. 2022-07-27 10:44:13 +02:00
Molly Miller
299fcea34c Make username labeling in metrics configurable. 2022-06-20 14:34:35 +01:00
Lionel Nicolas
19495b2d1d Add ability to configure prometheus listener port 2021-10-22 19:47:49 -04:00
Lionel Nicolas
c42cd844de Fix typo and formatting in --prometheus documentation 2021-10-22 19:47:16 -04:00
Giacomo Vacca
8aded3556e Issue #699 Return codes for prom server 2021-09-21 17:26:48 +02:00
KORAY VATANSEVER
22af3ea567 Add syslog facility configuration 2021-07-07 15:56:30 +03:00
Mészáros Mihály
708b83ea78 RESPONSE_ORIGIN attribute only if rfc5780 is on 2021-06-05 22:10:31 +02:00
Mészáros Mihály
54ef051844 Disable stun backward compatibility 2021-06-05 22:10:31 +02:00
Mészáros Mihály
eda11698f0 Add option no-rfc5780
To avoid any amplifiaction STUN binding attacks.
2021-06-05 22:10:31 +02:00
Mark Hills
bdf27616ba Do not mutate something which the DTLS listener server does not own
Multiple DTLS listener servers are created, and server->dtls_ctx is
the same object shared between them.

Set these callbacks once, and logically this is at the point where the
SSL context is created.
2021-03-23 16:02:06 +00:00
Mészáros Mihály
2204778ce1 Replace keep-address-family with allocation-default-address-family 2021-03-12 23:05:18 +01:00
Mészáros Mihály
e2c99c6803 Remove extra new line in error 2021-03-11 22:15:22 +01:00
brevilo
a52df6cafb
Define OPENSSL_VERSION_1_1_1 on systems where it doesn't (yet) exist
Otherwise preprocessor logic will fail and cause incompatible pointer type issues (by using wrong callback API)
2021-01-13 01:54:25 +01:00
Mészáros Mihály
104ab83f09 Automatically notify systemd if compiled 2021-01-10 20:57:43 +01:00
Mészáros Mihály
e367fabb0e Fix typo 2021-01-10 17:20:40 +01:00
Mészáros Mihály
ef7916842d Add systemd notification support 2021-01-07 17:51:34 +00:00
Mészáros Mihály
5b13fdd37b Fix: Read log options in first pass. Fixes #602 2021-01-07 10:33:14 +00:00
Mészáros Mihály
50ebef7a3f Fix g++ 2 errors and many warnings
Resolves #661 #654
2021-01-05 21:47:50 +00:00
Mészáros Mihály
6ce463e8e2 Removed wiki, due it was outdated and redundant. 2021-01-05 09:57:16 +00:00