Skip to content

Commit e581fe9

Browse files
committed
fuckin with in
Signed-off-by: John Andersen <[email protected]>
1 parent 49122d3 commit e581fe9

File tree

3 files changed

+68
-14
lines changed

3 files changed

+68
-14
lines changed

docs/registration_policies.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,11 @@ for cryptography_ssh_key in cryptography_ssh_keys:
203203
)
204204

205205
for jwk_key in jwk_keys:
206-
print(jwk_key, "kid=", jwk_key.thumbprint())
207206
cwt_cose_key = cwt.COSEKey.from_pem(
208207
jwk_key.export_to_pem(),
209-
kid=jwk_key.thumbprint(),
208+
kid=jwk_key.kid,
210209
)
211-
cwt_cose_keys.append(cwt_cose_key)
210+
# cwt_cose_keys.append(cwt_cose_key)
212211

213212
for cwt_cose_key in cwt_cose_keys:
214213
cwt_ec2_key_as_dict = cwt_cose_key.to_dict()
@@ -232,7 +231,7 @@ for cwt_cose_key in cwt_cose_keys:
232231
pprint.pprint(cwt_ec2_key_as_dict_labeled)
233232
pycose_cose_key = pycose.keys.ec2.EC2Key.from_dict(cwt_ec2_key_as_dict)
234233
pycose_cose_key.kid = cwt_ec2_key_as_dict_labeled['CRITICAL']
235-
# cwt_cose_key.kid = cwt_ec2_key_as_dict_labeled['CRITICAL']
234+
cwt_cose_key._kid = pycose_cose_key.kid
236235
pycose_cose_keys.append(pycose_cose_key)
237236

238237
verify_signature = False
@@ -241,14 +240,17 @@ for pycose_cose_key in pycose_cose_keys:
241240
msg.key = pycose_cose_key
242241
verify_signature = msg.verify_signature()
243242
if verify_signature:
243+
# msg.kid = pycose_cose_key.kid
244244
break
245-
msg.kid = pycose_cose_key.kid
246245

247246
unittest.TestCase().assertTrue(
248247
verify_signature,
249248
"Failed to verify signature on statement",
250249
)
251250

251+
pprint.pprint(pycose_cose_keys)
252+
pprint.pprint(cwt_cose_keys)
253+
252254
cwt_protected = cwt.decode(msg.phdr[CWTClaims], cwt_cose_keys)
253255
issuer = cwt_protected[1]
254256
subject = cwt_protected[2]

scitt_emulator/create_statement.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,41 @@ def create_claim(
8383
if private_key_pem_path and private_key_pem_path.exists():
8484
cwt_cose_key = cwt.COSEKey.from_pem(private_key_pem_path.read_bytes())
8585
else:
86-
# cwt_cose_key = cwt.COSEKey.generate_symmetric_key(alg=alg, kid=kid)
86+
import subprocess
8787
subprocess.check_call(
8888
[
89-
"bash"
89+
"bash",
9090
"-c",
9191
f"ssh-keygen -q -f /dev/stdout -t ecdsa -b 384 -N '' -I {kid} <<<y 2>/dev/null | python -c 'import sys; from cryptography.hazmat.primitives import serialization; print(serialization.load_ssh_private_key(sys.stdin.buffer.read(), password=None).private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption()).decode().rstrip())' > {private_key_pem_path}",
9292
]
9393
)
9494
cwt_cose_key = cwt.COSEKey.from_pem(private_key_pem_path.read_bytes())
95-
cwt_cose_key_to_cose_key = cwt_cose_key.to_dict()
96-
sign1_message_key = pycose.keys.ec2.EC2Key.from_dict(cwt_cose_key_to_cose_key)
95+
# cwt_cose_key = cwt.COSEKey.generate_ec2_key(alg=alg, kid=kid)
96+
import pprint
97+
cwt_ec2_key_as_dict = cwt_cose_key.to_dict()
98+
pprint.pprint(cwt_ec2_key_as_dict)
99+
import pprint
100+
import inspect
101+
cose_tags = {
102+
member.identifier: member.fullname
103+
for _member_name, member in inspect.getmembers(pycose.headers)
104+
if (
105+
hasattr(member, "identifier")
106+
and hasattr(member, "fullname")
107+
)
108+
}
109+
pprint.pprint(cose_tags)
110+
cwt_ec2_key_as_dict_labeled = {
111+
cose_tags.get(key, key): value
112+
for key, value in cwt_ec2_key_as_dict.items()
113+
}
114+
# print("cwt_ec2_key_as_dict_labeled['STATIC_KEY_ID']", cwt_ec2_key_as_dict_labeled['CRITICAL'])
115+
pprint.pprint(cwt_ec2_key_as_dict)
116+
pprint.pprint(cwt_ec2_key_as_dict_labeled)
117+
pycose_cose_key = pycose.keys.ec2.EC2Key.from_dict(cwt_ec2_key_as_dict)
118+
# pycose_cose_key.kid = cwt_ec2_key_as_dict_labeled['CRITICAL']
119+
# cwt_cose_key._kid = pycose_cose_key.kid
120+
sign1_message_key = pycose.keys.ec2.EC2Key.from_dict(cwt_ec2_key_as_dict)
97121

98122
# CWT_Claims (label: 14 pending [CWT_CLAIM_COSE]): A CWT representing
99123
# the Issuer (iss) making the statement, and the Subject (sub) to
@@ -109,11 +133,14 @@ def create_claim(
109133
# chosen by the Issuer
110134
# Example: github.com/opensbom-generator/spdx-sbom-generator/releases/tag/v0.0.13
111135
# 2 => tstr; sub, the subject of the statements,
112-
2: "asdflkajsdflkjsadflkj" + subject,
136+
2: subject,
113137
# * tstr => any
114138
}
115139
# }
116140
cwt_token = cwt.encode(cwt_claims, cwt_cose_key)
141+
print(cwt.decode(cwt_token , cwt_cose_key))
142+
import sys
143+
sys.exit(0)
117144

118145
# Protected_Header = {
119146
protected = {

tests/test_docs.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,37 @@ def test_docs_registration_policies(tmp_path):
184184
for name, content in docutils_find_code_samples(nodes).items():
185185
tmp_path.joinpath(name).write_text(content)
186186

187-
key = jwcrypto.jwk.JWK.generate(kty="EC", crv="P-384")
187+
# key = jwcrypto.jwk.JWK.generate(kty="EC", crv="P-384")
188188
# cwt_cose_key = cwt.COSEKey.generate_symmetric_key(alg=alg, kid=kid)
189-
private_key_pem_path.write_bytes(
190-
key.export_to_pem(private_key=True, password=None),
191-
)
192189
algorithm = "ES384"
193190
audience = "scitt.example.org"
194191
subject = "repo:scitt-community/scitt-api-emulator:ref:refs/heads/main"
192+
# create claim
193+
command = [
194+
"client",
195+
"create-claim",
196+
"--out",
197+
claim_path,
198+
"--issuer",
199+
"NOP",
200+
"--subject",
201+
subject,
202+
"--content-type",
203+
content_type,
204+
"--payload",
205+
payload,
206+
"--private-key-pem",
207+
private_key_pem_path,
208+
]
209+
execute_cli(command)
210+
assert os.path.exists(claim_path)
211+
claim_path.unlink()
212+
"""
213+
private_key_pem_path.write_bytes(
214+
key.export_to_pem(private_key=True, password=None),
215+
)
216+
"""
217+
key = jwcrypto.jwk.JWK.from_pem(private_key_pem_path.read_bytes())
195218

196219
# tell jsonschema_validator.py that we want to assume non-TLS URLs for tests
197220
os.environ["DID_WEB_ASSUME_SCHEME"] = "http"
@@ -259,6 +282,7 @@ def test_docs_registration_policies(tmp_path):
259282
"--url",
260283
service.url
261284
]
285+
"""
262286
check_error = None
263287
try:
264288
execute_cli(command)
@@ -269,6 +293,7 @@ def test_docs_registration_policies(tmp_path):
269293
assert check_error.operation["error"] == claim_denied_error_blocked
270294
assert not os.path.exists(receipt_path)
271295
assert not os.path.exists(entry_id_path)
296+
"""
272297

273298
# replace example issuer with test OIDC service issuer in allowlist
274299
allowlist_schema_json_path = tmp_path.joinpath("allowlist.schema.json")

0 commit comments

Comments
 (0)