Commit Graph

114 Commits

Author SHA1 Message Date
Shane
2944775261
Add define to disable OAuth support (#1713)
Redoing https://github.com/coturn/coturn/pull/1664 as requested. This
adds an optional OAUTH_DISABLED define to allow for disabling OAuth
support.
2025-07-02 11:36:50 +02: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
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
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
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
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
Michael Jones
d1db5e590d
Include what you use (#1512)
Use the include-what-you-use program to (partially) clean up header
includes, so that only includes which are needed, and no includes that
are not needed (or at least closer to that ideal) are done.

For a c-language project, the build-time improvements from this change
is minimal. This would have a much bigger impact on a C++ project than a
C-project for build times.

So for coturn, this change is mostly intended to just provide
consistency and make it easier to locate weird issues like strange
dependencies, and unnecessary connections between code.
2024-06-01 18:13:08 -07:00
redraincatching
90799f5c60
defined a magic number for stun fingerprinting (#1489)
The value `0x5354554e`, used twice in the `ns_turn_msg.c`, was unclear,
and was changed to a macro that better explained its usage, as defined
in [RFC
5389](https://datatracker.ietf.org/doc/html/rfc5389#section-15.5)
2024-05-26 18:34:10 -07:00
Stefan Junker
158fe9b698
Fix buffer overflow in generate_enc_password with increase rsalt by 2 (#1463)
before this change i see a bufferflow during `readable_string`.
2024-05-04 18:26:35 +02:00
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
Richard Russo
4bc872b663
strncpy doesn't return size_t (#1296)
follow up to https://github.com/coturn/coturn/pull/1282/files
2023-11-05 17:48:32 -08:00
Gustavo Garcia
597b36c5a2
Fix missing strncpy in fix_stun_check_message_integrity_str (#1282)
Co-authored-by: Gustavo Garcia <gustavogb@mail.com>
Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2023-10-04 10:06:40 -07: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
Gustavo Garcia
4e0d21e1b5
Fix memcpy len checks stun_is_challenge_response_str (#1280)
Add missing checks for length of realm/nonce/server_name before copying
those values to the buffer passed to stun_is_challenge_response_str.

The function stun_is_challenge_response_str is only used in uclient test
application.

Thank you very much @0xdea

Co-authored-by: Gustavo Garcia <gustavogb@mail.com>
2023-10-02 16:19:38 +02: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
Pavel Punsky
d3f0ad3be6
Update openssl API use to non-deprecated version (#1072)
Use version independent APIs for openssl-1.1.0 and above

Tested with turnutils_uclient against a turnserver with TLS and DTLS
modes
2022-11-02 19:36:20 -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
Arjun
716417e0fd
Fix : Issue 51563 in oss-fuzz (#1010)
```
==6418==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4e7530 in bcmp /src/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:906:10
    #1 0x55463d in stun_check_message_integrity_by_key_str coturn/src/client/ns_turn_msg.c:1989:5
    #2 0x554acc in stun_check_message_integrity_str coturn/src/client/ns_turn_msg.c:2008:9
    #3 0x5358c0 in LLVMFuzzerTestOneInput coturn/fuzz/FuzzStun.c:37:5
    #4 0x43ede3 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15
    #5 0x42a542 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:324:6
    #6 0x42fdec in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:860:9
    #7 0x459322 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #8 0x7f4cb21790b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/libc-start.c:308:16
    #9 0x42070d in _start
  Uninitialized value was created by an allocation of 'new_hmac' in the stack frame of function 'stun_check_message_integrity_by_key_str'
    #0 0x5538c0 in stun_check_message_integrity_by_key_str coturn/src/client/ns_turn_msg.c:1927
```
2022-10-08 17:59:08 -07:00
Pavel Punsky
bd9e44dd7c
Replace bcopy with memcpy (#991)
Replace all instances of `bcopy` with memcpy.

Inspired by https://github.com/coturn/coturn/pull/855
2022-09-20 10:39:11 +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
4ce784a878
Improve openssl3 and FIPS support (#955)
openssl-3.0 deprecated some APIs and introduced new APIs instead:

`SSL_get_peer_certificate ` -> `SSL_get1_peer_certificate `
`FIPS_mode()`->`EVP_default_properties_is_fips_enabled()`
`EVP_MD_CTX_set_flags()`->`EVP_default_properties_enable_fips()`
specifically for enabling FIPS mode

This change should workaround that by ifdef-ing old/new versions of
openssl and APIs - so pre-3.0 use existing APIs (so not change there)
and >=3.0 will use new APIs (whether it actually works or not is still
TBD as this is just a first step in openssl-3.0 support)

Should fix #886

Test Plan:
Run CI build that supports ubuntu-20.04 (openssl-1.1.1) and ubuntu-22.04
(openssl-3.0.2)
Both builds pass
None of them have FIPS support (which for 1.1.x stays the same as
before)

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-16 09:46:45 +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
Gustavo Garcia
f74f50c86d
Merge pull request #773 from haseebq/performance_fix
Fix for performance regression caused by CVE-2020-4067 fix
2022-08-10 11:41:08 +02:00
Mészáros Mihály
54ef051844 Disable stun backward compatibility 2021-06-05 22:10:31 +02:00
Haseeb Abdul Qadir
e88de80abd Make sure we zero out any padding added to the attribute 2021-05-22 11:53:25 -04:00
Cédric Krier
5b6739a793 Do not use FIPS and remove hardcode OPENSSL_VERSION_NUMBER with LibreSSL
Fix #552
2020-07-19 10:48:44 +02:00
islamoglus
a43d3b63b4 ignore md5 for boringssl 2020-06-11 07:40:00 +03:00
Mészáros Mihály
4722697645 Fix compiler warnings
* Changed type from int to size_t to avoid warning
  warning: comparison between signed and unsigned integer expressions
* Fixed string truncation warning
2020-03-03 15:26:01 +01:00
Mészáros Mihály
c534eaef41 Merge branch 'input-validation'
Merge PR #472
2020-02-18 14:46:11 +01:00
Mészáros Mihály
79361c170f Merge branch 'fips' 2020-02-18 14:36:37 +01:00
Mészáros Mihály
4badbbf018
Merge pull request #470 from FeralInteractive/compiler-fixes
Compiler warning fixes
2020-02-12 07:56:54 +01:00
Feral Interactive
efa7a47632 Silence shadow variable declaration warning.
'sar', 'value', and 'vlen' already exist in an outer scope and are safe to reuse since they're overwritten before being used again.
2019-11-20 00:03:46 +00:00
Feral Interactive
9b8baa8055 Validate the size of an attribute before returning it to the caller.
Previously this was being done in stun_attr_get_next_str() to check that the previous attribute didn't exceed the size of the underlying buffer, however by that point any maliciously crafted attributes would have already had their chance to attack the caller.
2019-11-19 23:48:41 +00:00
Feral Interactive
14cb1c94e7 Validate the size of the buffer in stun_get_command_message_len_str().
Without this the caller could read off the end of the underlying buffer if it receives a maliciously crafted packet with an invalid header size.
2019-11-19 23:48:34 +00:00
Feral Interactive
353e3b98e6 Add some casts to appease compiler warnings about narrowing. 2019-11-19 23:47:19 +00:00
Feral Interactive
b1990b6130 Liberally apply const where appropriate. 2019-11-19 23:47:11 +00:00
Feral Interactive
763d1f1b9c Fix a memory leak when an SHATYPE isn't supported.
Deallocating `str` happens at the end of the function, so don't skip it when encountering an unsupported SHATYPE.
2019-11-19 23:45:37 +00:00
Byron Clark
0e03fa86df Remove OPENSSL_FIPS wrappers.
Because we're building with a FIPS enabled OpenSSL instead of the FIPS
canister, the resulting build should be usable on both FIPS and non-FIPS
enabled systems. Since we can't rely on building with a FIPS enabled
OpenSSL, defer the check to runtime.
2019-05-26 10:52:51 -06:00
Byron Clark
6b01b6f450 Allow MD5 in FIPS mode.
This is one of those special cases where a non approved cryptographic
algorithm is allowed when operating in FIPS mode. Inform OpenSSL that
this is the case.

In the STUN RFC the long-term credential mechanism requires that the key
used in the HMAC-SHA1 generation be the MD5 of specific values:
https://tools.ietf.org/html/rfc5389#section-15.4

Since this is obfuscating parameters to be used in an approved
cryptographic algorithm, this is allowed usage per the [FIPS 140-2 Implementation Guidance](https://csrc.nist.gov/csrc/media/projects/cryptographic-module-validation-program/documents/fips140-2/fips1402ig.pdf).
See page 81.

Without this change, coturn crashes when trying to set up any long-term
credential mechanism.
2019-05-24 00:16:36 +00:00
Byron Clark
68feff5ca3 Use EVP_MD_CTX instead of MD5_CTX.
Switch to EVP_MD_CTX APIs for MD5 to match how other digest types are
created in this function.
2019-05-24 00:01:52 +00:00
Bradley T. Hughes
d2ee3ac291 Remove [su]{08,16,32,64}bits type defines
Do not overload the standard types with #defines, just use them
directly.
2019-03-08 09:08:30 +01:00
Bradley T. Hughes
7a43aae7c3 Remove ns_bzero(), ns_bcopy(), and ns_bcmp()
Do not overload bzero(), bcopy(), and bcmp() from strings.h
2019-03-07 08:39:20 +01:00
Bradley T. Hughes
b50fc77124 Remote turn_free()
Do not overload free() with a different API.
2019-03-07 07:58:12 +01:00
Bradley T. Hughes
fef016901e Remove turn_malloc()
Do not overload malloc() from stdlib.h
2019-03-06 23:38:20 +01:00
Mészáros Mihály
53bae81e78 SPARC64 mem alingment fixes 2019-03-02 21:18:41 +01:00
Oleg Moskalenko
95eec6b88b minor cleaning 2016-10-03 22:48:40 -07:00
Richard Garnier
027a760066 fix memory initialization 2016-10-04 09:50:05 +09:00
Richard Garnier
5a24333eaa max lifetime parameters 2016-09-20 13:57:31 +09:00
Mészáros Mihály
9b7256e32f nonce decode and display & fix auto random nonce generation 2016-09-07 15:28:27 +02:00
Oleg Moskalenko
7624480c8f compilation warning fixed 2016-09-05 21:53:39 -07:00