Skip to content

Commit

Permalink
feat: jwk validation
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Aug 12, 2024
1 parent 00371a2 commit b28b7fd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions didcomm_messaging/resolver/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class JWKResolver(DIDResolver):
"""Resolve did:jwk."""

PATTERN = re.compile(r"^did:jwk:(?P<did>.*)$")
PATTERN = re.compile(r"^did:jwk:(?P<did>[A-Za-z0-9\-_]+)$")

async def resolve(self, did: str) -> dict:
"""Resolve a did:jwk."""
Expand All @@ -22,7 +22,17 @@ async def resolve(self, did: str) -> dict:
else:
raise DIDResolutionError(f"Invalid DID: {did}")

jwk = json.loads(b64.decode(encoded))
try:
jwk = json.loads(b64.decode(encoded))
except json.JSONDecodeError:
raise DIDResolutionError("Invalid JWK")

if not isinstance(jwk, dict):
raise DIDResolutionError("Invalid JWK")

if "kty" not in jwk:
raise DIDResolutionError("Invalid JWK")

doc = {
"@context": [
"https://www.w3.org/ns/did/v1",
Expand Down

0 comments on commit b28b7fd

Please sign in to comment.