Commit Graph
1382 Commits
Author SHA1 Message Date
obgm e1491dee77 Merge pull request #226 from mrdeep1/logging-doc
New coap_logging(3) and updated Doxygen comments for logging
2018-07-26 14:08:25 +02:00
obgm 38246dd41d Merge pull request #230 from mrdeep1/sendqueue-cleanup
net.c: Flush out session->sendqueue when PDU is delayed
2018-07-26 14:02:36 +02:00
Olaf Bergmann e83d0ede27 pdu_parse_target.c: fix include path for coap.h 2018-07-26 13:02:33 +02:00
Olaf Bergmann 93f9ee61b3 build.sh: integrate OSS-Fuzz syntax checks in CI build 2018-07-26 12:35:27 +02:00
Olaf Bergmann 315067add0 configure.ac: add creation of tests/oss-fuzz/Makefile.ci 2018-07-26 12:29:13 +02:00
Olaf Bergmann f0f614897e Makefile.ci.in: Continuous integration checks for OSS-Fuzz
The sub-directory tests/oss-fuzz contains single files that are
used from the Open Source Software Fuzzer [1]. This change provides
a template Makefile with the proper flags for compiling libcoap
applications in a continuous integration environment such as travis.

Intended usage from top_srcdir is:

  make -C test/oss-fuzz -f Makefile.ci check clean

[1] https://github.com/google/oss-fuzz/
2018-07-26 12:22:35 +02:00
Jon Shallow a5cd7dcbd9 net.c,coap_session.c: Flush out session->sendqueue when PDU is delayed
Delayed PDUs (found by the limiting of 1 CON request outstanding) are
added to session->sendqueue by coap_session_delay_pdu().
The session->sendqueue is only flushed out when a session becomes established
by calling coap_session_connected().

This fix now calls coap_session_connected() whenever the current CON count
is decremented.

Additionally, CON tracking now only tracks UDP & DTLS sessions.

coap_session_connected() is updated to not sent out more than one CON
request.
2018-07-26 08:20:34 +01:00
obgm 733628c3d2 Merge pull request #229 from mrdeep1/con-active
Missing case for #201 to close down con_active
2018-07-25 18:01:06 +02:00
obgm ea97fbb835 Merge pull request #228 from mrdeep1/loss-level-restore
src/debug.c: Allow loss level of 0% to restore full flow
2018-07-25 17:53:00 +02:00
Jon Shallow 0a36832bd3 Missing case for #201 to close down con_active
The RST to a CoAP Ping was not decrementing the con_active count, so
all new CON requests were waiting for the Ping to expire.
2018-07-25 14:49:25 +01:00
Jon Shallow 4eeda95ac7 src/debug.c: Allow loss level of 0% to restore full flow
If a loss level is configured using coap_debug_set_packet_loss(), it
is not possible to restore full flow using 0% - as 0 is rejected as
being invalid.  This fix allows 0% to restore full traffic flows again.
2018-07-25 11:47:00 +01:00
obgm 9184a75a21 Merge pull request #225 from mrdeep1/dynamic-resource-server
coap-server: Support for being able to create dynamic resources on the fly
2018-07-25 11:17:16 +02:00
Jon Shallow 224153c206 coap-server: Support for being able to create dynamic resources on the fly
Add in -d max option, which then causes coap_resource_unknown_init() to get
called.

Number of dynamic resoures is limited by 'max'.  The current set of resources
can be determined by using .well-known/core

If max is reached, 4.06 is returned.

Fixed typo in man coap_resource(3) in example for unknown resources
2018-07-25 10:12:14 +01:00
Jon Shallow c695dea7cd New coap_logging(3) and updated Doxygen comments for logging
Documentation changes/updates only - no code changes.

configure.ac
include/coap/coap_dtls.h
include/coap/coap_session.h
include/coap/debug.h
man/Makefile.am
man/coap.txt.in
man/coap_context.txt.in
man/coap_logging.txt.in (new)
2018-07-25 09:48:02 +01:00
obgm 6bb40d5af3 Merge pull request #179 from mrdeep1/tcp-setup
coap_openssl tidy up, fix first PSK fails if both PSK and PKI are enabled on server
2018-07-25 10:18:54 +02:00
Jon Shallow bb0b19546f examples/coap-server.c, examples/client.c Support new coap_dtls_pki_t
Updated to support the new coap_dtls_pki_t.

Add in new -C and -R options to support / test PKI mutual authentication

Make sure time resource is triggered no more frequently than once a sec.
2018-07-25 09:16:00 +01:00
Jon Shallow 95fb280d58 Makefile.am: Exclude coap_dtls_context_set_pki_root_cas
Also, exclude coap_endpoint_new_dtls_session() as it is an internal function
2018-07-24 14:49:13 +01:00
Jon Shallow e2c3571598 libcoap-2.{map|sym}: Add in coap_context_set_pki_root_cas()
Also, remove coap_endpoint_new_dtls_session() as it is an internal function
2018-07-24 14:49:13 +01:00
Jon Shallow 9a1f0ab475 man pages: New coap_encryption(3) and coap_session(3)
Split out old coap_context(3) into coap_context(3), coap_encryption(3) and
coap_session(3) with coap_encryption(3) primarily updated to reflect the
updated PKI configuration options.

coap-client.txt.in
coap-server.txt.in

Update with new options making use of updated PKI interface
2018-07-24 14:49:04 +01:00
Jon Shallow bfa24d499f {coap_session|net}.c: Update internal coap_dtls_context_set_*() functions
Update calls to coap_dtls_context_set_*() functions
"\n" terminate coap_log() calls

src/coap_session.c:
coap_session_disconnected() Report the session disconnected reason

Warn if coap_new_client_session_psk() called without both key and
identity defined (OpenSSL cannot handle this)

src/net.c:
coap_context_set_pki_root_cas(): New function
2018-07-23 11:17:45 +01:00
Jon Shallow 340a3d03b4 {coap_notls|/coap_tinydtls}.c: Update internal coap_dtls_context_set_*() functions
coap_dtls_context_set_pki_root_cas(): New function
coap_dtls_context_set_psk(): Remove unused parameters, add in server parameter
coap_dtls_context_set_pki(): Add in server parameter
coap_dtls_context_check_keys_enabled(): Add in UNUSED

src/coap_tinydtls.c:
coap_dtls_free_session() set coap_session->tls = NULL
2018-07-23 11:17:44 +01:00
Jon Shallow 0355821afe {coap_dtls|net}.h: New coap_context_set_pki_root_cas(), updated coap_dtls_pki_t
coap_context_set_pki_root_cas(): New
coap_dtls_context_set_psk(): remove unused parameters, add in server parameter
coap_dtls_context_set_pki(): add in server parameter

coap_dtls_pki_t: Additional configuration parameters
coap_dtls_security_setup_t: Updated
coap_dtls_cn_callback_t: New
coap_dtls_sni_callback_t: New
coap_pki_key_t: New
coap_pki_key_pem_t: New
coap_pki_key_asn1_t: New
coap_dtls_sni_t: New

Comments tidy up.

Better Doxygen comments for coap_dtls.h and net.h

Doxygen fix for debug.h (introduced by #219 merge)
Doxygen update coap_endpoint_new_dtls_session() for in coap_session.h
2018-07-23 11:14:22 +01:00
Jon Shallow d7373da99d src/coap_openssl.c: Fix broken ASN1 setup in coap_dtls_context_set_pki()
coap_dtls_pki_t struct has been enhanced to have more configuration options.
These configuruation options then tell libcoap what needs to get checked by
the underlying OpenSSL library rather than the user application has to do it.
There still is support for the user application to do all the Certificate
checking etc.

A late change to the PKI Pull request got missed for the TLS case
in coap_dtls_context_set_pki() for the mapping of private key types to
the OpenSSL version.  Have now pulled common DTLS and TLS code into a seperate
function

Fixed coap_(d)tls_free_session to not shut down a session that is not yet
fully started, as well as calling SSL_shutdown() twice if appropriate
The ssl parameter is set to NULL after closedown

Made coap_dtls_context_set_psk() smarter in what was updated, depending on
whether called by a client or server

Make sure that coap_dtls_psk_client_callback is defined in
coap_dtls_context_set_psk() in case coap_dtls_context_set_pki() was called
first.  This fixes the first time issue after startup where a PSK client
was unable to establish a DTLS session - subsequent times were successful

Added in a set of callbacks, invoked from coap_dtls_context_set_pki(), so that
a server can differentiate between an incoming PSK or PKI connection request.
These are only invoked if no full_call_back was defined in the setup_data

Add in a set of user definable callbacs for checking CN and SNI provided
information

Add in support for the generation and detection of ALPN externsion

Output error message if PKI or PSK was not set up before a server endpoint was
set up and (D)TLS is being used.

Allow a client to talk to a server that is PKI enabled without the need for
a PreShared Key or PKI Certificate

Set the SSL information at the SSL, not the CTX level when it is a client
2018-07-23 10:26:05 +01:00
Jon Shallow c9763dbe8c src/coap_io.c: Add in TCP Keepalive to socket
To enable early detection of a TCP connection failure.

Tidy up linelength of some surrounding functions.
2018-07-23 10:26:05 +01:00
obgm 668c45e527 Merge pull request #219 from mrdeep1/coap-show-pdu
debug.c: Make coap_show_pdu() use fprintf() or coap_log() for output
2018-07-23 11:13:25 +02:00
Jon Shallow fd421dd119 debug.c: Make coap_show_pdu() use coap_log() or fprintf()
coap_show_pdu()'s API is now coap_show_pdu(coap_log_t, coap_pdu_t*)
New function void coap_set_show_pdu_output(int use_fprintf)
Default is use fprintf() instead of coap_log()

The output buffer size can be configuring -DCOAP_DEBUG_BUF_SIZE

Output COAP_OPTION_SIZE2 option as well

For binary data, output ascii readable equivalent immediately under the
hex output for ease of debugging.

include/coap/debug.h
src/debug.c

Update coap_show_pdu() API
New function coap_set_show_pdu_output()
Update coap_show_pdu() code

include/coap/pdu.h

Define the coap debug output debug buffer size
COAP_DEBUG_BUF_SIZE

examples/client.c
examples/contiki/coap-observer.c
src/net.c
tests/test_wellknown.c
tests/test_pdu.c

Update coap_show_pdu() calls

libcoap-2.map
libcoap-2.sym

New function coap_set_show_pdu_output()
2018-07-20 18:58:55 +01:00
obgm 30da5299ef Merge pull request #223 from mrdeep1/observe-leak
src/resource.c: Handle subscriber leak if app is not handling duplicates
2018-07-20 18:39:40 +02:00
Jon Shallow df665114c6 src/resource.c: Handle subscriber leak if app is not handling duplicates
If multiple GET requests for the same URI + QUERY with different tokens and
Observe =0 is set, then for each GET there is an increment of the
subscriptions.

Currently, if the application is not clearing out the duplicate subscribers,
then the subscriber list gets large and eventually runs out of memory.

This fix stops duplicate subscriptions for the same session with the same
URI + QUERY, deleting the original entry and replacing it with a new
subscription.
2018-07-20 17:02:50 +01:00
obgm bf4323ed55 Merge pull request #201 from mrdeep1/issue-198
Limit outstanding CON requests to 1 per session for congestion control
2018-07-20 17:33:23 +02:00
obgm a6ae051a82 Merge pull request #224 from mrdeep1/doxygen-warnings
Remove doxygen warnings re text in header files by correcting parameter names
2018-07-20 17:29:22 +02:00
obgm 3cfcfce5c0 Merge pull request #217 from mrdeep1/os-fuzz
Fix reported issues #212, #214 and refix #199, add in valgrind to do extra testing
2018-07-20 16:59:56 +02:00
Jon Shallow c37dc485bc Remove doxygen warnings re text in header files by correcting parameter names
include/coap/coap_dtls.h
include/coap/coap_session.h
include/coap/encode.h
include/coap/net.h
include/coap/str.h
include/coap/subscribe.h
src/resource.c

Several functions have been better commented as well.
2018-07-20 14:02:02 +01:00
Jon Shallow 96d8877606 Fix reported issues #212, #214 and refix #199, add in valgrind to do the testing
build-env/Dockerfile.build-env
scripts/build.sh

Add in valgrind testing of the tests

src/option.c

Issue #199 Better fix of ADVANCE_OPT_CHECK()

src/pdu.c

Issue #214 Validate token length in coap_pdu_parse_header()

src/uri.c

Issue #212 Check not reading off end of buffer in dots()

tests/test_pdu.c
tests/test_uri.c

Tests updated to include tests for #212 & #214
2018-07-12 15:30:17 +01:00
Jon Shallow ea72c3d770 Limit outstanding CON requests to NSTART per session for congestion control
https://tools.ietf.org/html/rfc7641#section-4.5

In order not to cause congestion, servers MUST strictly limit the number of
simultaneous outstanding notifications/responses that they transmit to a given
client to NSTART (1 by default; see Section 4.7 of RFC 7252 [RFC7252]).
An outstanding notification/response is either a confirmable message for which
an acknowledgement has not yet been received and whose last retransmission
attempt has not yet timed out or a non-confirmable message for which the
waiting time that results from the following rate-limiting rules has not yet
elapsed.

Delay sending of PDUs if active CON request waiting for ACK.

Do not start of another Observer unsolicited response if active CON waiting
waiting for ACK.

Display outgoing PDU if log level DEBUG or higher to help troubleshooting.

This does not fix the ratelimiting of non-confirmable messages, which
should be handled by the application.
2018-07-10 14:11:32 +01:00
obgm 92994031ea Merge pull request #176 from mrdeep1/coap-client-server-update
Add in support for PKI for coap-client and coap-server
2018-07-06 11:21:15 +02:00
Jon Shallow bf5dd5a82f coap-{client|server}: Add in PKI Support. Tidy up Usage output
examples/client.c

Add in support for using PKI certificates

examples/coap-server.c

Add in support for using PKI certificates
remove default PSK key
Add in '-h hint' option

Make Usage reflect actual options available to use

man/coap-client.txt.in

Include the missing options
Update -A option to be a single entity
Sort the options into ascending order as reported by Usage

man/coap-server.txt.in

Include the missing options
Add in '-h hint' option
2018-07-03 15:06:17 +01:00
obgm 479191b241 Merge pull request #211 from bshastry/oss-fuzz
oss-fuzz: Move test from oss-fuzz repo
2018-07-02 13:45:32 +02:00
Bhargava Shastry fb2e227d5e oss-fuzz: Addressed comment by @obgm 2018-07-02 13:24:32 +02:00
Bhargava Shastry c9ec873053 oss-fuzz: Addressed comment by @obgm 2018-07-02 13:21:55 +02:00
Bhargava Shastry 793940d283 oss-fuzz: Move test from oss-fuzz repo 2018-06-27 11:23:23 +02:00
Olaf Bergmann 118bbebbbc pdu.h: add COAP_OPTION_SIZE2
This change closes issue #210 [1].

[1] https://github.com/obgm/libcoap/issues/210
2018-06-26 10:04:33 +02:00
Olaf Bergmann 98ae07b1c2 Dockerfile.build-env: install git to enable travis builds
The LwIP build requires git to work, so this must be available
in the build-env docker image.
2018-06-25 11:54:20 +02:00
Olaf Bergmann 767a24ebfc added Dockerfiles for building the travis environment 2018-06-25 11:35:02 +02:00
obgm df4bad7e08 Merge pull request #200 from mrdeep1/issue-199
Fix end byte overrun in coap_opt_parse() if 2 byte sequence
2018-06-13 16:41:35 +02:00
Jon Shallow c5cd313ea3 option.c: Fix end byte overrun in coap_opt_parse() if 2 byte sequence
tests/test_pdu.c: Create t_parse_pdu15() which shows the issue

Credit to OSS-Fuzz for finding this - work done by Bhargava Shastry with
the libcoap testing
2018-06-13 11:46:51 +01:00
Olaf Bergmann 0f8a3b334f coap-rd.c: remove type cast from RD_ROOT_STR
To ensure correct use of RD_ROOT_STR in coap_make_str_const() the
type cast to const uint8_t * has been removed.
This change addresses CID 1469634.
2018-06-06 16:49:12 +02:00
Olaf Bergmann df7b36edd5 client.c: explicitly restrict URI port number to 16 bits
To document that uri.port input to coap_encode_var_safe() never
has more than 16 bits, an explicit bit mask has been added. This
change is supposed to avoid the false positive CID 1469635.
2018-06-06 16:42:47 +02:00
Olaf Bergmann ec9bf6eb4a client.c: fix bug in Accept option parser
cmdline_content_type() treated option numbers as 8-bit integers and
therefore could not parse values >255. Now, option numbers are
represented as uint16_t to allow for numbers between 0 and 65535.

Moreover, as RFC 7252 has made the Accept option non-repeatable,
cmdline_content_type() now will only add a single Accept option.
2018-06-06 16:30:40 +02:00
Olaf Bergmann 97d32e68c8 README.md: included cross-reference to libcoap-minimal
libcoap-minimal [1] contains small client and server examples that
illustrate the use of libcoap-2.

This change also updates the copyright year.

[1] https://github.com/obgm/libcoap-minimal
2018-06-05 15:26:03 +02:00
Olaf Bergmann 171f25e123 client.c: fix -Wstringop-overflow warning in cmdline_token()
Calling strncpy() on the variable (and erroneous) calculated token
length in cmdline_token() has caused stringop-overflow warning by
GCC 8. This change fixes the error and replaces strncpy() by
memcpy() to quieten the compiler.
2018-06-05 12:28:40 +02:00