Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: iat disclosable #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/complex_eidas/specification.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
user_claims:
!sd iat: 11
verified_claims:
verification:
trust_framework: eidas
Expand Down Expand Up @@ -33,5 +34,5 @@ holder_disclosed_claims:
{
"verification": { "evidence": [] },
"claims": { "gender": null, "place_of_birth": { "country": null } },
},
}
}
2 changes: 1 addition & 1 deletion examples/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ expiry_seconds: 86400000 # 1000 days
random_seed: 0

iat: 1683000000 # Tue May 02 2023 04:00:00 GMT+0000
exp: 1883000000 # Sat Sep 01 2029 23:33:20 GMT+0000
exp: 1883000000 # Sat Sep 01 2029 23:33:20 GMT+0000
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sd-jwt"
version = "0.10.4"
version = "0.11.0"
description = "The reference implementation of the IETF SD-JWT specification."
authors = ["Daniel Fett <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/sd_jwt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.4"
__version__ = "0.11.0"
2 changes: 1 addition & 1 deletion src/sd_jwt/bin/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,4 @@ def cb_get_issuer_key(issuer):
sys.exit(0)

if __name__ == "__main__":
run()
run()
29 changes: 27 additions & 2 deletions src/sd_jwt/bin/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@


import argparse
import datetime
import logging
import sys

from typing import Dict
from pathlib import Path

Expand All @@ -29,6 +31,19 @@
# Set logging to stdout
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

def get_value_from_disclosables(attr_name, testcase):
_res = None
try:
_res = testcase['user_claims'][
[
k for k,v in testcase['user_claims'].items()
if hasattr(k, "value") and k.value == attr_name
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I was lazy, I would have to inspect the type, like isinstance(x, SDObj)

][0]
]
except IndexError:
pass

return _res

def generate_test_case_data(settings: Dict, testcase_path: Path, type: str):
seed = settings["random_seed"]
Expand All @@ -42,12 +57,22 @@ def generate_test_case_data(settings: Dict, testcase_path: Path, type: str):
extra_header_parameters = testcase.get("extra_header_parameters", {})

claims = {}

_iat = get_value_from_disclosables("iat", testcase)

iat = _iat or settings.get("iat", int(datetime.datetime.utcnow().timestamp()))
exp = iat + (settings.get("exp_delta_seconds", 60) * 60)

if include_default_claims:
claims = {
"iss": settings["identifiers"]["issuer"],
"iat": settings["iat"],
"exp": settings["exp"],
"exp": settings.get("exp", exp)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are some claims that if not SD then they must/should be present since are required or recommended (that' include_default_claims).

IAT is one of these, if not present as SDobj it must be included in plain

}
else:
claims = dict()

if not _iat:
claims['iat'] = iat
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this must be refactored

I can remove that if and use claims['iat'] = _iat or iat


claims.update(testcase["user_claims"])

Expand Down
6 changes: 3 additions & 3 deletions src/sd_jwt/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def _verify_key_binding_jwt(
# Reassemble the SD-JWT in compact format and check digest
if self._serialization_format == "compact":
string_to_hash = self._combine(
self._unverified_input_sd_jwt,
*self._input_disclosures,
""
self._unverified_input_sd_jwt,
*self._input_disclosures,
""
)
expected_sd_jwt_presentation_hash = self._b64hash(string_to_hash.encode("ascii"))

Expand Down
4 changes: 3 additions & 1 deletion tests/testcases/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ expiry_seconds: 86400000 # 1000 days

random_seed: 0

exp_delta_seconds: 60

iat: 1683000000 # Tue May 02 2023 04:00:00 GMT+0000
exp: 1883000000 # Sat Sep 01 2029 23:33:20 GMT+0000
exp: 1883000000 # Sat Sep 01 2029 23:33:20 GMT+0000
Loading