Commit Graph
22 Commits
Author SHA1 Message Date
Jon Shallow b74aab1971 Support coap-client with no PKI or PSK defined, but using (D)TLS in GnuTLS
To reproduce the issue:

Server session
$ coap-server -v9 -n -k secretPSK -c server.pem -C ca.pem -R /etc/ssl/certs

Client session
$ examples/coap-client -v9  coaps://127.0.0.1/

include/coap2/coap_dtls.h:
src/coap_gnutls.c:

If neither coap_new_client_session_pki() or coap_new_client_session_psk()
is called, but coap_new_client_session() is (as done by coap-client if
no PKI or PSK options set), then set up a default PKI session to be
able to talk to a coap server.
2019-02-16 20:47:13 +00:00
Jon Shallow 829145cbba coap-client: Support using CA or Root CAs, but not Cert files
By defining the CA file or Root CAs in the client, the server's certificate
can be validated by the options in coap_dtls_pki_t parameter even if the client
does not define a certificate.
[The server must be configured not to require a Client Cert]

examples/client.c:

Add in the support to the coap-client to allow any of Root CA, CA and Cert
to be defined to set up PKI checking.

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

Remove the checks in the OpenSSL and GnuTLS underlying support that previously
used to enforce that both CA and Cert had to be set in the client.

Correct some of the PKI setup error messages to relect whether the failure is
on the client or the server.

include/coap2/coap_dtls.h:
src/coap_gnutls.c:
src/coap_notls.c:
src/coap_openssl.c:
src/coap_tinydtls.c:

Convert COAP_DTLS_ROLE_SERVER and COAP_DTLS_ROLE_CLIENT to enum
coap_dtls_role_t and use as appropriate to differentiate between the roles
in the different DTLS libraries
2019-02-15 18:00:52 +00:00
Carsten Schoenert aa802b3789 spelling: fix funtion -> function 2019-02-10 14:47:23 +01:00
Carsten Schoenert a54cd26c85 spelling: fix Addtional -> Additional 2019-02-10 14:47:20 +01:00
Olaf Bergmann 76daa297cd pdu.[hc]: make argument of coap_new_pdu() const
As the session object passed to coap_new_pdu() is not modified
it should be const.
2019-01-30 20:29:08 +01:00
Olaf Bergmann 48b1eff004 coap_session.[hc]: make argument of coap_session_max_pdu_size() const
As the session object passed to coap_session_max_pdu_size() is not
modified it should be const.
2019-01-30 20:27:10 +01:00
Jon Shallow 55d579449c Reserved Identifier fixes
include/coap2/libcoap.h
_LIBCOAP_H_ to COAP_LIBCOAP_H_
src/coap_session.c
_COAP_SESSION_H_ to COAP_SESSION_C_
include/coap2/coap_session.h
_SESSION_H_ to COAP_SESSION_H_

otherwise, all #define _COAP_xxxxx wrappers are now COAP_xxxxx

Fixes #291
2019-01-29 15:30:42 +00:00
Jon Shallow 164eef538b Clarify coap_add_data_blocked_response() usage
include/coap2/block.h
man/coap_pdu_setup.txt.in

Update documentation on coap_add_data_blocked_response() usage.
2019-01-11 16:39:02 +00:00
Olaf Bergmann 0388bb9e38 Renamed debug.[hc] to coap_debug.[hc]
Prefixing the file name with "coap_" helps avoiding a name clash
when libcoap is included as package in RIOT [1].

[1] https://github.com/RIOT-OS/RIOT
2019-01-07 00:51:10 +01:00
Jon Shallow 371c295fce Remove deprecated str typedef to remove namespace pollution
As str structure has been replaced by coap_string_t, remove it from the code
as it is no longer required, has been deprecated for some time and can cause
clashes with other str definitions.

Tidy up comment referring to str.
2018-12-27 11:51:42 +00:00
obgm 49e8e43eeb Merge pull request #283 from mrdeep1/mem_leak_hello
Possible to crash coap-server with uncompleted (D)TLS handshakes
2018-12-18 17:45:04 +01:00
Jon Shallow 15b42e9faa Possible to crash coap-server with uncompleted (D)TLS handshakes
For any TLS implementation, it is possible to crash the coap-server by
initiating (D)TLS handshakes but never completing them, thus continuing to use
more RAM.  Each partially completed handshake is left in the endpoint->sessions
chain in a state of COAP_SESSION_STATE_HANDSHAKE and unless
endpoint->max_idle_sessions is deliberately configured, these sessions will
never get deleted.

A cause of partially completed handshakes is when there is a PSK mismatch.

Furthermore, unnecessary CPU usage is used to search down long lists held in
endpoint->sessions.

This fix limits the  number of these sessions in a handshake state to the
number defined by endpoint->max_handshake_sessions if non zero or 100 to prevent
memory exhaustion.  By default, endpoint->max_handshake_sessions is 0.

Sessions in state COAP_SESSION_STATE_HANDSHAKE will get timed out after 30
seconds of inactivity.

This does not prevent a DOS attack by creating max_handshake_sessions as a
genuine new session will fail to get responded to until the number of current
COAP_SESSION_STATE_HANDSHAKE sessions drop.  However, the use of Cookie
exchanges by the underlying TLS library prior to a new session being created
and added into endpoint->sessions will filter out a lot of the DOS attacks.

include/coap2/coap_session.h

New default definition for COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS
New default definition for COAP_PARTIAL_SESSION_TIMEOUT_TICKS

include/coap2/net.h

Include max_handshake_sessions in coap_context_t

src/coap_session.c

In coap_endpoint_get_session() check the number of sessions in
COAP_SESSION_STATE_HANDSHAKE and handle accordingly when limits are hit, or
they need to be timed out.
2018-12-18 16:14:03 +00:00
Jon Shallow 8dcdbfb477 endpoint->hello information memory leak when coap_free_endpoint() called
Information set up in the pseudo session held in endpoint->hello is not freed
off when coap_free_endpoint() is called.

A solution is to split coap_session_free() into two parts with
coap_session_free() calling a new function coap_session_mfree().

Then coap_mfree_endpoint() can call coap_session_mfree() to free off the
endpoint specific hello information.

Makefile.am

Add coap_mfree_endpoint and coap_session_mfree to the CTAGS_IGNORE list.

libcoap-2.{map|sym}

Remove coap_mfree_endpoint as it is not a public function

include/coap2/coap_session.h

Add in new coap_session_mfree() function definition

src/coap_io.c

Call coap_session_mfree() from within coap_mfree_endpoint()

src/coap_session.c

Move some of the functionality out of coap_session_free() into a new
function coap_session_mfree() and  call coap_session_mfree().
2018-12-18 15:56:48 +00:00
Jon Shallow d8b399cfc9 New coap_show_tls_version() and coap_string_tls_version() functions
These new functions can be used to either update a buffer with, or coap_log()
out the current runtime TLS library along with the version of the library
that libcoap was built against.

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

Support for the new functions coap_show_tls_version() and coap_string_tls_version().
2018-11-27 11:42:21 +00:00
Jon Shallow 4a543d1198 Extend coap_tls_version_t to include both built and runtime TLS versions
This allows an application to determine what the built version is
as well as what the runtime version of a TLS library is.

include/coap2/coap_dtls.h

Add built_version to coap_tls_version_t

src/coap_openssl.c
src/coap_tinydtls.c

Additionally populate coap_tls_version_t with build_version when
coap_get_tls_library_version() is called.

src/coap_tinydtls.c

Correct the version returned as actual TinyDTLS version instead the
binary value of a DTLS packet type.
2018-11-27 11:42:04 +00:00
Carsten Schoenert 1d1eb455d6 spelling: fix seperate -> separate 2018-11-24 13:59:47 +01:00
Carsten Schoenert 32eea645b1 spelling: fix compatability -> compatibility 2018-11-24 13:59:34 +01:00
Jon Shallow 04ced3e5e5 Replace debug(), info() & warn() macros with appropriate coap_log()
This then removes the need for name polution/confict of debug(), info() and
warn() when building other projects that use libcoap and need to #include the
libcoap header files

Updated:
 examples/client.c
 examples/contiki/coap-observer.c
 examples/etsi_iot_01.c
 include/coap2/debug.h
 src/async.c
 src/block.c
 src/coap_io.c
 src/coap_openssl.c
 src/coap_session.c
 src/coap_tinydtls.c
 src/debug.c
 src/mem.c
 src/net.c
 src/option.c
 src/pdu.c
 src/resource.c
 src/uri.c

If the debug() etc. macros are still required, then the change to
include/coap2/debug.h just needs to be reverted.

There are also a couple of space changes - to cause log output to be columnar
e.g "ERR" was padded to "ERR ", so that "EMRG" or "ERR " log output output was
aligned in the same way.

This is a replacement for PR#51, and partially deals with name polution issues
raised in Issue #50.

Parameter re-aligned some long strings, splitting strings across multiple lines
2018-11-10 20:27:50 +00:00
Jon Shallow 4c95c50528 Clarify coap_resource_unknown_init() usage documentation
include/coap2/resource.h
man/coap_resource.txt.in
modified:   src/net.c (comment only)
2018-10-29 09:27:04 +00:00
Olaf Bergmann a8306bbb15 doxygen: fix warnings 2018-10-17 15:10:38 +02:00
Olaf Bergmann e782b4291f coap_hashkey.h: moved to include/coap2 2018-10-04 12:53:10 +02:00
Carsten Schoenert f584abc19e include: move header files to include/coap2
Automake is using the variable 'libcoap_include_HEADERS' as the list to
install the header files and is this list installing to $(prefix)
basically.
This commit is changing the primary installation folder for the header
files in addition to the previous commit.
2018-10-04 12:21:12 +02:00