|
| 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