Skip to content

Commit

Permalink
[MXCHIP] add ssl connetion lock
Browse files Browse the repository at this point in the history
  • Loading branch information
mxchipwanges committed Feb 29, 2024
1 parent e57e435 commit c449a4c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/supplemental/tls/mbedtls/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static mbedtls_ctr_drbg_context rng_ctx;
static nni_mtx rng_lock;
#endif

static nni_mtx ssl_conn_lock;

struct nng_tls_engine_conn {
void *tls; // parent conn
mbedtls_ssl_context ctx;
Expand Down Expand Up @@ -267,6 +269,7 @@ conn_init(nng_tls_engine_conn *ec, void *tls, nng_tls_engine_config *cfg)
{
int rv;

nni_mtx_lock(&ssl_conn_lock);
ec->tls = tls;

mbedtls_ssl_init(&ec->ctx);
Expand All @@ -279,6 +282,7 @@ conn_init(nng_tls_engine_conn *ec, void *tls, nng_tls_engine_config *cfg)
if (cfg->server_name != NULL) {
mbedtls_ssl_set_hostname(&ec->ctx, cfg->server_name);
}
nni_mtx_unlock(&ssl_conn_lock);

return (0);
}
Expand Down Expand Up @@ -713,6 +717,7 @@ nng_tls_engine_init_mbed(void)
return (rv);
}
#endif
nni_mtx_init(&ssl_conn_lock);

#ifdef CONFIG_MXCHIP_DEBUG_TLS
// mbedtls log level read from nanomq conf
Expand All @@ -725,12 +730,12 @@ nng_tls_engine_init_mbed(void)
#endif

rv = nng_tls_engine_register(&tls_engine_mbed);

#ifdef NNG_TLS_USE_CTR_DRBG
if (rv != 0) {
#ifdef NNG_TLS_USE_CTR_DRBG
nni_mtx_fini(&rng_lock);
}
#endif
nni_mtx_fini(&ssl_conn_lock);
}

return (rv);
}
Expand All @@ -742,4 +747,5 @@ nng_tls_engine_fini_mbed(void)
mbedtls_ctr_drbg_free(&rng_ctx);
nni_mtx_fini(&rng_lock);
#endif
nni_mtx_fini(&ssl_conn_lock);
}

0 comments on commit c449a4c

Please sign in to comment.