Commit Graph
2031 Commits
Author SHA1 Message Date
obgm b7fed2a706 Merge pull request #571 from Delsian/develop
refactor: replace magic numbers with defines
2021-02-23 17:50:06 +01:00
Olaf Bergmann 528c0293b7 README.md: Update build status badges
As travis-ci gets not triggered anymore, continuous integration has
been changed in commit 57a5a7e0 to use GitHub Actions. This change
updates the build status badges to report the GitHub Actions result
for the branches master and develop.
2021-02-23 10:56:28 +01:00
Eug Krashtan 6b58bfa96c examples: replace magic numbers with defines
CoAP response codes in examples represented by non-human-readable magic
numbers. It makes code harder to read, understand, and maintain.
Magic numbers there where replaced by human-readable enums.

Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
2021-02-22 21:20:31 +02:00
obgm f249117691 Merge pull request #579 from mrdeep1/keepalive_doc
DOC: Clarify coap_keepalive(3) documentation
2021-02-22 17:54:59 +01:00
obgm e42d7b7725 Merge pull request #598 from mrdeep1/mbedtls_version
configure.ac: Determine Mbed TLS library version for validity
2021-02-22 14:11:46 +01:00
Jon Shallow febed37ebf configure.ac: Determine Mbed TLS library version for validity
configure.ac:

Add in explicit library version checking as .pc file is not available.

m4/ac_check_cryptolibs.m4:

Add in AX_CHECK_MBEDTLS_VERSION for checking version compatibility.

configure.ac:
src/coap_mbedtls.c:

Correct brand name to Mbed TLS.
2021-02-20 11:08:29 +00:00
obgm 9f778cabca Merge pull request #583 from mrdeep1/doxygen_update
doxygen: Tidy up comments and add in missing modules
2021-02-19 16:04:13 +01:00
obgm 6a087687e8 Merge pull request #574 from mrdeep1/mbedTLS_naming
Mbed TLS: Update MbedTLS and mbedTLS to Mbed TLS to reflect brand name
2021-02-19 10:00:16 +01:00
obgm a15b3006d4 Merge pull request #561 from mrdeep1/tls_options
PKI: Make (D)TLS operation consistent across all TLS libraries
2021-02-19 09:48:55 +01:00
Jon Shallow 05d30e5ef1 PKI: Make (D)TLS operation consistent across all TLS libraries
The use of the verify_peer_cert and require_peer_cert variables in the
coap_dtls_pki_t structure was giving inconsistent results across all the
TLS libraries.  This primarily was down to the large numbers of options
available to control the TLS handshakes in OpenSSL compared to the limited
control available to mbedTLS port which followed later. require_peer_cert is
not easy to control in mbedTLS as it is an implicit configuration based on how
other, not always related, items were configured.

require_peer_cert was used by the server to control whether the client could
use anonymous certificates or not.  This is now controlled by verify_peer_cert.

require_peer_cert variable has been replaced with check_common_ca, so that
the OpenSSL functionality can continue, but enable GnuTLS / mbedTLS to
produce the same results.  This allows peers to mutually authenticate (because
the peer certs are signed by the same common CA) or not which was in effect
controlled by verify_peer_cert previously.

If check_common_ca is set, then allow_self_signed is ignored.

If is_rpk_not_cert is set, then all certificate validation is ignored.

In the examples, use of the -R option unsets check_common_ca, so disables
mutual authentication support by having a common CA.  This was needed as
mbedTLS and GnuTLS only have a single trust store for CAs.

configure.ac:

Increase the number of mbed libraries to use when checking for mbedTLS.

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

Add in -n (unset verify_peer_cert) option. In the case of coap-server and
coap-rd, make -n refer to verify_peer_cert.
Add in TLS library capabilites in usage().

Update usage() documentation as appropriate, with some changes to fit
everything into a 80 column output.

include/coap2/coap_dtls.h:
include/coap2/net.h:

Update with variable changes, and make the coap_dtls_pki_t parameter const for
the *_context_set_pki() functions.

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

Update documentation to reflect the examples option usage.

man/coap_context.txt.in:
man/coap_encryption.txt.in:
man/coap_session.txt.in:

Update with the new variable name and document as appropriate.

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

Update to make variable usage consistent. Update logging from LOG_WARNING to
LOG_INFO where there is an override of a PKI check failure by one of the
coap_dtls_pki_t variables.

Timing window closed for TLS where the peer does not like a certificate, sends
fatal alert and closes connection.  local then fails on writing the next
handshake - but now also reads in alert and reports on it.

src/coap_io.c:

Update logging from LOG_WARNING to LOG_INFO for EPIPE or ECONNRESET errors in
coap_socket_write().

src/net.c:

Handle the const coap_dtls_pki_t parameter in coap_context_set_pki() function.
2021-02-18 16:51:32 +00:00
obgm df6615bef5 Merge pull request #597 from mrdeep1/easier_troubleshoot
message id: Report everywhere the hex value for consistency
2021-02-16 10:08:23 +01:00
Jon Shallow 2e6cb55a50 message id: Report everywhere the hex value for consistency
coap_show_pdu() reports the Message ID (mid) as a hex value prefixes by i:.
Elsewhere it is reported as an integer or unsigned making those entries
difficult to match up with the reported PDU.

examples/coap-rd.c:
examples/etsi_iot_01.c:
src/async.c:
src/coap_session.c:
src/net.c:

Replace tid=%d, message %d and transaction %d with mid=0x%x for clarity.
2021-02-15 09:47:02 +00:00
obgm 475654021e Merge pull request #595 from mrdeep1/coap_prng_impl
coap_prng.c: Fix missing coap_prng_impl function.
2021-02-15 10:05:33 +01:00
Jon Shallow b0d46deef6 coap_prng.c: Fix missing coap_prng_impl function.
PR #590 unfortunately broke the standard builds.
2021-02-13 10:57:34 +00:00
obgm 9b45575cdf Merge pull request #586 from timgates42/bugfix_typo_updated
docs: fix simple typo, udated -> updated
2021-02-12 15:28:24 +01:00
obgm 85b45e0249 Merge pull request #590 from wenwu-glagle/pull_request
Fix some compile error in windows visual studio
2021-02-12 15:25:28 +01:00
Olaf Bergmann 4185e6215f [CI] main.yml: Enable building on all relevant events and branches 2021-02-12 13:01:39 +01:00
Olaf Bergmann 961afc742e [CI] main.yml: Set -Werror in compile matrix 2021-02-12 12:44:50 +01:00
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
沈文武 ad01c1d5eb Fix some compile error in windows visual studio
1. since coap_add_option_later() has been removed, so remove
coap_add_option_later in lib-coap-2.(map,sym) and pdu.h
2. [PRNG] need include coap_prng.c into visual studio project too, since new
functions for generating pseudo numbers replace the old macro-based
approach.
3. [PRNG] need define coap_prng() coap_prng_init() coap_set_prng() for
windows too since these function are exported in lib-coap-2.(map,sym)
2021-01-06 10:47:24 +08:00
Jon Shallow 12fd8a25f7 Update general copyrights to 2021
Update main copyright statements to 2021.
2021-01-04 10:37:05 +00:00
Jon Shallow f4d4cd60d8 Mbed TLS: Update MbedTLS and mbedTLS to Mbed TLS to reflect brand name
LICENSE:
README.md:
include/coap2/coap_dtls.h:
man/coap_encryption.txt.in:
man/coap_tls_library.txt.in:
src/coap_debug.c:
src/coap_mbedtls.c:

Replace MbedTLS and mbedTLS with "Mbed TLS".
2021-01-04 10:18:26 +00:00
Tim Gates 3e437e6910 docs: fix simple typo, udated -> updated
There is a small typo in include/coap2/coap_asn1_internal.h.

Should read `updated` rather than `udated`.
2020-12-20 07:32:03 +11:00
Jon Shallow 74fbbd3d55 doxygen: Tidy up comments and add in missing modules
Make documentation more consistent across doxygen output.

Add in caching module.
Add in encoding/decoding module.
Add in application i/o internal module.

Move deprecated items out of respective modules.
2020-12-16 12:26:45 +00:00
Jon Shallow 28ef9c4d51 DOC: Clarify coap_keepalive(3) documentation
Tidy up coap_keepalive(3) documentation.
2020-12-08 20:02:35 +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