Commit Graph

992 Commits

Author SHA1 Message Date
redraincatching
a3a7450104
refactored tri-state to bools (#1709)
refactored random tri-state to use two random booleans for clarity
2025-07-01 12:41:22 +02:00
redraincatching
16f801f646
addressed null pointer deref warnings (#1712)
addressing issues raised by code scanning, specifically null pointer
dereferences in server

ns_turn_server.c
-
[33](https://github.com/redraincatching/coturn/security/code-scanning/33)
ignored, the `is_rfc5780()` function exits early if the server is null
- this also catches
[36](https://github.com/redraincatching/coturn/security/code-scanning/36)
-
[34](https://github.com/redraincatching/coturn/security/code-scanning/34)
addressed
-
[174](https://github.com/redraincatching/coturn/security/code-scanning/174)
addressed

ns_turn_maps.c
-
[27](https://github.com/redraincatching/coturn/security/code-scanning/27),
[160](https://github.com/redraincatching/coturn/security/code-scanning/160),
[161](https://github.com/redraincatching/coturn/security/code-scanning/161),
[162](https://github.com/redraincatching/coturn/security/code-scanning/162),
[163](https://github.com/redraincatching/coturn/security/code-scanning/163),
[164](https://github.com/redraincatching/coturn/security/code-scanning/164),
[165](https://github.com/redraincatching/coturn/security/code-scanning/165)
false positives, suppressed with assert()

ns_turn_allocations.c
-
[9](https://github.com/redraincatching/coturn/security/code-scanning/9)
addressed

---------

Co-authored-by: Gustavo Garcia <gustavogb@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-01 12:40:11 +02:00
redraincatching
cb74638149
removed unnecessary null check (#1706)
removing an unnecessary null check as raised in [this code
scan](https://github.com/redraincatching/coturn/security/code-scanning/179)

the variable is confirmed to not be null in an outer loop guard

also changed the name of the variable in `rtcp_map_put`'s function
declaration to match that used in its function definition
2025-06-20 09:51:52 -07:00
Gustavo Garcia
62d91b0bc5
Fix compiler warnings in source files (#1704)
Two compiler warnings were addressed:

* In `src/apps/relay/http_server.c`, line 77, a `-Wpointer-sign` warning
occurred when initializing a `char *` with the `uint8_t *` return type
of `ioa_network_buffer_data()`.
* An explicit cast `(char *)` was added to
`ioa_network_buffer_data(nbh_http)` to resolve the type mismatch.

* In `src/apps/relay/acme.c`, line 59, a `-Wchar-subscripts` warning was
present because a `char` variable `c` was used as an array index. `char`
can be signed, potentially leading to negative indices.
* Initially, `c` was cast to `(unsigned char)` at the point of use:
`A[(unsigned char)c]`.
* This was later improved by changing the declaration of `c` from `const
char` to `const unsigned char c = req[k]

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2025-06-17 15:25:26 +02:00
redraincatching
afec2e2add
guarantee no oob write in strncat (#1702)
based on [this codescanning
alert](https://github.com/redraincatching/coturn/security/code-scanning/166)

guarantees that the `turn_params.cipher_list` will be null-terminated,
and that the call to strncpy cannot attempt to access out-of-bounds
memory
2025-06-12 11:15:46 +02:00
Scott Godin
1368e65988
Fix issues with Global Allocation Count for drain mode (#1699)
Fix issues with Global Allocation Count for drain mode

- move increment/decrement logic out of userdb.c and tie to Prometheus
logic for allocation tracking instead
- log global allocation count decrements at INFO level, when drain mode
is on
2025-06-11 14:15:36 -07:00
Pavel Punsky
678996a529
Update version to 4.7.0 (#1691)
Set new release version to 4.7.0
Updating minor version due to some breaking changes in options to enable
more secure/robust configuration without additional flags (or relying on
recommended conf file which people seem to skip during updates)
2025-05-30 14:13:59 -07:00
Pavel Punsky
cc5e18fc89
Make older TLS versions optional (#1693)
TLSv1 and TLSv1.1 can be enabled using `--tlsv1` and `--tlsv1_1`
arguments accordingly
That assumes openssl version being used has these versions enabled
(which as of openssl-3.5 is not by default)
2025-05-30 09:20:14 -07:00
Gustavo Garcia
d7197fa263
Add missing close socket when ioa_socket call fails (#1694)
Fixes [#1071](https://github.com/coturn/coturn/issues/1071)

Not sure how this case can happen but better to handle the error case.

Co-authored-by: tyranron <tyranron@gmail.com>
2025-05-30 09:19:24 -07:00
Michael Jones
9ae1e3b3cb
Add spdx tags to all source files (#1510)
With notable exceptions of:

src/apps/common/win/*
src/apps/relay/telnet.*

The purpose of this change is to add the SPDX tags from
https://spdx.dev/, which is a linux foundation project, to the source
code.

This provides automated code provenance tools, which are used in setting
up software bill of materials reports, an easy time verifying that the
code license is known and no incompatibilities are present in a
codebase.

No copyright date, author, or license changes are made.

Note also that
7e525c8e1c
is the original commit for the ACME code (acme.h and acme.c) which was
then moved to acme.h and acme.c in this commit
d4686750ee
but neither commit indicates what license the ACME code was submitted
as.

https://github.com/coturn/coturn?tab=License-1-ov-file#readme is the
3-clause BSD license, but https://github.com/coturn/coturn/pull/672
documents that the author's intent was for the MIT license. So I've used
the SPDX tag and content of the MIT license for this change.
2025-05-30 11:56:04 +02:00
Michael Jones
0af0fc3ec2
Address various minor clang-tidy warnings (#1513)
No specific methodology other than checking the github CI output for the
`clang-tidy` job, and fixing things one at a time.
2025-05-29 19:12:50 -07:00
Pavel Punsky
14f84fa48c
[BREAKING] Deprecate response-origin-only-with-rfc5780 (#1690)
Make this true - response-origin-only will only be enabled with rfc5780 option enabled
2025-05-28 16:37:20 -07:00
Pavel Punsky
4cc076d424
[BREAKING] Invert no-stun-backward-compatibility to be default on (#1689)
Deprecate `--no-stun-backward-compatibility` and set it to true by
default
Add new option `--stun-backward-compatibility`, off by default

Update example/recommended configuration files

This is a breaking change as passing `--no-stun-backward-compatibility`
will be rejected as invalid argument
2025-05-28 16:23:33 -07:00
Pavel Punsky
368355a06f
Invert RFC5780 option to default off (#1688)
Invert `--no-rfc5780` option to be true by default
Make it `--rfc5780` to enable it
Update example/recommended configuration files

Passing `--no-rfc5780` will have no effect as this is the default
behavior now
2025-05-28 15:08:57 -07:00
Gustavo Garcia
f17cd2d854
Fix compilation warning with const - non const conversions (#1686)
When building with default configuration at least in MacOS we get
warnings about those conversions from const char* to char*. Fix it by
making all those argv ""const char*"
2025-05-26 13:54:50 +02:00
Asmir Mehic
823fd71c98
Fix infinite loop in ns_turn_server.c (#1460)
In case ur_map_get returns 1 server will enter infinite loop because
newid != 0.

Co-authored-by: Asmir <asmir.mehic@viber.com>
2025-05-25 15:38:42 +02:00
Michael Jones
c37462b33a
Fix the ability to compile coturn using C++ compiler (#1546)
This adjusts the code to allow compilation with a C++ compiler, but
doesn't change the build to use a C++ compiler. Everything should
continue working as-is with existing c-compilers. This is just a "let it
work" change, not a "change how it works" change.
2025-05-25 10:53:13 +02:00
Gustavo Garcia
de84ecefb1
Restore returning 200 OK on root prometheus path for health check (#1678)
Restore the support to return a 200 OK in the root prometheus endpoint
(/) as stated in the documentation.

This feature was lost when removing libpromhttp

Fixes #1672
2025-05-22 11:37:29 +02:00
Gustavo Garcia
8a71069517
Improve MySQL connection error logging to include actual MySQL error message (#1679)
Address #270

MySQL reconnectiong after priviledge drop and reporting missleading
error log.
"Cannot open MySQL DB connection: <%s>, runtime error\n"

Always include the mysql error message for additional context.
2025-05-22 11:29:36 +02:00
maddy
c0b2c8d389
redis: use dbname param when redis is unauthenticated (#1668)
Fixes a regression pointed out at
<https://github.com/coturn/coturn/pull/1488#issuecomment-2801027711>.

A regression was introduced in the last PR where the dbname parameter
was not respected if using redis without authentication. The logic for
sending the select command responsible for switching to the correct
database was wrongly guarded behind authentication being provided. This
PR flattens the control flow so the select command is always sent,
whether using authentication or not.
2025-05-21 18:58:35 +02:00
Gustavo Garcia
b0dbf5cb8c
Show allocations increment/decrement logs behind verbose flag (#1677)
Fix #1657 

This log was added in a recent refactor for draining support and it is
very noisy. With this change the log is moved behind the "verbose" flag
and also does a minor cleanup to not have 2 duplicated lines for logging
when one is enough.

Co-authored-by: Gustavo Garcia <gustavogb@mail.com>
2025-05-21 13:47:48 +02:00
Pavel Punsky
791e4c9f7a
Add Content-Type header to prometheus response (#1662)
Prometheus v3 requires `Content-Type` header
Fixes #1658
2025-03-30 12:58:41 -07:00
nicolas-laduguie
a21733b23d
Fix infinite loop while triggering SIGHUP and log file reset causing … (#1630)
…segmentation fault

This reverts commit 8f9446cf8f.
2025-02-20 21:14:07 -08:00
redraincatching
01628a7a01
updated types to bool in _turn_params_ to reflect C11 (#1406)
approach was as follows, for the `_turn_params_` struct:
- if a variable of type `int` or `vint` was only being used as a
boolean, replace it with bool as defined in `<stdbool.h>`
- replace its declaration with true/false, depending on prior assignment
as 0/1

changes were only made when i was certain the variables were not being
used as an `int`, so i may have missed some

no changes were made to other sections of the code as int-to-bool
assignment is allowed in C, only code within the structs were changed,
but that can be changed with a later commit

---

from a documentation perspective, it's not clear as to what purpose or
benefit the vint alias has. the definition in `ns_turn_defs.h` simply
reads

```c
typedef int vint;
typedef vint *vintp;
```
with no comments, and it seems most (but not all) `vint`s are being used
as interim booleans through the code. this may just be from lack of
knowledge of the codebase, but it doesn't seem useful in any way, so it
would be helpful if someone with more expertise could clarify

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2025-02-20 21:03:13 -08:00
guoyingbo
22aae5d0d0
Windows '_WTA' bug (#1624)
Every time the '_WTA' is called, its initial value is null, so the
function returns directly.


c98bb93514/src/apps/common/apputils.c (L905-L908)

c98bb93514/src/apps/common/apputils.c (L939-L941)

c98bb93514/src/apps/common/apputils.c (L960-L962)

c98bb93514/src/apps/common/apputils.c (L981-L983)
2025-01-04 17:50:29 -08:00
Pavel Punsky
c98bb93514
Fix cmake issues detecting mongo and libsystemd on macOS (#1621)
- libsystemd does not exist on macOS - ignore it and reduce warnings
during cmake step
- mongo-c has cmake file on macOS - reusing the same code path and
reduce warnings
2024-12-27 14:52:44 -08:00
Pavel Punsky
58f1b8926c
Fix hiredis detection by cmake (#1620)
See #1618 for details

This fix allows proper hiredis detection on macOS when building with
cmake
2024-12-27 11:36:58 -08:00
Pavel Punsky
89a5600be1
Drop TLS version support detection (#1617)
With requiring openssl version at least 1.1.1 all versions of TLS (up to
and including 1.3) and DTLS 1.2 are supported
With that, no detection or ability to disable a version will be provided
2024-12-19 17:10:49 -08:00
Pavel Punsky
20da9cd09a
Cleanup ALPN_SUPPORTED define usage (#1616)
As of openssl 1.1.1 ALPN is supported - no need for all the ifdefs anymore
2024-12-19 16:41:45 -08:00
Pavel Punsky
9f779a64d0
Fix warnings type conversion (#1615) 2024-12-19 09:05:37 -08:00
Alex Gustafsson
790cc6f79e
Add parameter for specifying prometheus path (#1602)
Add a `--prometheus-path` parameter which allows users to specify at
what
path the metrics should be exposed.

This simplifies serving metrics on a specific path behind some
restrictive reverse proxies that expect the upstream server to serve
URLs with paths matching the requested path.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2024-12-18 14:50:38 -08:00
Michael Jones
c9878469fc
[BREAKING] Remove support for openssl older than 1.1.1 (#1397)
Openssl 1.1.1 is end-of-life in September 2023.
This PR removes support for versions of openssl OLDER than 1.1.1
1.1.1 should still be usable after this change is merged.

I don't see any value in supporting 1.1.1, but didn't see a reason to
purge support for 1.1.1 when there are so few checks for >= 3.0.

Note that this does also remove CI support for Ubuntu 16.04. The
official version of OpenSSL from Ubuntu for this release is listed here:
https://launchpad.net/ubuntu/+source/openssl as 1.0.2g

Since no newer releases of coturn will be backported by Canonical to
Ubuntu 16.04, anyone using Coturn on this operating system will have to
download and compile it themselves. They may build their own version of
OpenSSL if they somehow cannot upgrade to a newer version of Ubuntu.

My position is that these users should prefer to upgrade to a newer
operating system than worry about chasing newer releases of Coturn.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2024-12-13 13:06:24 -08:00
Pavel Punsky
ea280f9431
[BREAKING] Cleanup deprecated options (#1599)
Following configuration options deleted:
- `--secret-ts-exp-time`
- `--prod` - disables SOFTWARE_ATTRIBUTE in messages. Now it is default.
To enable SOFTWARE_ATTRIBUTE use `--software-attribute`
- `--no-sslv2`, `--no-sslv3` - old versions of SSL are not supported and
it is not possible to enable them

These are breaking changes - if the CLI command has any of those
arguments it will cause turnserver to terminate and notify about unknown
argument
2024-12-13 09:31:06 -08:00
Pavel Punsky
94fcfadce1
[BREAKING] Reverse SOFTWARE_ATTRIBUTE_OPT to avoid inverse logic (#1598)
As part of looking at #1588 , I figured that sending `SOFTWARE`
attribute is also part of a problem as it increases messages sent out by
coturn and thus increasing amplification factor. For 4.6.2, the
additional size is 24 bytes (4 bytes attribute header, and 20 bytes for
"Coturn-4.6.2 'Gorst'")

If we are to use an example from #1588, "A 62 byte request will be met
with Coturn’s 401 Unauthorized response which is 150 bytes, a factor of
~2.42." - without SOFTWARE the response will be 126 bytes which reduces
amplification factor to ~2.

As I observed with multiple providers using coturn - some of the are
sending it. Meaning, they do not set `--no-software-attribute` - most
probably due to lack of clarity about this setting.

I believe sending SOFTWARE_ATTRIBUTE should be off by default which is
hinted in the RFC
(https://datatracker.ietf.org/doc/html/rfc8489#section-16.1.2)

Detailed changes:
- Extract setting the attribute into a function to avoid code
duplication
- This option is now not reloadable
- The option is now called `software_attribute` because inverse logic
creates multiple double-not in the code which makes it harder to read.
- `no-software_attribute` is still functional but marked as deprecated
in documentation

Test Plan:
- Run local tests with different cli arguments (new and deprecated) and
confirm SOFTWARE attribute is off by default, and added when arguments
say so
2024-12-13 09:28:45 -08:00
Pavel Punsky
b6e53ca4c9
Update version to 4.6.3 (#1609)
preparing for new tag 4.6.3

---------

Co-authored-by: tyranron <tyranron@gmail.com>
2024-12-11 10:13:38 -08:00
Alex Gustafsson
d63704c72d
Implement custom prometheus http handler (#1591)
Implement a custom prometheus http handler in order to:

1. Support listening on a specified address as opposed to any
2. Remove the requirement on the unmaintained promhttp library

This feature comes with one limitation: if an IPv4 address is used, the
server will not listen on the IPv6-mapped address, even if IPv6 is
available. That is, dual-stacking does not work.

Solves: #1475

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2024-12-10 10:28:43 -08:00
maddy
c4a954a7fc
Allow authenticating with a username to redis (#1488)
Add ability to authenticate to redis with a password (and optionally username for redis 6.0)

Tested by building and using with redis on old and new versionss
2024-11-18 16:51:02 -08:00
Scott Godin
edcdfc8b02
Add new Drain feature (#1529)
Add new Drain feature

-when coturn server is in drain mode
  -current allocations will continue to work as usual
  -new allocations will be rejected with a 403 (Forbidden) response
  -when all allocations go away, then coturn will shutdown
-Enable drain mode with either
  -signaling SIGUSR1
  -turn_admin_server "drain" CLI command

This contribution is from Wire. https://wire.com/
2024-10-27 18:56:58 -07:00
Michael Jones
af4c44a818
Additional refactoring of ns_turn_allocation.* to address security scanner concerns (#1514)
You can see the list here:
https://github.com/coturn/coturn/security/code-scanning

In this case, i'm attempting to address:

ns_turn_allocation.c:725 -- Dereferencing NULL pointer. 'ub->bufs'
contains the same NULL value as 'realloc()' did.
ns_turn_allocation.c:724 -- 'realloc' might return null pointer:
assigning null pointer to 'ub->bufs', which is passed as an argument to
'realloc', will cause the original memory block to be leaked.
ns_turn_allocation.c:604 -- Dereferencing NULL pointer. 'a->tcs.elems'
contains the same NULL value as 'realloc()' did.
    ns_turn_allocation.c:582 -- Dereferencing NULL pointer 'tc'.
ns_turn_allocation.c:603 -- 'realloc' might return null pointer:
assigning null pointer to 'a->tcs.elems', which is passed as an argument
to 'realloc', will cause the original memory block to be leaked.
    ns_turn_allocation.c:525 -- Using uninitialized memory '*chi'.
    ns_turn_allocation.c:229 -- Using uninitialized memory '*slot'.

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2024-10-18 20:54:47 -07:00
Sven Tennie
cbb04aa9a2
Delete dead code (#1563)
`stun_port` isn't read after setting it. Thus, we can remove it.
2024-10-04 10:27:31 -07:00
Mészáros Mihály
e78d8f4fae
Fix cli auth (#1578)
Fix to avoid accept all password except the right cli_password

Co-authored-by: Mészáros Mihály <misi@eper.majd.eu>
2024-10-04 10:26:17 -07:00
Michael Jones
b523616b1f
Use bool, instead of int, for the functions in ns_turn_msg.c (#1553)
And address knockon effects in other files, e.g. adjust if-statements
and other function parameters and return types.
2024-08-23 17:49:14 -07:00
Pavel Punsky
858b088a88
Reformat code (#1557)
Reformat to address linter error
2024-08-21 15:42:18 -07:00
Michael Jones
eee52ad1b9
Update libtelnet (#1545)
to commit
5f5ecee776

Which is the lastest commit in the "develop" branch. 

This seems to fix a couple of places where non-0 is mistakenly returned
as "success" -- why projects don't use bool for these return types is
beyond my understanding.
2024-08-04 17:33:33 -07:00
Michael Jones
958f70d5c2
Use calloc where appropriate, avoid memset when normal buffer initialization works (#1550)
Depends on https://github.com/coturn/coturn/pull/1547
2024-08-04 17:30:58 -07:00
Michael Jones
c4da2a8ea4
Fix make lint (#1547) 2024-08-04 17:21:34 -07:00
Michael Jones
5fa67a65f5
Fix compiler warnings from continuous integration (#1555)
Almost all of the warnings were about truncating pointers, because
sizeof(void*) != sizeof(long) on all platforms.
2024-08-04 15:44:15 -07:00
David Smitmanis
1f74024a30
windows: Only attempt to bind when the network interface is up (#1527)
Previously if the system had an interface with a static IP configured,
coturn would attempt to bind to that address, even if the interface was
down. This would fail, and prevent coturn from starting (even if there
were other usable interfaces)
2024-07-26 22:22:25 -07:00
Pavel Punsky
c7d431a36a
Memset user_db before reading conf file, not after (#1537)
Fixes #1533 and #1534

Memsetting `turn_params.default_users_db` before reading conf file, not
after.
Because auth is read in first iteration so secret was wiped out.

# test plan
Add new test script that uses config file to setup turnserver instead of
cli arguments and confirm it works (fails without the change)
2024-07-14 16:59:26 -07:00
Michael Jones
c3d235b6e9
Check the result of malloc in send_message_to_redis (#1515) 2024-06-02 16:36:27 -07:00