Skip to content

Commit 337748a

Browse files
simensrostadnordicjm
authored andcommitted
net: nrf_cloud_coap: Separate nrf cloud coap sec tags
Separate sec tags used for JWT generation and DTLS. This makes it possible to point the DTLS sec tag to a dev tag to get decrypted DTLS traffic in modem traces. Signed-off-by: Simen S. Røstad <[email protected]> Signed-off-by: Justin Morton <[email protected]>
1 parent 378219e commit 337748a

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ Libraries for networking
968968
* Experimental support for shadow transform requests over MQTT using the :c:func:`nrf_cloud_shadow_transform_request` function.
969969
This functionality is enabled by the :kconfig:option:`CONFIG_NRF_CLOUD_MQTT_SHADOW_TRANSFORMS` Kconfig option.
970970
* The :kconfig:option:`CONFIG_NRF_CLOUD_COMBINED_CA_CERT_SIZE_THRESHOLD` and :kconfig:option:`CONFIG_NRF_CLOUD_COAP_CA_CERT_SIZE_THRESHOLD` Kconfig options to compare with the current root CA certificate size.
971+
* The functions :c:func:`nrf_cloud_sec_tag_coap_jwt_set` and :c:func:`nrf_cloud_sec_tag_coap_jwt_get` to set and get the sec tag used for nRF Cloud CoAP JWT signing.
971972

972973
* Updated:
973974

@@ -1010,6 +1011,7 @@ Libraries for networking
10101011
* Removed the experimental status (:kconfig:option:`CONFIG_EXPERIMENTAL`) from the :kconfig:option:`CONFIG_NRF_CLOUD_COAP_DOWNLOADS` Kconfig option.
10111012

10121013
* Added the :kconfig:option:`CONFIG_NRF_CLOUD_COAP_DISCONNECT_ON_FAILED_REQUEST` Kconfig option to disconnect the CoAP client on a failed request.
1014+
* Added the :kconfig:option:`CONFIG_NRF_CLOUD_COAP_JWT_SEC_TAG` Kconfig option to allow for a separate sec tag to be used for nRF Cloud CoAP JWT signing.
10131015

10141016
* :ref:`lib_lwm2m_client_utils` library:
10151017

include/net/nrf_cloud.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,10 @@ int nrf_cloud_credentials_configured_check(void);
12161216
* @note This API only needs to be called if the default configured sec tag value is no
12171217
* longer applicable. This function does not perform any management of the
12181218
* device's connection to nRF Cloud.
1219+
* For CoAP, changing this value will change the sec tag used for the DTLS connection only.
1220+
* Use @ref nrf_cloud_sec_tag_coap_jwt_set to set the sec tag used for JWT signing.
1221+
* For normal operation, the DTLS and JWT sec tags should be the same. They should only
1222+
* differ for debugging purposes (network traffic decryption).
12191223
*
12201224
* @param sec_tag The sec tag.
12211225
*
@@ -1229,6 +1233,31 @@ void nrf_cloud_sec_tag_set(const sec_tag_t sec_tag);
12291233
*/
12301234
sec_tag_t nrf_cloud_sec_tag_get(void);
12311235

1236+
/**
1237+
* @brief Set the sec tag containing the private key used to sign CoAP JWTs for nRF Cloud
1238+
* authentication.
1239+
* The default sec tag value is @kconfig{CONFIG_NRF_CLOUD_COAP_JWT_SEC_TAG}.
1240+
*
1241+
* @note This API requires @kconfig{CONFIG_NRF_CLOUD_COAP} to be enabled.
1242+
* This API only needs to be called if the default configured sec tag value is no
1243+
* longer applicable. This function does not perform any management of the
1244+
* device's authentication status with nRF Cloud.
1245+
*
1246+
* @param sec_tag The sec tag.
1247+
*
1248+
*/
1249+
void nrf_cloud_sec_tag_coap_jwt_set(const sec_tag_t sec_tag);
1250+
1251+
/**
1252+
* @brief Get the sec tag containing the private key used to sign CoAP JWTs for nRF Cloud
1253+
* authentication.
1254+
*
1255+
* @note This API requires @kconfig{CONFIG_NRF_CLOUD_COAP} to be enabled.
1256+
*
1257+
* @return The sec tag.
1258+
*/
1259+
sec_tag_t nrf_cloud_sec_tag_coap_jwt_get(void);
1260+
12321261
/** @} */
12331262

12341263
#ifdef __cplusplus

subsys/net/lib/nrf_cloud/Kconfig.nrf_cloud_coap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ config NRF_CLOUD_COAP_SERVER_HOSTNAME
2323
config NRF_CLOUD_COAP_SEC_TAG
2424
int "Security tag for credentials"
2525
default NRF_CLOUD_SEC_TAG
26+
help
27+
Security tag containing the nRF Cloud CoAP CA certificate and private key required for
28+
the DTLS connection to nRF Cloud.
29+
NRF_CLOUD_COAP_JWT_SEC_TAG defaults to the same sec tag value, so the private key
30+
is also used for authentication.
31+
32+
config NRF_CLOUD_COAP_JWT_SEC_TAG
33+
int "[For Debug Use] Security tag for JWT credentials"
34+
default NRF_CLOUD_COAP_SEC_TAG
35+
help
36+
Security tag containing the private key used to sign CoAP JWTs for nRF Cloud
37+
authentication.
38+
The private key in this sec tag must have its corresponding public key registered for
39+
the device on nRF Cloud.
40+
Using this option allows for a different private key to be stored in
41+
NRF_CLOUD_COAP_SEC_TAG that can be used to decrypt DTLS traffic.
2642

2743
config NRF_CLOUD_COAP_SERVER_PORT
2844
int "CoAP server port"

subsys/net/lib/nrf_cloud/src/nrf_cloud_info.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ int nrf_cloud_print_details(void)
148148
LOG_INF("Sec tag: %d", nrf_cloud_sec_tag_get());
149149
LOG_INF("Host name: %s", host_name);
150150

151+
#if defined(CONFIG_NRF_CLOUD_COAP)
152+
LOG_INF("-CoAP JWT: %d", nrf_cloud_sec_tag_coap_jwt_get());
153+
#endif
154+
151155
#endif /* CONFIG_NRF_CLOUD_VERBOSE_DETAILS */
152156

153157
return err;

subsys/net/lib/nrf_cloud/src/nrf_cloud_jwt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,15 @@ int nrf_cloud_jwt_generate(uint32_t time_valid_s, char *const jwt_buf, size_t jw
470470
const char *id_ptr;
471471
struct jwt_data jwt = {
472472
.audience = NULL,
473-
.sec_tag = nrf_cloud_sec_tag_get(),
474473
.key = JWT_KEY_TYPE_CLIENT_PRIV,
475474
.alg = JWT_ALG_TYPE_ES256,
476475
.jwt_buf = jwt_buf,
477476
.jwt_sz = jwt_buf_sz
478477
};
479478

479+
jwt.sec_tag = IS_ENABLED(CONFIG_NRF_CLOUD_COAP) ?
480+
nrf_cloud_sec_tag_coap_jwt_get() : nrf_cloud_sec_tag_get();
481+
480482
#if defined(CONFIG_MODEM_JWT)
481483
/* Check if modem time is valid */
482484
char buf[GET_TIME_RSP_SZ];

subsys/net/lib/nrf_cloud/src/nrf_cloud_sec_tag.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,18 @@ sec_tag_t nrf_cloud_sec_tag_get(void)
2626
{
2727
return nrf_cloud_sec_tag;
2828
}
29+
30+
#if defined(CONFIG_NRF_CLOUD_COAP)
31+
static sec_tag_t coap_jwt_sec_tag = CONFIG_NRF_CLOUD_COAP_JWT_SEC_TAG;
32+
33+
void nrf_cloud_sec_tag_coap_jwt_set(const sec_tag_t sec_tag)
34+
{
35+
coap_jwt_sec_tag = sec_tag;
36+
LOG_DBG("CoAP JWT sec tag updated: %d", coap_jwt_sec_tag);
37+
}
38+
39+
sec_tag_t nrf_cloud_sec_tag_coap_jwt_get(void)
40+
{
41+
return coap_jwt_sec_tag;
42+
}
43+
#endif /* CONFIG_NRF_CLOUD_COAP */

0 commit comments

Comments
 (0)