Skip to content

Commit 312e6f7

Browse files
gregersryggrlubos
authored andcommitted
samples: net: download: add CONFIG_SAMPLE_PROVISION_CERT kconfig option
The default is to provision a root CA certificate from a file. Disable this option to avoid overwriting an existing certificate already stored in the modem. Signed-off-by: Gregers Gram Rygg <[email protected]>
1 parent aee6b33 commit 312e6f7

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ Matter samples
336336
Networking samples
337337
------------------
338338

339-
|no_changes_yet_note|
339+
* :ref:`download_sample` sample:
340+
341+
* Added the :ref:`CONFIG_SAMPLE_PROVISION_CERT <CONFIG_SAMPLE_PROVISION_CERT>` Kconfig option to provision the root CA certificate to the modem.
342+
The certificate is provisioned only if the :ref:`CONFIG_SAMPLE_SECURE_SOCKET <CONFIG_SAMPLE_SECURE_SOCKET>` Kconfig option is set to ``y``.
340343

341344
NFC samples
342345
-----------

samples/net/download/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
1010
project(download)
1111

1212
# Generate hex file from pem file
13-
if(CONFIG_SAMPLE_SECURE_SOCKET)
13+
if(CONFIG_SAMPLE_PROVISION_CERT)
1414
get_filename_component(FILE_NAME ${CONFIG_SAMPLE_CERT_FILE} NAME)
1515
set(OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/certs/${FILE_NAME}.inc")
1616
add_definitions(-DSAMPLE_CERT_FILE_INC="${OUTPUT_FILE}")

samples/net/download/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@ config SAMPLE_SEC_TAG
1010
int "Security tag"
1111
default 42
1212

13+
config SAMPLE_PROVISION_CERT
14+
bool "Provision root CA certificate"
15+
default y
16+
help
17+
Provision the root CA certificate for the server to the modem. This is needed for secure
18+
connections.
19+
Disable this option to avoid overwriting an existing root CA certificate already stored in
20+
the modem.
21+
1322
config SAMPLE_CERT_FILE
1423
string "Certificate file name"
1524
default "cert/file-example.pem"
25+
depends on SAMPLE_PROVISION_CERT
26+
1627
endif
1728

1829
choice SAMPLE_FILE

samples/net/download/README.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Overview
2727
********
2828

2929
The sample first initializes the :ref:`nrfxlib:nrf_modem` and AT communications.
30-
Next, it provisions a certificate to the modem using the :ref:`modem_key_mgmt` library if the :ref:`CONFIG_SAMPLE_SECURE_SOCKET <CONFIG_SAMPLE_SECURE_SOCKET>` option is set.
30+
Next, if the :ref:`CONFIG_SAMPLE_PROVISION_CERT <CONFIG_SAMPLE_PROVISION_CERT>` is set, it provisions a certificate to the modem using the :ref:`modem_key_mgmt` library if the :ref:`CONFIG_SAMPLE_SECURE_SOCKET <CONFIG_SAMPLE_SECURE_SOCKET>` option is set.
3131
When using an nRF91 Series device, the provisioning of the certificates must be done before connecting to the LTE network since the certificates can only be provisioned when the device is not connected.
3232
The certificate file name and security tag can be configured using the :ref:`CONFIG_SAMPLE_SEC_TAG <CONFIG_SAMPLE_SEC_TAG>` and the :ref:`CONFIG_SAMPLE_CERT_FILE <CONFIG_SAMPLE_CERT_FILE>` options, respectively.
3333

@@ -46,7 +46,7 @@ To enable CoAP block-wise transfer, it is necessary to enable :ref:`Zephyr's CoA
4646
Using TLS and DTLS
4747
==================
4848

49-
By default, the :ref:`CONFIG_SAMPLE_SECURE_SOCKET <CONFIG_SAMPLE_SECURE_SOCKET>` option is set, which means that the sample provisions the certificate found in the :file:`samples/net/download/cert` folder.
49+
By default, the :ref:`CONFIG_SAMPLE_PROVISION_CERT <CONFIG_SAMPLE_PROVISION_CERT>` option is set, which means that the sample provisions the certificate found in the :file:`samples/net/download/cert` folder.
5050
The certificate file name is indicated by the :ref:`CONFIG_SAMPLE_CERT_FILE <CONFIG_SAMPLE_CERT_FILE>` option.
5151
This certificate will work for the default test files.
5252
If you are using a custom download test file, you must provision the correct certificate for the servers from which the certificates will be downloaded.
@@ -68,13 +68,18 @@ Check and configure the following configuration options for the sample:
6868
.. _CONFIG_SAMPLE_SECURE_SOCKET:
6969

7070
CONFIG_SAMPLE_SECURE_SOCKET - Secure socket configuration
71-
If enabled, this option provisions the certificate to the modem.
71+
If enabled, downloading is done using a secure socket over TLS or DTLS.
7272

7373
.. _CONFIG_SAMPLE_SEC_TAG:
7474

7575
CONFIG_SAMPLE_SEC_TAG - Security tag configuration
7676
This option configures the security tag.
7777

78+
.. _CONFIG_SAMPLE_PROVISION_CERT:
79+
80+
CONFIG_SAMPLE_PROVISION_CERT - Root CA Certificate provision
81+
If enabled, this option provisions the certificate to the modem.
82+
7883
.. _CONFIG_SAMPLE_CERT_FILE:
7984

8085
CONFIG_SAMPLE_CERT_FILE - Certificate file name configuration

samples/net/download/src/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static struct net_if *net_if;
4141
static K_SEM_DEFINE(network_connected_sem, 0, 1);
4242

4343
#if CONFIG_SAMPLE_SECURE_SOCKET
44+
static int sec_tag_list[] = { SEC_TAG };
45+
#if CONFIG_SAMPLE_PROVISION_CERT
4446
static const char cert[] = {
4547
#include SAMPLE_CERT_FILE_INC
4648

@@ -49,9 +51,9 @@ static const char cert[] = {
4951
*/
5052
IF_ENABLED(CONFIG_TLS_CREDENTIALS, (0x00))
5153
};
52-
static int sec_tag_list[] = { SEC_TAG };
5354
BUILD_ASSERT(sizeof(cert) < KB(4), "Certificate too large");
54-
#endif
55+
#endif /* CONFIG_SAMPLE_PROVISION_CERT */
56+
#endif /* CONFIG_SAMPLE_SECURE_SOCKET */
5557

5658
static char dl_buf[2048];
5759

@@ -78,7 +80,7 @@ static mbedtls_sha256_context sha256_ctx;
7880

7981
static int64_t ref_time;
8082

81-
#if CONFIG_SAMPLE_SECURE_SOCKET
83+
#if CONFIG_SAMPLE_PROVISION_CERT
8284
static int cert_provision(void)
8385
{
8486
int err;
@@ -286,7 +288,7 @@ int main(void)
286288
return err;
287289
}
288290

289-
#if CONFIG_SAMPLE_SECURE_SOCKET
291+
#if CONFIG_SAMPLE_PROVISION_CERT
290292
/* Provision certificates before connecting to the network */
291293
err = cert_provision();
292294
if (err) {

0 commit comments

Comments
 (0)