Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: app_jwt: add an application core jwt generator and add a sample for usage #19561

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ayla-nordicsemi
Copy link
Contributor

@ayla-nordicsemi ayla-nordicsemi commented Dec 16, 2024

Add a JWT generator in lib directory and add a sample application to demonstrate the usage.

@tokangas : the jwt generator interface API is defined here "include/user_app_jwt.h", your feedback on this interface is welcome !

@ayla-nordicsemi ayla-nordicsemi self-assigned this Dec 16, 2024
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Dec 16, 2024
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Dec 16, 2024

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 42

Inputs:

Sources:

more details

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (0)

Outputs:

Toolchain

Version:
Build docker image:

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ❌ Toolchain
  • ❌ Build twister
  • ❌ Integration tests

Note: This message is automatically posted and updated by the CI

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from ebc5af3 to 4b8344f Compare December 16, 2024 15:00
@github-actions github-actions bot added doc-required PR must not be merged without tech writer approval. and removed changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Dec 16, 2024
Copy link
Contributor

@tokangas tokangas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message needs some work. If the name of the library is user_app_jwt, the title should start with lib: user_app_jwt:. There should be empty lines after the title and before the signature. Add also a description for the commit, in addition to the Jira item, which is internal.

I did not go through the whole PR yet, will continue later.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from 4b8344f to c534625 Compare December 17, 2024 16:03
@ayla-nordicsemi ayla-nordicsemi changed the title lib: jwt: add a jwt generator and add a sample for usage lib: app_jwt: add an application core jwt generator and add a sample for usage Dec 17, 2024
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch 7 times, most recently from 406a065 to 87a8425 Compare December 19, 2024 10:59
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from 703aa8e to be3bd43 Compare February 12, 2025 14:30
@NordicBuilder
Copy link
Contributor

You can find the documentation preview for this PR at this link.

Note: This comment is automatically posted by the Documentation Publish GitHub Action.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch 5 times, most recently from bfeeb2e to ad0f24c Compare February 14, 2025 14:27
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from ad0f24c to ff379df Compare February 14, 2025 14:46
@peknis peknis requested a review from a team February 17, 2025 06:47
LOG_INF("JWT(%d) : %s", strlen(jwt_str), jwt_str);
} else {
LOG_ERR("jwt_generate error : %d", ret);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editorial: Extra semicolon (;) at the end of this line.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch 2 times, most recently from 03eca79 to 381e21e Compare February 17, 2025 13:14
Copy link
Contributor

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply comments throughout whole PR

JWT_KEY_TYPE_ENDORSEMENT = 8,
};

/**@brief JWT signing algorithm */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

differs from other help text with space before brief

Comment on lines 63 to 70
/** Defines how long the JWT will be valid; in seconds (from generation).
* The 'iat' and 'exp' claims will be populated either the application
* has or not a valid date and time.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually has the form:

/**
 * First line of comment
 */

and top/bottom lines are delimiters only to prevent jagged text indent (for information only)

*
* The API doesn't verify the time source validity, it is up to the caller to make sure
* that the system has access to a valid time source, otherwise "iat" field will
* containt the time since boot in seconds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*contain

Comment on lines +101 to +127
* @retval 0 If the operation was successful.
* Otherwise, a (negative) error code is returned, check header errno.h for a full list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 @retvals one per line, apply comments throughout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean it should be like this :

Suggested change
* @retval 0 If the operation was successful.
* Otherwise, a (negative) error code is returned, check header errno.h for a full list.
* @retval 0 If the operation was successful.
* @retval a (negative) error code is returned, check header errno.h for a full list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @retval -errno Negative errno for other failures.

Comment on lines 11 to 13
# needed for time and date
select POSIX_API
# needed to print integer values in JSON
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments start with capital letters


/* Length of JTI field, this should be at least UUIDv4 size
* + size of board name
**/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/

return -EINVAL;
}
/* this will hold 4 integer words in string format */
/*(string Length 8 + 1) */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after /*

bool "Json Web Token Sample"
select APP_JWT
help
"Enable sample-specific configurations."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there quotes in help text

Comment on lines 7 to 9
menuconfig JWT_SAMPLE
bool "Json Web Token Sample"
select APP_JWT
help
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this even in a Kconfig? Put it in prj.conf ?

JWT signing verification
========================

Flag CONFIG_APP_JWT_VERIFY_SIGNATURE allow to verify the JWT signature against the IAK key.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use proper

:kconfig:option:`CONFIG_x`

syntax

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from 381e21e to 4d3dfc4 Compare February 17, 2025 14:29
@@ -0,0 +1,11 @@
.. _lib_app_jwt:

Library Application JWT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Application JWT is a single library, it would be better to placed under the "nrf\doc\nrf\libraries\others" folder.

@@ -0,0 +1,80 @@
.. _app_jwt:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. _app_jwt:
.. _lib_app_jwt:

As per the guideline here: https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/templates/library_template_README.html

Comment on lines +3 to +4
Application JWT
###################
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Application JWT
###################
Application JWT
###############

Application JWT
###################

The Application JWT library provides access to the `JSON Web Token (JWT)`_ generation feature from application core using signing and identity services from secure core.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Application JWT library provides access to the `JSON Web Token (JWT)`_ generation feature from application core using signing and identity services from secure core.
The Application JWT library provides access to the `JSON Web Token (JWT)`_ generation feature from application core using signing services and secure core using identity services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signing is done by Secure core,
Identification (generation of the UUID) is also done by secure core.

maybe rephrasing to the following to avoid any ambiguities :

Suggested change
The Application JWT library provides access to the `JSON Web Token (JWT)`_ generation feature from application core using signing and identity services from secure core.
The Application JWT library provides access to the `JSON Web Token (JWT)`_ generation feature from Application core using Secure core signing service and identity service.

* :Kconfig:option:`CONFIG_SSF_PSA_CRYPTO_SERVICE_ENABLED`
* :Kconfig:option:`CONFIG_SSF_DEVICE_INFO_SERVICE_ENABLED`

#. Read the device UUID (:c:func:`app_jwt_get_uuid`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#. Read the device UUID (:c:func:`app_jwt_get_uuid`)
#. Read the device UUID (:c:func:`app_jwt_get_uuid`).

* :c:member:`app_jwt_data.jwt_buf` - Required.
Buffer for the generated, null-terminated, JWT string.
Buffer size has to be al least 600 bytes, at most 900 bytes.
The user has to provide a valid buffer, library doesn't do any allocation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The user has to provide a valid buffer, library doesn't do any allocation.
You must to provide a valid buffer, library does not do any allocation.


Application JWT
###################

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. contents::
:local:
:depth: 2

Comment on lines +3 to +4
jwt generator
###################
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jwt generator
###################
JWT generator
#############

:local:
:depth: 2

This sample shows how Application core can generate a JWT signed with the IAK.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This sample shows how Application core can generate a JWT signed with the IAK.
This sample shows how application core can generate a JWT signed with the IAK.


* - Board
- Support
* - nrf9280pdk/nrf9280/cpuapp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether the nRF9280 PDK should be mentioned in the public docs now? Please check this with the PMT.
Hence, sample doc is not completely reviewed.

Also, the table should be pulled from the sample.yml file - https://raw.githubusercontent.com/nrfconnect/sdk-nrf/refs/heads/main/doc/nrf/templates/sample_README.rst.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(jwt_sample, CONFIG_JWT_SAMPLE_LOG_LEVEL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing extra enter on top LOG_MODULE_REGISTER...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to address the unite test for this in a separate PR?

static char *jwt_payload_create(const char *const sub, const char *const aud, uint64_t exp)
{
int err = 0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to have a space between all these declarations

@ayla-nordicsemi ayla-nordicsemi marked this pull request as draft February 19, 2025 10:19
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from 4d3dfc4 to 7342368 Compare February 20, 2025 10:49
Copy link

github-actions bot commented Feb 20, 2025

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch 6 times, most recently from e320229 to 9d95b0b Compare February 24, 2025 15:23
Ref: NRFX-6688

Signed-off-by: Aymen LAOUINI <aymen.laouini@nordicsemi.no>
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_jwt_generation_for_user_application branch from 9d95b0b to 9140593 Compare February 24, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-required PR must not be merged without tech writer approval.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants