Skip to content

Commit 2bdd2f2

Browse files
committed
TLSSocketWrapper: add test for certificates stored in filesystem
1 parent dd1adbd commit 2bdd2f2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Case cases[] = {
231231
Case("TLSSOCKET_SEND_REPEAT", TLSSOCKET_SEND_REPEAT),
232232
Case("TLSSOCKET_SEND_TIMEOUT", TLSSOCKET_SEND_TIMEOUT),
233233
Case("TLSSOCKET_NO_CERT", TLSSOCKET_NO_CERT),
234+
Case("TLSSOCKET_CERT_IN_FILESYSTEM", TLSSOCKET_CERT_IN_FILESYSTEM),
234235
// Temporarily removing this test, as TLS library consumes too much memory
235236
// and we see frequent memory allocation failures on architectures with less
236237
// RAM such as DISCO_L475VG_IOT1A and NUCLEO_F207ZG (both have 128 kB RAM)

connectivity/netsocket/tests/TESTS/netsocket/tls/tls_tests.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void TLSSOCKET_SEND_UNCONNECTED();
8989
void TLSSOCKET_SEND_CLOSED();
9090
void TLSSOCKET_SEND_REPEAT();
9191
void TLSSOCKET_NO_CERT();
92+
void TLSSOCKET_CERT_IN_FILESYSTEM();
9293
void TLSSOCKET_SIMULTANEOUS();
9394
void TLSSOCKET_SEND_TIMEOUT();
9495

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020, Arduino SA, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
#include "TLSSocket.h"
20+
#include "greentea-client/test_env.h"
21+
#include "unity/unity.h"
22+
#include "utest.h"
23+
#include "tls_tests.h"
24+
#include "HeapBlockDevice.h"
25+
#include "LittleFileSystem.h"
26+
27+
using namespace utest::v1;
28+
29+
#if defined(MBEDTLS_SSL_CLI_C) && defined(MBEDTLS_FS_IO)
30+
31+
void TLSSOCKET_CERT_IN_FILESYSTEM()
32+
{
33+
SKIP_IF_TCP_UNSUPPORTED();
34+
35+
HeapBlockDevice bd(((strlen(tls_global::cert) / 512) + 1) * 512);
36+
LittleFileSystem fs("fs");
37+
TEST_ASSERT_EQUAL(0, fs.mount(&bd));
38+
39+
FILE *fp = fopen("/fs/certs.pem", "wb");
40+
int ret = fwrite(tls_global::cert, strlen(tls_global::cert), 1, fp);
41+
fclose(fp);
42+
43+
TLSSocket sock;
44+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
45+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.set_root_ca_cert_path("/fs"));
46+
47+
SocketAddress a;
48+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, NetworkInterface::get_default_instance()->gethostbyname(ECHO_SERVER_ADDR, &a));
49+
a.set_port(ECHO_SERVER_PORT_TLS);
50+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(a));
51+
}
52+
53+
#endif // defined(MBEDTLS_SSL_CLI_C)

0 commit comments

Comments
 (0)