Commit Graph
1935 Commits
Author SHA1 Message Date
obgm b373aeca57 Merge pull request #525 from mrdeep1/testdriver
testdriver: Add in support for access to libcoap internal functions
2020-07-23 12:04:15 +02:00
obgm 65041c934d Merge pull request #475 from mrdeep1/pkcs11_support
PKCS11: Add in PKCS11 support for PKI
2020-07-23 11:40:50 +02:00
Olaf Bergmann 5f2f4ecf81 tinydtls: update to latest version
This change points the submodule to the changed tinydtls repository
which now lives at https://github.com/eclipse/tinydtls and updates
to the latest development HEAD.

Closes PR #531. [1]

[1] https://github.com/obgm/libcoap/pull/531
2020-07-23 10:00:32 +02:00
Jon Shallow b1245a95d7 testdriver: Add in support for access to libcoap internal functions
libtool marks functions included in the Makefile.am CTAGS_IGNORE list as
nm type 't' in .so library files so that they are not globally visible.
This means that tests/testdriver is unable to access these functions.

However, when building .a files, these functions remain as nm type 'T', so
are globally available.

This change causes tests/testdriver to always be be built with the .a
library file.

configure.ac:

Always enable --enable-static if --enable-tests is set.
Include this --enable-static requirement in the help information.

tests.Makefile.am

Change the default library type to always be .a and re-order parameters.
2020-07-16 11:25:22 +01:00
Jon Shallow 9443d9034a PKCS11: Add in PKCS11 support for PKI
Add in a new PKI_KEY type for PKCS11 URI to get the PKI information from a
smart card or HSM device.

Currently only OpenSSL and GnuTLS are supported.

Makefile.am:

Do not expose coap_dtls_shutdown() function.

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

Add in support for using pkcs11: URIs for defining the Certificates and
Private Keys.

include/coap2/coap_dtls.h:

Add in COAP_PKI_KEY_PKCS11 Key type.

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

Update documentation for supporting PKCS11.

man/coap_encryption.txt.in:

Add in documentation for COAP_PKI_KEY_PKCS11.
Correct some typos.

HOWTO.dual.gnutls (new):
HOWTO.dual.openssl (new):
HOWTO.dual.softhsm2 (new):
HOWTO.pkcs11 (new):

HowTo information.

src/coap_gnutls.c:
src/coap_openssl.c:

Add in PKCS11 support.

src/coap_mbedtls.c:

PKCS11 not yet supported.
Add in no-op coap_dtls_shutdown() function.

src/coap_notls.c:
src/coap_tinydtls.c:

Add in no-op coap_dtls_shutdown() function.

src/net.c:

Invoke coap_dtls_shutdown() function in coap_cleanup().

NOTE: There are memory leaks after cleanly closing down.  These are not within
libcoap as far as can be determined.  These leaks are a work in progress.
2020-07-07 09:15:58 +01:00
obgm 4107f42d90 Merge pull request #522 from mrdeep1/block_restriction
net.c: Relax TCP CSM Block-Wise-Transfer tests
2020-07-01 10:52:22 +02:00
Jon Shallow 63ab45b6a2 net.c: Relax TCP CSM Block-Wise-Transfer tests
If the initial coap_send() PDU initiates a TCP/TLS connection, the PDU is
delayed until the CSM packets are exchanged.  If the initial PDU contains
a BLOCK1 or BLOCK2 option, the PDU gets dropped as Block-Wise-Transfer in the
CSM has not been seen yet.  Seen if '-b X' option is used for coap-client.

The check is now only when the session has fully established and the
situation only logged and the PDU Not dropped.
2020-06-30 21:45:26 +01:00
obgm 098fa85395 Merge pull request #512 from mrdeep1/tcp_fixes
TCP: Prevent incorrectly formed PDUs causing RAM exhaustion.
2020-06-30 14:04:20 +02:00
Olaf Bergmann 448e08ae6c Merge branch 'develop' of github.com:obgm/libcoap into develop 2020-06-29 17:30:54 +02:00
Olaf Bergmann 0d2ba8ce35 CMakeLists.txt: add coap_prng.c and rename prng.h 2020-06-19 17:51:51 +02:00
Olaf Bergmann f92bfe9af3 Renamed prng.h to coap_prng.h 2020-06-19 17:51:25 +02:00
Olaf Bergmann 8fdc5696f7 configure.ac: check for getrandom() 2020-06-19 17:44:20 +02:00
Olaf Bergmann f17112659e [PRNG] improve pseudo number generation on platform POSIX
These new functions for generating pseudo numbers replace the old
macro-based approach:

coap_prng() replaces prng() to generate new pseudo random numbers.
This function uses getrandom() if HAVE_GETRANDOM is defined at
build time.

coap_prng_init() replaces prng_init() to seed the pseudo random
number generator. The function does nothing if HAVE_GETRANDOM is
set at build time.

coap_set_prng() can be used to register a custom pseudo number
generation function replacing the default.
2020-06-19 17:40:13 +02:00
Olaf Bergmann f0e8ebe0d0 coap-server.c: free allocated uri memory in hnd_delete
This fixes CID 1483548.
2020-06-19 16:51:55 +02:00
Olaf Bergmann 784c2ddc5f coap-server.c: fix memory leak in hnd_unkown_put()
Reverse the sequence of sanity checks to avoid allocating a new object
when not necessary.

This fixes CID 1483549.
2020-06-19 16:49:13 +02:00
Olaf Bergmann c98cc237b3 net.c: fix memory leak for query in handle_request
The storage for query was not released when coap_add_token() has
failed. As the query is used only if successful, the storage
allocation is moved downwards to improve handling of error cases.

This fixes CID 1483550.
2020-06-19 16:42:42 +02:00
Olaf Bergmann 48dc4538ce resource.[hc], net.c: fix use after free for query string
If a resource is observed, handle_request() passes the ownership
of a Uri-Query to the observer structure for later retrieval. In
this case, the query is not free'd in handle_request. However, if
the observer data structure ("subscription") was not created due
to insufficient memory, the query string must not be deleted as
it is used for the resource handler callback later in
handle_request(). The solution here passes ownership to the
observer only if case coap_add_observer() is successful.

This fixes CID 1483551.
2020-06-19 16:27:51 +02:00
Olaf Bergmann ec3dfda228 coap-server.c: Fix memory leak in hnd_put()
Added missing coap_delete_string() for uri_path in case of an error
return.

This fixes CID 1483553.
2020-06-19 16:13:50 +02:00
Olaf Bergmann da38169b42 examples-code-check.c: add NULL pointer check before closing file
This fixes CID 1495717.
2020-06-19 16:07:37 +02:00
Olaf Bergmann ba45a57efc coap-server.c: add missing fclose in read_file_mem
This fixes CID 1495722.
2020-06-19 16:01:29 +02:00
Olaf Bergmann e413fd545b coap-server.c: avoid fopen on NULL pointer in read_file_mem
As the behavior for calling fopen() on a NULL pointer is undefined in
ISO C99, a check is added before passing the file name to fopen().

This fixes CID 1495723.
2020-06-19 16:01:29 +02:00
Olaf Bergmann 1fded5dace coap-server.c: close file after reading SNI file
Add missing fclose() to cmdline_read_pki_sni_check() and
cmdline_read_psk_sni_check().

This fixes CIDs 1495719 and 1495724.
2020-06-19 16:01:09 +02:00
Olaf Bergmann 9c64e90517 net.c: fix check_return false positive from Coverity
In coap_io_do_epoll(), read() is called after timeout to clear the
file descriptor associated with the firing timer. As this function is
only called for its side effect, the result is ignored. Coverity scan
reports this as check_return event. A cast to void has been added to
document that the result is ignored on purpose.

This fixes CID 1495728.
2020-06-19 15:19:08 +02:00
Olaf Bergmann f97a7c5bde coap_session.c: avoid false positives with coverity for session release
coap_session_release() decrements a reference counter and releases
session resources when zero is reached. In certain function call
chains this leads to false positives with Coverity code analysis.
This change adds specific primitives to avoid these false positives.
This behavior is controlled by pre-processor conditionals.
2020-06-19 15:09:35 +02:00
Olaf Bergmann 7efa65077b Makefile.am: Add EXTRA_CFLAGS to AM_CFLAGS
Invoking make with EXTRA_CFLAGS allows to pass build configuration
parameters on the command line.
2020-06-19 15:09:35 +02:00
Jon Shallow e66b2aea83 DTLS: Fix identity length checking
src/coap_tinydtls.c:

Pass the correct identity size to coap_get_session_client_psk()
2020-06-19 15:09:35 +02:00
Olaf Bergmann e0cc7ebf32 net.c: fix possible derefence after null errors
Fix possible null pointer dereference in coap_get_context_server_hint()
and coap_get_context_server_psk().

These issues have been detected by Coverity scan as CIDs 1495725 and
1495729.
2020-06-19 15:09:35 +02:00
Olaf Bergmann 832dc349a8 Merge branch 'develop' of github.com:obgm/libcoap into develop 2020-06-16 11:08:05 +02:00
obgm 6e1927f04b Merge pull request #495 from mrdeep1/identity_len
DTLS: Fix identity length checking
2020-06-16 11:06:37 +02:00
Olaf Bergmann a40adc80c6 net.c: fix possible derefence after null check
Fix possible null pointer dereference in coap_get_context_server_psk().

This issue has been detected by Coverity scan as CID 1495725.
2020-06-16 10:05:23 +02:00
Jon Shallow 88151d3eb7 TCP: Prevent incorrectly formed PDUs causing RAM exhaustion.
src/net.c:

Add in a sanity check that the PDU length is not more that the negotiated
CSM size for incoming data.
Track CSM remote supports block transfer.
Do not allow Block options if CSM has not negotiated block transfer.

src/coap_session.c:

Include block-wise-transfer is supported in the CSM

include/coap2/coap_session.h:

Make MTU size bigger than 32 bits as CSM mtu size can be greater than 32 bits.
Track CSM remote supports block transfer.

include/coap2/pdu.h:

Make COAP_DEFAULT_MAX_PDU_RX_SIZE a unsigned long to be bigger than 32 bits.
2020-06-16 08:28:14 +01:00
obgm 04958a1069 Merge pull request #508 from kabeer27/improving-pdu-fuzzer
[Oss-Fuzz] Improving pdu_parse_fuzzer
2020-06-15 18:24:41 +02:00
kabeer27 c5526a3652 [Oss-Fuzz] Improving pdu_parse_target.c 2020-06-15 13:41:01 +05:30
obgm 9a61290b0b Merge pull request #505 from mrdeep1/cmake_shared_lib
CMakeLists.txt: Put BUILD_SHARED_LIBS option before add_library()
2020-06-08 11:11:27 +02:00
Olaf Bergmann 6b19f19562 uri.h: improved documentation 2020-06-03 10:06:25 +02:00
Olaf Bergmann 617ac895ec Merge branch 'develop' of github.com:obgm/libcoap into develop 2020-06-03 09:48:17 +02:00
obgm a178bd15d1 Merge pull request #509 from mrdeep1/rfc_8782
RFC7872: Add in media type application/dots+cbor
2020-06-03 09:39:29 +02:00
Jon Shallow 9dd16a3260 RFC7872: Add in media type application/dots+cbor
include/coap2/pdu.h:
src/coap_debug.c:

Include in coap_show_pdu() output if appropriate.
2020-06-01 11:29:03 +01:00
Olaf Bergmann 2c7c35cf74 coap.h.in: Set LIBCOAP_VERSION 2020-05-29 08:11:44 +02:00
Olaf Bergmann 149f7cb3b1 configure.ac: Define numeric version string
The symbol LIBCOAP_VERSION is set to a decimal 9-digit sequence of
form MMMmmmuuu where MMM is the major version number, mmm the minor
version number and uuu the micro version number.
2020-05-29 08:11:44 +02:00
Olaf Bergmann ffeeee1976 pdu.h: add Content-Format number for application/cwt
RFC 8392 defines the CoAP Content-Format number 61 for application/cwt
(CBOR web tokens).
2020-05-13 16:40:58 +02:00
Olaf Bergmann 93e75e44e3 [RIOT] coap_debug.h: define missing log levels
RIOT defines a subset of the syslog levels in log.h with different
numeric values. The remaining levels are defined here. Note that
output granularity differs from what would be expected when adhering
to the syslog levels.
2020-05-10 20:18:38 +02:00
Olaf Bergmann a78c753e8c [RIOT] coap_io_riot.c: fix timeout parameter in coap_io_process() 2020-05-10 16:41:30 +02:00
Olaf Bergmann 42ae470d2d [RIOT] coap_io_riot.c: Fix data type of parameter timeout_ms
Commit afefd95ce has changed the signature of coap_io_process() to use
a uint32_t for the timeout parameter.
2020-05-10 16:41:30 +02:00
Olaf Bergmann 93c0fcd8e1 [RIOT] coap_config.h.riot: undef HAVE_STRNLEN
strnlen() is not available on all RIOT boards, therefore the
substitution in libcoap is used for now.
2020-05-10 16:41:30 +02:00
Olaf Bergmann 789202ccb8 [RIOT] net.h: exclude coap_io_process_with_fds()
RIOT supports fd_set only for BOARD=native. For now,
coap_io_process_with_fds() is completely disabled on RIOT as it is not
yet implemented in coap_io_riot.c, anyway.
2020-05-10 13:46:50 +02:00
obgm aa4d148e25 Merge pull request #468 from mrdeep1/async_crash
async: Fix session->ref assertion failure and timeout values
2020-05-07 11:50:19 +02:00
Jon Shallow 8559e40cce async: Fix session->ref assertion failure and timeout values
Calling coap_free_context() does not free off any async entries, and so
raises assertion errors when coming to freeing off sessions if any async
entries exist.

async_data_t is a union, but the size of val and ptr are not the same - so
usage can have uninitialized data - hence bad timeout values.

Makefile.am:

Do not expose coap_delete_all*() functions.

examples/coap-server.c:

Fix async_data_t issue.

examples/etsi_iot_01.c:

Fix 32 bit compiler warnings using same logic as coap-server for holding the
async timeout value.

examples/lwip/Makefile:

Include async.c for the LwIP build.

include/coap2/async.h

Define coap_delete_all_async() function.

include/coap2/net.h
include/coap2/resource.h

Document coap_delete_all*() functions as internal.

libcoap-2.map
libcoap-2.sym

Remove non-exposed coap_delete_all*() functions.

src/async.c

Provide coap_delete_all_async() function.

src/net.c

Call coap_delete_all_async() from within coap_free_context().
2020-05-07 09:44:41 +01:00
Olaf Bergmann 43cb3c0778 README.md: Change target of build status badge link
The travis CI build status badges now point to the branches page at
travis-ci.com to provide a quick overview of the build status.
2020-05-07 07:51:41 +02:00
Jon Shallow 0bd77be830 CMakeLists.txt: Put BUILD_SHARED_LIBS option before add_library()
To build shared libraries, either the BUILD_SHARED_LIBS=ON option can be
defined globally for building, otherwise defining BUILD_SHARED_LIBS as an
OPTION in CMakeLists.txt works providing the OPTION is defined before the
add_library() call.

This fix is to move the OPTION BUILD_SHARED_LIBS to before the
add_library() call.

NOTE: Shared Library support is not currently available for Windows as the
appropriate functions are not currently exported.

BUILDING:

Document the Windows limitation and tidy up a bit.
2020-05-06 20:53:05 +01:00