Implement CN and SNI call-back checks for GnuTLS. The validate_cn_call_back
function provides "RPK" for the common name and the ASN1 of the peers
certificate.
Update coap-server and coap-client to enable validate_cn_call_back and
validate_sni_call_back for RPK.
Install in PREFIX/share/libcoap/examples the source for coap-client.c and
coap-server.c with a standalone Makefile for ease of standalone code
development.
Add in configure option --enable-examples-source.
Included is a README, LICENSE and COPYING.
Example applications are built against the libcoap public API
and therefore prefix libcoap includes with "coap3)/".
The only exception is coap-rd which uses uthash.h from the internal
API. Therefore, "-Iinclude/coap3" is additionally passed as CPPFLAG
for coap-rd.
Move coap_pdu_t to coap_pdu_internal.h.
Move internal PDU based function definitions to coap_pdu_internal.h.
Replace most references to "struct coap_pdu_t" with "coap_pdu_t".
Create new enum coap_pdu_type_t, enum coap_pdu_code_t and coap_option_num_t,
using them where appropriate for clarity of documentation.
Provide new functions to allow applications to access/update parts of
coap_pdu_t as appropriate and document as appropriate.
Update examples to use these new access functions where appropriate.
The new configuration option --disable-async now allows to switch
of support for asynchronous operations.
The new function coap_async_is_supported() can be used to check
if the library was built with async support.
Move coap_async_state_t to coap_async_internal.h and rename to coap_async_t
as it no longer has any state.
Refactor the async logic to simplify usage and provide libcoap based delay
functionality support for request/response traffic such as multicast. Let
libcoap decide when the delayed response is to be sent.
Move internal async based function definitions to coap_async_internal.h.
Replace most references to "struct coap_async_state_t" with
"coap_async_t".
Provide new functions to allow applications to access parts of
coap_async_t as appropriate.
Update examples to use these new access functions where appropriate.
Add in new man page.
Move coap_context_t and coap_queue_t to coap_net_internal.h.
Move internal context and queue based function definitions to
coap_net_internal.h.
Replace most references to "struct coap_context_t" with "coap_context_t".
Provide new functions to allow applications to access parts of coap_context_t
as appropriate and document these functions.
Update examples to use these new access functions where appropriate.
For the man documentation, move the server session setup functions to (new)
coap_endpoint_server(3) and update coap_context(3) with all the context access
functions as these are common to both the client and server.
Move coap_session_t and coap_addr_hash_t to coap_session_internal.h.
Move internal session based function definitions to coap_session_internal.h.
Replace most references to "struct coap_session_t" with "coap_session_t".
Provide new functions to allow applications to access parts of coap_session_t
as appropriate and document these functions.
Update examples to use these new access functions where appropriate.
For the man documentation, move the client session setup functions to (new)
coap_endpoint_client(3) and update coap_session(3) with all the session access
functions as these are common to both the client and server.
[coap_endpoint_server(3) will be created when coap_context_t is obfuscated.]
include/coap2/net.h:
src/net.c:
Update code using #587 as a base to fix potential issues.
Fixes CID 1502429
CMakeLists.txt:
cmake_coap_config.h.in:
Test for <net/if.h>
examples/coap-rd.c:
examples/coap-server.c:
man/coap-rd.txt.in:
man/coap-server.txt.in:
Add in -G option to support specifying interface to use for multicasting.
Otherwise, the interface allocated by the O/S is used depending on the
address (if any) bound to.
man/Makefile.am:
man/coap_context.txt.in:
Document the coap_join_mcast_group_intf() function.
src/coap_debug.c:
Make sure that coap_print_addr() returns a NULL terminated buffer.
This change renames `coap_join_mcast_group` to `coap_join_mcast_group_intf`
and adds an extra `const char *ifname` parameter to specify the interface
name.
A `coap_join_mcast_group` macro is defined to maintain backwards API
compatibility.
`coap_is_mcast` has been modified to recognize IPv6-mapped IPv4 multicast
addresses. Without this `coap_network_send` treats these addresses as
unicast which makes `semdmsg` fail with EINVAL.
Examples have been updated to use the new call.
Fixes
CID 1502435:
CID 1502432:
CID 1502423:
False Positives
CID 1502434: Cant see why code is not reached
CID 1502433: Could make blk_size uint8_t:3 I guess.
CID 1502430: Dont know why it is complaining
CID 1502427:
CID 1502426: Code looks fine to me - context->session could be set.
CID 1502424:
Fixed by other PRs
CID 1502422: #610
CID 1502431: #610
CID 1502428: #610
CID 1502429: #587 with my additional fixes
CoAP transaction id was formerly defined as a hash of the remote address and
message id of the CoAP PDU. It now only refers to, and is used as, the
message id.
Replace occurences of 'transaction id' with 'message id' to reflect naming in
RFC7252.
Correct the definition of coap_tid_t to what it actually represents.
Replace occurrences of coap_tid_t with coap_mid_t.
Replace uses of tid with mid
Remove unused function coap_find_transaction().
Remove the UNUSED and UNUSED_PARAM definitions and use a single definition
of COAP_UNUSED as defined in libcoap.h
Replace all UNUSED / UNUSED_PARAM usages with COAP_UNUSED.
Correctly track the tokens so that the token that application sees in the
response is the same token as used in the initial request.
Update coap-server so that response data can be sent back to echo the data
that was in the request.
Fixes
CID 1502431
CID 1502428
CID 1502422
Change some of the types of variables, and cast change sizes where known to
be safe.
There still are some C4116 warning and a couple of C4090 warning which are OK,
so disabled by a #pragma.
.github/workflows/main.yml:
Build all the cmake TLS variants.
CMakeLists.txt:
Add in missing file.
examples/tiny.c:
include/coap2/encode.h:
Move COAP_PSEUDOFP_ENCODE_8_4 functions from encode.h to tiny.c.
Fix COAP_PSEUDOFP_ENCODE_8_4_DOWN 'ls' ordering complaint.
man/examples-code-check.c:
Fix compile warning, allow 'Unused but set variables' in examples and set
-Werror when compling the examples.
examples/lwip/Makefile:
Remove compilation option -fpack-struct
Merging #552 and #554 into develop caused Observe CON 2.05 initial block
response not to get an ACK from the client and so the Observe response kept
getting re-transmitted and caused other CON traffic to get queued up.
Troubleshooting highlighted an issue when a PUT/POST was updating the contents
of a resource and an Observe was active sending many payloads in a body.
src/net.c:
Make sure that an ACK is sent (if appropriate) when working with a block based
response.
examples/coap-server.c:
Give dynamic data associated with a resource a reference count, and only free
off the data when the reference count has dropped to 0.
Update coap_opt_filter_t to be a structure rather than a 16bit array that is
aliased with the real structure format.
Update code to use pointers where appropriate.
.github/workflows/main.yml:
Do a 'make check' for matrix builds.
Move documentation into separate job to reduce matrix build times
Add in CMake job.
Add in distribution job.
Add in tinydtls job.
Add in contiki/lwip job.
scripts/github_dist.sh:
Do the distribution checks using a script.
examples/etsi_iot_01.c:
examples/tiny.c:
Fix include coap.h directory in old examples.
README.md:
Update status badges to get only the branch actions and remove CMake
status badge.
Create a new include/coap2/coap_resource_internal.h to hold all the information
not available to applications.
Makefile.am:
Include coap_resource_internal.h in EXTRA_DIST.
Remove functions no longer visible from CTAGS_IGNORE.
examples/coap-rd.c:
examples/contiki/server.c:
examples/etsi_iot_01.c:
tests/test_wellknown.c
Replace direct access to coap_resource_t variables with functions as
appropriate.
include/coap2/resource.h:
include/coap2/subscribe.h:
include/coap2/coap_resource_internal.h: (New)
include/coap2/coap_subscribe_internal.h:
Move coap_resource_t, coap_addr_t, non API #defines and non API functions from
resource.h into coap_resource_internal.h, coap_subscribe_internal.h and
subscribe.h.
Replace inline functions accessing coap_resource_t with actual function
definitions.
Add new functions coap_resource_release_userdata_handler() and
coap_attr_get_value().
include/coap2/block.h:
Use coap_resource_t typedef.
include/coap2/coap_forward_decls.h:
Include coap_resource_t and coap_addr_t typedefs. Also typedef coap_context_t
to get rid of #include circular requirements.
include/coap2/coap_internal.h:
win32/libcoap.vcxproj:
win32/libcoap.vcxproj.filters:
Include coap_resource_internal.h.
include/coap2/net.h:
Remove "typedef struct coap_context_t" and do this in coap_forward_decls.h.
src/resource.c:
Update with the replaced inline functions. Add in the new functions
coap_resource_release_userdata_handler() and coap_attr_get_value().
libcoap-2.map:
libcoap-2.sym:
Update with new function visibility.
man/Makefile.am:
man/coap_attribute.txt.in:
man/coap_observe.txt.in:
man/coap_resource.txt.in:
Update with the new coap_resource_t and coap_attr_t usage.
In handle_response() the ACK is sent before calling ctx->response_handler() so
if the response_handler() wants to send RST the server ignores it as the ACK
has already been received.
By updating coap_response_handler_t to return a value, this can be used to
send the ACK (return of COAP_RESPONSE_OK) or a RST (return of COAP_RESPONSE_FAIL)
after ctx->response_handler() is called.
include/coap2/net.h:
man/coap_handler.txt.in:
Create a new enum coap_response_t for use as the return value for
coap_response_handler_t.
Update coap_response_handler_t and associated documentation.
src/net.c:
Send CoAP ACK or RST depending on return value of ctx->response_handler().
examples/client.c:
Update message_handler() to use the new coap_response_handler_t return values
(coap_response_t).
Remove block handling logic from coap-client and coap-server and make use of the
new libcoap functionality.
Add in new -L option to be able to define how libcoap is to work with block
handling. Update documentation accordingly.
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>
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.
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.