Commit Graph

1464 Commits

Author SHA1 Message Date
Pavel Punsky
080ca02768
Update libtelnet to 0.23 (portability issues) (#1005)
Split out work on libtelnet from #855 
Required to update libtelnet to introduce compatibility with Windows

This change contains vanilla code of
[libtelnet](https://github.com/seanmiddleditch/libtelnet) v0.23 (latest
tag)

Test Plan:
- run turnserver locally, set cli password, connect to the turnserver
cli interface
- run a few commands - get output
2022-10-07 14:51:46 -07:00
Pavel Punsky
3492644c11
Remove debug publish to redis (#1008)
This code is in as back as git can see. Removed for now as it has no use
at all.
Also reduces traffic to redis (though will not reduce any load on redis)

Refs #150
2022-10-06 16:57:44 -07:00
Pavel Punsky
d9e74af75d
Cleanup unused include of header files (#1004)
Using clang-tidy to detect unused header files

Inspired by #855

Test Plan:
- Rebuild all on mac, review no warnings/errors
- Pass builds/docker build - review for no issues
2022-10-05 10:28:40 +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
Tom Bevan
9a6393e908
Malformed response to mobility refresh request (#1006)
Hello, and thank you for this great project!

When sending a mobility refresh request, the server is responding with
an invalid stun packet. Specifically, only the last 24 bytes generated
for message integrity are sent.

Request:

![image](https://user-images.githubusercontent.com/4522385/193647719-c9038761-86fe-4eb3-b899-20cdd5084796.png)

Response:

![image](https://user-images.githubusercontent.com/4522385/193647883-31c919e0-f7ae-4db2-9b82-028bd8cdb24f.png)


This appears to be caused by the buffer length not being updated when
`STUN_ATTRIBUTE_SOFTWARE` is added to the response, as it's being
assigned to a `len` variable scoped to that conditional.

As a result, the next call to `stun_get_command_message_len_str` when
handling message integrity returns `-1` and resizes the buffer, etc.

Passing in the original `len` to `stun_attr_add_str` for attribute
software fixes the issue, but apologies if this is not the right way to
fix this!
2022-10-05 10:24:45 +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
05c0b6e34c
Build CI with prometheus support (#999)
Install dependencies and build with prometheus support during CI builds

Ubuntu 16.04 has issues supporting `MHD_USE_EPOLL_INTERNAL_THREAD` so
disabling it (using SELECT)
Should not impact anything as the only reason we use Ubuntu 16.04 is to
validate build against openssl-1.0.2

Fixes  #998
2022-09-29 14:03:03 -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
e87c42524a
Fix TLS1.3 support
Fix TLS1.3 support

`TLSv1_3_SUPPORTED` was not defined so TLS1.3 was not enabled properly
2022-09-28 20:28:09 -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
Joachim Bauch
57f5a25099
Use epoll for promhttp server if supported. (#997)
Before:
```
./bin/turnserver --prometheus -m 32
...
Socket descriptor larger than FD_SETSIZE: 2660 > 1024
0: : ERROR: Could not start Prometheus collector!
```

After:
```
./bin/turnserver --prometheus -m 32
...
0: : Prometheus collector started successfully.
```

Also added `MHD_USE_ERROR_LOG` so the actual problems during startup of
promhttp are printed. Without it the `Socket descriptor larger than
FD_SETSIZE: 2660 > 1024` error was not visible and finding the cause of
the startup problems of promhttp was not obvious at first.
2022-09-27 10:25:14 -07:00
Pavel Punsky
2cb395caa5
Fix issues reported by cppcheck (#987)
Fix a few additional warnings raised by cppcheck

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-24 10:08:35 +02: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
Gustavo Garcia
0f0197e250
Add CI tests in older ubuntu version (#981)
This should help catching issues like the one in #978 with older
versions of openssl or other libraries used
2022-09-19 18:51:02 +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
9370bb742d
Fix a warning (#988)
There are too many defines that are, eventually, used in one place so
just inlining.

Current code generates following warning:
```
warning: macro expansion producing 'defined' has undefined behavior [-Wexpansion-to-defined]
```

With the fix there is no warning

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-17 08:29:32 +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
Robert Scheck
50f33bf04e
Preserve file timestamps when using install(1) (#983)
- Preserve file timestamps when using `install`
- Use permissions `0644` rather than default `0755` for installing man
pages

The alternative calls of `cp` are using `cp -p` as well (if `install` is
unavailable).
2022-09-16 09:44:00 +02:00
Pavel Punsky
9af9f6306a
Fix renegotiation flag for older version of openssl (#978)
`SSL_OP_NO_RENEGOTIATION` is only supported in openssl-1.1.0 and above
Older versions have `SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS `

Fixes #977 and #952

Test:
Build in a docker container running running openssl-1.0.2g (ubuntu
16.04) successfully (without the fix getting the same errors)
2022-09-14 12:29:26 +02:00
tyranron
8b66fa4ff2
Improve GitHub release notes of Docker image 2022-09-13 15:52:09 +03:00
tyranron
01d725e65b
Improve Docker CI pipeline
- omit publishing and releasing Docker images in forks
- verify Git tag to match Makefile before releasing
- auto-cancel concurrent CI pipelines for the same Git ref
2022-09-13 13:19:07 +03:00
tyranron
79f9c65dd8
Upgrade Docker image to 4.6.0 Coturn version 2022-09-13 12:38:37 +03:00
tyranron
b7b43edd33
Fix ChangeLog for 4.6.0 release (#976) 2022-09-13 12:34:00 +03:00
Gustavo Garcia
f67326fe35
Increase version to 4.6.0 (#976)
Increase the version number for the 4.6.0 release.
It uses the codename Gorst.
2022-09-13 09:33:12 +02:00
Gustavo Garcia
35c9e8d52f
Update ChangeLog 2022-09-12 19:29:06 +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
e2ff7caf9d
Fix long log line printing (#974)
`vsnprintf` will stop at the max buffer size as provided in its 2nd
argument

But the return value is `The number of characters that would have been
written if n had been sufficiently large` meaning it can be larger than
actual buffer size
`fwrite` will actually use the larger, incorrect number and dump
unrelated memory to log (and crash with high confidence)

Test:
- Query admin interface with super long path (>16KB) - crash
- With the fix - no crash with the same input, log line cut off

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-08 11:24:28 +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
a09aa989b6
Do not write outside of a buffer in admin interface (#972)
Writing outside of a buffer can only happen if incoming HTTP request is longer than UDP_STUN_BUFFER_SIZE (16KB).

This change validates that the request is no longer than the buffer size and drops it if it is the case

Fixes #342

Test plan:
- Run in debugger and send a 16KB request using curl - response returns, logs correct
- Send 16KB + 1b request - warning logged and request dropped

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-05 12:07:07 -07:00
Pavel Punsky
6d9b75dbef
Fix uclient certificate loading bug (#970)
When using `turnutils_uclient` with `-S` flag (TLS or DTLS) it is not required to load certificates. Only load certificates when corresponding flags are provided

Fixes #376 which prevented using `turnutils_uclient` for testing TLS/DTLS connections

Test plan:
- Run local turnserver with certificates `./bin/turnserver --cert ./bin/public.pem --pkey ./bin/private.key --use-auth-secret  --static-auth-secret=secret --realm=north.gov --allow-loopback-peers --no-cli --verbose`
- Run fixed uclient without TLS/DTLS`./bin/turnutils_uclient -e 127.0.0.1 -X -g -u user -W secret 127.0.0.1` and get success result (just to make sure non-secure still works)
- Run fixed uclient with TLS `./bin/turnutils_uclient -e 127.0.0.1 -X -g -u user -W secret -t -S 127.0.0.1` and get success result
- Run fixed uclient with DTLS `./bin/turnutils_uclient -e 127.0.0.1 -X -g -u user -W secret -S 127.0.0.1` and get success result
- Run unpatched uclient with TLS `./bin/turnutils_uclient -e 127.0.0.1 -X -g -u user -W secret -t -S 127.0.0.1` - error about missing certificate files

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-04 14:56:49 +02:00
Pavel Punsky
483c7223be
Fix duplicate TCP flag in run_tests.sh script (#971)
Typo that caused UDP test to actually run TCP
2022-09-04 14:56:10 +02:00
Pavel Punsky
8dab694478
Update ChangeLog 2022-08-29 13:24:00 -07:00
Gustavo Garcia
c8663f4a91
fix turn session leak (#962)
Actually, as below, before fixing, the sessions_map may be larger and
larger when register_callback_on_ioa_socket inside
open_client_connection_session retrun -1. The reason is that, if
register_callback_on_ioa_socket return -1, no read/write/ event will be
registered and no timeout event will be registered, in this case, the
session will never be deleted from sessions_map.

![image](https://user-images.githubusercontent.com/23566147/186558792-089ed9b2-9eb0-4ece-b7c0-99eaca10ea99.png)

After fixing, when register_callback_on_ioa_socket fail,it doesn't
return immediately, instead, we still register
client_to_be_allocated_timeout_handler in the next step of
open_client_connection_session. In this case, the unuseful session will
be deleted and freed after timeout.

@eakraly @ggarber
2022-08-29 21:56:47 +02:00
Gustavo Garcia
b26a621eb1
Add build and test for openssl-3.0 (#961)
Add GitHub action that builds and runs tests using openssl-3.0 (default
version in ubuntu 22.04)

It is expected to fail until openssl-3.0 compatibility is introduced
(#955)

A change in cmake action is to make sure we actually run ubuntu:20.04
(which uses openssl-1.1.1). Otherwise, GH will change the version of
ubuntu-latest at some point and it might not be very visible
2022-08-28 20:21:47 +02:00
Gustavo Garcia
a5050b39d4
Document dependency of new-log-timestamp-format on new-log-timestamp (#963)
Fixes #847
2022-08-28 19:36:06 +02:00
Pavel Punsky
41a8aa09ff Document dependency between new-log-timestamp-format and new-log-timestamp 2022-08-27 20:34:35 -07:00
Pavel Punsky
d06aef24b7 Move to matrix structure 2022-08-26 10:49:31 -07:00
huhaipeng
f22376ce29 fix turn session leak 2022-08-26 11:17:13 +08:00
Pavel Punsky
9d412d86b6 Lock runner version on ubuntu 20.04 so we get openssl-1.1.1 2022-08-25 20:00:11 -07:00
Pavel Punsky
9d3a649ede no message 2022-08-25 19:57:05 -07:00
Pavel Punsky
5a86dd373c no message 2022-08-25 19:48:51 -07:00
Pavel Punsky
bd266b383d Add new actions: build and test with 3 different versions of openssl 2022-08-25 16:56:51 -07:00
Gustavo Garcia
4909e506ae
Enable compilation of coturn on Solaris 11.4 (#951)
Unfortunately, PR #789 breaks the possibility to compile coturn in Oracle Solaris 11.4 (SRU 48). It is caused by the fact that LOG_FTP is not defined in Oracle Solaris' "/usr/include/sys/syslog.h". 

They define the following syslog facility codes:
```
#define LOG_KERN        (0<<3)  /* kernel messages */
#define LOG_USER        (1<<3)  /* random user-level messages */
#define LOG_MAIL        (2<<3)  /* mail system */
#define LOG_DAEMON      (3<<3)  /* system daemons */
#define LOG_AUTH        (4<<3)  /* security/authorization messages */
#define LOG_SYSLOG      (5<<3)  /* messages generated internally by syslogd */
#define LOG_LPR         (6<<3)  /* line printer subsystem */
#define LOG_NEWS        (7<<3)  /* netnews subsystem */
#define LOG_UUCP        (8<<3)  /* uucp subsystem */
#define LOG_AUTHPRIV    (10<<3) /* sensitive/private security/auth messages */
#define LOG_AUDIT       (13<<3) /* audit subsystem */
#define LOG_CRON        (15<<3) /* cron/at subsystem */
        /* other codes through 15 reserved for system use */
#define LOG_LOCAL0      (16<<3) /* reserved for local use */
#define LOG_LOCAL1      (17<<3) /* reserved for local use */
#define LOG_LOCAL2      (18<<3) /* reserved for local use */
#define LOG_LOCAL3      (19<<3) /* reserved for local use */
#define LOG_LOCAL4      (20<<3) /* reserved for local use */
#define LOG_LOCAL5      (21<<3) /* reserved for local use */
#define LOG_LOCAL6      (22<<3) /* reserved for local use */
#define LOG_LOCAL7      (23<<3) /* reserved for local use */
```

So omitting LOG_FTP should fix this for Solaris. As I really doubt that it is needed, I hereby submit a PR which omits LOG_FTP for all operating systems. Other Solaris derivatives (OpenIndiana Hipster, OmniOS) don't seem to be affected, I've checked and found that in their recent versions, LOG_FTP is defined. FreeBSD does also define LOG_FTP.
2022-08-23 09:24:02 +02:00
Steffen Moser
7cfa7b1c4d
Merge branch 'coturn:master' into master 2022-08-23 09:01:03 +02:00
Gustavo Garcia
c964054811
Disable systemd when building on macOS using CMake (#953)
systemd is not available on macOS - should be disabled in CMake 

Test plan:
- Run cmake in a clean folder
- Run make
- Observe that compilation error about missing include `<systemd/sd-daemon.h>` is gone
2022-08-23 09:00:07 +02:00
Steffen Moser
02461e9fbc First step to re-enable compilation with OpenSSL 1.0.x 2022-08-23 08:58:45 +02:00
Steffen Moser
4ffc49d7be
Merge branch 'coturn:master' into master 2022-08-23 08:56:31 +02:00
Pavel Punsky
ed29e986c1 Disable systemd when building on macOS using CMake 2022-08-22 18:53:43 -07:00
Pavel Punsky
7a38f02699
Fix cmake build on macOS (#949)
macOS does not have `pthread_barrier_*` so need to define `TURN_NO_THREAD_BARRIERS` as a workaround

Fixes #946 

Tests plan: 
- run cmake to generate make files
- run make to build turnserver
- run `examples/run_tests.sh` and pass successfully
2022-08-22 16:27:21 -07:00
Steffen Moser
b722c84b45 Allow compilation on Solaris 11.4 2022-08-22 11:22:59 +02:00