From dbbd83693176d837fa670d3b96eb75738d6ffedd Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 13 Jan 2020 17:10:18 +0100 Subject: [PATCH] Move mbedlts print func to SSLMbedTLSContext. --- modules/mbedtls/ssl_context_mbedtls.cpp | 5 +++++ modules/mbedtls/ssl_context_mbedtls.h | 2 ++ modules/mbedtls/stream_peer_mbedtls.cpp | 15 +++++---------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp index 82584e3494f..12598979881 100644 --- a/modules/mbedtls/ssl_context_mbedtls.cpp +++ b/modules/mbedtls/ssl_context_mbedtls.cpp @@ -38,6 +38,11 @@ static void my_debug(void *ctx, int level, fflush(stdout); } +void SSLContextMbedTLS::print_mbedtls_error(int p_ret) { + printf("mbedtls error: returned -0x%x\n\n", -p_ret); + fflush(stdout); +} + Error SSLContextMbedTLS::_setup(int p_endpoint, int p_transport, int p_authmode) { ERR_FAIL_COND_V_MSG(inited, ERR_ALREADY_IN_USE, "This SSL context is already active"); diff --git a/modules/mbedtls/ssl_context_mbedtls.h b/modules/mbedtls/ssl_context_mbedtls.h index 9145e0fd725..ea3bf4ec38b 100644 --- a/modules/mbedtls/ssl_context_mbedtls.h +++ b/modules/mbedtls/ssl_context_mbedtls.h @@ -51,6 +51,8 @@ protected: static PoolByteArray _read_file(String p_path); public: + static void print_mbedtls_error(int p_ret); + Ref certs; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index b88d9e48a45..03c59222671 100755 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -33,11 +33,6 @@ #include "core/io/stream_peer_tcp.h" #include "core/os/file_access.h" -void _print_error(int ret) { - printf("mbedtls error: returned -0x%x\n\n", -ret); - fflush(stdout); -} - int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { if (buf == NULL || len <= 0) return 0; @@ -88,8 +83,8 @@ Error StreamPeerMbedTLS::_do_handshake() { while ((ret = mbedtls_ssl_handshake(ssl_ctx->get_context())) != 0) { if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) { // An error occurred. - ERR_PRINTS("TLS handshake error: " + itos(ret)); - _print_error(ret); + ERR_PRINT("TLS handshake error: " + itos(ret)); + SSLContextMbedTLS::print_mbedtls_error(ret); disconnect_from_stream(); status = STATUS_ERROR; return FAILED; @@ -188,7 +183,7 @@ Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, in disconnect_from_stream(); return ERR_FILE_EOF; } else if (ret <= 0) { - _print_error(ret); + SSLContextMbedTLS::print_mbedtls_error(ret); disconnect_from_stream(); return ERR_CONNECTION_ERROR; } @@ -233,7 +228,7 @@ Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r disconnect_from_stream(); return ERR_FILE_EOF; } else if (ret <= 0) { - _print_error(ret); + SSLContextMbedTLS::print_mbedtls_error(ret); disconnect_from_stream(); return ERR_CONNECTION_ERROR; } @@ -264,7 +259,7 @@ void StreamPeerMbedTLS::poll() { disconnect_from_stream(); return; } else if (ret < 0) { - _print_error(ret); + SSLContextMbedTLS::print_mbedtls_error(ret); disconnect_from_stream(); return; }