Build problem for echo client sample with (D)TLS

Hi,

I am trying to compile the sample 

  zephyr/samples/net/sockets/echo_client

from the v2.3.0-rc1 version for the Thingy91, with TLS support:

$ west build -b thingy91_nrf9160_ns -- -DOVERLAY_CONFIG=overlay-tls.conf

This does not build, see below for the output. When omitting the overlay for TLS, the build works. What do I have to change to make it work?

Thanks, Thomas

-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client
-- Using NCS Toolchain 2.2.0 for building. (/home/tludwig/ncs/toolchains/v2.2.0/cmake)
-- Found Python3: /home/tludwig/ncs/toolchains/v2.2.0/usr/local/bin/python3 (found suitable exact version "3.8.10") found components: Interpreter
-- Cache files will be written to: /home/tludwig/.cache/zephyr
-- Zephyr version: 3.2.99 (/home/tludwig/ncs/v2.3.0-rc1/zephyr)
-- Found west (found suitable version "0.13.1", minimum required is "0.7.1")
-- Board: thingy91_nrf9160_ns
-- Found host-tools: zephyr 0.15.2 (/home/tludwig/ncs/toolchains/v2.3.0-rc1/opt/zephyr-sdk)
-- Found toolchain: zephyr 0.15.2 (/home/tludwig/ncs/toolchains/v2.3.0-rc1/opt/zephyr-sdk)
-- Found Dtc: /home/tludwig/ncs/toolchains/v2.2.0/usr/local/bin/dtc (found suitable version "1.4.7", minimum required is "1.4.6")
-- Found BOARD.dts: /home/tludwig/ncs/v2.3.0-rc1/nrf/boards/arm/thingy91_nrf9160/thingy91_nrf9160_ns.dts
-- Generated zephyr.dts: /home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: /home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/build/zephyr/dts.cmake

warning: MBEDTLS_SSL_MAX_CONTENT_LEN (defined at modules/mbedtls/Kconfig:69,
modules/mbedtls/Kconfig:69) was assigned the value '2048' but got the value ''. Check these
unsatisfied dependencies: ((MBEDTLS_BUILTIN && MBEDTLS) || (MBEDTLS_BUILTIN && MBEDTLS && 0)) (=n).
See docs.zephyrproject.org/.../kconfig.html and/or look
up MBEDTLS_SSL_MAX_CONTENT_LEN in the menuconfig/guiconfig interface. The Application Development
Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
might be helpful too.


warning: TEST_RANDOM_GENERATOR (defined at subsys/random/Kconfig:8) was assigned the value 'y' but
got the value 'n'. Check these unsatisfied dependencies: (!ENTROPY_HAS_DRIVER) (=n). See
docs.zephyrproject.org/.../kconfig.html and/or look up
TEST_RANDOM_GENERATOR in the menuconfig/guiconfig interface. The Application Development Primer,
Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be
helpful too.


warning: The choice symbol MBEDTLS_BUILTIN (defined at modules/mbedtls/Kconfig:27,
modules/mbedtls/Kconfig:27) was selected (set =y), but MBEDTLS_LIBRARY_NRF_SECURITY (defined at
/home/tludwig/ncs/v2.3.0-rc1/nrf/Kconfig.nrf:31) ended up as the choice selection. See
docs.zephyrproject.org/.../kconfig.html and/or look up
MBEDTLS_BUILTIN in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.


warning: Experimental symbol NET_SOCKETS_SOCKOPT_TLS is enabled.


warning: Experimental symbol NET_SOCKETS_ENABLE_DTLS is enabled.


warning: Experimental symbol NET_CONNECTION_MANAGER is enabled.


warning: MBEDTLS_DTLS (defined at modules/mbedtls/Kconfig.tls-generic:34, /home/tludwig/ncs/v2.3.0-rc1/nrfxlib/nrf_security/Kconfig:120, modules/mbedtls/Kconfig.tls-generic:34) has direct dependencies ((MBEDTLS_TLS_VERSION_1_1 || MBEDTLS_TLS_VERSION_1_2) && !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) && MBEDTLS_BUILTIN && MBEDTLS_CFG_FILE = "config-tls-generic.h" && MBEDTLS) || ((MBEDTLS_TLS_VERSION_1_2 || MBEDTLS_SSL_PROTO_TLS1_2) && !MBEDTLS_BUILTIN) || ((MBEDTLS_TLS_VERSION_1_1 || MBEDTLS_TLS_VERSION_1_2) && !(NRF_SECURITY || NORDIC_SECURITY_BACKEND) && MBEDTLS_BUILTIN && MBEDTLS_CFG_FILE = "config-tls-generic.h" && MBEDTLS && 0) with value n, but is currently being y-selected by the following symbols:
- NET_SOCKETS_ENABLE_DTLS (defined at subsys/net/lib/sockets/Kconfig:99), with value y, direct dependencies NET_SOCKETS_SOCKOPT_TLS && NET_SOCKETS && NETWORKING (value: y), and select condition NET_NATIVE && NET_SOCKETS_SOCKOPT_TLS && NET_SOCKETS && NETWORKING (value: y)
Parsing /home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/Kconfig
Loaded configuration '/home/tludwig/ncs/v2.3.0-rc1/nrf/boards/arm/thingy91_nrf9160/thingy91_nrf9160_ns_defconfig'
Merged configuration '/home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/prj.conf'
Merged configuration '/home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/overlay-tls.conf'

error: Aborting due to Kconfig warnings

CMake Error at /home/tludwig/ncs/v2.3.0-rc1/zephyr/cmake/modules/kconfig.cmake:328 (message):
command failed with return code: 1
Call Stack (most recent call first):
/home/tludwig/ncs/v2.3.0-rc1/nrf/cmake/modules/kconfig.cmake:29 (include)
/home/tludwig/ncs/v2.3.0-rc1/zephyr/cmake/modules/zephyr_default.cmake:108 (include)
/home/tludwig/ncs/v2.3.0-rc1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
/home/tludwig/ncs/v2.3.0-rc1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!
FATAL ERROR: command exited with status 1: /home/tludwig/ncs/toolchains/v2.3.0-rc1/usr/local/bin/cmake -DWEST_PYTHON=/home/tludwig/ncs/toolchains/v2.3.0-rc1/usr/local/bin/python3.8 -B/home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client/build -GNinja -DBOARD=thingy91_nrf9160_ns -DOVERLAY_CONFIG=overlay-tls.conf -S/home/tludwig/ncs/v2.3.0-rc1/zephyr/samples/net/sockets/echo_client

Parents
  • Hi Thomas,

    Thank you for waiting!

    I should have thought of this earlier, but the nRF9160 already handles "native" TLS/DTLS through the modem, and so has no need for a TLS stack in the application itself. So the overlay is actually not necessary, as far as I can tell. You would only use it if you have special requirements. See https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/doc/slm_description.html#native-tls

    and see these two related DevZone posts:

     RE: How to interpret and resolve unsatisfied dependencies? 

     RE: Why does application that builds using nRF Connect SDK v2.0.0 fail to build under SDK v2.1.0  

    I hope that answers your question.

    Best regards,

    Raoul

  • Hi Raoul,

    Thanks for your answer and the pointers.

    While I prefer to configure mbedtls myself, using certificates, it would be also OK using the in-modem DTLS with PSK. However, there is no working example for a simple echo client (there are CoAP and LwM2M samples), that is why I tried the Zehyr echo client sample with overlay-tls.conf.

    Manually adding the defines

    #define CONFIG_NET_SOCKETS_SOCKOPT_TLS 
    #define CONFIG_NRF_MODEM_LIB 
    #define CONFIG_MODEM_KEY_MGMT 

    as suggested in the last link you sent, did not work.

    So, in another effort, I had created, based on the samples/nrf9160/udp sample, my own DTLS echo client. For testing, we have a machine on the Internet where I run OpenSSL's s_server:

    openssl s_server -dtls1_2 -accept 4567 -nocert -psk "01020304050607080901020304050607" --psk_identity "urn:imei:352656100832081" --psk_hint "My server" -state -trace

    The thingy91 connected to the server but the DTLS handshake never worked: The trace from s_server indicated that the client always wanted to renegotiate, endlessly. The OpenSSL s_sever works fine with other DTLS clients.

    This motivated me to use mbedtls directly instead of DTLS being encapsulated in BSD sockets. This way, I hoped that I could better understand what is going on. However, I realised that the modem needs mbedtls configured in a specific way; this seems to restrict what can be done in the application.

    To resolve this issue, I took the following approach: The modem is only used for the link layer and for UDP, using the nrf_* functions (I do not need to multiplex with other network interfaces). The nrf_* socket API is only used for UDP. I patched a copy of mbedtls-3.3.0 such that all symbols and all include files are renamed; this way, there is (hopefully) no interference with the nRF Connect SDK's mbedtls library.

    In this way, I managed to establish a working communication. I still need to test it more thoroughly but right now, this seems the way to go. I still would welcome a PSK-based DTLS echo client in nrf/samples/nrf9160.

    Of course this approach is a bit cumbersome and certainly more complex than using the DTLS extension of the socket API. It also precludes the use of any libraries that use the socket API. On the upside, one gets feedback about the progress of the DTLS handshake, the operations are non-blocking and features such as the protection against replay attacks can be activated.

    Best regards,
    Thomas

  • > The thingy91 connected to the server but the DTLS handshake never worked: The trace from s_server indicated that the client always wanted to renegotiate, endlessly. The OpenSSL s_sever works fine with other DTLS clients.

    If you like, provide the capture (maybe only selected messages). The behavior sounds strange. AFAIK both end uses hexadecimal encoded secrets so that common error cause seems not to apply. Which version of openssl are you running, a 3.x? Then you maybe caught by RFC5746 getting mandatory. Clients, even if not implementing renegotiation, needs to provide a minimal RFC5746 implementation. Or you need to disable that on the server side: 

     -legacy_renegotiation      Enable use of legacy renegotiation (dangerous)
     -client_renegotiation      Allow client-initiated renegotiation
     -no_renegotiation          Disable all renegotiation.
     -legacy_server_connect     Allow initial connection to servers that don't support RI
     -no_resumption_on_reneg    Disallow session resumption on renegotiation
     -no_legacy_server_connect  Disallow initial connection to servers that don't support RI

    I guess, it's "-legacy_renegotiation" may help.

  • you may also try to ask about the zephyr/mbedtls setup in https://github.com/zephyrproject-rtos/zephyr/issues maybe you can get some hints there.

Reply Children
No Data
Related