Skip to content

Commit d49b653

Browse files
committed
lib: nrf_cloud: integrate app_jwt library
Replace internal JWT implementation with the app_jwt library. Requires the usage of prime256v1 keys. Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
1 parent 80618f1 commit d49b653

File tree

7 files changed

+53
-342
lines changed

7 files changed

+53
-342
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ Libraries for networking
908908

909909
* Added the :kconfig:option:`CONFIG_NRF_CLOUD` Kconfig option to prevent unintended inclusion of nRF Cloud Kconfig variables in non-nRF Cloud projects.
910910
* Updated to use the :ref:`lib_downloader` library for CoAP downloads.
911+
* Updated to use the :ref:`lib_app_jwt` library to generate JWT tokens.
911912

912913
Libraries for NFC
913914
-----------------

include/app_jwt.h

+3-13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" {
2323
#include <stdint.h>
2424
#include <stdbool.h>
2525
#include <strings.h>
26+
#include <modem/modem_jwt.h>
2627

2728
/** @brief Maximum size of a JWT string, could be used to allocate JWT
2829
* output buffer.
@@ -44,25 +45,14 @@ extern "C" {
4445
/** @brief Size in bytes of each JWT String field */
4546
#define APP_JWT_CLAIM_MAX_SIZE 64
4647

47-
/** @brief The type of key to be used for signing the JWT. */
48-
enum app_jwt_key_type {
49-
JWT_KEY_TYPE_CLIENT_PRIV = 2,
50-
JWT_KEY_TYPE_ENDORSEMENT = 8,
51-
};
52-
53-
/** @brief JWT signing algorithm */
54-
enum app_jwt_alg_type {
55-
JWT_ALG_TYPE_ES256 = 0,
56-
};
57-
5848
/** @brief JWT parameters required for JWT generation and pointer to generated JWT */
5949
struct app_jwt_data {
6050
/** Sec tag to use for JWT signing */
6151
unsigned int sec_tag;
6252
/** Key type in the specified sec tag */
63-
enum app_jwt_key_type key_type;
53+
enum jwt_key_type key_type;
6454
/** JWT signing algorithm */
65-
enum app_jwt_alg_type alg;
55+
enum jwt_alg_type alg;
6656

6757
/**
6858
* Indicates if a 'kid' claim is required or not, if set to 1, 'kid' claim

lib/app_jwt/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ zephyr_library()
99
zephyr_library_sources(
1010
app_jwt.c
1111
)
12+
13+
zephyr_link_libraries(mbedTLS)

lib/app_jwt/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
menuconfig APP_JWT
88
bool "Application JWT Library"
9-
depends on SSF_CLIENT && SSF_PSA_CRYPTO_SERVICE_ENABLED && SSF_DEVICE_INFO_SERVICE_ENABLED
109
select BASE64
1110
# Needed for time and date
1211
select DATE_TIME
@@ -15,6 +14,7 @@ menuconfig APP_JWT
1514
# Needed to print integer values in JSON
1615
select CJSON_LIB
1716
select CBPRINTF_FP_SUPPORT
17+
select MBEDTLS
1818

1919
if APP_JWT
2020

lib/app_jwt/app_jwt.c

+4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
#include <date_time.h>
1515
#include <psa/crypto.h>
1616
#include <psa/crypto_extra.h>
17+
#if defined(CONFIG_BOARD_NATIVE_SIM)
18+
#define IAK_APPLICATION_GEN1 0x41020100
19+
#else
1720
#include <psa/nrf_platform_key_ids.h>
21+
#endif
1822

1923
#include <cJSON.h>
2024

subsys/net/lib/nrf_cloud/Kconfig

+1-8
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,7 @@ config NRF_CLOUD_JWT_SOURCE_CUSTOM
103103
select EXPERIMENTAL
104104
select TLS_CREDENTIALS
105105
select BASE64
106-
select TINYCRYPT
107-
select TINYCRYPT_SHA256
108-
select TINYCRYPT_ECC_DSA
109-
select TINYCRYPT_CTR_PRNG
110-
select TINYCRYPT_AES
111-
select CJSON_LIB
112-
depends on NEWLIB_LIBC_FLOAT_PRINTF || PICOLIBC_IO_FLOAT
113-
depends on DATE_TIME
106+
select APP_JWT
114107
help
115108
JWTs are created and signed by the nRF Cloud library, not the modem.
116109
The signing key is obtained from the TLS credentials module.

0 commit comments

Comments
 (0)