Commit graph

42 commits

Author SHA1 Message Date
Andrzej Głąbek 010730aff6 modules: mbedtls: Provide mbedtls_hardware_poll() conditionally
This is a follow-up to commit c7327f5f70.

Wrap implementation of the `mbedtls_hardware_poll()` function in
`#if defined(CONFIG_MBEDTLS_ZEPHYR_ENTROPY)` so that the function
is provided only when that option is activated.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2022-11-22 13:17:43 +09:00
Robert Lubos b76c35d809 modules: mbedtls: Replace select statement with depends on for EC
Instead of using "select" on certain EC configurations, which is
considered unsafe for various reasons, use a "depends on" and rely on
the user to set a proper configuration in the config file.

Update the respective project configurations to comply with the new
configuration scheme.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-10-07 15:12:42 +02:00
Marcin Niestroj fa5937aaed modules: mbedtls: support stripping newline from debug log messages
Debug log messages generated by mbedTLS library contain newline at the end
of log string. Remove this newline, if it exists, so that log output is
much more user friendly.

Add a dedicated Kconfig option for that, so it can be disabled on request.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Marcin Niestroj af37c09440 modules: mbedtls: convert mbedTLS log levels to Zephyr log levels
So far LOG_DBG() was used inside debug hook for mbedTLS library. This meant
that it was hard to distinct log messages by simply looking at the log
level number, even though Zephyr logging subsystem supports colorful logs
depending on log level.

Choose an appropriate Zephyr LOG_*() macro based on log level coming from
mbedTLS library. Remove log level number from formatted log messages, as it
is now redundant.

One controversial thing about this change is that mbedTLS' "2 State change"
log level is mapped to Zephyr's "warning" log level. Those are not really
warnings in real life, but rather informational messages. However, using
"warning" log level for those allows to clearly distinguish between "2
State change" and "3 Informational" debug messages from mbedTLS.
Additionally, mbedTLS debug message implementation does not seem to be safe
to use in production, so keeping in mind MBEDTLS_DEBUG will be enabled just
during debugging phase, printing "2 State change" logs as warnings should
not be a big deal.

Set default MBEDTLS_DEBUG_LEVEL value depending on selected Zephyr logging
module level, so that only single option needs to be configured in
application project.

Remove prompt for MBEDTLS_DEBUG_LEVEL, so that interactively (e.g. via
menuconfig) adjusting MBEDTLS_LOG_LEVEL will always result in automatically
updating MBEDTLS_DEBUG_LEVEL option. This is to prevent so called "stuck
symbol syndrome".

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Marcin Niestroj e4c11fd8aa modules: mbedtls: support extracting __FILE__ basename at buildtime
So far there was a runtime basename extraction of filenames passed to
mbedTLS debug hook. This has both runtime penalty as well as code size
penalty.

Introduce a buildtime support of extracting basename of source filenames
logged using logging subsystem, so that there is no need to do it at
runtime.

Provide Kconfig options for both buildtime and runtime basename extraction,
as in some cases the buildtime basename extraction might not work,
depending on toolchain used for building Zephyr. Default to buildtime when
using Zephyr SDK, as that is proven to work. Use runtime basename
extraction in other cases (other toolchains used).

This saves approximately 204 bytes of code footprint for sample
application with native TLS sockets built for nRF52840.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Marcin Niestroj 6653fd945f modules: mbedtls: set mbedTLS debug threshold during module initialization
mbedTLS library threshold initialization was done in native TLS socket
implementation (which tends to use mbedTLS now) and inside mbedTLS
benchmark test. Move that to mbedTLS module initialization, as this is a
global setting.

Update description of CONFIG_MBEDTLS_DEBUG_LEVEL to clarify when
mbedtls_debug_set_threshold() is called.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Marcin Niestroj a418ad4bb4 modules: mbedtls: move debug log hook implementation to modules/mbedtls/
So far there was a debug log hook installed in TLS socket implementation.
However, mbedTLS (with debug enabled) might be used outside from TLS socket
and even outside from networking context.

Add new module, which implements debug log hook and makes it available
whenever CONFIG_MBEDTLS_DEBUG is enabled.

Note that debug hook needs to be installed for each mbedTLS context
separately, which means that this requires action from mbedTLS users, such
as TLS sockets implementation.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Marcin Niestroj 6b386336ba modules: mbedtls: convert tabs to spaces in CMakeLists.txt
This is just a whitespace cleanup.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-08-17 12:03:52 +02:00
Eugene Cohen 03cfd130a8 modules: mbedtls: update flags to suppress unused var and func
Add module specific compiler flags to suppress reporting unused
variables and unused functions in mbedtls building.

Signed-off-by: Eugene Cohen <quic_egmc@quicinc.com>
Signed-off-by: Dave Aldridge <quic_daldridg@quicinc.com>
2022-08-15 14:32:23 +02:00
Robert Lubos ab024565f0 modules: mbedtls: Update Kconfig defaults for OSCORE/EDHOC
Set proper Kconfig defaults for mbed TLS if OSCORE/EDHOC is enabled.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-12 16:17:59 +02:00
Robert Lubos c7327f5f70 modules: mbedtls: Add mbed TLS entropy source based on Zephyr entropy
Add entropy source for mbed TLS based on Zephyr entropy driver.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-12 16:17:59 +02:00
Robert Lubos 1c1bb51730 modules: mbedtls: Add separate configs for EC algorithms
Instead of relying on selected ciphesuite to enable mbed TLS EC configs,
add separate config entries to enable them. This allows to use EC
functionality w/o TLS/DTLS enabled.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-12 16:17:59 +02:00
Robert Lubos fc81f67e9a modules: mbedtls: Add Kconfig entry for PSA API
Add Kconfig option to enable PSA API in mbed TLS.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-12 16:17:59 +02:00
Robert Lubos d288e24c6c modules: mbedtls: Workaround for incorrect inclusion in mbedtls
psa_crypto_cipher.c includes an internal header with <>, causing
complication errors in Zephyr (header not found).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-08-12 16:17:59 +02:00
Marcin Niestroj 48a9334826 modules: mbedtls: remove MBEDTLS_ECP_MAX_BITS from mbedTLS configs
According to mbedTLS' Changelog "Mbed TLS 3.0.0 branch released
2021-07-07" -> "Removals":

   MBEDTLS_ECP_MAX_BITS is no longer a configuration option because it
   is now determined automatically based on supported curves.

Hence remove MBEDTLS_ECP_MAX_BITS from configuration files to fix build
issues with Zephyr when there is unfortunate order of include
statements.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-07-02 14:13:45 +02:00
Marcin Niestroj dfe9a91da2 modules: mbedtls: bring back SHA384 support
Before mbedTLS 3.0 there was just SHA512 option, which enabled both SHA384
and SHA512 support. mbedTLS 3.0 introduced SHA384 specific option, which
means that SHA384 got unsupported after merging
commit 4e6cfb67f9 ("modules: mbedTLS: Bump mbedTLS to 3.0").

Introduce SHA384 Kconfig options, so that support for it can be selected in
project configuration if needed. Since SHA384 still depends on SHA512 to be
selected, add such dependency in Kconfig.

Select SHA384 support in non-generic (not configured by Kconfig) mbedTLS
config headers, so that previous (before mbedTLS 3.0 was merged) behavior
is regained.

Fixes: 4e6cfb67f9 ("modules: mbedTLS: Bump mbedTLS to 3.0")
Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2022-06-15 09:11:09 +02:00
Pete Skeggs 6a9854e2ca modules: mbedtls: Add Kconfig option to enable Extended Master Secret
Add Kconfig option for `config-tls-generic.h` to enable the Extended
Master Secret extension.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
2022-06-05 14:26:48 +02:00
Gerard Marull-Paretas 5f5a905784 modules: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all modules code to the
new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:57:47 +02:00
Robert Lubos bbba7c951d modules: mbedtls: Extend generic config with SSL cache
Add Kconfig configuration options which allow to configure
session caching in mbed TLS.

Note, that mbed TLS only takes care of server-side caching, the
application (socket layer) needs to implement a session storage for
client.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2022-04-28 11:31:07 +02:00
Eduardo Montoya b25de879e8 modules: mbedTLS: deselect unneeded hashes for OpenThread
SHA256 and SHA512 hashes are not needed for OpenThread.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
2022-04-08 15:50:53 -07:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Gerard Marull-Paretas dffaf5375c kconfig: tweak Kconfig prompts
Tweak some Kconfig prompts after the removal of "Enable...".

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Flavio Ceolin 26d7a929d4 modules: mbedTLS: Add Kconfig options for hashing
Add explicit Kconfig options to enable SHA support on mbedTLS.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2022-03-01 16:32:43 -05:00
Robert Lubos 2bc43cf94d modules: mbedtls: Remove MBEDTLS_ECP_MAX_BITS from generic config
MBEDTLS_ECP_MAX_BITS is now set automatically by mbed TLS, redefining it
in the config file ends up in compilation warnings.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-12-08 08:56:03 -05:00
Sam Chen 671ab46e2b modules/mbedtls: add the PKCS5 enabler
Kconfig support to `MBEDTLS_PKCS5_C` feature

Signed-off-by: Sam Chen <sam.chen@iota.org>
2021-11-11 07:18:47 -05:00
Marcin Niestroj c32b524d6d mbedtls: support configuration of PSK maximum length via Kconfig
So far maximum PSK length was configured by mbedTLS as 32 bytes.
Introduce Kconfig option that will configure it instead of relying on
default value from mbedTLS library, so that user can easily adjust that
value to application needs.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-11-10 08:28:15 -05:00
David Brown 1491551ca6 modules: Allow for Mbed TLS module to match upstream
Use the Mbed TLS module, expecting the upstream directory layout rather
than the nested directory we've been using before.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-10-18 09:51:06 -05:00
David Brown 7d8640aec3 modules: mbedtls: Fix buffer size configs for 3.0
Mbed TLS 3.0 changes the configuration defines used to determine the
buffer size used for TLS.  We were still setting the old one, which was
causing Mbed TLS to revert back to the large default buffer size.  Set
both the in and out buffer sizes to match the config setting.  A future
improvement may be to separate this into two configurations within the
Zephyr config.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-10-07 14:02:40 -05:00
Flavio Ceolin 0f39eac07c modules: mbdetls: define MBEDTLS_SHA224_c
Newer versions of mbedTLS require MBEDTLS_SHA224_C definition to use
sha256.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-10-07 14:02:40 -05:00
Frank Audun Kvamtrø fb90efef1b modules: mbedtls: Allow custom mbedtls implementation
-The current scheme in zephyr has the two choices MBEDTLS_BUILTIN
 and MBEDTLS_LIBRARY, but the choice of MBEDTLS_LIBRARY requires
 setting CONFIG_MBEDTLS_INSTALL_PATH for includes and library linking.
 This may not be neccesary when an alternative implementation of the
 library is being used. This adds support for custom choices in
 MBEDTLS_IMPLEMENTATION which can be added in an out-of-tree Kconfig
 file.
-Made else an elseif(CONFIG_MBEDTLS_LIBRARY.
-Removed reduntant assertion between the two choices.

Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
2021-09-29 15:32:40 -04:00
Marcin Niestroj 84c5a469ab module: mbedtls: add shell module
Add mbedTLS specific shell module, which allows (for now) to show heap
allocation statistics.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2021-07-14 21:14:35 -04:00
Robert Lubos 6ca92495e5 modules: mbedTLS: Add separate Kconfig entry for MBEDTLS_HAVE_TIME_DATE
Currently the MBEDTLS_HAVE_TIME_DATE mbedTLS option is enabled based on
the CONFIG_POSIX_API option. This doesn't seem right, since the enabling
the POSIX API does not guarantee that there is a valid time source in
the system. This was the case for the qemu_x86 platform, where enabling
POSIX_API caused TLS handshake failures due to certificate validation
errors caused by no valid time avaialble in the system.

Fix this by adding a specific KConfig entry for date/time configuration
in mbedTLS. Applications that need to enforce date verification in
mbedTLS should enable it explicitly instead of relying on the
non-obvious implicit configuration.

Fixes #35401

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2021-06-01 07:30:15 -05:00
Ioannis Glaropoulos 81e9ea5cad config: using CONFIG_MBEDTLS_USER_CONFIG_FILE as safeguard
Now using CONFIG_MBEDTLS_USER_CONFIG_FILE instead of
CONFIG_MBEDTLS_USER_CONFIG_ENABLE for inclusion of user config file.

The Kconfig MBEDTLS_USER_CONFIG_ENABLE setting now now determines if
MBEDTLS_USER_CONFIG_FILE is visible.

This removes the problem of MBEDTLS_USER_CONFIG_FILE to be stuck on its
first value.

Users can use MBEDTLS_USER_CONFIG_ENABLE to get the prompt and define
their own value.

As the CONFIG_MBEDTLS_USER_CONFIG_FILE is default promptless then we can
use this setting directly as it will only be defined if another Kconfig
file specifies a default value to use, or user enables:
MBEDTLS_USER_CONFIG_ENABLE.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 15:24:23 -05:00
Torsten Rasmussen 5888428541 mbedtls: kconfig: created MBEDTLS_PROMPTLESS and CUSTOM_MBEDTLS_CFG_FILE
Introducing MBEDTLS_PROMPTLESS and CUSTOM_MBEDTLS_CFG_FILE settings.
The MBEDTLS_PROMPTLESS can be set to true whenever configuration of
mbedTLS is done from a subsystem or module.

Such an example is OpenThread, which selects mbedTLS for some predefined
crypto settings using OPENTHREAD_MBEDTLS=y.

Unfortunately, extensive use of select can easily cause stuck symbol
syndrome making it harder than neccesarry for users to later reconfigure
as they easily get stuck in incompatible configurations.

Providing a MBEDTLS_PROMPTLESS allows such configurations to disable the
MBEDTLS prompt itself when selected but avoid stuck symbol if user
select another security configuration.

Similar with CUSTOM_MBEDTLS_CFG_FILE which ensures that user must
explicitly select this symbol before providing a custom mbedTLS config
file.

Today, other parts the Kconfig tree may set a default value for
MBEDTLS_CFG_FILE but that value is stuck and thus changed Kconfig
selections elsewhere in the tree will not adjust the value.

Introducing CUSTOM_MBEDTLS_CFG_FILE ensures it is known when the user
has provided the value.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 15:24:23 -05:00
Torsten Rasmussen c5097101f3 mbedtls: kconfig: MBEDTLS_USER_CONFIG_FILE default without a prompt
This commit removes the prompt from MBEDTLS_USER_CONFIG_FILE unless
MBEDTLS_USER_CONFIG_ENABLE is true.

This fixes issues where other parts would specify a default value for
MBEDTLS_USER_CONFIG_FILE that would become stuck and not updated if
user re-configured the system using menuconfig.

Disabling the prompt ensures that only when a user specifically enables
MBEDTLS_USER_CONFIG_ENABLE and specify a custom user value in
MBEDTLS_USER_CONFIG_FILE the setting will be fixed.

Also updates the manifest with related change in the mbedtls project.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 15:24:23 -05:00
David Brown 4164b17034 modules: mbedtls: Enable PKCS1 v2.1
This Mbed TLS configuration option was being selected based on a
non-existent Kconfig option, and hence would never be defined.  v2.1 of
PKCS1 was published in 2003.  Use of v1.5 has been deprecated since
2016, and should not be used in new or existing designs.

Enable the v2.1 version in any situation where RSA is used for
signatures.  In the future, we should disable v1.5 entirely, but only
after all uses have been determined and possibly corrected.

No significant weaknesses have been found in v1.5, however v2.1 has a
significant security proof.  However, v2.1 does require an entropy
source, which may be an issue in some embedded device situations (which
likely are problematic for other cryptographic reasons).

Signed-off-by: David Brown <david.brown@linaro.org>
2021-05-09 09:59:22 -05:00
Ioannis Glaropoulos 1a7f9598ba modules: mbedtls: updates to reflect module directory restructuring
Updates in CMakeLists.txt to reflect the restructuring
in the module directory. This also bumps mbetls version
to 2.26.0.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 09:59:22 -05:00
Ioannis Glaropoulos 1eccc71cc2 modules: mbedtls: move the configs into the main tree
Move the mbedtls configs directory in the main tree.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 09:59:22 -05:00
Ioannis Glaropoulos 67aadc2ef4 modules: mbedtls: add name for implementation choice symbol
Add a name for the Kconfig choice symbol
indicating the mbedtls implementation.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 09:59:22 -05:00
Ioannis Glaropoulos c48c50db42 modules: mbedtls: move CMakeLists.txt. into the main tree
We move the Zephyr-specific CMakeLists.txt file into
the main Zephyr tree. We also move the zephyr_init.c
source file.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-09 09:59:22 -05:00