Skip to content

Commit eb0caf5

Browse files
simensrostadrlubos
authored andcommitted
samples: net: Unify certificate handling
Update NET samples to be able to import and use certificates in valid PEM format. Signed-off-by: Simen S. Røstad <[email protected]>
1 parent 625d048 commit eb0caf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+187
-286
lines changed

applications/asset_tracker_v2/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ add_subdirectory_ifdef(CONFIG_WATCHDOG_APPLICATION src/watchdog)
3030
# Include nRF modem library header file for PC builds.
3131
# These are used throughout the application in type definitions.
3232
if (CONFIG_BOARD_QEMU_X86 OR CONFIG_BOARD_NATIVE_POSIX)
33-
target_include_directories(app PRIVATE ${NRFXLIB_DIR}/nrf_modem/include/)
33+
target_include_directories(app PRIVATE ${NRFXLIB_DIR}/nrf_modem/include/)
3434

35-
# Make folder containing certificates global so that it can be located by the configured
36-
# cloud library.
37-
zephyr_include_directories(src/cloud-certs)
35+
# Make the folder that contains the certificates global so that it can be located by the
36+
# nRF Cloud library. For the other clouds integrations, the certificates are handled by the
37+
# MQTT helper library, see CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES.
38+
if (CONFIG_NRF_CLOUD_PROVISION_CERTIFICATES)
39+
zephyr_include_directories(src/cloud-certs)
40+
endif()
3841

39-
target_compile_options(app PRIVATE
40-
-DCONFIG_LTE_NEIGHBOR_CELLS_MAX=10)
42+
target_compile_options(app PRIVATE
43+
-DCONFIG_LTE_NEIGHBOR_CELLS_MAX=10)
4144
endif()
4245

4346
if(CONFIG_ASSET_TRACKER_V2_LTO)
44-
target_compile_options(app PRIVATE "-flto")
47+
target_compile_options(app PRIVATE "-flto")
4548
endif()

applications/asset_tracker_v2/boards/native_sim.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@ CONFIG_BUILD_S1_VARIANT=n
116116

117117
# Watchdog
118118
CONFIG_WATCHDOG_APPLICATION=n
119+
120+
# Cloud module certificates
121+
CONFIG_MQTT_HELPER_CERTIFICATES_FOLDER="src/cloud-certs"

applications/asset_tracker_v2/src/cloud-certs/ca-cert.pem

Lines changed: 0 additions & 3 deletions
This file was deleted.

applications/asset_tracker_v2/src/cloud-certs/client-cert.pem

Lines changed: 0 additions & 3 deletions
This file was deleted.

applications/asset_tracker_v2/src/cloud-certs/private-key.pem

Lines changed: 0 additions & 3 deletions
This file was deleted.

doc/nrf/libraries/networking/aws_iot.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ There are multiple ways to generate and register these certificates:
188188
189189
#. Take note of the certificate ARN, as it will be required later.
190190
#. Download the `Amazon Root CA 1`_ PEM file as :file:`ca-cert.pem`.
191-
#. Provision the certificates and private key at runtime to the Mbed TLS stack.
192-
This is achieved by placing the PEM files into a :file:`certs/` subdirectory and ensuring the :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES` Kconfig option is enabled.
193-
For more information, refer to the :ref:`aws_iot` sample as well as the :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FILE` Kconfig option.
191+
#. Place the PEM files into the folder path specified by the :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FOLDER` option, default is :file:`<app_src_dir>/certs/`.
192+
Ensure that the :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES` option is set.
193+
#. If the files are placed correctly, the :ref:`lib_mqtt_helper` library finds the certificates and provisions them to the Mbed TLS stack when connecting to AWS IoT.
194194

195195
.. rst-class:: numbered-step
196196

doc/nrf/libraries/networking/azure_iot_hub.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,6 @@ The following are the ways to generate and register device certificates:
342342
343343
#. Provision the certificates and private key at runtime to the Mbed TLS stack.
344344
This is achieved by placing the PEM files into a :file:`certs/` subdirectory and ensuring the :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES` Kconfig option is enabled.
345-
The PEM files need to be converted to string format to be compiled into the firmware.
346-
347-
To do this, enclose each line in the PEM file with double quotes and finish each line with a newline character, using the following command:
348-
349-
.. code-block:: console
350-
351-
sed -i'.org' 's/.*/"&\\n"/' <pem_file>
352-
353345
For more information, refer to the :ref:`azure_iot_hub` sample as well as the :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FILE` Kconfig option.
354346

355347
.. rst-class:: numbered-step

doc/nrf/libraries/networking/mqtt_helper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Additionally, configure the following options as per the needs of your applicati
2727
* :kconfig:option:`CONFIG_MQTT_HELPER_RX_TX_BUFFER_SIZE`
2828
* :kconfig:option:`CONFIG_MQTT_HELPER_PAYLOAD_BUFFER_LEN`
2929
* :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES`
30-
* :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FILE`
30+
* :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FOLDER`
3131

3232
API documentation
3333
*****************

doc/nrf/releases_and_maturity/migration/migration_guide_2.7.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ Samples and applications
3131

3232
This section describes the changes related to samples and applications.
3333

34-
|no_changes_yet_note|
34+
* For applications using the :ref:`lib_mqtt_helper` library:
35+
36+
* The ``CONFIG_MQTT_HELPER_CERTIFICATES_FILE`` is now replaced by :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FOLDER`.
37+
The new option is a folder path where the certificates are stored.
38+
The folder path must be relative to the root of the project.
39+
40+
If you are using the :ref:`lib_mqtt_helper` library, you must update the Kconfig option to use the new option.
41+
42+
* When using the :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES` Kconfig option, the certificate files must be in standard PEM format.
43+
This means that the PEM files must not be converted to string format anymore.
3544

3645
Libraries
3746
=========

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ Multicore samples
243243
Networking samples
244244
------------------
245245

246-
|no_changes_yet_note|
246+
* Updated:
247+
248+
* The networking samples to support import of certificates in valid PEM formats.
247249

248250
NFC samples
249251
-----------
@@ -356,6 +358,11 @@ Libraries for networking
356358
* The :kconfig:option:`CONFIG_NRF_CLOUD_LOCATION_ANCHOR_LIST` Kconfig option to enable including Wi-Fi anchor names in the location callback.
357359
* The :kconfig:option:`CONFIG_NRF_CLOUD_LOCATION_ANCHOR_LIST_BUFFER_SIZE` Kconfig option to control the buffer size used for the anchor names.
358360

361+
* :ref:`lib_mqtt_helper` library:
362+
363+
* Changed the library to read certificates as standard PEM format. Previously the certificates had to be manually converted to string format before compiling the application.
364+
* Replaced the ``CONFIG_MQTT_HELPER_CERTIFICATES_FILE`` Kconfig option with :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FOLDER`. The new option specifies the folder where the certificates are stored.
365+
359366
Libraries for NFC
360367
-----------------
361368

0 commit comments

Comments
 (0)