Skip to content

Commit 7f55748

Browse files
valeriosettimmahadevan108
authored andcommitted
jwt: remove TinyCrypt usage
As part of TinyCrypt deprecation process (#79566) this commit removes usage of this library from the JWT subsystem and its related tests. Signed-off-by: Valerio Setti <[email protected]>
1 parent 3d45ee7 commit 7f55748

File tree

9 files changed

+54
-164
lines changed

9 files changed

+54
-164
lines changed

doc/releases/migration-guide-4.0.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,21 @@ Shell
576576
JWT (JSON Web Token)
577577
====================
578578

579-
* By default, the signature is now computed through PSA Crypto API for both RSA and ECDSA.
580-
The newly-added :kconfig:option:`CONFIG_JWT_USE_LEGACY` can be used to switch
581-
back to previous libraries (TinyCrypt for ECDSA and Mbed TLS for RSA).
582-
The conversion to the PSA Crypto API is being done in preparation for the
583-
deprecation of TinyCrypt. (:github:`78243` and :github:`43712`)
579+
* By default, the signature is now computed using the PSA Crypto API for both RSA and ECDSA
580+
(:github:`78243`). The conversion to the PSA Crypto API is part of the adoption
581+
of a standard interface for crypto operations (:github:`43712`). Moreover,
582+
following the deprecation of the TinyCrypt library (:github:`79566`), usage
583+
of TinyCrypt was removed from the JWT subsystem (:github:`79653`).
584+
585+
* The following new symbols were added to allow specifying both the signature
586+
algorithm and crypto library:
587+
588+
* :kconfig:option:`CONFIG_JWT_SIGN_RSA_PSA` (default) RSA signature using the PSA Crypto API;
589+
* :kconfig:option:`CONFIG_JWT_SIGN_RSA_LEGACY` RSA signature using Mbed TLS;
590+
* :kconfig:option:`CONFIG_JWT_SIGN_ECDSA_PSA` ECDSA signature using the PSA Crypto API.
591+
592+
They replace the previously-existing Kconfigs ``CONFIG_JWT_SIGN_RSA`` and
593+
``CONFIG_JWT_SIGN_ECDSA``. (:github:`79653`)
584594

585595
Architectures
586596
*************

doc/releases/release-notes-4.0.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,14 @@ Libraries / Subsystems
608608

609609
* JWT (JSON Web Token)
610610

611-
* The following new Kconfigs were added to specify which library to use for the
612-
signature:
611+
* The following new symbols were added to allow specifying both the signature
612+
algorithm and crypto library:
613613

614-
* :kconfig:option:`CONFIG_JWT_USE_PSA` (default) use the PSA Crypto API;
615-
* :kconfig:option:`CONFIG_JWT_USE_LEGACY` use legacy libraries, i.e. TinyCrypt
616-
for ECDSA and Mbed TLS for RSA.
614+
* :kconfig:option:`CONFIG_JWT_SIGN_RSA_PSA` (default) RSA signature using the PSA Crypto API;
615+
* :kconfig:option:`CONFIG_JWT_SIGN_RSA_LEGACY` RSA signature using Mbed TLS;
616+
* :kconfig:option:`CONFIG_JWT_SIGN_ECDSA_PSA` ECDSA signature using the PSA Crypto API.
617+
618+
(:github:`79653`)
617619

618620
HALs
619621
****

subsys/jwt/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
zephyr_library()
44
zephyr_library_sources(jwt.c)
55

6-
zephyr_library_sources_ifdef(CONFIG_JWT_SIGN_ECDSA_LEGACY jwt_legacy_ecdsa.c)
76
zephyr_library_sources_ifdef(CONFIG_JWT_SIGN_RSA_LEGACY jwt_legacy_rsa.c)
8-
zephyr_library_sources_ifdef(CONFIG_JWT_USE_PSA jwt_psa.c)
7+
8+
if (CONFIG_JWT_SIGN_RSA_PSA OR CONFIG_JWT_SIGN_ECDSA_PSA)
9+
zephyr_library_sources(jwt_psa.c)
10+
endif()
911

1012
zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)

subsys/jwt/Kconfig

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,34 @@ if JWT
1212

1313
choice
1414
prompt "JWT signature algorithm"
15-
default JWT_SIGN_RSA
15+
default JWT_SIGN_RSA_PSA
1616
help
1717
Select which algorithm to use for signing JWT tokens.
1818

19-
config JWT_SIGN_RSA
20-
bool "Use RSA signature (RS-256)"
21-
22-
config JWT_SIGN_ECDSA
23-
bool "Use ECDSA signature (ES-256)"
24-
25-
endchoice
26-
27-
choice
28-
default JWT_USE_PSA
29-
prompt "Select crypto library to be used"
19+
config JWT_SIGN_RSA_LEGACY
20+
bool "Use RSA signature (RS-256). Use Mbed TLS as crypto library."
21+
depends on CSPRNG_ENABLED
22+
select MBEDTLS
23+
select MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3024

31-
config JWT_USE_PSA
32-
bool "PSA crypto API library"
25+
config JWT_SIGN_RSA_PSA
26+
bool "Use RSA signature (RS-256). Use PSA Crypto API."
3327
select MBEDTLS if !BUILD_WITH_TFM
3428
select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM
29+
select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
30+
select PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
31+
select PSA_WANT_ALG_RSA_PKCS1V15_SIGN
32+
select PSA_WANT_ALG_SHA_256
3533

36-
config JWT_USE_LEGACY
37-
bool "Legacy library: TinyCrypt for ECDSA, Mbed TLS for RSA"
38-
39-
endchoice
40-
41-
# Prompless Kconfigs to effectively select which algorithm and library will be used
42-
# to sign the JWT. User's selections on the above choices will determine which
43-
# element will be picked here.
4434
config JWT_SIGN_ECDSA_PSA
45-
bool
46-
default y
47-
depends on JWT_SIGN_ECDSA && JWT_USE_PSA
35+
bool "Use ECDSA signature (ES-256). Use PSA Crypto API."
36+
select MBEDTLS if !BUILD_WITH_TFM
37+
select MBEDTLS_PSA_CRYPTO_C if !BUILD_WITH_TFM
4838
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT
4939
select PSA_WANT_ALG_ECDSA
5040
select PSA_WANT_ECC_SECP_R1_256
5141
select PSA_WANT_ALG_SHA_256
5242

53-
config JWT_SIGN_ECDSA_LEGACY
54-
bool
55-
default y
56-
depends on JWT_SIGN_ECDSA && JWT_USE_LEGACY
57-
select TINYCRYPT
58-
select TINYCRYPT_SHA256
59-
select TINYCRYPT_ECC_DSA
60-
select TINYCRYPT_CTR_PRNG
61-
select TINYCRYPT_AES
62-
63-
config JWT_SIGN_RSA_PSA
64-
bool
65-
default y
66-
depends on JWT_SIGN_RSA && JWT_USE_PSA
67-
select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
68-
select PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
69-
select PSA_WANT_ALG_RSA_PKCS1V15_SIGN
70-
select PSA_WANT_ALG_SHA_256
71-
72-
config JWT_SIGN_RSA_LEGACY
73-
bool
74-
default y
75-
depends on JWT_SIGN_RSA && JWT_USE_LEGACY
76-
depends on CSPRNG_ENABLED
77-
select MBEDTLS
78-
select MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
43+
endchoice
7944

8045
endif # JWT

subsys/jwt/jwt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
#include "jwt.h"
1616

17-
#if defined(CONFIG_JWT_SIGN_RSA)
17+
#if defined(CONFIG_JWT_SIGN_RSA_PSA) || defined(JWT_SIGN_RSA_LEGACY)
1818
#define JWT_SIGNATURE_LEN 256
19-
#else /* CONFIG_JWT_SIGN_ECDSA */
19+
#else /* CONFIG_JWT_SIGN_ECDSA_PSA */
2020
#define JWT_SIGNATURE_LEN 64
2121
#endif
2222

@@ -143,10 +143,10 @@ static int jwt_add_header(struct jwt_builder *builder)
143143
* Use https://www.base64encode.org/ for update
144144
*/
145145
const char jwt_header[] =
146-
#ifdef CONFIG_JWT_SIGN_RSA
146+
#if defined(CONFIG_JWT_SIGN_RSA_PSA) || defined(CONFIG_JWT_SIGN_RSA_LEGACY)
147147
/* {"alg":"RS256","typ":"JWT"} */
148148
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9";
149-
#else /* CONFIG_JWT_SIGN_ECDSA */
149+
#else /* CONFIG_JWT_SIGN_ECDSA_PSA */
150150
/* {"alg":"ES256","typ":"JWT"} */
151151
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9";
152152
#endif

subsys/jwt/jwt_legacy_ecdsa.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

subsys/jwt/jwt_psa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ int jwt_sign_impl(struct jwt_builder *builder, const unsigned char *der_key, siz
2424
psa_algorithm_t alg;
2525
int ret;
2626

27-
#if defined(CONFIG_JWT_SIGN_ECDSA)
27+
#if defined(CONFIG_JWT_SIGN_ECDSA_PSA)
2828
psa_set_key_type(&attr, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
2929
psa_set_key_algorithm(&attr, PSA_ALG_ECDSA(PSA_ALG_SHA_256));
3030
alg = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
31-
#else /* CONFIG_JWT_SIGN_RSA */
31+
#else
3232
psa_set_key_type(&attr, PSA_KEY_TYPE_RSA_KEY_PAIR);
3333
psa_set_key_algorithm(&attr, PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256));
3434
alg = PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_SHA_256);
35-
#endif /* CONFIG_JWT_SIGN_ECDSA || CONFIG_JWT_SIGN_RSA */
35+
#endif
3636
psa_set_key_usage_flags(&attr, PSA_KEY_USAGE_SIGN_MESSAGE);
3737

3838
status = psa_import_key(&attr, der_key, der_key_len, &key_id);

tests/subsys/jwt/src/jwt-test-private.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*/
66

7-
#if defined(CONFIG_JWT_SIGN_RSA)
7+
#if defined(CONFIG_JWT_SIGN_RSA_PSA) || defined(CONFIG_JWT_SIGN_RSA_LEGACY)
88

99
/* To generate the key in the correct format use the following command:
1010
* $ openssl genrsa 2048 | openssl rsa -outform DER | xxd -i
@@ -113,7 +113,7 @@ unsigned char jwt_test_private_der[] = {
113113
0x05, 0xfd, 0x71, 0xb0, 0x3e
114114
};
115115

116-
#else /* CONFIG_JWT_SIGN_ECDSA */
116+
#else /* CONFIG_JWT_SIGN_ECDSA_PSA */
117117

118118
/* Here's how to generate the key in the correct format:
119119
* - generate the key using OpenSSL:

tests/subsys/jwt/testcase.yaml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,17 @@ common:
99
extra_configs:
1010
- CONFIG_TEST_RANDOM_GENERATOR=y
1111
tests:
12-
libraries.encoding.jwt.ecdsa.legacy:
13-
extra_configs:
14-
- CONFIG_JWT_SIGN_ECDSA=y
15-
- CONFIG_JWT_USE_LEGACY=y
1612
libraries.encoding.jwt.ecdsa.psa:
1713
extra_configs:
18-
- CONFIG_JWT_SIGN_ECDSA=y
19-
- CONFIG_JWT_USE_PSA=y
14+
- CONFIG_JWT_SIGN_ECDSA_PSA=y
2015
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y
2116
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y
2217
libraries.encoding.jwt.rsa.legacy:
2318
filter: CSPRNG_ENABLED
2419
extra_configs:
25-
- CONFIG_JWT_SIGN_RSA=y
26-
- CONFIG_JWT_USE_LEGACY=y
20+
- CONFIG_JWT_SIGN_RSA_LEGACY=y
2721
libraries.encoding.jwt.rsa.psa:
2822
extra_configs:
29-
- CONFIG_JWT_SIGN_RSA=y
30-
- CONFIG_JWT_USE_PSA=y
23+
- CONFIG_JWT_SIGN_RSA_PSA=y
3124
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y
3225
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y

0 commit comments

Comments
 (0)