Skip to content

Enable PSA tests on K64F/K66F and fix missing PSA Crypto init in TLSSocketWrapper #14815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions connectivity/mbedtls/platform/inc/platform_mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#ifndef __PLATFORM_MBED__H__
#define __PLATFORM_MBED__H__

#if (defined(FEATURE_EXPERIMENTAL_API) && defined(FEATURE_PSA) && defined(MBEDTLS_ENTROPY_NV_SEED))
#if defined(FEATURE_EXPERIMENTAL_API) && defined(FEATURE_PSA)

#if defined(MBEDTLS_ENTROPY_NV_SEED)

#include "default_random_seed.h"

Expand All @@ -37,19 +39,8 @@
* MBEDTLS_ENTROPY_NV_SEED is enabled. */
#define MBEDTLS_PSA_INJECT_ENTROPY

#endif // (defined(FEATURE_PSA) && defined(MBEDTLS_ENTROPY_NV_SEED))

#if DEVICE_TRNG
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#endif
#endif

#if defined(MBEDTLS_CONFIG_HW_SUPPORT)
#include "mbedtls_device.h"
#endif
#endif // defined(MBEDTLS_ENTROPY_NV_SEED)

#if defined(FEATURE_PSA)
/* The following configurations are a needed for Mbed Crypto submodule.
* They are related to the persistent key storage feature.
*/
Expand All @@ -58,6 +49,17 @@
#undef MBEDTLS_PSA_CRYPTO_STORAGE_FILE_C

#define MBEDTLS_ENTROPY_HARDWARE_ALT

#endif // defined(FEATURE_EXPERIMENTAL_API) && defined(FEATURE_PSA)

#if DEVICE_TRNG
#if !defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
#define MBEDTLS_ENTROPY_HARDWARE_ALT
#endif
#endif

#if defined(MBEDTLS_CONFIG_HW_SUPPORT)
#include "mbedtls_device.h"
#endif

/*
Expand Down
14 changes: 14 additions & 0 deletions connectivity/netsocket/source/TLSSocketWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include "mbed_error.h"
#include "rtos/Kernel.h"

#if defined(MBEDTLS_USE_PSA_CRYPTO)
#include "psa/crypto.h"
#endif

// This class requires Mbed TLS SSL/TLS client code
#if defined(MBEDTLS_SSL_CLI_C)

Expand All @@ -41,6 +45,16 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont
_clicert_allocated(false),
_ssl_conf_allocated(false)
{
#if defined(MBEDTLS_USE_PSA_CRYPTO)
// It is safe to call psa_crypto_init() any number of times as
// defined by the PSA Crypto API. There is no standard "deinit"
// function.
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
tr_err("psa_crypto_init() failed (" PRIu32 ")", status);
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */

#if defined(MBEDTLS_PLATFORM_C)
int ret = mbedtls_platform_setup(nullptr);
if (ret != 0) {
Expand Down
37 changes: 37 additions & 0 deletions tools/test_configs/HeapBlockDeviceAndEthernetAndExperimental.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"config": {
"echo-server-addr" : {
"help" : "IP address of echo server",
"value" : "\"echo.mbedcloudtesting.com\""
},
"echo-server-port" : {
"help" : "Port of echo server",
"value" : "7"
},
"echo-server-discard-port" : {
"help" : "Discard port of echo server",
"value" : "9"
},
"echo-server-port-tls" : {
"help" : "Port of echo server for TLS",
"value" : "2007"
},
"echo-server-discard-port-tls" : {
"help" : "Discard port of echo server for TLS",
"value" : "2009"
},
"sim-blockdevice": {
"help": "Simulated block device, requires sufficient heap",
"macro_name": "MBED_TEST_SIM_BLOCKDEVICE",
"value": "HeapBlockDevice"
}
},
"target_overrides": {
"*": {
"target.network-default-interface-type": "ETHERNET",
"target.features_add": [
"EXPERIMENTAL_API"
]
}
}
}
2 changes: 2 additions & 0 deletions tools/test_configs/config_paths.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"ETHERNET" : "EthernetInterface.json",
"EXPERIMENTAL": "experimental.json",
"HEAPBLOCKDEVICE": "HeapBlockDevice.json",
"HEAPBLOCKDEVICE_AND_ETHERNET": "HeapBlockDeviceAndEthernetInterface.json",
"HEAPBLOCKDEVICE_AND_ETHERNET_AND_EXPERIMENTAL": "HeapBlockDeviceAndEthernetAndExperimental.json",
"HEAPBLOCKDEVICE_AND_WIFI": "HeapBlockDeviceAndWifiInterface.json",
"ESP8266_WIFI" : "ESP8266Interface.json",
"ISM43362_WIFI" : "ISM43362Interface.json",
Expand Down
9 changes: 9 additions & 0 deletions tools/test_configs/experimental.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"target_overrides": {
"*": {
"target.features_add": [
"EXPERIMENTAL_API"
]
}
}
}
9 changes: 4 additions & 5 deletions tools/test_configs/target_configs.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
{
"K64F": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET",
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET_AND_EXPERIMENTAL",
"test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER", "ESP8266_WIFI", "ETHERNET"]
},
"K66F": {
"default_test_configuration": "EXPERIMENTAL"
},
"NUCLEO_F429ZI": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "HEAPBLOCKDEVICE_AND_ETHERNET",
"test_configurations": ["HEAPBLOCKDEVICE_AND_ETHERNET", "NANOSTACK_MAC_TESTER"]
},
"DISCO_L475VG_IOT01A": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE",
"test_configurations": ["ISM43362_WIFI"]
},
"DISCO_F413ZH": {
"nsapi.socket-stats-enable": true,
"default_test_configuration": "NONE",
"test_configurations": ["ISM43362_WIFI"]
},
Expand Down