Skip to content

Commit 84c7651

Browse files
authored
fix: EdDSA to Ed25519 token migration (#786)
* refactor: changed EdDSA to Ed25519 algorithm in tokens
1 parent 6e85d84 commit 84c7651

7 files changed

Lines changed: 25 additions & 21 deletions

File tree

diracx-core/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies = [
1818
"cachetools",
1919
"email_validator",
2020
"gitpython",
21-
"joserfc >=1.1.0",
21+
"joserfc >=1.5.0",
2222
"pydantic >=2.10",
2323
"pydantic-settings",
2424
"pyyaml",

diracx-core/src/diracx/core/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ class AuthSettings(ServiceSettingsBase):
204204
generation and verification.
205205
"""
206206

207-
token_allowed_algorithms: list[str] = ["RS256", "EdDSA"] # noqa: S105
207+
# TODO: EdDSA should be removed later due to "SecurityWarning: EdDSA is deprecated via RFC 9864"
208+
token_allowed_algorithms: list[str] = ["RS256", "EdDSA", "Ed25519"] # noqa: S105
208209
"""List of allowed cryptographic algorithms for JWT token signing.
209210
210-
Supported algorithms include RS256 (RSA with SHA-256) and EdDSA
211-
(Edwards-curve Digital Signature Algorithm). Default: ["RS256", "EdDSA"]
211+
Supported algorithms include RS256 (RSA with SHA-256) and Ed25519
212+
(Edwards-curve Digital Signature Algorithm). Default: ["RS256", "Ed25519"]
212213
"""
213214

214215
access_token_expire_minutes: int = 20

diracx-core/tests/test_secrets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_token_signing_key(tmp_path):
1515
OKPKey.generate_key(
1616
parameters={
1717
"key_ops": ["sign", "verify"],
18-
"alg": "EdDSA",
18+
"alg": "Ed25519",
1919
"kid": uuid7().hex,
2020
}
2121
)

diracx-logic/src/diracx/logic/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def new_key(
4040
"""Create a fresh private signing key."""
4141
parameters = {
4242
"key_ops": ["sign", "verify"],
43-
"alg": "EdDSA",
43+
"alg": "Ed25519",
4444
"kid": uuid7().hex,
4545
}
4646
return JWKRegistry.generate_key(

diracx-routers/tests/auth/test_standard.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ async def test_refresh_token_invalid(test_client, auth_httpx_mock: HTTPXMock):
783783

784784
new_auth_settings = AuthSettings(
785785
token_issuer="https://iam-auth.web.cern.ch/",
786-
token_allowed_algorithms=["EdDSA", "RS256"],
786+
token_allowed_algorithms=["RS256", "Ed25519"],
787787
token_keystore=json.dumps(KeySet(keys=[key]).as_dict(private=True)),
788788
state_key=Fernet.generate_key(),
789789
allowed_redirects=[
@@ -833,34 +833,34 @@ async def test_keystore(test_client):
833833
"kid": uuid7().hex,
834834
},
835835
)
836-
eddsa_key = OKPKey.generate_key(
836+
ed25519_key = OKPKey.generate_key(
837837
"Ed25519",
838838
{
839839
"key_ops": ["sign", "verify"],
840-
"alg": "EdDSA",
840+
"alg": "Ed25519",
841841
"kid": uuid7().hex,
842842
},
843843
)
844844

845-
# Generate the keystore with eddsa key only first
846-
jwks = KeySet(keys=[eddsa_key])
845+
# Generate the keystore with ed25519 key only first
846+
jwks = KeySet(keys=[ed25519_key])
847847

848848
# Generate the keystore with rsa key only first
849849
auth_settings = AuthSettings(
850850
token_issuer=issuer,
851-
token_allowed_algorithms=["RS256"], # We purposefully remove EdDSA
851+
token_allowed_algorithms=["RS256"], # We purposefully remove Ed25519
852852
token_keystore=json.dumps(jwks.as_dict(private=True)),
853853
state_key=state_key,
854854
allowed_redirects=allowed_redirects,
855855
)
856856

857857
# Encode/Decode with the keystore: should not work
858-
# because EdDSA is not part of the allowed algorithms
858+
# because Ed25519 is not part of the allowed algorithms
859859
with pytest.raises(UnsupportedAlgorithmError):
860860
token = create_token(payload, auth_settings)
861861

862-
# Add EdDSA to the allowed algorithms
863-
auth_settings.token_allowed_algorithms.append("EdDSA")
862+
# Add Ed25519 to the allowed algorithms
863+
auth_settings.token_allowed_algorithms.append("Ed25519")
864864

865865
# Encode/Decode with the keystore: should work
866866
token = create_token(payload, auth_settings)
@@ -871,7 +871,10 @@ async def test_keystore(test_client):
871871

872872
auth_settings = AuthSettings(
873873
token_issuer=issuer,
874-
token_allowed_algorithms=["RS256", "EdDSA"], # We purposefully remove EdDSA
874+
token_allowed_algorithms=[
875+
"RS256",
876+
"Ed25519",
877+
],
875878
token_keystore=json.dumps(jwks.as_dict(private=True)),
876879
state_key=state_key,
877880
allowed_redirects=allowed_redirects,
@@ -882,7 +885,7 @@ async def test_keystore(test_client):
882885
await verify_dirac_refresh_token(token, auth_settings)
883886

884887
# Remove 'sign' operation from the RSA key:
885-
# should still work because eddsa_key is still there
888+
# should still work because ed25519_key is still there
886889
auth_settings.token_keystore.jwks.keys[1].get("key_ops").remove("sign")
887890
token = create_token(payload, auth_settings)
888891
await verify_dirac_refresh_token(token, auth_settings)

diracx-testing/src/diracx/testing/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def private_key() -> OKPKey:
6161
return OKPKey.generate_key(
6262
parameters={
6363
"key_ops": ["sign", "verify"],
64-
"alg": "EdDSA",
64+
"alg": "Ed25519",
6565
"kid": uuid7().hex,
6666
}
6767
)

docs/admin/reference/env-variables.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ generation and verification.
7171

7272
### `DIRACX_SERVICE_AUTH_TOKEN_ALLOWED_ALGORITHMS`
7373

74-
*Optional*, default value: `['RS256', 'EdDSA']`
74+
*Optional*, default value: `['RS256', 'EdDSA', 'Ed25519']`
7575

7676
List of allowed cryptographic algorithms for JWT token signing.
7777

78-
Supported algorithms include RS256 (RSA with SHA-256) and EdDSA
79-
(Edwards-curve Digital Signature Algorithm). Default: ["RS256", "EdDSA"]
78+
Supported algorithms include RS256 (RSA with SHA-256) and Ed25519
79+
(Edwards-curve Digital Signature Algorithm). Default: ["RS256", "Ed25519"]
8080

8181
### `DIRACX_SERVICE_AUTH_ACCESS_TOKEN_EXPIRE_MINUTES`
8282

0 commit comments

Comments
 (0)