Skip to content

Commit 4c206f2

Browse files
jukkarnashif
authored andcommitted
net: https: Allow mbedtls debugging for https-server
The mbedtls debugging function was set before the ssl config struct was initialized. This meant that it was not possible to activate mbedtls debug prints. This commit sets the debug print option after the config struct has been initialized. Fixed also the debug prints which print extra \n which looks very bad in debugging outputs. This commit does not enable mbedtls debugging, it just makes it possible to output mbedtls debug prints. In order to get mbedlts debug prints one needs to do this: * set DEBUG_THRESHOLD to >0 in http_server.c * enable CONFIG_NET_DEBUG_HTTP in project config file * enable MBEDTLS_DEBUG_C in mbedtls config file (see file pointed by CONFIG_MBEDTLS_CFG_FILE option) * in qemu, one needs to increase the size of the available RAM, this setting does the trick, CONFIG_RAM_SIZE=300 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent b5cfd9a commit 4c206f2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

subsys/net/lib/http/http_server.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ static void https_disable(struct http_server_ctx *ctx);
2929

3030
#if defined(MBEDTLS_DEBUG_C)
3131
#include <mbedtls/debug.h>
32+
/* - Debug levels (from ext/lib/crypto/mbedtls/include/mbedtls/debug.h)
33+
* - 0 No debug
34+
* - 1 Error
35+
* - 2 State change
36+
* - 3 Informational
37+
* - 4 Verbose
38+
*/
3239
#define DEBUG_THRESHOLD 0
3340
#endif
3441

@@ -958,6 +965,7 @@ static void my_debug(void *ctx, int level,
958965
const char *file, int line, const char *str)
959966
{
960967
const char *p, *basename;
968+
int len;
961969

962970
ARG_UNUSED(ctx);
963971

@@ -969,6 +977,12 @@ static void my_debug(void *ctx, int level,
969977

970978
}
971979

980+
/* Avoid printing double newlines */
981+
len = strlen(str);
982+
if (str[len - 1] == '\n') {
983+
((char *)str)[len - 1] = '\0';
984+
}
985+
972986
NET_DBG("%s:%04d: |%d| %s", basename, line, level, str);
973987
}
974988
#endif /* MBEDTLS_DEBUG_C && CONFIG_NET_DEBUG_HTTP */
@@ -1281,11 +1295,6 @@ static void https_handler(struct http_server_ctx *ctx)
12811295

12821296
heap_init(ctx);
12831297

1284-
#if defined(MBEDTLS_DEBUG_C) && defined(CONFIG_NET_DEBUG_HTTP)
1285-
mbedtls_debug_set_threshold(DEBUG_THRESHOLD);
1286-
mbedtls_ssl_conf_dbg(&ctx->https.mbedtls.conf, my_debug, NULL);
1287-
#endif
1288-
12891298
#if defined(MBEDTLS_X509_CRT_PARSE_C)
12901299
mbedtls_x509_crt_init(&ctx->https.mbedtls.srvcert);
12911300
#endif
@@ -1296,6 +1305,11 @@ static void https_handler(struct http_server_ctx *ctx)
12961305
mbedtls_entropy_init(&ctx->https.mbedtls.entropy);
12971306
mbedtls_ctr_drbg_init(&ctx->https.mbedtls.ctr_drbg);
12981307

1308+
#if defined(MBEDTLS_DEBUG_C) && defined(CONFIG_NET_DEBUG_HTTP)
1309+
mbedtls_debug_set_threshold(DEBUG_THRESHOLD);
1310+
mbedtls_ssl_conf_dbg(&ctx->https.mbedtls.conf, my_debug, NULL);
1311+
#endif
1312+
12991313
/* Load the certificates and private RSA key. This needs to be done
13001314
* by the user so we call a callback that user must have provided.
13011315
*/

0 commit comments

Comments
 (0)