Skip to content

Commit c739586

Browse files
committed
client: add support for secondary root ca certificate
1 parent 2487a8a commit c739586

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ target_sources(app PRIVATE "src/main.c")
4040
# Definitions
4141
target_compile_definitions(app PRIVATE PROJECT_NAME="mender-stm32l4a6-zephyr-example")
4242

43-
# Generate Root CA include file
44-
generate_inc_file_for_target(app "src/AmazonRootCA1.cer" "${ZEPHYR_BINARY_DIR}/include/generated/AmazonRootCA1.cer.inc")
43+
# Generate Root CA include files
44+
generate_inc_file_for_target(app "src/AmazonRootCA1.der" "${ZEPHYR_BINARY_DIR}/include/generated/AmazonRootCA1.der.inc")
45+
generate_inc_file_for_target(app "src/GoogleTrustServicesR4.der" "${ZEPHYR_BINARY_DIR}/include/generated/GoogleTrustServicesR4.der.inc")

prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ CONFIG_MENDER_CLIENT_ADD_ON_CONFIGURE=y
2424
#CONFIG_MENDER_CLIENT_TROUBLESHOOT_SHELL=y
2525
#CONFIG_MENDER_CLIENT_TROUBLESHOOT_FILE_TRANSFER=y
2626
CONFIG_MENDER_STORAGE_NVS_SECTOR_COUNT=4
27+
CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_PRIMARY=1
28+
CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_SECONDARY=2
2729

2830
# Required to get Device Troubleshoot add-on working
2931
#CONFIG_HEAP_MEM_POOL_SIZE=1500
File renamed without changes.

src/GoogleTrustServicesR4.der

525 Bytes
Binary file not shown.

src/main.c

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,40 @@ LOG_MODULE_REGISTER(mender_stm32l4a6_zephyr_example, LOG_LEVEL_INF);
4040
#include <zephyr/llext/buf_loader.h>
4141
#endif /* CONFIG_LLEXT */
4242

43+
#ifdef CONFIG_NET_SOCKETS_SOCKOPT_TLS
44+
#include <zephyr/net/tls_credentials.h>
45+
#endif /* CONFIG_NET_SOCKETS_SOCKOPT_TLS */
46+
4347
/*
4448
* Amazon Root CA 1 certificate, retrieved from https://www.amazontrust.com/repository in DER format.
4549
* It is converted to include file in application CMakeLists.txt.
4650
*/
47-
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
48-
#include <zephyr/net/tls_credentials.h>
49-
#if defined(CONFIG_TLS_CREDENTIAL_FILENAMES)
50-
static const unsigned char ca_certificate[] = "AmazonRootCA1.cer";
51+
#ifdef CONFIG_NET_SOCKETS_SOCKOPT_TLS
52+
#ifdef CONFIG_TLS_CREDENTIAL_FILENAMES
53+
static const unsigned char ca_certificate_primary[] = "AmazonRootCA1.der";
54+
#else
55+
static const unsigned char ca_certificate_primary[] = {
56+
#include "AmazonRootCA1.der.inc"
57+
};
58+
#endif /* CONFIG_TLS_CREDENTIAL_FILENAMES */
59+
#endif /* CONFIG_NET_SOCKETS_SOCKOPT_TLS */
60+
61+
/*
62+
* Google Trust Services Root R4 certificate, retrieved from https://pki.goog/repository in DER format.
63+
* It is converted to include file in application CMakeLists.txt.
64+
* This secondary Root CA certificate is to be used if the device is connected to a free hosted Mender account (for which artifacts are saved on a Cloudflare server instead of the Amazon S3 storage)
65+
*/
66+
#ifdef CONFIG_NET_SOCKETS_SOCKOPT_TLS
67+
#if (0 != CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_SECONDARY)
68+
#ifdef CONFIG_TLS_CREDENTIAL_FILENAMES
69+
static const unsigned char ca_certificate_secondary[] = "GoogleTrustServicesR4.der";
5170
#else
52-
static const unsigned char ca_certificate[] = {
53-
#include "AmazonRootCA1.cer.inc"
71+
static const unsigned char ca_certificate_secondary[] = {
72+
#include "GoogleTrustServicesR4.der.inc"
5473
};
55-
#endif
56-
#endif
74+
#endif /* CONFIG_TLS_CREDENTIAL_FILENAMES */
75+
#endif /* (0 != CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_SECONDARY) */
76+
#endif /* CONFIG_NET_SOCKETS_SOCKOPT_TLS */
5777

5878
#include "mender-client.h"
5979
#include "mender-configure.h"
@@ -504,10 +524,17 @@ main(void) {
504524
/* Wait until the network interface is operational */
505525
k_event_wait_all(&mender_client_events, MENDER_CLIENT_EVENT_NETWORK_UP, false, K_FOREVER);
506526

507-
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
508-
/* Initialize certificate */
509-
tls_credential_add(CONFIG_MENDER_NET_CA_CERTIFICATE_TAG, TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate, sizeof(ca_certificate));
510-
#endif
527+
#ifdef CONFIG_NET_SOCKETS_SOCKOPT_TLS
528+
/* Initialize certificate(s) */
529+
assert(0
530+
== tls_credential_add(
531+
CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_PRIMARY, TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate_primary, sizeof(ca_certificate_primary)));
532+
#if (0 != CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_SECONDARY)
533+
assert(0
534+
== tls_credential_add(
535+
CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_SECONDARY, TLS_CREDENTIAL_CA_CERTIFICATE, ca_certificate_secondary, sizeof(ca_certificate_secondary)));
536+
#endif /* (0 != CONFIG_MENDER_NET_CA_CERTIFICATE_TAG_SECONDARY) */
537+
#endif /* CONFIG_NET_SOCKETS_SOCKOPT_TLS */
511538

512539
/* Read base MAC address of the device */
513540
char mac_address[18];

0 commit comments

Comments
 (0)