Skip to content

Commit 2229a2f

Browse files
author
Seppo Takalo
committed
Need to protect members with MBEDTLS_PK_C and X509_CRT_PARSE flags.
This is dependency to X509_CRT_PARSE but just to make sure that also the 'mbedtls_pk_context' structure is not used if that flag is not enabled.
1 parent 46c4601 commit 2229a2f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

features/netsocket/TLSSocketWrapper.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
4848
mbedtls_entropy_init(&_entropy);
4949
mbedtls_ctr_drbg_init(&_ctr_drbg);
5050
mbedtls_ssl_init(&_ssl);
51+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
5152
mbedtls_pk_init(&_pkctx);
53+
#endif
5254

5355
if (hostname) {
5456
set_hostname(hostname);
@@ -63,9 +65,8 @@ TLSSocketWrapper::~TLSSocketWrapper()
6365
mbedtls_entropy_free(&_entropy);
6466
mbedtls_ctr_drbg_free(&_ctr_drbg);
6567
mbedtls_ssl_free(&_ssl);
68+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
6669
mbedtls_pk_free(&_pkctx);
67-
68-
#ifdef MBEDTLS_X509_CRT_PARSE_C
6970
set_own_cert(NULL);
7071
set_ca_chain(NULL);
7172
#endif
@@ -119,7 +120,7 @@ nsapi_error_t TLSSocketWrapper::set_client_cert_key(const char *client_cert_pem,
119120
nsapi_error_t TLSSocketWrapper::set_client_cert_key(const void *client_cert, size_t client_cert_len,
120121
const void *client_private_key_pem, size_t client_private_key_len)
121122
{
122-
#if !defined(MBEDTLS_X509_CRT_PARSE_C)
123+
#if !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PK_C)
123124
return NSAPI_ERROR_UNSUPPORTED;
124125
#else
125126

@@ -483,7 +484,7 @@ int TLSSocketWrapper::ssl_send(void *ctx, const unsigned char *buf, size_t len)
483484
return size;
484485
}
485486

486-
#ifdef MBEDTLS_X509_CRT_PARSE_C
487+
#if defined(MBEDTLS_X509_CRT_PARSE_C)
487488

488489
mbedtls_x509_crt *TLSSocketWrapper::get_own_cert()
489490
{

features/netsocket/TLSSocketWrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ class TLSSocketWrapper : public Socket {
232232
static int ssl_send(void *ctx, const unsigned char *buf, size_t len);
233233

234234
mbedtls_ssl_context _ssl;
235+
#ifdef MBEDTLS_X509_CRT_PARSE_C
235236
mbedtls_pk_context _pkctx;
237+
#endif
236238
mbedtls_ctr_drbg_context _ctr_drbg;
237239
mbedtls_entropy_context _entropy;
238240

0 commit comments

Comments
 (0)