Skip to content

Commit 34f358c

Browse files
committed
Enable loading x509 certificates from filesystem
1 parent a01a085 commit 34f358c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

features/mbedtls/src/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

features/netsocket/TLSSocketWrapper.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,15 @@ 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+
#endif
111+
default:
112+
ret = mbedtls_x509_crt_parse(crt, static_cast<const unsigned char *>(root_ca), len);
113+
}
114+
if (ret != 0) {
108115
print_mbedtls_error("mbedtls_x509_crt_parse", ret);
109116
mbedtls_x509_crt_free(crt);
110117
delete crt;

0 commit comments

Comments
 (0)