Skip to content

Commit 1c02a26

Browse files
authored
Merge pull request #394 from italia/freeze1.0
freeze: code for 1.0
2 parents c75742c + 38a8876 commit 1c02a26

File tree

27 files changed

+406
-182
lines changed

27 files changed

+406
-182
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ it is [Satosa-Saml2Spid](https://github.com/italia/Satosa-Saml2Spid).
9797

9898
Please read this [README](README.SATOSA.md) any details about how to configure SaToSa with the OpenID4VP Relying Party backend.
9999

100+
## Executing Tests Using Preexisting MongoDb Instances
101+
102+
Use the env variable PYEUDIW_MONGO_TEST_AUTH_INLINE
103+
104+
````
105+
PYEUDIW_MONGO_TEST_AUTH_INLINE=satosa:thatpassword@ pytest
106+
````
107+
100108
## Contribute
101109

102110
Your contribution is welcome, no question is useless and no answer is obvious, we need you.

example/satosa/integration_test/commons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def create_authorize_response(vp_token: str, state: str, response_uri: str) -> s
195195
{
196196
"id": "pid-sd-jwt:unique_id+given_name+family_name",
197197
"path": "$.vp_token.verified_claims.claims._sd[0]",
198-
"format": "vc+sd-jwt"
198+
"format": "dc+sd-jwt"
199199
}
200200
],
201201
"aud": response_uri

example/satosa/pyeudiw_backend.yaml

Lines changed: 122 additions & 14 deletions
Large diffs are not rendered by default.

oldies/openid4vp/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def vp_parser(jwt: str) -> Vp:
2424
match typ.lower():
2525
case "jwt":
2626
return VpSdJwt(jwt)
27-
case "vc+sd-jwt":
27+
case "dc+sd-jwt":
2828
raise NotImplementedError(
29-
"parsing of vp tokens with typ vc+sd-jwt not supported yet"
29+
"parsing of vp tokens with typ dc+sd-jwt not supported yet"
3030
)
3131
case "mcdoc_cbor":
3232
return VpMDocCbor(jwt)

pyeudiw/openid4vp/authorization_response.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AuthorizeResponsePayload,
1414
ResponseMode,
1515
)
16+
from pyeudiw.jwt.utils import decode_jwt_header
1617

1718

1819
_S = TypeVar('_S', str, list[str])
@@ -117,8 +118,15 @@ class DirectPostJwtJweParser(AuthorizationResponseParser):
117118
https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-response-mode-direct_postjw
118119
"""
119120

120-
def __init__(self, jwe_decryptor: JWEHelper):
121+
def __init__(
122+
self,
123+
jwe_decryptor: JWEHelper,
124+
enc_alg_supported: list[str] = [],
125+
enc_enc_supported: list[str] = []
126+
) -> None:
121127
self.jwe_decryptor = jwe_decryptor
128+
self.enc_alg_supported = enc_alg_supported
129+
self.enc_enc_supported = enc_enc_supported
122130

123131
def parse_and_validate(
124132
self, context: satosa.context.Context
@@ -131,6 +139,19 @@ def parse_and_validate(
131139
raise AuthRespParsingException(
132140
"invalid data in direct_post.jwt request body", e
133141
)
142+
143+
header = decode_jwt_header(resp_data.response)
144+
145+
if not header.get("alg") in self.enc_alg_supported:
146+
raise AuthRespValidationException(
147+
"invalid data in direct_post.jwt: alg not supported"
148+
)
149+
150+
if not header.get("enc") in self.enc_enc_supported:
151+
raise AuthRespValidationException(
152+
"invalid data in direct_post.jwt: enc not supported"
153+
)
154+
134155
try:
135156
payload = self.jwe_decryptor.decrypt(resp_data.response)
136157
except JWEDecryptionError as e:

pyeudiw/openid4vp/schemas/vp_formats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class VcSdJwt(BaseModel):
1919

2020

2121
class VpFormats(BaseModel):
22-
vc_sd_jwt: VcSdJwt = Field(..., alias="vc+sd-jwt")
22+
vc_sd_jwt: VcSdJwt = Field(..., alias="dc+sd-jwt")

pyeudiw/openid4vp/vp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pyeudiw.tools.base_logger import BaseLogger
22

33
JWT_TYPE = "JWT"
4-
VC_SD_JWT_TYPE = "vc+sd-jwt"
4+
VC_SD_JWT_TYPE = "dc+sd-jwt"
55
WALLET_ATTESTATION_TYPE = "wallet-attestation+jwt"
66
MDOC_BCOR_TYPE = "mdoc_cbor"
77

pyeudiw/openid4vp/vp_sd_jwt_vc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@
66
from pyeudiw.jwt.utils import decode_jwt_header
77
from pyeudiw.sd_jwt.schema import is_sd_jwt_kb_format
88
from pyeudiw.openid4vp.presentation_submission.base_vp_parser import BaseVPParser
9+
from pyeudiw.trust.dynamic import CombinedTrustEvaluator
910

1011

1112
class VpVcSdJwtParserVerifier(BaseVPParser):
13+
14+
def __init__(self, trust_evaluator: CombinedTrustEvaluator, sig_alg_supported: list[str] = [], **kwargs) -> None:
15+
"""
16+
Initialize the VpVcSdJwtParserVerifier with the trust evaluator.
17+
18+
:param trust_evaluator: The trust evaluator instance.
19+
:type trust_evaluator: CombinedTrustEvaluator
20+
:param sig_alg_supported: List of supported signature algorithms.
21+
:type sig_alg_supported: list[str]
22+
"""
23+
self.sig_alg_supported = sig_alg_supported
24+
super().__init__(trust_evaluator, **kwargs)
25+
1226
def _get_issuer_name(self, sdjwt: SdJwt) -> str:
1327
"""
1428
Get the issuer name from the token payload.
@@ -47,6 +61,10 @@ def validate(
4761
static_trust_materials = {}
4862
header = decode_jwt_header(token)
4963

64+
alg = header.get("alg", None)
65+
if alg not in self.sig_alg_supported:
66+
raise ValueError(f"Unsupported algorithm: {alg}")
67+
5068
if "x5c" in header:
5169
static_trust_materials["x5c"] = header["x5c"]
5270

pyeudiw/presentation_exchange/schemas/oid4vc_presentation_definition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PresentationDefinitionClaimFormatDesignations(
5555
PresentationDefinitionClaimFormatDesignations2,
5656
],
5757
Dict[
58-
Annotated[str, Field(pattern=r"^vc\+sd-jwt$")],
58+
Annotated[str, Field(pattern=r"^dc\+sd-jwt$")],
5959
PresentationDefinitionClaimFormatDesignations3,
6060
],
6161
]
@@ -71,7 +71,7 @@ class PresentationDefinitionClaimFormatDesignations(
7171
PresentationDefinitionClaimFormatDesignations2,
7272
],
7373
Dict[
74-
Annotated[str, Field(pattern=r"^vc\+sd-jwt$")],
74+
Annotated[str, Field(pattern=r"^dc\+sd-jwt$")],
7575
PresentationDefinitionClaimFormatDesignations2,
7676
],
7777
] = Field(..., title="Presentation Definition Claim Format Designations")

pyeudiw/satosa/default/openid4vp_backend.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,37 +73,6 @@ def __init__(
7373

7474
self.default_exp = int(self.config["jwt"]["default_exp"])
7575

76-
federation_jwks = self.config["trust"]["federation"]["config"][
77-
"federation_jwks"
78-
]
79-
if isinstance(federation_jwks, str):
80-
try:
81-
self.config["trust"]["federation"]["config"]["federation_jwks"] = (
82-
json.loads(federation_jwks)
83-
)
84-
except json.JSONDecodeError as e:
85-
raise ValueError(
86-
f"Invalid federation_jwks {self.config['trust']['federation']['config']['federation_jwks']} JSON: {e}"
87-
)
88-
89-
if isinstance(
90-
self.config["trust"]["federation"]["config"]["federation_jwks"], dict
91-
):
92-
self.config["trust"]["federation"]["config"]["federation_jwks"] = [
93-
self.config["trust"]["federation"]["config"]["federation_jwks"]
94-
]
95-
96-
if isinstance(self.config["metadata_jwks"], str):
97-
try:
98-
self.config["metadata_jwks"] = json.loads(self.config["metadata_jwks"])
99-
except json.JSONDecodeError as e:
100-
raise ValueError(
101-
f"Invalid metadata_jwks {self.config['metadata_jwks']} JSON: {e}"
102-
)
103-
104-
if isinstance(self.config["metadata_jwks"], dict):
105-
self.config["metadata_jwks"] = [self.config["metadata_jwks"]]
106-
10776
self.metadata_jwks_by_kids = {i["kid"]: i for i in self.config["metadata_jwks"]}
10877
self.config["metadata"]["jwks"] = {
10978
"keys": [JWK(i).public_key for i in self.config["metadata_jwks"]]

0 commit comments

Comments
 (0)