Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mbedtls/ssl: free cert chain when mbedtls_client_preload_filepath ena… #3335

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/secure-streams/private-lib-secure-streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ typedef struct lws_ss_handle {

union {
struct { /* LWSSSP_H1 */
#if defined(WIN32)
#if defined(WIN32) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
uint8_t dummy;
#endif
} h1;
struct { /* LWSSSP_H2 */
#if defined(WIN32)
#if defined(WIN32) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
uint8_t dummy;
#endif
} h2;
struct { /* LWSSSP_WS */
#if defined(WIN32)
#if defined(WIN32) || defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
uint8_t dummy;
#endif
} ws;
Expand Down
32 changes: 23 additions & 9 deletions lib/tls/mbedtls/wrapper/library/ssl_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,18 @@ SSL_CTX* SSL_CTX_new(const SSL_METHOD *method, void *rngctx)

#if defined(LWS_HAVE_mbedtls_x509_crt_parse_file)
if (mbedtls_client_preload_filepath) {
mbedtls_x509_crt **px = (mbedtls_x509_crt **)ctx->client_CA->x509_pm;

*px = malloc(sizeof(**px));
mbedtls_x509_crt_init(*px);
n = mbedtls_x509_crt_parse_file(*px, mbedtls_client_preload_filepath);
if (n < 0)
lwsl_err("%s: unable to load cert bundle 0x%x\n", __func__, -n);
else
lwsl_info("%s: loaded cert bundle %d\n", __func__, n);
mbedtls_x509_crt **px = (mbedtls_x509_crt **)ctx->client_CA->x509_pm;

*px = malloc(sizeof(**px));
mbedtls_x509_crt_init(*px);
n = mbedtls_x509_crt_parse_file(*px, mbedtls_client_preload_filepath);
if (n < 0) {
lwsl_err("%s: unable to load cert bundle 0x%x\n", __func__, -n);
mbedtls_x509_crt_free(*px);
free(*px);
} else {
lwsl_info("%s: loaded cert bundle %d\n", __func__, n);
}
}
#endif

Expand All @@ -257,6 +260,17 @@ void SSL_CTX_free(SSL_CTX* ctx)

ssl_cert_free(ctx->cert);

#if defined(LWS_HAVE_mbedtls_x509_crt_parse_file)
if (mbedtls_client_preload_filepath) {
mbedtls_x509_crt **px = (mbedtls_x509_crt **)ctx->client_CA->x509_pm;

if (*px) {
mbedtls_x509_crt_free(*px);
free(*px);
}
}
#endif

X509_free(ctx->client_CA);

if (ctx->alpn_protos) {
Expand Down