Commit Graph
1642 Commits
Author SHA1 Message Date
obgm 5b1d753da0 Merge pull request #365 from mrdeep1/dtls_retry
Fix GnuTLS DTLS retries when Client Hello is not responded to
2019-06-28 12:19:45 +02:00
obgm 0b75251acd Merge pull request #349 from mrdeep1/gnutls_mem_leek
Fix memory leak in GnuTLS client that does not have security defined
2019-06-27 18:19:39 +02:00
Jon Shallow cc63387dad Fix memory leak in GnuTLS client that does not have security defined
If a CoAP client using GnuTLS does not have PSK or PKI security defined
but communicatioes with coaps:// with a CoAP server that has PKI defined,
then there is a memory leak when the session is closed down.

src/coap_gnutls.c:

Free off PKI credentials if a client and PSK or PKI was not explicitly
defined in coap_dtls_free_gnutls_env().
2019-06-27 14:52:58 +01:00
obgm d1642c3e68 Merge pull request #361 from mrdeep1/block2_well-known_core
Fix final data size in last BLOCK2 response for .well-known/core
2019-06-27 15:32:36 +02:00
obgm 39b2505a2e Merge pull request #367 from mrdeep1/fix_openssl_1_1_1c
Stop valgrind errors when using OpenSSL 1.1.1c
2019-06-27 14:07:34 +02:00
obgm c4aa140127 Merge pull request #366 from mrdeep1/size1_addition
Add SIZE1 Option when sending BLOCK1 Option in packets in Client
2019-06-27 13:59:30 +02:00
obgm 5f5ab48e34 Merge pull request #340 from mrdeep1/cancel_rst_observe
Fix RST deleting observer for non-confirmable observe
2019-06-26 14:39:25 +02:00
Jon Shallow ff8f8d2c6b Stop valgrind errors when using OpenSSL 1.1.1c
Issue introduced by OpenSSL 1.1.1c causes valgrind errors to be reported.  See
https://www.mail-archive.com/openssl-commits@openssl.org/msg21701.html and
https://github.com/openssl/openssl/pull/8606 which did not make 1.1.1c

scripts/build.sh:
tests/valgrind_suppression:

Temporarily suppress valgrind errors when SSL_CTS_new() is called when running
the tests.

Note: This suppression will also need to be applied when running valgrind
against other CoAP executables using OpenSSL 1.1.1c to prevent the valgrind
errors getting reported.

src/coap_openssl.c:

memset cookie_secret to 0 to stop valgrind warning.
2019-06-25 20:26:43 +01:00
obgm d7eab5f22d Merge pull request #364 from mrdeep1/coap_deprecated
Fix COAP_DEPRECATED for Windows C++ builds
2019-06-25 11:11:19 +02:00
Jon Shallow 21f16515b5 Add SIZE1 Option when sending BLOCK1 Option in packets
As per https://tools.ietf.org/html/rfc7959#section-4
...
Implementation Notes:

   o  As a quality of implementation consideration, block-wise transfers
      for which the total size considerably exceeds the size of one
      block are expected to include size indications, whenever those can
      be provided without undue effort (preferably with the first block
      exchanged)
...

examples/client.c:

Include SIZE1 Option when sending data using BLOCK1 Option.
2019-06-24 16:21:30 +01:00
Jon Shallow 3a50a29ced Fix GnuTLS DTLS retries when Client Hello is not responded to
GnuTLS currently does not retry to send the Client Hello packets if there was
no (Server Hello) response.  This was never correctly implemented.

src/coap_gnutls.c:

Fix receive_timout() so that it differentiates between DTLS and TLS.
If DTLS, if data has already been read in, indicate this.
if this is a coap_dtls_handle_timeout() call, only check readfds
(writefds will always be true, causing confusion).

Set DTLS timeouts where appropriate.

Update coap_dtls_*_timeout() functions to return the correct values.

include/coap2/coap_dtls.h:
src/coap_gnutls.c:
src/coap_io.c:
src/coap_notls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:

Add in coap_tick_t now parameter to coap_dtls_get_timeout() for better
accuracy.
2019-06-21 16:51:01 +01:00
Jon Shallow da33226631 Fix COAP_DEPRECATED for Windows C++ builds
include/coap2/libcoap.h:

Simplify COAP_DEPRECATED definition to generically handle Windows
or other builds when setting the define for COAP_DEPRECATED.

Fixes #363
2019-06-21 09:47:24 +01:00
Jon Shallow d84ac69b67 Fix final data size in last BLOCK2 response for .well-known/core
src/net.c:

Corect the length for the final block size.

Add in an ETAG and SIZE2 option into the response as suggested by RFC7959.

examples/client.c:

Warn if URI path is too long for internal buffer (found when testing that
a large WellKnown response triggered sending BLOCK2 correctly).

Increase internal buffersize to allow longer URIs.

To reproduce issue

coap-client -b 256 coap://127.0.0.1/.well-known/core

As reported by Zafi Ramarosandratana.  See #360 which this fixes.
2019-06-20 12:35:57 +01:00
Olaf Bergmann a5ffdf323d coap-server.c: Fix NULL pointer dereferencing in hnd_get()
As the field value in struct dynamic_resource_t may be NULL,
hnd_get() must check before accessing resource_entry->value->length
and resource_entry->value->s.

This bug was detected by Andy Ryan doing a GET after a PUT with
an empty payload to unknown_put/something.
2019-06-06 10:12:34 +02:00
obgm e7349da198 Merge pull request #348 from mrdeep1/message_id
Remove unused message_id from coap_context_t and coap_async_t
2019-06-04 14:34:48 +02:00
obgm b1cd797269 Merge pull request #339 from mrdeep1/client_tcp_b_issue
coap-client: Fix using -b NN with TCP connections
2019-06-04 14:33:01 +02:00
obgm 1a5f75e3c8 Merge pull request #356 from mrdeep1/no_listening_server
Fix handling ICMP Port Unreachable messages
2019-06-04 14:26:43 +02:00
Jon Shallow b1ebb503b4 Fix handling ICMP Port Unreachable messages
Once a ICMP Port Unreachable message is received, the session is
disconnected by a call to coap_session_disconnect().  However if the session
is of type CON,  the logic currently tries to retransmit the packet, but
nothing gets sent out.

src/coap_session.c:

Make sure that any entries on the context->sendqueue for the disconnected
session are removed.

examples/client.c:

Add in a Nack handler so that the client immediately exits on the session
disconnect.  Additionally this also tidies up the exit after transmission
retries.
2019-06-03 20:58:08 +01:00
Olaf Bergmann a2c3cc54e3 coap_session.c: Fix format string for size_t argument
This change removes a compiler warning caused by a wrong format string
argument in debug output.
2019-05-09 15:35:52 +02:00
Olaf Bergmann 552fc37cde coap_debug.c: Improve len parameter handling for inet_ntop()
Commit 32e219a has resolved an issue with the size parameter for
inet_ntop() in a way that introduces errors on certain Linux
platforms. This change now passes the exact size for AF_INET
and AF_INET6 to fix that.
2019-05-09 14:09:41 +02:00
Jon Shallow 93e558ba02 Remove unused message_id from coap_context_t and coap_async_t
It appears that message_id was left in coap_context_t and coap_async_t
when coap_session_t was created.

include/coap2/async.h:
include/coap2/net.h:

Remove message_id.

src/net.c:

No longer just set message_id.
2019-05-06 15:51:23 +01:00
obgm a5f434e685 Merge pull request #337 from mrdeep1/have_struct_cmsghdr
Handle platforms that do not have 'struct cmsghdr' defined
2019-04-26 15:35:53 +02:00
Jon Shallow 173f160498 Handle platforms that do not have 'struct cmsghdr' defined
configure.ac:

Test for the presence of 'struct cmsghdr' and set HAVE_STRUCT_CMSGHDR
if appropriate.

src/coap_io.c:

Revert to recvfrom() and sendto() if HAVE_STRUCT_CMSGHDR is not defined,
instead of using recvmsg() and sendmsg().
2019-04-26 13:34:16 +01:00
obgm 633ed03f03 Merge pull request #333 from mrdeep1/new_dtls_sessions_lost
Fix DTLS session loss when multiple connections in a short time
2019-04-26 14:00:53 +02:00
Jon Shallow 3829cd6137 Fix DTLS session loss when multiple connections in a short time
endpoint->hello is used to hold the 5 tuple etc. information about a new
connection that has come in.  Once the DTLS handshake has been completed
a new coap_session_t is created for the ongoing encrypted work.

However, if a second new DTLS request comes in before the first session
has completed the DTLS handshakes, it will overwrite the endpoint->hello
information causing the first request to stall / get lost.

GnuTLS already has to check that the initial DTLS packet is a Client Hello
before starting up a GnuTLS session, so moving this logic up a level to
the initial DTLS packet makes sense to create a coap_session_t at this
point and getting rid of the temporary endpoint->hello gets rid of this
issue.

Makefile.am:

Replace coap_endpoint_new_dtls_session with coap_session_new_dtls_session

include/coap2/coap_session.h:

Remove coap_session_t hello;
Replace coap_endpoint_new_dtls_session with coap_session_new_dtls_session

src/coap_gnutls.c:

Remove references to endpoint->hello
Remove Client Hello check code (move it to coap_endpoint_get_session())

src/coap_io.c:

Remove references to freeing off ep->hello

src/coap_session.c:

Remove endpoint->hello code.
Check for Client Hello in coap_endpoint_get_session() if no session, is DTLS
and don't build coap_session if not a Client Hello.
Otherwise, always build a new coap_session.

Timeout Client Hello session if inactive to prevent a DoS.

Replace coap_endpoint_new_dtls_session with coap_session_new_dtls_session

src/coap_net.c:

Replace coap_endpoint_new_dtls_session with coap_session_new_dtls_session
2019-04-26 12:45:58 +01:00
Jon Shallow 7a4d2db8f3 Fix RST deleting observer for non-confirmable observe
Code works as expected for confirmable observes as the sent pdu is
retained for potential re-transmission.

For non-confirmable observes, the RST is seen in the response packet but
previously had no way of finding the observe/subscription to cancel.

Keep the last sent message id in coap_subscription_t (as tid) and when the
RST comes in, search for the subscription that has the same message id as
the pdu and remove that subscription.

include/coap2/subscribe.h:

Add in tid to coap_subscription_t (as per coap_pdu_t).

src/net.c:

Match tid in incoming RST pdu with a subscription.  If found, delete the
subscription.

src/resource.c:

Save tid in both pdu and subscription when sending off an observe response.

To test code, make the following temporary change to coap-client

diff --git a/examples/client.c b/examples/client.c
index 4d3e4c7..0020b68 100644
--- a/examples/client.c
+++ b/examples/client.c
@@ -348,7 +348,8 @@ message_handler(struct coap_context_t *ctx,
 #endif

   /* check if this is a response to our original request */
-  if (!check_token(received)) {
+static int count = 0;
+  if (!check_token(received) || ++count == 5) {
     /* drop if this was just some message, or send RST in case of notification */
     if (!sent && (received->type == COAP_MESSAGE_CON ||
                   received->type == COAP_MESSAGE_NON))

and run (coap-server running on the same host)

coap-client -N -s 10 coap://127.0.0.1/time
2019-04-25 08:45:19 +01:00
Jon Shallow 422faa4fef coap-client: Fix using -b NN with TCP connections
Issue reproducable with (coap-server also running)

coap-client -b32 coap+tcp://[::1]

and note the partial response.

examples/client.c:

Set doing_getting_block if processing Block2 responses.
Add in a doing_getting_block test to not break out of the main while(){} loop.

[coap_can_exit() always returns 1 for TCP connections as there is nothing on
the session->delayqueue]
2019-04-24 15:19:45 +01:00
Olaf Bergmann e0c6df7703 net.c: Include netdb.h only if HAVE_NETDB_H is defined
Platforms that do not have getaddrinfo() most likely do not have
the netdb.h include file as well.
This change includes netdb.h only if HAVE_NETDB_H is defined
(usually by configure).
2019-04-17 15:45:29 +02:00
Olaf Bergmann 933ddcbf20 .gitignore: Ignore only auto-generated coap_config.h{,.in}
The libcoap repository contains hand-crafted configuration files
for various platform such as Windows, Contiki, and LwIP. These
are now excluded from .gitignore to be able to track changes.
2019-04-17 15:17:28 +02:00
Olaf Bergmann 32e219a9fc coap_debug.c: Fix len parameter for inet_ntop()
On RIOT, inet_ntop() expects the size parameter to reflect the
length of the given address. A larger value causes inet_ntop()
to return ENOSPC.

This change passes the address size as a workaround, or the actual
number of remaining bytes in the output buffer in case less than
address size bytes remain.
2019-04-17 13:37:27 +02:00
obgm a335938f09 Merge pull request #336 from mrdeep1/inter_h_dependencies
coap_dtls.h: Remove inter .h file dependencies
2019-04-17 10:41:29 +02:00
Olaf Bergmann 1b5cb7e4ab [tinydtls] Updated to latest develop version
ext/tinydtls now points to
https://github.com/eclipse/tinydtls/commit/7f8c86e501e690301630029fa9bae22424adf618
2019-04-16 18:11:07 +02:00
obgm 106eb9edc9 Merge pull request #325 from mrdeep1/constrained_stack
For limited stacks, remove large items off the stack and make them static
2019-04-16 18:05:45 +02:00
Jon Shallow 96e61d3c4d coap_dtls.h: Remove inter .h file dependencies
Adding in new structures to .h files that are typedef'd to not include
"struct" which are then referenced by other .h files can easily set up
recursive requirements that cannot be fulfilled.

In particular, adding in a new typedef'd struct to coap_dtls.h cannot
easily be used by coap_session.h

include/coap2/coap_dtls.h:

In coap_dtls.h, forward reference the (outside of the file) structures
and then prefix the coap_*_t entries with "struct", so making the
entries "struct coap_*_t" entries as appropriate
2019-04-16 16:09:32 +01:00
obgm 1d484849e8 Merge pull request #312 from mrdeep1/group_reg
Fix mcast registrations when using TCP
2019-04-12 15:09:20 +02:00
Jon Shallow fda991f541 Fix mcast registrations when using TCP
As coap-server now sets up 2 (or 4) endpoints, UDP and TCP based, all
subsequent endpoints are pre-pended to the ctx->endpoint list. Thus
ctx->endpoint will always be TCP based.  Setting IPV6_JOIN_GROUP on a TCP
socket is a no-no.

As join() is complex function, it should be within libcoap so as to not require
detailed knowledge of how internal structures work (which really should be
opaque to the application writer).

include/coap2/net.h:
src/net.c:
libcoap-2.map:
libcoap-2.sym:
Create coap_join_mcast_group() in src/net.c (as it is a network layer
function using the (fixed) join() code. (Iterate through the ctx->endpoint list
looking for UDP based endpoints and only do the IPV6_JOIN_GROUP on them.)
There is no support for WITH_CONTIKI or WITH_LWIP at this point (returns -1).

examples/coap-server.c:
Remove join() code and replace call to join() with coap_join_mcast_group()

examples/coap-rd.c:
Remove join() code and replace call to join() with coap_join_mcast_group()

man/coap-rd.txt.in:
Correct a typo in the coap-ed man page
2019-04-12 13:54:50 +01:00
Jon Shallow cb18375df7 For limited stacks, remove large items off the stack and make them static
When there is a limited stack size, having large data items on the stack
can easily cause stack overflows.

This makes integration with any constrained stack O/S a lot easier.

include/coap2/coap_mutex.h:

Create coap_ mutex functions which are platform independent to protect
the (now) static variables if compiled with "-DCOAP_CONSTRAINED_STACK=1"

Makefile.am:

Include include/coap2/coap_mutex.h for distribution

coap_config.h.contiki:
coap_config.h.lwip:

As CONTIKI and LWIP have constrained stacks, set
"#define COAP_CONSTRAINED_STACK 1"

src/coap_debug.c:
src/coap_io.c:
src/net.c:

coap_show_pdu()
coap_log_impl()
coap_run_once()
coap_read_session()
coap_read_endpoint()
Move large data items out of the functions' stack and make them static
variables (defined within the function) if COAP_CONSTRAINED_STACK is defined.
Protect the usage of these static variables by mutexes.

Note: if "-DCOAP_CONSTRAINED_STACK=0" is used, then the stack will not
be constrained.
2019-04-11 15:53:21 +01:00
obgm 3bd5f488df Merge pull request #332 from mrdeep1/coap_free_endpoint_fix
coap_free_endpoint does not clean up tinydtls encryption sessions
2019-04-11 14:46:00 +02:00
Jon Shallow bc789edff8 coap_free_endpoint does not clean up tinydtls encryption sessions
Following on from #324 where coap_session_mfree() had to be moved in
coap_session_free() to correctly allow for tinydtls cleanup, session->endpoint
and session->context should not be cleared out prior to call of
coap_sesson_free() in coap_free_endpoint().

src/coap_session.c:

Remove lines setting session->endpoint and session->context to NULL
2019-04-11 10:47:17 +01:00
Olaf Bergmann 302bbffebd [tinydtls] update submodule to development HEAD 2019-04-08 16:27:17 +02:00
Olaf Bergmann affeac8983 Merge branch 'develop' of github.com:obgm/libcoap into develop 2019-04-08 14:33:31 +02:00
Olaf Bergmann 429bc1ed30 [tinydtls] Updated submodule URI to new development HEAD
The tinyDTLS source repository now lives at GitHub [1]. This
change updates the submodule URI and includes the latest commits
from the development branch.

[1] https://github.com/eclipse/tinydtls
2019-04-08 14:28:52 +02:00
obgm bab80cff21 Merge pull request #328 from mrdeep1/gnutls_psk_username_fix
Fix #321 was not correctly implemented
2019-04-08 10:23:24 +02:00
Jon Shallow a106ecc319 Fix #321 was not correctly implemented
While #321 prevented a core dump, that fix still caused memory corruption.

src/coap_gnutls.c:

Correct the code to correctly NULL terminate the created username.
2019-04-07 17:48:46 +01:00
obgm af1d602486 Merge pull request #327 from mrdeep1/contiki_lwip
server (lwip & contiki) run out of sessions
2019-04-05 16:19:02 +02:00
obgm 303be16e86 Merge pull request #317 from mrdeep1/cmsg_checks
packet->ifindex has random values if recvmsg() does not update msg_control
2019-04-05 15:49:16 +02:00
Jon Shallow 10b1b17aec server (lwip & contiki) run out of sessions
As a server, idle sessions are left around in case the client wants to do
further work using the same 5 tuple IP information.
With constrained systems, the number of sessions is limited, and so it is
easy to run out of sessions.

src/coap_session.c:

If there is an idle session, context->max_idle_sessions is not set and
a new session cannot be created, free off the oldest session and retry
the creation again.

examples/contiki/README:
examples/lwip/README:

Tidy up the documentation
2019-04-05 14:30:12 +01:00
obgm 6940fcb4c2 Merge pull request #324 from mrdeep1/session_free
dtls_send_to_peer: cannot find local interface reported on coap_session_free
2019-04-05 15:05:34 +02:00
Jon Shallow 1158541f63 dtls_send_to_peer: cannot find local interface reported on coap_session_free
In coap_session_free(), as coap_session_mfree() is called after
the session has been deleted out the endpoint or context sessions,
dtls_send_to_peer() is unable to find the session to send out the
Alert/Warning Close Notify message packet.

src/coap_session.c:

Move coap_session_mfree() to before setting deleting session out of endpoint or context sessions in coap_session_free().

Note: TinyDTLS has been separately updated to not report ALRT on a
Close Notify - see https://github.com/eclipse/tinydtls/pull/5.
2019-04-05 13:56:03 +01:00
obgm 260472be04 Merge pull request #321 from mrdeep1/gnutls_psk_username_crash
Client crashes in gnutls psk setup
2019-04-01 13:33:57 +02:00