Commit Graph
1526 Commits
Author SHA1 Message Date
Jon Shallow 371c295fce Remove deprecated str typedef to remove namespace pollution
As str structure has been replaced by coap_string_t, remove it from the code
as it is no longer required, has been deprecated for some time and can cause
clashes with other str definitions.

Tidy up comment referring to str.
2018-12-27 11:51:42 +00:00
Olaf Bergmann 23c60dee6f client.c: remove trailing newline from output for '-o -'
The CLI option '-o file' redirects the received payload into the
given file, where '-' denotes stdout. As the function close_output()
used to append a newline to the end of the output, certain tools
such as cbor2pretty.rb have failed, complaining about the trailing
character.

This change now writes the newline if only if option '-o' was not
specified.
2018-12-20 17:57:16 +01:00
Olaf Bergmann d52de2b8e9 configure.ac: set release state to rc3 v4.2.0-rc3 2018-12-20 14:29:08 +01:00
obgm 49e8e43eeb Merge pull request #283 from mrdeep1/mem_leak_hello
Possible to crash coap-server with uncompleted (D)TLS handshakes
2018-12-18 17:45:04 +01:00
obgm 092bc021b4 Merge pull request #282 from mrdeep1/endpoint_free_hello_leak
endpoint->hello information memory leak when coap_free_endpoint() called
2018-12-18 17:32:51 +01:00
Jon Shallow 15b42e9faa Possible to crash coap-server with uncompleted (D)TLS handshakes
For any TLS implementation, it is possible to crash the coap-server by
initiating (D)TLS handshakes but never completing them, thus continuing to use
more RAM.  Each partially completed handshake is left in the endpoint->sessions
chain in a state of COAP_SESSION_STATE_HANDSHAKE and unless
endpoint->max_idle_sessions is deliberately configured, these sessions will
never get deleted.

A cause of partially completed handshakes is when there is a PSK mismatch.

Furthermore, unnecessary CPU usage is used to search down long lists held in
endpoint->sessions.

This fix limits the  number of these sessions in a handshake state to the
number defined by endpoint->max_handshake_sessions if non zero or 100 to prevent
memory exhaustion.  By default, endpoint->max_handshake_sessions is 0.

Sessions in state COAP_SESSION_STATE_HANDSHAKE will get timed out after 30
seconds of inactivity.

This does not prevent a DOS attack by creating max_handshake_sessions as a
genuine new session will fail to get responded to until the number of current
COAP_SESSION_STATE_HANDSHAKE sessions drop.  However, the use of Cookie
exchanges by the underlying TLS library prior to a new session being created
and added into endpoint->sessions will filter out a lot of the DOS attacks.

include/coap2/coap_session.h

New default definition for COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS
New default definition for COAP_PARTIAL_SESSION_TIMEOUT_TICKS

include/coap2/net.h

Include max_handshake_sessions in coap_context_t

src/coap_session.c

In coap_endpoint_get_session() check the number of sessions in
COAP_SESSION_STATE_HANDSHAKE and handle accordingly when limits are hit, or
they need to be timed out.
2018-12-18 16:14:03 +00:00
obgm 11a688760d Merge pull request #284 from mrdeep1/client_server_documentation
coap-client/coap-server help documentation splitting out PSK and PKI options
2018-12-18 17:04:11 +01:00
Jon Shallow 8dcdbfb477 endpoint->hello information memory leak when coap_free_endpoint() called
Information set up in the pseudo session held in endpoint->hello is not freed
off when coap_free_endpoint() is called.

A solution is to split coap_session_free() into two parts with
coap_session_free() calling a new function coap_session_mfree().

Then coap_mfree_endpoint() can call coap_session_mfree() to free off the
endpoint specific hello information.

Makefile.am

Add coap_mfree_endpoint and coap_session_mfree to the CTAGS_IGNORE list.

libcoap-2.{map|sym}

Remove coap_mfree_endpoint as it is not a public function

include/coap2/coap_session.h

Add in new coap_session_mfree() function definition

src/coap_io.c

Call coap_session_mfree() from within coap_mfree_endpoint()

src/coap_session.c

Move some of the functionality out of coap_session_free() into a new
function coap_session_mfree() and  call coap_session_mfree().
2018-12-18 15:56:48 +00:00
obgm 4626dea3a6 Merge pull request #281 from mrdeep1/duplicate_gnutls_handshake
GnuTLS If a bad key was used, it is not possible to get a new session
2018-12-18 16:41:56 +01:00
Jon Shallow 1e06285b2b GnuTLS If a bad key was used, it is not possible to get a new session
src/coap_gnutls.c:

The GnuTLS server session information held in endpoint->hello was getting
polluted when a bad PSK was being used, and so a new session attempt with a
good PSK would fail. The only way to get around this was to restart the
coap-server.

OpenSSL handles this by initiating the handshake response (DTLSv1_listen()),
creating a new coap session and then using the new session to continue with
the SSL handshake (SSL_accept()) until the SSL session is set up.

For GnuTLS, there is no initial handshake initiation as everything is done
inside gnutls_handshake().  To get around this, in the post_client_hello
function a flag is set in g_env->seen_client_hello so that coap_dtls_hello()
knows that that a SSL session is being set up, but not yet complete.
This flag is cleared when coap_dtls_hello() returns 1 indicating that the
interim client_hello has been seen and it is safe to duplicate the session.

The do_gnutls_handshake() function has been cleaned up.

The coap_dtls_send() function has been updated to send any outstanding data
if the SSL session has just completed.
2018-12-18 15:07:48 +00:00
obgm ed9e8da5ac Merge pull request #279 from mrdeep1/gnutls_tls_read
coap_gnutls.c: coap_tls_read() support retrying the read
2018-12-13 17:27:20 +01:00
Olaf Bergmann 167ce8b144 coap_io.c: set send address when IP_PKTINFO is missing
Try IP_SENDSRCADDR to set the address of the sending interface for
sendmsg() on platforms that do not provide IP_PKTINFO (such as
FreeBSD).
2018-12-13 17:08:11 +01:00
Jon Shallow 26a045ba3d coap-client/coap-server help documentation splitting out PSK and PKI options
Re-organize usage() and man pages to seperate out the PSK and PKI options
for clarity - as they may not be available for all TLS library versions

examples/client.c
examples/coap-server.c
man/coap-client.txt.in
man/coap-server.txt.in
2018-12-12 11:23:49 +00:00
Jon Shallow e6661fbdfc Support FreeBSD 11.2 builds
src/coap_io.c:
ifdef out IPv4 struct in_pktinfo code that does not compile, copying what
has been done later in the same coap_network_send() function.

tests/test_session.c
Correctly reverse the parameters to coap_new_client_session() in t_session6()
so that the test application does not bind to local-address, port 5683 twice.
[It seems that other distrubutions are happy with this when just SO_REUSEADDR
is used on the socket, but FreeBSD needs SO_REUSEPORT enabled as well.]

BUILDING
Record that gmake is required to build TinyDTLS for FreeBSD, not make.
2018-12-10 20:15:25 +00:00
Jon Shallow 0e0c7ba1d4 coap_gnutls.c: coap_tls_read() support retrying the read
Support the case of GNUTLS_E_AGAIN for retrying the read at a
later point
2018-12-10 15:09:55 +00:00
obgm 19822b5765 Merge pull request #275 from mrdeep1/etsi_iot_01
Update etsi_iot_01 and tiny examples to build with current API
2018-12-08 14:41:50 +01:00
Jon Shallow 0bcbd3fb5c Update scripts/build.sh to build coap-etsi_iot_01 and coap-tiny examples
Travis now checks exmples continue to build, even if there is an API
change.
2018-12-07 20:22:56 +00:00
Jon Shallow c216a8801d Update the etsi test cases in the examples directory
examples/etsi_coaptest.sh
examples/etsi_testcases.sh

Minor corrections to the scripts to get them working
2018-12-07 20:22:56 +00:00
Jon Shallow 78c59ff300 Add in support for building coap-etsi_iot_01 and coap-tiny examples
examples/Makefile.am

Support building the additional examples using 'make check'.

.gitignore

Ignore the new examples executables.
2018-12-07 20:22:56 +00:00
Jon Shallow 157985cb95 Update examples/tiny.c to use the new API
Update all the coap_ calls to use the new API, and the updated structures.
Introduce using session instead of context.
Correct all the compiler warnings.
2018-12-07 20:22:45 +00:00
Jon Shallow 37e7a974a6 Update examples/etsi_iot_01.c to use the new API
Update all the coap_ calls to use the new API, and the updated structures.
Introduce using session instead of context.
Correct all the compiler warnings.
Keep the payload in the resource rather than separately.
2018-12-07 20:14:40 +00:00
Olaf Bergmann 3b72bce3f0 AUTHORS: include author names of substantial contributions
The authors file now lists the names of authors that have siginificantly
contributed to the current code base. A link to the GH contributors'
page is included as a reference to authors with fewer or minor
contributions.
2018-12-05 09:15:50 +01:00
Olaf Bergmann bac6b61a4e client.c, coap-server.c: updated copyright information 2018-12-01 09:27:24 +01:00
obgm ea4bca7335 Merge pull request #277 from nmeum/fix-U-option
coap-client: The -U option doesn't expect an argument
2018-11-28 13:15:11 +01:00
Sören Tempel 1c789a7beb coap-client: The -U option doesn't expect an argument
Thus it must not be postfixed with a colon character in the optstring.
While at it move the option to the beginning of the opstring to the
other options which don't expect an argument.

Without this commit the -U option is unusable.
2018-11-28 13:00:33 +01:00
obgm 47fc7a8bb8 Merge pull request #271 from mrdeep1/block1
Fix packet recovery support for BLOCK1 option in examples for lossy connections
2018-11-28 13:00:26 +01:00
Olaf Bergmann 96fdf63264 Dockerfile.develop: need cn-cbor docs before install
The install target of cn-cbor's Makefile fails when the documentation
files have not been generated. To fix this, the doc target is
explicitly invoked before install.
2018-11-28 10:16:20 +01:00
obgm 54956954ca Merge pull request #273 from mrdeep1/gnutls
Add in support for GnuTLS >= 3.3.0
2018-11-28 10:11:59 +01:00
Jon Shallow ad383aa3b2 Replace signal() with sigaction() in examples
examples/coap-server.c:
examples/etsi_iot_01.c:

Replace signal() with sigaction() for handling SIGINT or SIGTERM

examples/client.c:

Include sigaction() for catching SIGINT or SIGTERM for a clean shutdown.
2018-11-27 15:33:53 +00:00
Jon Shallow e935d068ff src/coap_tinydtls.c: Clean up to remove compiler warnings
undef PACKAGE_* so that TinyDTLS versions are used instead

include dtls_debug.h to get in the correct function definitions instead of
hardcoding some of them.

Create a read-write version of some of the const parameters passed in to
the interim functions before calling the underlying TinyDTLS functions.
2018-11-27 15:33:52 +00:00
Jon Shallow e172e6865b Include GnuTLs in the Travis build
.travis.yml

Add in the gnutls build.

build-env/Dockerfile.build-env
build-env/Dockerfile.develop

Add in libgnutls28-dev to the apt-get list.

scripts/build.sh
scripts/dist.sh

Support TLS set to gnutls for building.
2018-11-27 15:33:52 +00:00
Jon Shallow 48ee2ec551 Documentation support for building libcoap with GnuTLS
BUILDING:

Also include documentation on how to get TinyDTLS submodule into
the project.
2018-11-27 15:33:52 +00:00
Jon Shallow 3e8071f011 Update man pages with GnuTLS support
man/coap-client.txt.in
man/coap-rd.txt.in
man/coap-server.txt.in

Document usage over -v7 for extra GnuTLS library output.

man/coap_attribute.txt.in
man/coap_context.txt.in
man/coap_encryption.txt.in
man/coap_handler.txt.in
man/coap_logging.txt.in
man/coap_observe.txt.in
man/coap_pdu_setup.txt.in
man/coap_recovery.txt.in
man/coap_resource.txt.in
man/coap_session.txt.in
man/coap_tls_library.txt.in

Include new -lcoap-@LIBCOAP_API_VERSION@-gnutls option.
Remove trailing spaces at end of line

man/coap_encryption.txt.in

Update with GnuTLS information

man/coap_logging.txt.in

Update with more information about logging levels.

man/coap_tls_library.txt.in

Include new functions coap_show_tls_version() and coap_string_tls_version()
2018-11-27 15:33:43 +00:00
Jon Shallow cbfa1790d3 Update examples to include using coap_string_tls_version() in usage()
examples/client.c
examples/coap-rd.c
examples/coap-server.c

Add in call to coap_string_tls_version() in usage().
2018-11-27 11:42:21 +00:00
Jon Shallow 72740cb687 tests/test_tls.c: Add in GnuTLS build support
HAVE_GNUTLS -> HAVE_LIBGNUTLS

Correct TinyDTLS version checks as TinyDTLS is now returning the
actual TinyDTLS library version.

For TinyDTLS builds, #undef PACKAGE_* to remove compiler warnings.
2018-11-27 11:42:21 +00:00
Jon Shallow d8b399cfc9 New coap_show_tls_version() and coap_string_tls_version() functions
These new functions can be used to either update a buffer with, or coap_log()
out the current runtime TLS library along with the version of the library
that libcoap was built against.

include/coap2/debug.h
src/debug.c
libcoap-2.map
libcoap-2.sym

Support for the new functions coap_show_tls_version() and coap_string_tls_version().
2018-11-27 11:42:21 +00:00
Jon Shallow 8a3b46eee4 Bump minimum GnuTLS version to 3.3.0
Makefile.am

Include src/coap_gnutls.c

configure.ac

Update minimum GnuTLS version to 3.3.0
2018-11-27 11:42:21 +00:00
Jon Shallow 3d932bdcd4 Revert out commit c362d56 disabling gnutls support
Re-enable building with --with-gnutls
2018-11-27 11:42:21 +00:00
Jon Shallow d144a1d5b0 src/coap_notls.c: Include ignoring GnuTLS builds 2018-11-27 11:42:21 +00:00
Jon Shallow 11de84bcc7 src/coap_gnutls.c: Add in GnuTLS support interface module
src/coap_gnutls.c

New file including support for GnuTLS >= 3.3.0
2018-11-27 11:42:21 +00:00
Jon Shallow 4a543d1198 Extend coap_tls_version_t to include both built and runtime TLS versions
This allows an application to determine what the built version is
as well as what the runtime version of a TLS library is.

include/coap2/coap_dtls.h

Add built_version to coap_tls_version_t

src/coap_openssl.c
src/coap_tinydtls.c

Additionally populate coap_tls_version_t with build_version when
coap_get_tls_library_version() is called.

src/coap_tinydtls.c

Correct the version returned as actual TinyDTLS version instead the
binary value of a DTLS packet type.
2018-11-27 11:42:04 +00:00
Carsten Schoenert ea29a48fd7 spelling: fix whith -> with 2018-11-24 13:59:54 +01:00
Carsten Schoenert 1d1eb455d6 spelling: fix seperate -> separate 2018-11-24 13:59:47 +01:00
Carsten Schoenert df6c2529f9 spelling: fix outputing -> outputting 2018-11-24 13:59:41 +01:00
Carsten Schoenert 32eea645b1 spelling: fix compatability -> compatibility 2018-11-24 13:59:34 +01:00
Carsten Schoenert 637a09cfbd spelling: fix bandwith -> bandwidth 2018-11-24 13:58:44 +01:00
Carsten Schoenert 55d359d259 spelling: fix apropriate -> appropriate 2018-11-24 13:57:14 +01:00
obgm 22e4ffda5a Merge pull request #276 from neuronabr/neuronabr
Add missing semicolon.
2018-11-24 13:34:23 +01:00
neuronabr f56ce3d10c Add missing semicolon. 2018-11-23 18:00:18 +01:00
obgm 1eadd91366 Merge pull request #269 from mrdeep1/replace_debug_etc
Replace debug(), info() & warn() macros with appropriate coap_log()
2018-11-11 18:18:41 +01:00