Skip to content

Commit c3fff6e

Browse files
committed
mbedtls: allow storing certificates in filesystem
1 parent cdc2d45 commit c3fff6e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

connectivity/mbedtls/source/x509_crt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@
8080
#if !defined(_WIN32) || defined(EFIX64) || defined(EFI32)
8181
#include <sys/types.h>
8282
#include <sys/stat.h>
83+
#if defined(__MBED__)
84+
#include <platform/mbed_retarget.h>
85+
#else
8386
#include <dirent.h>
87+
#endif /* __MBED__ */
8488
#endif /* !_WIN32 || EFIX64 || EFI32 */
8589
#endif
8690

connectivity/netsocket/source/TLSSocketWrapper.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,17 @@ nsapi_error_t TLSSocketWrapper::set_root_ca_cert(const void *root_ca, size_t len
103103

104104
/* Parse CA certification */
105105
int ret;
106-
if ((ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(root_ca),
107-
len)) != 0) {
106+
switch (len) {
107+
#if defined(MBEDTLS_FS_IO)
108+
case 0:
109+
ret = mbedtls_x509_crt_parse_path(crt, static_cast<const char *>(root_ca));
110+
break;
111+
#endif
112+
default:
113+
ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(root_ca), len);
114+
break;
115+
}
116+
if (ret < 0) {
108117
print_mbedtls_error("mbedtls_x509_crt_parse", ret);
109118
mbedtls_x509_crt_free(crt);
110119
delete crt;

0 commit comments

Comments
 (0)