Skip to content

Commit 9fd046a

Browse files
committed
scitt: create_claim: Update to rev a4645e4bc3e78ad5cfd9f8347c7e0ac8267c1079 of SCITT arch
Related: ietf-wg-scitt/draft-ietf-scitt-architecture@a4645e4 Signed-off-by: John Andersen <[email protected]>
1 parent 56d522d commit 9fd046a

File tree

5 files changed

+17
-46
lines changed

5 files changed

+17
-46
lines changed

docs/registration_policies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ scitt-emulator server --workspace workspace/ --tree-alg CCF --use-lro
153153
Create claim from allowed issuer (`.org`) and from non-allowed (`.com`).
154154

155155
```console
156-
$ scitt-emulator client create-claim --issuer did:web:example.com --content-type application/json --payload '{"sun": "yellow"}' --out claim.cose
156+
$ scitt-emulator client create-claim --issuer did:web:example.com --subject "solar" --content-type application/json --payload '{"sun": "yellow"}' --out claim.cose
157157
A COSE-signed Claim was written to: claim.cose
158158
$ scitt-emulator client submit-claim --claim claim.cose --out claim.receipt.cbor
159159
Traceback (most recent call last):
@@ -175,7 +175,7 @@ Failed validating 'enum' in schema['properties']['issuer']:
175175
On instance['issuer']:
176176
'did:web:example.com'
177177

178-
$ scitt-emulator client create-claim --issuer did:web:example.org --content-type application/json --payload '{"sun": "yellow"}' --out claim.cose
178+
$ scitt-emulator client create-claim --issuer did:web:example.org --subject "solar" --content-type application/json --payload '{"sun": "yellow"}' --out claim.cose
179179
A COSE signed Claim was written to: claim.cose
180180
$ scitt-emulator client submit-claim --claim claim.cose --out claim.receipt.cbor
181181
Claim registered with entry ID 1

scitt_emulator/client.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import httpx
1010

1111
import scitt_emulator.scitt as scitt
12+
from scitt_emulator import create_statement
1213
from scitt_emulator.tree_algs import TREE_ALGS
1314

1415
DEFAULT_URL = "http://127.0.0.1:8000"
@@ -72,10 +73,6 @@ def post(self, *args, **kwargs):
7273
return self._request("POST", *args, **kwargs)
7374

7475

75-
def create_claim(issuer: str, content_type: str, payload: str, claim_path: Path):
76-
scitt.create_claim(claim_path, issuer, content_type, payload)
77-
78-
7976
def submit_claim(
8077
url: str,
8178
claim_path: Path,
@@ -170,16 +167,7 @@ def cli(fn):
170167
parser = fn(description="Execute client commands")
171168
sub = parser.add_subparsers(dest="cmd", help="Command to execute", required=True)
172169

173-
p = sub.add_parser("create-claim", description="Create a fake SCITT claim")
174-
p.add_argument("--out", required=True, type=Path)
175-
p.add_argument("--issuer", required=True, type=str)
176-
p.add_argument("--content-type", required=True, type=str)
177-
p.add_argument("--payload", required=True, type=str)
178-
p.set_defaults(
179-
func=lambda args: scitt.create_claim(
180-
args.out, args.issuer, args.content_type, args.payload
181-
)
182-
)
170+
create_statement.cli(sub.add_parser)
183171

184172
p = sub.add_parser(
185173
"submit-claim", description="Submit a SCITT claim and retrieve the receipt"

scitt_emulator/scitt.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
import cbor2
1313
from pycose.messages import CoseMessage, Sign1Message
1414
import pycose.headers
15-
from pycose.keys.ec2 import EC2Key
16-
import pycose.keys.curves
1715

18-
# temporary claim header labels, see draft-birkholz-scitt-architecture
19-
COSE_Headers_Issuer = 391
16+
from scitt_emulator.create_statement import CWTClaims
2017

2118
# temporary receipt header labels, see draft-birkholz-scitt-receipts
2219
COSE_Headers_Service_Id = "service_id"
@@ -236,10 +233,10 @@ def _create_receipt(self, claim: bytes, entry_id: str):
236233
raise ClaimInvalidError(
237234
"Claim does not have a content type header parameter"
238235
)
239-
if COSE_Headers_Issuer not in msg.phdr:
240-
raise ClaimInvalidError("Claim does not have an issuer header parameter")
241-
if not isinstance(msg.phdr[COSE_Headers_Issuer], str):
242-
raise ClaimInvalidError("Claim issuer is not a string")
236+
if CWTClaims not in msg.phdr:
237+
raise ClaimInvalidError("Claim does not have a CWTClaims header parameter")
238+
239+
# TODO Verify CWT
243240

244241
# Extract fields of COSE_Sign1 for countersigning
245242
outer = cbor2.loads(claim)
@@ -304,28 +301,6 @@ def verify_receipt(self, cose_path: Path, receipt_path: Path):
304301
self.verify_receipt_contents(receipt_contents, countersign_tbi)
305302

306303

307-
def create_claim(claim_path: Path, issuer: str, content_type: str, payload: str):
308-
# Create COSE_Sign1 structure
309-
protected = {
310-
pycose.headers.Algorithm: "ES256",
311-
pycose.headers.ContentType: content_type,
312-
COSE_Headers_Issuer: issuer,
313-
}
314-
msg = Sign1Message(phdr=protected, payload=payload.encode("utf-8"))
315-
316-
# Create an ad-hoc key
317-
# Note: The emulator does not validate signatures, hence the short-cut.
318-
key = EC2Key.generate_key(pycose.keys.curves.P256)
319-
320-
# Sign
321-
msg.key = key
322-
claim = msg.encode(tag=True)
323-
324-
with open(claim_path, "wb") as f:
325-
f.write(claim)
326-
print(f"A COSE signed Claim was written to: {claim_path}")
327-
328-
329304
def create_countersign_to_be_included(
330305
body_protected, sign_protected, payload, signature
331306
):

tests/test_cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def test_client_cli(use_lro: bool, tmp_path):
7373
claim_path,
7474
"--issuer",
7575
issuer,
76+
"--subject",
77+
"test",
7678
"--content-type",
7779
content_type,
7880
"--payload",
@@ -248,6 +250,8 @@ def test_client_cli_token(tmp_path):
248250
claim_path,
249251
"--issuer",
250252
issuer,
253+
"--subject",
254+
"test",
251255
"--content-type",
252256
content_type,
253257
"--payload",

tests/test_docs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def test_docs_registration_policies(tmp_path):
196196
claim_path,
197197
"--issuer",
198198
non_allowlisted_issuer,
199+
"--subject",
200+
"test",
199201
"--content-type",
200202
content_type,
201203
"--payload",
@@ -236,6 +238,8 @@ def test_docs_registration_policies(tmp_path):
236238
claim_path,
237239
"--issuer",
238240
allowlisted_issuer,
241+
"--subject",
242+
"test",
239243
"--content-type",
240244
content_type,
241245
"--payload",

0 commit comments

Comments
 (0)