mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-29 21:08:24 +00:00
Merge pull request #3222 from cesanta/mbedrbose
Add verbose MbedTLS errors
This commit is contained in:
4 files changed
+24
-8
No files matched your search
+11
-4
@@ -14038,6 +14038,13 @@ void mg_tls_ctx_free(struct mg_mgr *mgr) {
|
|||||||
#define MG_MBEDTLS_RNG_GET
|
#define MG_MBEDTLS_RNG_GET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int mg_tls_err(struct mg_connection *c, int rc) {
|
||||||
|
char s[80];
|
||||||
|
mbedtls_strerror(rc, s, sizeof(s));
|
||||||
|
MG_ERROR(("%lu %s", ((struct mg_connection *) c)->id, s));
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
static int mg_mbed_rng(void *ctx, unsigned char *buf, size_t len) {
|
static int mg_mbed_rng(void *ctx, unsigned char *buf, size_t len) {
|
||||||
mg_random(buf, len);
|
mg_random(buf, len);
|
||||||
(void) ctx;
|
(void) ctx;
|
||||||
@@ -14113,7 +14120,7 @@ void mg_tls_handshake(struct mg_connection *c) {
|
|||||||
MG_VERBOSE(("%lu pending, %d%d %d (-%#x)", c->id, c->is_connecting,
|
MG_VERBOSE(("%lu pending, %d%d %d (-%#x)", c->id, c->is_connecting,
|
||||||
c->is_tls_hs, rc, -rc));
|
c->is_tls_hs, rc, -rc));
|
||||||
} else {
|
} else {
|
||||||
mg_error(c, "TLS handshake: -%#x", -rc); // Error
|
mg_error(c, "TLS handshake: -%#x", -mg_tls_err(c, rc)); // Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14151,7 +14158,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
&tls->conf,
|
&tls->conf,
|
||||||
c->is_client ? MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
|
c->is_client ? MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
|
||||||
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
|
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
|
||||||
mg_error(c, "tls defaults %#x", -rc);
|
mg_error(c, "tls defaults %#x", -mg_tls_err(c, rc));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
mbedtls_ssl_conf_rng(&tls->conf, mg_mbed_rng, c);
|
mbedtls_ssl_conf_rng(&tls->conf, mg_mbed_rng, c);
|
||||||
@@ -14175,7 +14182,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
if (!mg_load_key(opts->key, &tls->pk)) goto fail;
|
if (!mg_load_key(opts->key, &tls->pk)) goto fail;
|
||||||
if (tls->cert.version &&
|
if (tls->cert.version &&
|
||||||
(rc = mbedtls_ssl_conf_own_cert(&tls->conf, &tls->cert, &tls->pk)) != 0) {
|
(rc = mbedtls_ssl_conf_own_cert(&tls->conf, &tls->cert, &tls->pk)) != 0) {
|
||||||
mg_error(c, "own cert %#x", -rc);
|
mg_error(c, "own cert %#x", -mg_tls_err(c, rc));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14186,7 +14193,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((rc = mbedtls_ssl_setup(&tls->ssl, &tls->conf)) != 0) {
|
if ((rc = mbedtls_ssl_setup(&tls->ssl, &tls->conf)) != 0) {
|
||||||
mg_error(c, "setup err %#x", -rc);
|
mg_error(c, "setup err %#x", -mg_tls_err(c, rc));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
c->is_tls = 1;
|
c->is_tls = 1;
|
||||||
|
|||||||
@@ -2657,6 +2657,7 @@ int mg_rsa_mod_pow(const uint8_t *mod, size_t modsz, const uint8_t *exp, size_t
|
|||||||
|
|
||||||
#if MG_TLS == MG_TLS_MBED
|
#if MG_TLS == MG_TLS_MBED
|
||||||
#include <mbedtls/debug.h>
|
#include <mbedtls/debug.h>
|
||||||
|
#include <mbedtls/error.h>
|
||||||
#include <mbedtls/net_sockets.h>
|
#include <mbedtls/net_sockets.h>
|
||||||
#include <mbedtls/ssl.h>
|
#include <mbedtls/ssl.h>
|
||||||
#include <mbedtls/ssl_ticket.h>
|
#include <mbedtls/ssl_ticket.h>
|
||||||
|
|||||||
+11
-4
@@ -12,6 +12,13 @@
|
|||||||
#define MG_MBEDTLS_RNG_GET
|
#define MG_MBEDTLS_RNG_GET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int mg_tls_err(struct mg_connection *c, int rc) {
|
||||||
|
char s[80];
|
||||||
|
mbedtls_strerror(rc, s, sizeof(s));
|
||||||
|
MG_ERROR(("%lu %s", ((struct mg_connection *) c)->id, s));
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
static int mg_mbed_rng(void *ctx, unsigned char *buf, size_t len) {
|
static int mg_mbed_rng(void *ctx, unsigned char *buf, size_t len) {
|
||||||
mg_random(buf, len);
|
mg_random(buf, len);
|
||||||
(void) ctx;
|
(void) ctx;
|
||||||
@@ -87,7 +94,7 @@ void mg_tls_handshake(struct mg_connection *c) {
|
|||||||
MG_VERBOSE(("%lu pending, %d%d %d (-%#x)", c->id, c->is_connecting,
|
MG_VERBOSE(("%lu pending, %d%d %d (-%#x)", c->id, c->is_connecting,
|
||||||
c->is_tls_hs, rc, -rc));
|
c->is_tls_hs, rc, -rc));
|
||||||
} else {
|
} else {
|
||||||
mg_error(c, "TLS handshake: -%#x", -rc); // Error
|
mg_error(c, "TLS handshake: -%#x", -mg_tls_err(c, rc)); // Error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +132,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
&tls->conf,
|
&tls->conf,
|
||||||
c->is_client ? MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
|
c->is_client ? MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER,
|
||||||
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
|
MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT)) != 0) {
|
||||||
mg_error(c, "tls defaults %#x", -rc);
|
mg_error(c, "tls defaults %#x", -mg_tls_err(c, rc));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
mbedtls_ssl_conf_rng(&tls->conf, mg_mbed_rng, c);
|
mbedtls_ssl_conf_rng(&tls->conf, mg_mbed_rng, c);
|
||||||
@@ -149,7 +156,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
if (!mg_load_key(opts->key, &tls->pk)) goto fail;
|
if (!mg_load_key(opts->key, &tls->pk)) goto fail;
|
||||||
if (tls->cert.version &&
|
if (tls->cert.version &&
|
||||||
(rc = mbedtls_ssl_conf_own_cert(&tls->conf, &tls->cert, &tls->pk)) != 0) {
|
(rc = mbedtls_ssl_conf_own_cert(&tls->conf, &tls->cert, &tls->pk)) != 0) {
|
||||||
mg_error(c, "own cert %#x", -rc);
|
mg_error(c, "own cert %#x", -mg_tls_err(c, rc));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +167,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((rc = mbedtls_ssl_setup(&tls->ssl, &tls->conf)) != 0) {
|
if ((rc = mbedtls_ssl_setup(&tls->ssl, &tls->conf)) != 0) {
|
||||||
mg_error(c, "setup err %#x", -rc);
|
mg_error(c, "setup err %#x", -mg_tls_err(c, rc));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
c->is_tls = 1;
|
c->is_tls = 1;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#if MG_TLS == MG_TLS_MBED
|
#if MG_TLS == MG_TLS_MBED
|
||||||
#include <mbedtls/debug.h>
|
#include <mbedtls/debug.h>
|
||||||
|
#include <mbedtls/error.h>
|
||||||
#include <mbedtls/net_sockets.h>
|
#include <mbedtls/net_sockets.h>
|
||||||
#include <mbedtls/ssl.h>
|
#include <mbedtls/ssl.h>
|
||||||
#include <mbedtls/ssl_ticket.h>
|
#include <mbedtls/ssl_ticket.h>
|
||||||
|
|||||||
Reference in new issue
Block a user