dtls: check length in ClientHello

Without this patch a DTLS server could read over the reserved buffer in
case a corrupted handshake message was send.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: use dtls_get_peer() to get the peer config

The code from the dtls_get_peer() was copied instead of calling the
function. dtls_get_peer() also missed some more debugging functionality
added to the copied function.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: deactivate debugging when NDEBUG is set

Do not compile debug.c if --without-debug was given in the configure
script. We replace all the functions exported by debug.c with empty
implementations. The compiler should then remove all the coded.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: move hexdump() and dump() to debug.c

Instead of having 3 hexdump() and 2 dump() implementations in the code
copy them all to debug.c and expose it in the header.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: move declatration for dsrv_print_addr() into debug.h

Instead of declaring dsrv_print_addr() somewhere near it usage, move
the declaration into the debug.h header file.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: use correct log channel

dsrv_log() just wrote some part of the log message to the correct
output stream and not all of it.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: replace hexdump() with dtls_dsrv_hexdump_log()

hexdump() just wrote the dump to stdout without checking the configured
log level or the output stream. dtls_dsrv_hexdump_log() uses the same
log mechanisms as the default log function.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: add possibility for short hex dump

The short output is then comparable to the old dump() call.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: add own function to print keyblock

The code to dump the keyblock was copied 3 times into the code, extract
it into an own function and use the new log functions.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: replace most of the debug() calls

This replaces most of the dump() calls with calls to
dtls_dsrv_hexdump_log() to log the message to the appropriate log
channel. the ifndef is not needed any more because
dtls_dsrv_hexdump_log() is replaced with an empty function in case
NDEBUG is set.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: add method to log the session.

Instead of coping code to write the session into a char buffer call a
function in debug.c now.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
debug: print tls keys through the log functions

Instead of having some own and ifndefed code just call some log
functions.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>