Skip to content

Commit 17dd894

Browse files
committed
Merge branch 'main' of https://github.com/italia/eudi-wallet-it-python into fix/default_sig_enc_algs
2 parents 462085d + e2454c5 commit 17dd894

File tree

12 files changed

+92
-69
lines changed

12 files changed

+92
-69
lines changed

example/satosa/pyeudiw_backend.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ config:
122122
x: Q46FDkhMjewZIP9qP8ZKZIP-ZEemctvjxeP0l3vWHMI
123123
y: IT7lsGxdJewmonk9l1_TAVYx_nixydTtI1Sbn0LkfEA
124124
alg: ES256
125-
- crv: P-256
126-
d: KzQBowMMoPmSZe7G8QsdEWc1IvR2nsgE8qTOYmMcLtc
127-
kid: dDwPWXz5sCtczj7CJbqgPGJ2qQ83gZ9Sfs-tJyULi6s
128-
use: sig
129-
kty: EC
130-
x: TSO-KOqdnUj5SUuasdlRB2VVFSqtJOxuR5GftUTuBdk
131-
y: ByWgQt1wGBSnF56jQqLdoO1xKUynMY-BHIDB3eXlR7
132125
- kty: RSA
133126
d: QUZsh1NqvpueootsdSjFQz-BUvxwd3Qnzm5qNb-WeOsvt3rWMEv0Q8CZrla2tndHTJhwioo1U4NuQey7znijhZ177bUwPPxSW1r68dEnL2U74nKwwoYeeMdEXnUfZSPxzs7nY6b7vtyCoA-AjiVYFOlgKNAItspv1HxeyGCLhLYhKvS_YoTdAeLuegETU5D6K1xGQIuw0nS13Icjz79Y8jC10TX4FdZwdX-NmuIEDP5-s95V9DMENtVqJAVE3L-wO-NdDilyjyOmAbntgsCzYVGH9U3W_djh4t3qVFCv3r0S-DA2FD3THvlrFi655L0QHR3gu_Fbj3b9Ybtajpue_Q
134127
e: AQAB
@@ -189,8 +182,6 @@ config:
189182
- module: pyeudiw.openid4vp.vp_sd_jwt_vc
190183
class: VpVcSdJwtParserVerifier
191184
format: dc+sd-jwt
192-
config:
193-
sig_alg_supported: *sig_alg_supported
194185
- module: pyeudiw.openid4vp.vp_mdoc_cbor
195186
class: VpMDocCbor
196187
format: mso_mdoc

pyeudiw/federation/schemas/openid_credential_verifier.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum
2-
from typing import List
2+
from typing import List, Union
33

44
from pydantic import BaseModel, HttpUrl, PositiveInt
55

@@ -55,17 +55,17 @@ class OpenIDCredentialVerifier(BaseModel):
5555
client_name: str
5656
jwks: JwksSchema
5757
contacts: List[str]
58-
request_uris: List[HttpUrl]
59-
redirect_uris: List[HttpUrl]
60-
default_acr_values: List[HttpUrl]
58+
request_uris: Union[None, List[Union[HttpUrl, None]]]
59+
redirect_uris: Union[None, List[Union[HttpUrl, None]]]
60+
default_acr_values: List[Union[HttpUrl, None]]
6161
authorization_signed_response_alg: List[AuthorizationSignedResponseAlg]
6262
authorization_encrypted_response_alg: List[EncryptionAlgValuesSupported]
6363
authorization_encrypted_response_enc: List[EncryptionEncValuesSupported]
64-
subject_type: str
65-
require_auth_time: bool
64+
# subject_type: str
65+
# require_auth_time: bool
66+
# default_max_age: PositiveInt
6667
id_token_encrypted_response_alg: List[EncryptionAlgValuesSupported]
6768
id_token_encrypted_response_enc: List[EncryptionEncValuesSupported]
6869
id_token_signed_response_alg: List[SigningAlgValuesSupported]
69-
default_acr_values: List[AcrValuesSupported]
70-
default_max_age: PositiveInt
70+
default_acr_values: List[Union[AcrValuesSupported, None]]
7171
vp_formats: VpFormats

pyeudiw/openid4vp/authorization_request.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def build_authorization_request_claims(
5050
"""
5151

5252
nonce = nonce or str(uuid.uuid4())
53-
53+
if authorization_config.get("auth_iss_id"):
54+
_iss = authorization_config["auth_iss_id"]
55+
else:
56+
_iss = client_id
57+
5458
claims = {
5559
"client_id_scheme": "http", # that's federation.
5660
"client_id": client_id,
@@ -61,7 +65,7 @@ def build_authorization_request_claims(
6165
"response_uri": response_uri,
6266
"nonce": nonce,
6367
"state": state,
64-
"iss": authorization_config.get("auth_iss_id", client_id),
68+
"iss": _iss,
6569
"iat": iat_now(),
6670
"exp": exp_from_now(minutes=authorization_config["expiration_time"]),
6771
}

pyeudiw/openid4vp/presentation_submission/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(
2323
self,
2424
config: dict,
2525
trust_evaluator: CombinedTrustEvaluator,
26+
sig_alg_supported: list[str] = [],
2627
) -> None:
2728
"""
2829
Initialize the PresentationSubmissionHandler handler with the submission data.
@@ -64,7 +65,7 @@ def __init__(
6465
if not issubclass(cls, BaseVPParser):
6566
raise TypeError(f"Class '{class_name}' must inherit from BaseVPParser.")
6667

67-
self.handlers[format_name] = cls(trust_evaluator=self.trust_evaluator, **module_config)
68+
self.handlers[format_name] = cls(trust_evaluator=self.trust_evaluator, **module_config, sig_alg_supported=sig_alg_supported)
6869
except ModuleNotFoundError:
6970
raise ImportError(f"Module '{module_name}' not found for format '{format_conf['name']}'.")
7071
except AttributeError:

pyeudiw/satosa/default/openid4vp_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def __init__(
116116
credential_presentation_handlers_configuration = self.config.get("credential_presentation_handlers", {})
117117
self.vp_token_parser = PresentationSubmissionHandler(
118118
credential_presentation_handlers_configuration,
119-
self.trust_evaluator
119+
self.trust_evaluator,
120+
self.config.get("jwt", {}).get("sig_alg_supported", [])
120121
)
121122

122123
def get_trust_backend_by_class_name(self, class_name: str) -> TrustHandlerInterface:

pyeudiw/satosa/default/request_handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def request_endpoint(self, context: Context, *args) -> Response:
6969
}
7070

7171
# load all the trust handlers request jwt header parameters, if any
72-
7372
trust_params = self.trust_evaluator.get_jwt_header_trust_parameters(issuer=self.client_id)
7473
_protected_jwt_headers.update(trust_params)
7574

pyeudiw/tests/openid4vp/test_presentation_submission.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@
4545

4646
def test_handler_initialization():
4747

48-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
48+
ps = PresentationSubmissionHandler(
49+
trust_evaluator=trust_ev,
50+
config=mock_format_config,
51+
sig_alg_supported=["ES256", "ES384", "ES512"]
52+
)
4953

5054
assert len(ps.handlers) == 3, "Not all handlers were created."
5155

@@ -54,7 +58,11 @@ def test_handler_initialization():
5458
assert isinstance(ps.handlers["fail_parser"], MockFailingParser), "Handler for 'fail_parser' format is incorrect."
5559

5660
def test_handler_correct_parsing():
57-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
61+
ps = PresentationSubmissionHandler(
62+
trust_evaluator=trust_ev,
63+
config=mock_format_config,
64+
sig_alg_supported=["ES256", "ES384", "ES512"]
65+
)
5866

5967
parsed_tokens = ps.parse(valid_submission, ["vp_token_1", "vp_token_2"])
6068

@@ -63,7 +71,10 @@ def test_handler_correct_parsing():
6371
assert parsed_tokens[1] == {"parsed": "vp_token_2"}, "Token 2 was not parsed correctly."
6472

6573
def test_handler_missing_handler():
66-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
74+
ps = PresentationSubmissionHandler(
75+
trust_evaluator=trust_ev,
76+
config=mock_format_config,
77+
sig_alg_supported=["ES256", "ES384", "ES512"])
6778

6879
invalid_submission = {
6980
"id": "submission_id",
@@ -81,7 +92,11 @@ def test_handler_missing_handler():
8192
assert str(e) == "Handler for format 'non_existent_format' not found.", "Incorrect exception message."
8293

8394
def test_handler_invalid_path():
84-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
95+
ps = PresentationSubmissionHandler(
96+
trust_evaluator=trust_ev,
97+
config=mock_format_config,
98+
sig_alg_supported=["ES256", "ES384", "ES512"]
99+
)
85100

86101
invalid_submission = {
87102
"id": "submission_id",
@@ -99,7 +114,11 @@ def test_handler_invalid_path():
99114
assert str(e) == "Invalid path format: invalid_path", "Incorrect exception message."
100115

101116
def test_handler_mismatched_tokens():
102-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
117+
ps = PresentationSubmissionHandler(
118+
trust_evaluator=trust_ev,
119+
config=mock_format_config,
120+
sig_alg_supported=["ES256", "ES384", "ES512"]
121+
)
103122

104123
invalid_submission = {
105124
"id": "submission_id",
@@ -116,7 +135,11 @@ def test_handler_mismatched_tokens():
116135
assert str(e) == "Number of VP tokens (1) does not match the number of descriptors (2).", "Incorrect exception message."
117136

118137
def test_handler_invalid_submission():
119-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
138+
ps = PresentationSubmissionHandler(
139+
trust_evaluator=trust_ev,
140+
config=mock_format_config,
141+
sig_alg_supported=["ES256", "ES384", "ES512"]
142+
)
120143

121144
invalid_submission = {
122145
"fail": "submission"
@@ -130,7 +153,11 @@ def test_handler_invalid_submission():
130153
assert False, f"Incorrect exception type: {type(e)}"
131154

132155
def test_handler_parser_failure():
133-
ps = PresentationSubmissionHandler(trust_evaluator=trust_ev, config=mock_format_config)
156+
ps = PresentationSubmissionHandler(
157+
trust_evaluator=trust_ev,
158+
config=mock_format_config,
159+
sig_alg_supported=["ES256", "ES384", "ES512"]
160+
)
134161

135162
invalid_submission = {
136163
"id": "submission_id",

pyeudiw/tests/settings.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def base64url_to_int(val):
141141
"A192GCM",
142142
"A256GCM",
143143
],
144+
"sig_alg_supported": [
145+
"RS256",
146+
"ES256",
147+
"ES384",
148+
"ES512",
149+
"EdDSA",
150+
],
144151
},
145152
"authorization": {
146153
"url_scheme": "haip", # haip://
@@ -394,16 +401,7 @@ def base64url_to_int(val):
394401
"module": "pyeudiw.openid4vp.vp_sd_jwt_vc",
395402
"class": "VpVcSdJwtParserVerifier",
396403
"format": "dc+sd-jwt",
397-
"config": {
398-
"sig_alg_supported": [
399-
"RS256",
400-
"RS384",
401-
"RS512",
402-
"ES256",
403-
"ES384",
404-
"ES512",
405-
]
406-
}
404+
"config": {}
407405
},
408406
{
409407
"module": "pyeudiw.openid4vp.vp_mdoc_cbor",

pyeudiw/tests/trust/mock_trust_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pyeudiw.trust.handler.interface import TrustHandlerInterface
22
from pyeudiw.trust.model.trust_source import TrustSourceData
33
from pyeudiw.trust.model.trust_source import TrustEvaluationType
4-
from datetime import datetime
54
from pyeudiw.tools.utils import exp_from_now
65

76
mock_jwk = {
@@ -55,19 +54,20 @@ def extract_and_update_trust_materials(
5554
) -> TrustSourceData:
5655
trust_source = self.get_metadata(issuer, trust_source)
5756

57+
5858
if issuer == self.client_id:
5959
trust_param = TrustEvaluationType(
6060
attribute_name="trust_param_name",
6161
jwks=[mock_jwk, mock_jwk_private],
62-
expiration_date=datetime.fromtimestamp(exp_from_now(self.exp)),
62+
expiration_date=exp_from_now(self.exp),
6363
trust_param_name={'trust_param_key': 'trust_param_value'},
6464
trust_handler_name=str(self.__class__.__name__)
6565
)
6666
else:
6767
trust_param = TrustEvaluationType(
6868
attribute_name="trust_param_name",
6969
jwks=[mock_jwk, mock_jwk_private],
70-
expiration_date=datetime.fromtimestamp(exp_from_now(self.exp)),
70+
expiration_date=exp_from_now(self.exp),
7171
trust_param_name={"trust_param_key": "trust_param_value"},
7272
trust_handler_name=str(self.__class__.__name__)
7373
)
@@ -99,7 +99,7 @@ def extract_and_update_trust_materials(
9999
trust_param = TrustEvaluationType(
100100
attribute_name="trust_param_name",
101101
jwks=[mock_jwk],
102-
expiration_date=datetime.fromtimestamp(exp_from_now(self.exp)),
102+
expiration_date=exp_from_now(self.exp),
103103
trust_param_name={'updated_trust_param_key': 'updated_trust_param_value'},
104104
trust_handler_name=str(self.__class__.__name__)
105105
)

pyeudiw/tests/trust/test_dynamic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from uuid import uuid4
22

3+
import time
34
from pyeudiw.storage.db_engine import DBEngine
45
from pyeudiw.tests.settings import CONFIG
56
from pyeudiw.tests.trust import correct_config, not_conformant
@@ -131,6 +132,7 @@ def test_cache_first_strategy_expired():
131132
uuid_url = f"http://{uuid4()}.issuer.it"
132133

133134
assert trust_ev.get_jwt_header_trust_parameters(uuid_url) == {'trust_param_name': {'trust_param_key': 'trust_param_value'}}
135+
time.sleep(1)
134136
assert trust_ev.get_jwt_header_trust_parameters(uuid_url) == {'trust_param_name': {'updated_trust_param_key': 'updated_trust_param_value'}}
135137

136138
def test_cache_first_strategy_expired_revoked():

0 commit comments

Comments
 (0)