Commit Graph
2008 Commits
Author SHA1 Message Date
Olaf Bergmann 16ea2dca63 [CI] main.yml: Enable more checks 2021-02-12 12:44:47 +01:00
Olaf Bergmann 391be3176e [CI] main.yml: Run unit tests with valgrind 2021-02-12 12:40:44 +01:00
Olaf Bergmann 57a5a7e089 [CI] main.yml: basic build steps 2021-02-12 12:09:01 +01:00
Olaf Bergmann 5bcb0a1578 Revert ".github: removed consistently failing github workflow"
This reverts commit 610c3f6bf2.
2021-02-12 12:09:01 +01:00
Olaf Bergmann 2df4850180 net.c: Suppress warning for -Wunused-result
On systems where read() is declared with the attribute
warn_unused_result, a cast to void is not sufficient to suppress the
resulting warning. This change therefore checks the result explicitly.
2021-02-12 12:06:51 +01:00
Olaf Bergmann f681525272 coap-server.c: fix typecast warning for verify_cn_callback
This change fixes a warning output by clang for the cast from void* to
the potentially smaller enum coap_dtls_role_t (-Wvoid-pointer-to-enum-cast).
2021-01-13 15:56:28 +01:00
Olaf Bergmann 238fded2d8 pdu.c: fix heap overflow in coap_pdu_parse_opt()
coap_opt_length() must be called next_option_safe() to avoid
out-of-bound reads for malformed options.

Thanks to Marten Geuking for providing a detailed bug report.
2021-01-13 15:34:09 +01:00
obgm 7e6b2a9ec3 Merge pull request #589 from mrdeep1/now_2021
Update general copyrights to 2021
2021-01-07 12:05:37 +01:00
Jon Shallow 12fd8a25f7 Update general copyrights to 2021
Update main copyright statements to 2021.
2021-01-04 10:37:05 +00:00
obgm f29f053d53 Merge pull request #569 from mrdeep1/cmdline_read_user
cmdline_read_user: Fix NULL terminating code
2020-11-13 22:58:59 +01:00
Olaf Bergmann 5aa8d0c6a8 .gitignore: ignore autosave files 2020-11-13 22:57:08 +01:00
obgm 3650f6e8c3 Merge pull request #515 from mrdeep1/cygwin
Cygwin: Add in compiler support
2020-11-13 22:21:05 +01:00
Jon Shallow 05f6f8d401 cmdline_read_user: Fix NULL terminating code
Add indirection to pointer when NULL terminating the 'user' variable in
cmdline_read_user().
2020-11-13 17:00:19 +00:00
Jon Shallow cb8c7bffc9 Cygwin: Add in compiler support
See https://sourceforge.net/p/libcoap/mailman/message/37039434/

Works for

Computer: Windows 10 64 bit & CYGWIN_NT-10.0 x86_64
Cygwin: 3.1.5-1
OpenSSL: 1.1.1g
gcc:9.3.0

and gcc-10.2.0 + openssl1.1.1f

configure.ac:

Support cygwin build environment.  If so, set -D_CYGWIN_ENV in CFLAGS.

libtool: warning: undefined symbols not allowed in x86_64-pc-cygwin shared libraries; building static only
still to be fixed.

.gitignore:

Ignore *.exe filenames

src/coap_io.c:

define ipi_spec_dst as ipi_addr if _CYGWIN_ENV

examples/client.c:
examples/coap-rd.c:
examples/coap-server.c:
examples/etsi_iot_01.c
man/examples-code-check.c:
src/coap_io.c:
src/coap_tcp.c:

Fix compiler warnings.

sizeof(socklen_t) != sizeof(size_t) [-Wsign-compare]
isdigit() etc. complain about byte size array subscripts [-Wchar-subscripts]
snprintf size checks [-Wformat-truncation=]

Update
2020-11-13 16:12:24 +00:00
Olaf Bergmann ae9429fc20 coap_debug.c: Check value of COAP_DEBUG_BUF_SIZE
The technical lower bound of COAP_DEBUG_BUF_SIZE in the code is 5.
Sensible values should be significantly larger than 32 to ensure that
information can be displayed through this buffer.
2020-11-13 09:25:20 +01:00
obgm 9e0fe9a14f Merge pull request #469 from mrdeep1/debug_buf_size
coap_debug.c: Make the PDU debug output amount fully configurable by a -D option
2020-11-13 08:26:27 +01:00
Jon Shallow 767c707761 coap_debug.c: Make the PDU debug output amount fully configurable by a -D option
There are 2 output buffers - outbuf[] and buf[].  buf[] is limited in size
but used for printing out the data portion of the PDU before getting included
in outbuf[].

Make the printing of the data portion of the PDU go straight into outbuf[] to
get around the buf[] limitation.

Now the maximium amount of the printing out of the PDU can be controlled by
CPPFLAGS="-DCOAP_DEBUG_BUF_SIZE=xxxx" as a parameter to ./configure, where
xxxx is the output buffer size (e.g. use 4096).
2020-11-12 15:41:54 +00:00
obgm 471b171a1e Merge pull request #484 from mrdeep1/client_add_nl_option
coap-client: Add in option to add in newline after receipt of data
2020-11-12 16:02:27 +01:00
obgm 6f5256f3cf Merge pull request #518 from mrdeep1/server_port
coap-server: Clarify -p port usage
2020-11-12 10:08:05 +01:00
Jon Shallow 222b68566f coap-client: Add in option to add in newline after receipt of data
examples/client.c:

Add in -w option to add in a NL at end of receiving data - including after
re-assembling a BLOCK2 set of data.

man/coap-client.txt.in:

Document -w option.

Request raised by Issue #473.
2020-11-11 22:12:28 +00:00
Jon Shallow e383f977fc coap-server: Clarify -p port usage
Update usage() and man page examples on how the '-p port' option works.
2020-11-11 21:53:19 +00:00
obgm 33ba0fc261 Merge pull request #538 from mrdeep1/endpoint_t
coap_endpoint_t: Update usage of struct coap_endpoint_t to coap_endpoint_t
2020-11-11 20:12:40 +01:00
obgm d80f53e7f9 Merge pull request #511 from mrdeep1/proxy_support
Proxy: Update Proxy support for Proxy-Uri: CoAP option
2020-11-11 20:08:20 +01:00
Jon Shallow 9083189f95 Proxy: Update Proxy support for Proxy-Uri: CoAP option
Add code to better support the Proxy-Uri: and Proxy-Scheme: CoAP Options.

examples/client.c:

Make sure that the Proxy-Uri: option is added (if set) when clearing down an
observation (fixes #112).
Check that Proxy-Uri: option has a maximum data length of 1034 bytes.
Handle user defined Proxy-Scheme: option correctly.
Update -P option to include scheme to be used when connecting to the proxy.

examples/coap-server.c:

Add in hnd_proxy_uri() handler function. This has support for a direct or ongoing
proxy connection for the coap* protocols. The ongoing connection is set up as a
different CoAP session and is assocated with the incoming session for relaying
requests / responses.

Internal functions taken from client.c are used where appropriate.

Proxy support code has a SERVER_CAN_PROXY wrapper, so footprint can easily be
reduced if required.

New -P and -u options added to support ongoing connections.

include/coap2/net.h:

Add in tracking the proxy uri handler into coap_context_t.

include/coap2/resource.h:

Track whether a resource definition is for Proxy-Uri:/Proxy-Scheme:.
Define the coap_resource_proxy_uri_init() function for handling the Proxy-Uri:
option or Proxy-Scheme: option in an incoming request.

include/coap2/uri.h:

Add in COAP_URI_SCHEME_HTTP and COAP_URI_SCHEME_HTTPS as valid Proxy-Uri:
schemes.
Define the coap_split_proxy_uri() function (similar to coap_split_uri() but
supports the proxy extras.  Both now use a common sub function internally.

libcoap-2.map:
libcoap-2.sym:

Expose the new coap_resource_proxy_uri_init() and coap_split_proxy_uri()
functions.

man/Makefile.am:

Handle coap_resource_get_userdata(3) now being over the 10 definition limit
in man/coap_resource.txt.in.

man/coap-client.txt.in:

Update documentation for the -P option.

man/coap-server.txt.in:

Document the new -P proxy option.
Document the new -u user option.

man/coap_resource.txt.in:

Include documentation for coap_resource_proxy_uri_init().

src/coap_debug.c:

Output the Proxy-Scheme: Option as text.

src/net.c:

Sanity check and handle COAP_OPTION_PROXY_URI and COAP_OPTION_PROXY_SCHEME
in handle_request().

src/resource.c:

Add in coap_resource_proxy_uri_init() function.
Handle the addition of a proxy uri handler in coap_add_resource().

src/uri.c:

Rename coap_split_uri() to coap_split_uri_sub() and add in extra proxy
handling support based on input parameters.

Create new coap_split_uri() and coap_split_proxy_uri() which call
coap_split_uri_sub() appropriately.

TODO:

Remove reference to Proxy support required

src/coap_gnutls.c:

Fix a double deallocate found during testing
2020-11-11 17:46:17 +00:00
obgm 5c23771267 Merge pull request #560 from dismirlian/reconnect
Update interface index with received packet's index when getting session
2020-11-03 11:50:19 +01:00
Diego Ismirlian 2ab713f3ca Update interface index with received packet's index when getting session 2020-10-28 16:55:45 -03:00
Jon Shallow 8d2a788c1c coap_endpoint_t: Update usage of struct coap_endpoint_t to coap_endpoint_t
Use 'coap_endpoint_t' instead of 'struct coap_endpoint_t' in library source
files where possible.

Remove unnecessary 'struct xxx_t;' forward declarations.

Remove unnecessary 'void coap_free_endpoint(coap_endpoint_t *ep);'
2020-10-22 13:37:47 +01:00
obgm db4c9da2f7 Merge pull request #510 from mrdeep1/rpk_support
RPK RFC7250: Add in support
2020-10-22 14:00:44 +02:00
Jon Shallow cd56fa9902 README.md: Update which libraries support RPK 2020-10-22 12:21:37 +01:00
Jon Shallow e5d052cd57 RPK: Move common asn1 code into separate file
src/coap_asn1.c: (New)
include/coap2/coap_asn1_internal.h: (New)

Created and common asn1 functions added in

Makefile.am:
include/coap2/coap_internal.h:

Reference the new files.

src/coap_gnutls.c:
src/coap_tinydtls.c:

Updated to use new common asn1 functions.
2020-10-22 12:21:37 +01:00
Jon Shallow 25fbb26c60 RPK: Do not support PKI key type COAP_PKI_KEY_PEM
Support of COAP_PKI_KEY_PEM requires reading files which may not be supported
in libcoap running in a non Posix environment.

Remove RPK support when using PKI key type COAP_PKI_KEY_PEM.  Update
coap-server and coap-client to read the optional .pem files into memory and
use PKI key type COAP_PKI_KEY_PEM_BUF instead.
2020-10-22 12:21:30 +01:00
Jon Shallow d40f2d6a3f RPK RFC7250: Add in support
Currently OpenSSL and MBedTLS do not support RFC7250. See
https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Extensions
last column.

GnuTLS >= 3.6.6 required.

TinyDTLS update required.

New option is_rpk_not_cert added to PKI setup structure which is enabled
in coap-client and coap-server by the -M option and the use of a PUBLIC KEY
instead of a CERTIFICATE in the cert file.  If file is EC PRIVATE KEY, then
it can be used for both the public and private key files.

man/coap-client.txt.in:
man/coap-server.txt.in:

Document -M option.

man/coap_encryption.txt.in:
man/coap-server.txt.in:
man/coap_context.txt.in:

Add in documentation for RPK.

examples/client.c:
examples/coap-server.c:

Add in support for is_rpk_not_cert and -M option.
Stop sending ::1 for SNI - use localhost instead.

include/coap2/coap_dtls.h:

Add in is_rpk_not_cert option.

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

Add in coap_new_binary() and coap_delete_binary() functions.

src/coap_openssl.c:

Report RPK is not supported if invoked.
Check that all received data is used up for error recovery.

src/coap_mbedtls.c:

Report RPK is not supported if invoked.
Handle more MbedTLS generated errors.
Check that all received data is used up for error recovery.

src/coap_gnutls.c:

Add in support for RPK.
Add in sending Hello Verify if not cookie match in Client Hello
Check that all received data is used up for error recovery.

src/coap_tinydtls.c:

Add in support for RPK.

HOWTO.pkcs11:

Update for use with RPK.
Use .der file for '-C ca_file' definitions as later GnuTLS needs CA
to be trusted in HSM.
2020-10-21 15:54:20 +01:00
obgm f9535b9690 Merge pull request #558 from mrdeep1/option_update
Update libcoap.{map|sym} files
2020-10-20 21:56:07 +02:00
Olaf Bergmann 610c3f6bf2 .github: removed consistently failing github workflow
The github workflow fails very often due to broken setup or timeouts,
therefore it has been disabled for now.
2020-10-20 21:08:47 +02:00
Jon Shallow 8bdd4afaa9 Update libcoap.{map|sym} files
Missed from commit 605f990e.

Also fixes a compiler warning now that coap_opt_length() returns uin32_t.
2020-10-20 15:24:13 +01:00
Olaf Bergmann 94e84dbf91 [unit tests] replace coap_opt_delta()
Commit 605f990e has remove the function coap_opt_delta() which
was still used in the unit tests. This now has been replaced
by coap_opt_parse().
2020-10-20 15:14:48 +02:00
obgm fd33471010 Merge pull request #556 from mrdeep1/gnutls_alert_close_notify
coap_gnutls.c: Report Close notify at LOG_DEBUG, not LOG_WARNING
2020-10-20 14:47:14 +02:00
obgm 336caecf55 Merge pull request #555 from mrdeep1/coap_add_option
coap_add_option: Fix code rebase logging level issue
2020-10-20 14:46:47 +02:00
obgm b8c66fb401 Merge pull request #537 from mrdeep1/deprecated_warnings
Deprecated: Replace deprecated functions in library
2020-10-20 14:46:04 +02:00
Olaf Bergmann 605f990ef6 option.[hc]: remove unused function coap_opt_delta() 2020-10-20 13:16:19 +02:00
Olaf Bergmann b1ee9c8912 options: fix integer overflow in option parser
As the numeric range of CoAP option codes is [0..65804], the data
type for representing these codes must be uint32_t rather than
uint16_t.

Fixes OSS-Fuzz 26371. [1]

[1] https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26371
2020-10-20 13:16:00 +02:00
Jon Shallow 2f81b94603 coap_gnutls.c: Report Close notify at LOG_DEBUG, not LOG_WARNING
Reduce the level of reporting of Close notify alerts for default logging levels.
2020-10-16 05:32:04 -04:00
Jon Shallow f52ef9adaa coap_add_option: Fix code rebase logging level issue
PR #476 added in coap_insert_option() which could be called by
coap_add_option() with with a coap_log() message set to LOG_DEBUG.

When PR #539 was merged in, this upped the logging level to LOG_WARNING which
now causes test/testdriver to report unecessary messages.

Logging level reverted to LOG_DEBUG.
2020-10-16 05:16:57 -04:00
obgm 4ca959ca53 Merge pull request #499 from mrdeep1/coap_cache
coap_cache: Add in Cache Key and Cache Entry support
2020-10-14 16:32:35 +02:00
Jon Shallow 1a349d5cb4 coap_cache: Add in Cache Key and Cache Entry support
This updates the initial work done for adding in cache support

include/coap2/coap_cache.h: (new)
include/coap2/coap_cache_internal.h: (new)
src/coap_cache.c: (new)

New files to support cache support.

CMakeLists.txt:
Makefile.amMakefile.am:
Makefile.libcoap:
configure.ac:
examples/lwip/Makefile:
include/coap2/coap.h.in:
include/coap2/coap.h.windows:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:

Add in the new files.

examples/client.c:

Fix valgrind reported memory leak.

examples/coap-server.c:

Add in new example_data resource that uses the new caching logic.
Update hnd_put() to use the new cache logic for BLOCK1 PUTs.

include/coap2/coap_forward_decls.h:
include/coap2/coap_internal.h:
include/coap2/coap_session.h:
include/coap2/net.h:

Add in new cache support.

libcoap-2.map:
libcoap-2.sym:

Include the new functions.

man/Makefile.am:
man/coap.txt.in:
man/coap_cache.txt.in: (new)

Update documentation.

src/coap_io.c:

Idle timeout cache entries.

src/coap_session.c:

Delete cache entry when session is deleted.

src/net.c:

Delete cache entries when context is freed off.

src/coap_gnutls.c:
src/coap_mbedtls.c:
src/coap_notls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:

Add in SHA256 digest support.
2020-10-14 10:04:12 -04:00
obgm aba6646852 Merge pull request #539 from mrdeep1/option_checks
Options: Sanity check CoAP options in the PDU
2020-10-14 16:03:57 +02:00
Olaf Bergmann 0b142f9eda coap_cache: initial caching code 2020-10-14 09:33:37 -04:00
Jon Shallow e0a6593728 memory: Add in support for creating coap_binary_t objects
Add in coap_new_binary() and coap_delete_binary() functions which operate
in the same way as coap_new_string() and coap_delete_string() but work on
coap_binary_t objects.

include/coap2/str.h:
src/str.c:

Add in the coap_new_binary(), coap_resize_binary() and coap_delete_binary()
functions.

configure.ac:
man/Makefile.am:
man/coap.txt.in:
man/coap_string.txt.in: (new)

Add in documentation for the coap_string functions.

libcoap-2.map:
libcoap-2.sym:

Update with new functions.

coap_config.h.contiki:
include/coap2/lwippools.h:
include/coap2/mem.h:
src/mem.c:

Add support for fixed memory allocations for Cacke-Key and Cache-Entry
2020-10-14 09:33:37 -04:00
Jon Shallow 4d039eb01d Options: Sanity check CoAP options in the PDU
include/coap2/pdu.h:
src/pdu.c:
tests/test_pdu.c:

Change parameter max_delta to max_opt to better reflect actual usage.

include/coap2/pdu.h:
src/pdu.c:

Remove unneeded COAP_OPT_LONG and COAP_OPT_END definitions.

Remove unused function coap_add_option_later().

src/pdu.c:

Update coap_pdu_parse_opt() to sanity check the valid lengths of all the
known options.

src/coap_io_lwip.c:
src/net.c:

Ignore packets < 4 bytes
Send back a RST for UDP/DTLS if malformed PDU.

src/option.c:

Clean up coap_option_filter_get() documentation.
2020-10-14 09:26:27 -04:00
Olaf Bergmann e581813a55 [tinydtls] update to latest version
libcoap now includes tinydtls commit 290c48d
2020-10-14 15:05:53 +02:00