Skip to content

Commit

Permalink
fix: sd jwt validation when jwks are taken
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Sep 1, 2023
1 parent 8060538 commit 98fe920
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pyeudiw/federation/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ class KeyValidationError(Exception):

class InvalidChainError(Exception):
pass


class ProtocolMetadataNotFound(Exception):
pass
10 changes: 9 additions & 1 deletion pyeudiw/trust/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from pyeudiw.federation.trust_chain_validator import StaticTrustChainValidator
from pyeudiw.federation.exceptions import ProtocolMetadataNotFound
from pyeudiw.storage.db_engine import DBEngine
from pyeudiw.jwt.utils import unpad_jwt_payload

Expand Down Expand Up @@ -105,7 +106,14 @@ def get_final_metadata(self, metadata_type: str) -> dict:
# TODO - apply metadata policy and get the final metadata
# for now the final_metadata is the EC metadata -> TODO final_metadata
self.final_metadata = unpad_jwt_payload(self.trust_chain[0])
return self.final_metadata
try:
# TODO: there are some cases where the jwks are taken from a uri ...
return self.final_metadata['metadata'][metadata_type]['jwks']
except KeyError as e:
raise ProtocolMetadataNotFound(
f"{metadata_type} not found in the final metadata:"
f" {self.final_metadata}"
)

def get_trusted_jwks(self, metadata_type: str) -> list:
return self.get_final_metadata(
Expand Down

0 comments on commit 98fe920

Please sign in to comment.