Commit Graph
1176 Commits
Author SHA1 Message Date
Serafin Leschke e394ca2953 resource.h: Introduce new field user_data
The library API lacks a way to store context for the handlers. A
LED-handler for example needs to now on which pin the specific LED
is connected in order to control it. Or a higher level API would like to save the
object pointer to the object responsible for the resource.

This change will introduce a void pointer for the user to save context.
He can then retrieve the context in the handler if needed.
2018-03-13 09:29:53 +01: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
obgm 4885d87f6d Merge pull request #140 from mrdeep1/coap-server-pki-fix
coap-server: Re-order code (move fill_keystore) to support PKI
2018-02-26 17:25:44 +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
Olaf Bergmann 90d90232c4 .travis.yml: minimize build matrix 2018-02-16 10:43:28 +01:00
Olaf Bergmann 67291e397b tests: revert commit a3da53d to re-enable IPv6 in unit tests 2018-02-15 20:05:01 +01:00
Olaf Bergmann e40c6ea799 .travis.yml: enable IPv6 on travis docker
This workaround has been suggested [1] to fix the recent IPv6 issue
in travis docker containers.

[1] https://github.com/travis-ci/travis-ci/issues/8711
2018-02-15 20:03:40 +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
Olaf Bergmann c46de196e5 .travis.yml: added tinydtls build to POSIX test matrix 2018-02-15 12:14:16 +01:00
obgm 1b97885ec8 Merge pull request #138 from mrdeep1/pki-support
Addition of PKI support
2018-02-15 12:03:50 +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 b8b1c18ffd net.h: Update coap_context_set_pki() definition 2018-02-14 20:58:15 +00:00
Jon Shallow f820857315 coap_session.h: Move coap_new_client_session_pki() def from coap_dtls.h
Moving coap_dtls_security_setup_t into coap_dtls_pki_t helped with the previous
into its logical place.
2018-02-14 20:54:21 +00:00
Jon Shallow fa6f292997 coap_dtls.h: Move coap_dtls_security_setup_t into coap_dtls_pki_t
Update functions appropriately.
Move coap_new_client_session_pki() back into coap_session.h (its correct place)
Add in enum coap_asn1_privatekey_type_t
2018-02-14 20:50:43 +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
Olaf Bergmann 0d2922a45b .travis.yml: enable unit tests for openssl builds
This change sets TESTS=yes for the TLS=openssl build
2018-02-14 17:43:33 +01:00
Olaf Bergmann c74e1da5a9 tests: add unit test boilerplate for (D)TLS
A simple structure for (D)TLS-specific unit tests has been added.
Currently, only general support and the version number as reported
by coap_get_tls_library_version() are checked.
2018-02-14 17:28:37 +01:00
Olaf Bergmann b1943714ad Merge branch 'mrdeep1-tls-supported' into develop
Close PR #134 [1]

[1] https://github.com/obgm/libcoap/pull/134
2018-02-14 17:25:53 +01:00
Olaf Bergmann 16685d7736 Merge branch 'tls-supported' of https://github.com/mrdeep1/libcoap into mrdeep1-tls-supported 2018-02-14 16:21:27 +01:00
Olaf Bergmann a3da53d5e3 tests: use IPv4 in unit tests for robustness
As unit tests with IPv6 addresses keep failing on docker-based
travis CI, this changes reverts to IPv4 usage in following files:

    test_wellknown.c
    test_sendqueue.c
2018-02-14 16:06:52 +01:00
Jon Shallow c4729fa801 libcoap-1.map, libcoap-1.sym: Expose coap_get_tls_library_version() 2018-02-14 09:55:53 +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 93c8471233 debug.h: Add in parameter format checking to coap_log_impl() for GNUC
For GNUC. make the function

void coap_log_impl(coap_log_t level,
               const char *format, ...) __attribute__ ((format(printf, 2, 3)));
2018-02-12 15:28:24 +00:00
Jon Shallow b2205d2e40 examples/coap-server.c: Re-order code (move fill_keystore) to support PKI
fill_keystore() now needs to be before coap_new_endpoint() is called.
2018-02-12 11:58:59 +00:00
Jon Shallow 85e7f1fc54 libcoap-1.map, libcoap-1.sym: Add in new PSK and PKI functions
coap_context_set_pki
coap_dtls_context_check_keys_enabled
coap_dtls_context_set_pki
coap_dtls_context_set_psk
coap_new_client_session_pki
2018-02-12 10:21:01 +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 0b88e51a88 net.h: Add in new function
New function coap_context_set_pki()

Update function coap_context_set_psk ()to return failure value
2018-02-11 20:04:04 +00:00
Jon Shallow 5b340adfb8 coap_dtls.h: Add support for setting up PKI
Define
coap_dtls_pki_t
coap_dtls_security_setup_t

Functions
coap_new_client_session_pki
coap_dtls_context_set_psk
coap_dtls_context_set_pki
coap_dtls_context_check_keys_enabled
2018-02-11 19:32:15 +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 fbe814d905 net.h: Add function definitions for ping and TCP pong handlers
If the application needs to see CoAP ping requests or CoAP TCP pong responses
then there needs to be a handler that can be set up that is called
appropriately.
2018-02-10 20:54:17 +00:00