374 Commits

Author SHA1 Message Date
Achim Kraus
8195166595 dtls-client.c: add support_cid option.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2025-05-04 17:43:56 +02:00
Achim Kraus
e7cf9db7d6 Add client dtls connection ID.
Simple client side implementation indicates support and uses the cid of
the server, when negotiated by that.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2025-05-04 17:43:08 +02:00
Jon Shallow
8a9e048120 sigint: Handle SIGINT cleanups cleanly
Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2025-01-18 14:03:21 +01:00
Achim Kraus
1f1bc2ab57 dtls-client.c: apply option for local port.
The previous version ignores the option for the local port. That may be
caused by issues using the same default local port for the server and
client.
This enables the use of an specific local port and changes the default
to an ephemeral free port, similar to quite a lot of other UDP clients.
The DEFAULT_PORT is therefore only used for the destination.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-08-28 16:20:56 +02:00
Achim Kraus
c063d72770 dtls-client.c: accept options after arguments.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-08-28 16:01:26 +02:00
Achim Kraus
11c5c53719 dtls.c: support empty client certificate.
Use empty client certificate, if a certificate is requested but no
certificate is available.

Issue #186

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-08-28 11:30:58 +02:00
Achim Kraus
f7ced4e426 crypto.h: use DTLS_EC_KEY_SIZE for dtls_handshake_parameters_ecdsa_t.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-08-27 18:39:35 +02:00
Achim Kraus
1f2dbaa826 dtls.c, crypto.h: add documentation for handling dtls_user_parameters_t.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-08-27 18:37:36 +02:00
Achim Kraus
9d6cf54a31 dtls.c: use more precise logging messages.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-06-02 17:20:16 +02:00
Achim Kraus
4a6a782360 dtls-server.c: check for left cli-arguments.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-05-13 10:27:26 +01:00
Achim Kraus
802e137b92 dtls.c: fix formatting of GET_VAR_FIELD.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-05-13 10:18:06 +01:00
Achim Kraus
42732c4d45 README.md: add some details and references.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-05-13 10:17:40 +01:00
Sebastian Schüller
c6609c83e3 dtls_debug.c: only enable _GNU_SOURCE for MinGW builds. 2024-05-13 10:17:15 +01:00
Achim Kraus
1ccfd9c0a2 dtls.c: exclude Extensions when calculating cookie.
Do not calculate the cookie using the Extensions as these are
different between DTLS1.2 and DTLS1.3

https://datatracker.ietf.org/doc/html/rfc6347#section-4.2.1

When responding to a HelloVerifyRequest, the client MUST use the same
parameter values (version, random, session_id, cipher_suites,
compression_method) as it did in the original ClientHello.  The
server SHOULD use those values to generate its cookie and verify that
they are correct upon cookie receipt.

https://www.rfc-editor.org/rfc/rfc9147.html#section-5.3

The ClientHello up to, but not including the Extensions is the same for
DTLS1.2 and DTLS1.3

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-05-12 07:57:43 +01:00
Achim Kraus
a83514b8fa dtls.c: add check for valid handshake message type when version is 1.0.
Fixes issue #209.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-05-12 07:56:04 +01:00
Achim Kraus
8c55636287 dtls_debug.h: explicitly cast macro parameter to size_t.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2024-03-18 11:18:31 +00:00
Achim Kraus
0e865aae7c dtls_debug.c: enable _GNU_SOURCE to prevent %zu error on MinGW build.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-12-22 11:09:07 +01:00
Jon Shallow
95d02ee28e crypto.c: Support -O3 compiler builds
Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2023-09-13 12:56:29 +02:00
Achim Kraus
f1d47d533b Fix includes for zephyr 3.2.99.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-08-07 14:55:38 +02:00
Achim Kraus
9afb881a2c dtls.c: explain calculation for cipher suites (max).
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-08-07 14:54:41 +02:00
Achim Kraus
b3d84685b3 Add renegotiation info to test clients.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-07-27 15:47:12 +02:00
Achim Kraus
e64b6c1aad dtls.c: add RFC5746 minimal version implementation.
Supports RFC5746 minimal version without renegotiation.
Add detailed documentation about the message length calculations.
Add TLS_EMPTY_RENEGOTIATION_INFO_SCSV to DTLS_CH_LENGTH_MAX.
Remove eclipse_curves from ServerHello length.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-07-27 15:47:12 +02:00
Jon Shallow
4eed14e1a7 peer.c: Include <string.h> to fix memcpy() warning 2023-07-27 13:28:15 +02:00
Olaf Bergmann
0427dd4b4e tests/Makefile.in: set _POSIX_C_SOURCE=200112L
This change replaces the pre-processor symbol _GNU_SOURCE set in
the Makefile with _POSIX_C_SOURCE to provide support for kill(2)
and getaddrinfo(3).

Change-Id: Ib4c9ade28b663d86a182ee34cbf262526240cd7d
2023-07-27 13:27:42 +02:00
Olaf Bergmann
f04c89c367 dtls-client.c: set NI_MAXSERV if not defined
NI_MAXSERV is defined automatically when _GNU_SOURCE is provided.
This change sets the value to 32 (the default on Linux) when undefined.

Change-Id: I37bb5509383cb53b6e35cefa635f4647a3e2c721
2023-07-27 13:27:42 +02:00
Benjamin Valentin
ba830a3906 dtls_debug: mock dsrv_log() when NDEBUG is set
Setting NDEBUG already replaces dtls_dsrv_hexdump_log(), dtls_dsrv_log_addr()
etc with dummy implementations.

This extends this to also replace dsrv_log() and dtls_{get,set}_log_level()
with a no-op implementation.
2023-07-24 10:59:58 +02:00
Jon Shallow
7fd6414648 tests: Fix compiler clash over index usage in test suites
Some compilers complain that index is already defined in <strings.h>.
Replace index with lindex.

Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2023-07-22 15:29:10 +02:00
Olaf Bergmann
d055d8d001 session.h: Move inclusion of string.h into .c files
string.h is required for memcmp() that is used in session.c and
dtls_debug.c. Therefore, the header file needs to be included
only in these two files.

Change-Id: I11db1c37a7cc13d8fa2826f6d3e38d3765f4a4ec
2023-07-22 15:19:13 +02:00
Achim Kraus
7667849af3 dtls.c: fix length checks in SKIP_VAR_FIELD.
Check for field length before reading the length to skip from the field.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-07-14 16:29:43 +02:00
Achim Kraus
62975bfe65 dtls.c: fix length checks in check_certificate_request.
Add GET_VAR_FIELD.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-07-14 16:29:43 +02:00
Achim Kraus
3159ca6065 dtls.c: remove rudiments of renegotiation.
Renegotiation has been removed.
Cleanup some leftovers internal renegotiation errors.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-07-12 16:53:27 +02:00
Jon Shallow
c9bbc0340f ccm.c: Remove documentation erroneous return statement for void function
Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2023-07-12 11:31:12 +02:00
Achim Kraus
b82a72b816 Amend source formatting with rule for function definitions with multiple
lines.

See discussion in PR #184.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-24 13:21:08 +02:00
Jon Shallow
a5fa982aa5 dtls_prng_posix.c: Fix random() only support
Use of random() requires that _GNU_SOURCE is defined.
Cannot use variables named rand.

Make sure that dtls_prng.o is rebuilt whenever any of the
platform-specific/dtls_prng_*.c files are updated.

Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2023-04-24 11:31:29 +02:00
Jon Shallow
11c8e7d612 dtls.c: Reduce logging for unsupported tls extensions
Every unsupported tls extension is logged using dtls_warn(), and the default
logging level is set to DTLS_LOG_WARN.

Update logging call to dtls_notice(), to reduce logging output noise.

Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2023-04-24 11:30:34 +02:00
Achim Kraus
90ca321f0e Add cipher suite selection to test applications.
Introduce new cli argument -c.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-17 14:07:10 +02:00
Achim Kraus
9eb6780c4c Fix some typos and return values.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-17 14:07:10 +02:00
Achim Kraus
f08802f93d dtls.c: add callback for peer specific selection of parameters as cipher
suites.

Adds dtls_user_parameters_t for these user parameters.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-17 14:07:10 +02:00
Achim Kraus
004aba8f7a dtls.c: add cipher_suite_param_t
Use cipher_suite_param_t for cipher-suite specific mac_len and
key_exchange_algorithm. Introduce dtls_cipher_index_t for simplified
cipher-suite parameter lookup. Cleanup old functions.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-01 10:29:04 +02:00
Achim Kraus
224aa865ea dtls.c: add support for CCM cipher suites.
Add cipher suites with full 16 byte MAC.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-01 10:29:04 +02:00
Achim Kraus
de74a02cb5 dtls.c: fix processing of alerts.
If alerts remove the peer, additional records need to be dropped.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-03-31 23:46:52 +02:00
Benjamin Valentin
5e14e4930b RIOT: make use od for hexdump 2023-02-25 14:37:17 +01:00
Achim Kraus
5477e6885b dtls_prng_posix.c: fail for posix without HAVE_GETRANDOM nor
HAVE_RANDOM.

Support random().
Add #error with explanation and hint to solve it.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-02-25 14:34:25 +01:00
Achim Kraus
86f23c65ff dtls-server.c: drop messages exceeding the buffer size.
Add function "is_command" and command "server:exit".

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-01-24 13:08:18 +01:00
Achim Kraus
efb9dc203e dtls-client.c: fix "buf" size error in "handle_stdin".
Replace the "sizeof(buf)" with passed in size.
Drop received messages exceeding the buffer size.
Introduced "buf_ready", true, if last character in "buf" is a newline.
Use "strstr" to detect command.
Add "client:exit" command.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-01-24 13:08:18 +01:00
Achim Kraus
0c4ddd0e1c dtls-server.c: apply source code formating.
Add license header.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-01-24 13:08:18 +01:00
Achim Kraus
5aca36f9c5 dtls-client.c: apply source code formating.
Add license header.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-01-24 13:08:18 +01:00
Achim Kraus
c58f484ac4 dtls.c: minor cleanup of cookie check.
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-01-21 11:14:01 +01:00
Benjamin Valentin
4cb6adcd58 RIOT: remove redundant CFLAGS
Those flags are already configured by the RIOT package.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2023-01-21 11:13:28 +01:00
Benjamin Valentin
8a36274474 RIOT: make use of log.h for dsrv_log()
Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
2023-01-21 11:13:28 +01:00