Commit Graph
221 Commits
Author SHA1 Message Date
obgm bf43c3af6c Merge pull request #137 from mrdeep1/session-retries
Require support for configuring session recovery parameters
2018-03-06 16:43:51 +01:00
Jon Shallow 9c6c72565e net.c: Remove 'cc Rate Control', update code to use session recovery parameters
Remove 'cc Rate Control' which is now in coap_session.h.

Update Q, ACK_TIMEOUT and ACK_RANDOM_FACTOR #defines to include session's
recovery parameters, now in coap_fixed_point_t.

Update calc_timeout() to include session (now called coap_calc_timeout()).

Update coap_retransmit() to use session's max_retransmit.
2018-03-05 16:12:18 +00:00
Jon Shallow fb626df651 coap_session.c: Add in new functions, set the defaults and update calc_timeout
Add in the new functions
coap_session_set_max_retransmit()
coap_session_set_ack_timeout()
coap_session_set_ack_random_factor()
coap_session_get_max_transmit()
coap_session_get_ack_timeout()
coap_session_get_ack_random_factor()

Add in the default values in coap_make_session()

Update coap_calc_timeout() in coap_session_delay_pdu()
2018-03-05 16:12:18 +00:00
obgm 3870bfc809 Merge pull request #142 from mrdeep1/coap-write-missing-tls
coap_write can assert if s->tls is not set when determining next to resend packet
2018-03-01 13:13:19 +01:00
Olaf Bergmann 7872a80fb4 network I/O: fixed socket creation for multicast communication
This bugfix allows clients to send datagrams to IP multicast groups.
After introducing the concept of client sessions, datagram sockets
have been connected to their remote peer in coap_socket_connect_udp().
As this operation fails for multicast addresses, sending to multicast
groups was not possible anymore.

coap_socket_connect_udp() now checks whether the given server address
is a multicast address. If this is the case, connect() is not called
and the flag COAP_SOCKET_MULTICAST is set in the coap_socket_t
structure while COAP_SOCKET_CONNECTED is cleared.

The flag COAP_SOCKET_CONNECTED is now set by coap_socket_connect_udp()
and coap_socket_connect_tcp1().

coap_read_session() now allows reading from sockets that have either
the flag COAP_SOCKET_CONNECTED or COAP_SOCKET_MULTICAST set.
2018-02-28 15:44:32 +01:00
obgm b6f6cb274c Merge pull request #141 from mrdeep1/coap-log-syntax
Add in GNU compiler checking of parameter syntax for coap_log() functions
2018-02-26 17:35:10 +01:00
Olaf Bergmann 9b9b39a3cd Merge branch 'develop' of github.com:obgm/libcoap into develop 2018-02-26 17:18:43 +01:00
obgm fafd4745b7 Merge pull request #136 from mrdeep1/ping-pong-handlers
Ping Pong handlers: Need for applications to see ping requests / pong responses
2018-02-26 17:17:54 +01:00
Olaf Bergmann 46c908af8f coap_session.c: fix session release
coap_session_t uses reference counting hence client sessions must be
released by coap_session_release() instead of directly calling
coap_session_free().
2018-02-20 13:55:25 +01:00
obgm 08f7f5c2ce Merge pull request #131 from mrdeep1/fd-close-leak
coap_io.c: Fix file descriptor leaks when "connections" fail
2018-02-20 13:53:11 +01:00
obgm 63cac59c62 Merge pull request #132 from mrdeep1/coap_session_send-assert
coap_openssl.c: client assert error if DTLS error closed socket
2018-02-20 13:52:56 +01:00
John Carter c7936acf71 coap_io.c: fix apparently uninitialized buffer in syscall param
Valgrind reports Syscall param  sendmsg(msg.msg_control) points to
uninitialised byte(s) due alignment padding in the CMSG macros
leaving uninitialized gaps in struct sent to the sendmsg system call.

This issue was reported including this patch on the libcoap-developers
mailing list [1].

[1] https://sourceforge.net/p/libcoap/mailman/message/36141279/

Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2018-02-15 19:38:42 +01:00
Jon Shallow eb84476fd1 coap_io.c: remove coap_socket_close() added in error to this fix
Reverting out this part of the change.  This should be managed and done at
the application layer.
2018-02-15 09:51:05 +00:00
Jon Shallow 47b46d6907 coap_io.c: Fix file descriptor leaks when "connections" fail
If a TCP connection connection fails, or a an ICMP Unreachable is received
for a UDP packet, then the file descriptor is not closed off.  Eventually
all fails when no more file descriptors are allowed.
2018-02-15 09:51:05 +00:00
Jon Shallow 137789fbc7 coap_openssl.c: Fix dtls typo should be tls in coap_dtls_new_context()
Correct parameter typo to SSL_CTX_set_cipher_list() from original TLS merge
2018-02-14 23:07:08 +00:00
Jon Shallow 675edad34c coap_notls.c, coap_tinydtls.c: Fix stub functions coap_dtls_context_set_pki() 2018-02-14 21:59:21 +00:00
Jon Shallow 0704792698 net.c: Update coap_context_set_pki() parameters
Remove setup_callback parameter
2018-02-14 21:04:47 +00:00
Jon Shallow 2a99d04648 coap_session.c: Update coap_new_client_session_pki() parameters
Remove setup_callback parameter
2018-02-14 21:03:37 +00:00
Jon Shallow 969cdcb457 coap_openssl.c: Update with coap_dtls_pki_t changes and asn1 private key types
Move coap_dtls_security_setup_t into coap_dtls_pki_t

Map COAP_ASN1_PKEY_* into EVP_PKEY_* for call SSL_CTX_use_PrivateKey_ASN1()
2018-02-14 21:00:20 +00:00
Jon Shallow 047c9fb082 Fix coap_notls.c, coap_tinydtls.c: after update merge from obgm/develop
Conficts created by Pull request #134
2018-02-14 19:24:58 +00:00
Jon Shallow b02019d439 net.c: Include call to ping handler if COAP_SIGNALING_PING is received
Include missing ping potential intercept handler code.
2018-02-12 19:59:34 +00:00
Jon Shallow 0b7d1d8644 coap_io.c: Prevent coap_write() blowing up if opaque tls is not set
When determing whether to do a re-transmit timeout based on
coap_dtls_get_timeout, if s->tls is not set (unable to set up TLS session,
TLS error etc.), then coap_write() assert's when calling
coap_dtls_get_timeout().  This fix just sets the timeout to 0 if s->tls is not
set.
2018-02-12 15:44:12 +00:00
Jon Shallow 64aa7ca30c coap_io.c: Fix coap_log warning message
Adding in '__attribute__ ((format(printf, 2, 3))' causes
coap_log(LOG_DEBUG, coap_socket_strerror()); to give a warning in coap_run_once
2018-02-12 15:28:58 +00:00
Jon Shallow 740680c365 net.c: Add in PKI support
Update coap_context_set_psk() to return on failure.  Add in call to
coap_dtls_context_set_psk() function

Add in new function coap_context_set_pki()

Update #includes for compilation
2018-02-12 10:19:56 +00:00
Jon Shallow 7ae49c3b41 coap_session.c: Support PSK new function and PKI
Update coap_new_client_session_psk() to clean up and return on error.  Add in
call to coap_dtls_context_set_psk()

Add in new function coap_new_client_session_pki()

Additional check for a call of coap_new_client_session_*() in
coap_new_endpoint()
2018-02-12 10:15:22 +00:00
Jon Shallow c4840b7ce1 coap_openssl.c: Fix coding error in coap_dtls_context_set_pki() 2018-02-12 10:14:01 +00:00
Jon Shallow 752da7179b coap_openssl.c: Seperate out PSK specifics and add in PKI support
Remove PSK specifics from coap_dtls_new_context() and put into new
coap_dtls_context_set_psk().

Create a new coap_dtls_context_set_pki() for PKI.

Include checks that either of coap_dtls_context_set_psk() or
coap_dtls_context_set_pki() have been called before setting up a (D)TLS
session

Update #includes for compilation
2018-02-12 09:52:31 +00:00
Jon Shallow aaa43301b7 coap_tinydtls.c: Add in PKI stub functions
Update #includes and add in stub functions
coap_dtls_context_set_pki
coap_dtls_context_set_psk
coap_dtls_context_check_keys_enabled
2018-02-12 09:50:32 +00:00
Jon Shallow 6d479ee6cb coap_notls.c: Add in PKI stub functions
Update #includes and add in stub functions
coap_dtls_context_set_pki
coap_dtls_context_set_psk
coap_dtls_context_check_keys_enabled
2018-02-12 09:48:42 +00:00
Jon Shallow 3e4de1273d coap_io.c: Update #include to allow compilation
Replace #include "coap_dtls.h" with #include "net.h"
2018-02-12 09:47:00 +00:00
Jon Shallow 1615d4e3b7 net.c: Include ping request / pong response handler support
If the application needs to see CoAP ping requests or CoAP TCP pong responses
then this update provides calling the configured handlers at the appropriate
points.
2018-02-10 20:57:27 +00:00
Jon Shallow 47205bd56c coap_openssl.c: Add in coap_get_tls_library_version() function
Add in coap_get_tls_library_version() for determining TLS build base + version

Do not allow a dynamic openssl library to be loaded and used at application
runtime that is less than OpenSSL version 1.1.0.
2018-02-10 19:39:27 +00:00
Jon Shallow 30794440af coap_tinydtls.c: Add in coap_get_tls_library_version() function
Add in coap_get_tls_library_version() for determining TLS build base + version
2018-02-10 19:38:08 +00:00
Jon Shallow 7d14b745c9 coap_notls.c: Add in coap_get_tls_library_version() function
Add in coap_get_tls_library_version() for determining TLS build base + version
2018-02-10 19:35:28 +00:00
Jon Shallow 50b97074e8 coap_openssl.c: client assert error if DTLS error closed socket
For a client, if a DTLS session is closed with ICMP unavailable packet, when
the TLS session is closed in the application with SSL_shutdown(), the OpenSSL
underlying library triggers a BIO_write() which calls coap_dgram_write() which
then 'assert's in coap_session_send().
(sock->flags == COAP_SOCKET_EMPTY && session->endpoint == NULL).

Fix is not to call coap_session_send() from coap_dgram_write() if socket is
closed and this is not an endpoint (not a server).
2018-02-10 03:36:43 +06:00
Olaf Bergmann 660c4168bc coap_session.c: send COAP_DEFAULT_MTU in CSM
This change replaces the hard-coded 1152 bytes by the configurable
COAP_DEFAULT_MTU.
2017-12-22 14:31:56 +01:00
Olaf Bergmann 8e011ec500 net.c: dynamically grow PDU size for TCP
This change was provided by Jean-Claude Michelou to fix issue #123 [1].
It dynamically grows a partial TCP PDU during read.

[1] https://github.com/obgm/libcoap/issues/123
2017-12-22 13:56:48 +01:00
Olaf Bergmann d3b5535960 pdu.[hc]: Export coap_pdu_resize() 2017-12-22 13:55:37 +01:00
Olaf Bergmann 8ee4bb2586 pdu.c: fix len returned by coap_get_data() for empty payload
John Carter has provided this (slightly edited) patch to set len to 0
for PDUs that do not contain a payload. This makes this function more
robust for callers that do not care about the function result.

This change fixes issue 120 [1].

[1] https://github.com/obgm/libcoap/issues/120
2017-11-16 14:18:20 +01:00
jcmichelou c93f535d4a openssl, session: Fix memory leaks. 2017-11-04 23:38:02 +01:00
Olaf Bergmann 9bf7032232 coap_session.c: additional NULL pointer check
Coverity scan CID 1458386 has detected a potential NULL pointer
being dereferenced in coap_session_free().
2017-11-03 15:05:48 +01:00
Olaf Bergmann 6fb2e671d1 async.c: added missing check for NULL in coap_free_async()
Coverity scan has detected a possible NULL pointer being dereferenced
before it is checked, see CID 1458391.
2017-11-03 14:55:33 +01:00
Olaf Bergmann 1f51ba7636 coap_openssl.c: removed dead code from coap_dgram_ctrl()
The dead code detected by Coverity scan in CID 1458395 has been
replaced with explicitly setting the return value to 1 (the default
that has previously been used).
2017-11-03 14:42:05 +01:00
Olaf Bergmann 4b52182b8d net.c: fix possible NULL pointer dereference
Fixes CID 1458397 detected by Coverity scan.
2017-11-03 14:22:32 +01:00
Olaf Bergmann 67a9210dbd net.c: fixed memory leak in coap_send()
coap_send() always takes the ownership of the pdu that is passed
as argument to send, i.e., the memory will be released automatically
when the pdu is not needed anymore.
2017-11-03 14:07:16 +01:00
Olaf Bergmann 027d9601eb net.c: always initialize bytes_read
In CID 1459612, Coverity scan has complained about uninitialized use
of the variable bytes_read. Although this is a false positive here,
it seems to be more safe to always initialize bytes_read.
2017-11-03 13:54:07 +01:00
Olaf Bergmann 313a655a9a pdu.c: fix explicit NULL pointer dereference
Fixes CID 1459615 found by Coverity scan.
2017-11-03 13:37:56 +01:00
Olaf Bergmann 6a3abd257e coap_session.c: fixed default port selection for client TCP session
In coap_session_create_client(), the default port for TCP did not
correctly distinguish between TCP and TLS as pointed out in [1] by
Joan Shallow. This change applies the suggested fix.

[1] https://sourceforge.net/p/libcoap/mailman/message/36092184/
2017-11-03 10:41:05 +01:00
jcmichelou 3f77c117ea resource: Fix issues #90, #91 and #92
The value of the observe option is kept for each resource rather than being global to the context.
The value of the observe option must wrap to be stay below 2^24.
The value of the observe option must be different from the initial value when a notification is sent.
2017-10-25 20:22:01 +02:00
jcmichelou e125888ded openssl: Handshake can also complete in SSL_accept and SSL_connect. 2017-10-21 19:16:23 +02:00