Skip to content

Commit 2e8ea4f

Browse files
committed
test: docs: registration polcies: Ensure both ssh and oidc notary public key resolvers tested seperatly
Signed-off-by: John Andersen <[email protected]>
1 parent 91262c3 commit 2e8ea4f

7 files changed

+60
-43
lines changed

scitt_emulator/key_loader_format_did_jwk.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,17 @@ def key_loader_format_did_jwk(
3737
cose=None,
3838
)
3939
]
40+
41+
42+
def to_object_jwk(verification_key: VerificationKey) -> dict:
43+
if not isinstance(verification_key.original, jwcrypto.jwk.JWK):
44+
return
45+
46+
return {
47+
"content_type": verification_key.original_content_type,
48+
"key": {
49+
**verification_key.original.export_public(as_dict=True),
50+
"use": "sig",
51+
"kid": verification_key.original.thumbprint(),
52+
},
53+
}

scitt_emulator/key_loader_format_url_referencing_oidc_issuer.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from scitt_emulator.did_helpers import did_web_to_url
1616
from scitt_emulator.key_helper_dataclasses import VerificationKey
17+
from scitt_emulator.key_loader_format_did_jwk import to_object_jwk
1718

1819

1920
CONTENT_TYPE = "application/jwk+json"
@@ -72,17 +73,3 @@ def transform_key_instance_jwcrypto_jwk_to_cwt_cose(
7273
key.export_to_pem(),
7374
kid=key.thumbprint(),
7475
)
75-
76-
77-
def to_object_oidc_issuer(verification_key: VerificationKey) -> dict:
78-
if verification_key.original_content_type != CONTENT_TYPE:
79-
return
80-
81-
return {
82-
"content_type": verification_key.original_content_type,
83-
"key": {
84-
**verification_key.original.export_public(as_dict=True),
85-
"use": "sig",
86-
"kid": verification_key.original.thumbprint(),
87-
},
88-
}

scitt_emulator/key_loader_format_url_referencing_ssh_authorized_keys.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import contextlib
2+
import dataclasses
23
import urllib.parse
34
import urllib.request
45
from typing import List, Tuple
@@ -15,6 +16,7 @@
1516

1617
from scitt_emulator.did_helpers import did_web_to_url
1718
from scitt_emulator.key_helper_dataclasses import VerificationKey
19+
from scitt_emulator.key_loader_format_did_jwk import to_object_jwk
1820

1921
CONTENT_TYPE = "application/key+ssh"
2022

@@ -57,11 +59,27 @@ def key_loader_format_url_referencing_ssh_authorized_keys(
5759
def transform_key_instance_cryptography_ecc_public_to_jwcrypto_jwk(
5860
key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey,
5961
) -> jwcrypto.jwk.JWK:
60-
if not isinstance(key, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey):
62+
if not isinstance(
63+
key, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
64+
):
6165
raise TypeError(key)
6266
return jwcrypto.jwk.JWK.from_pem(
6367
key.public_bytes(
6468
encoding=serialization.Encoding.PEM,
6569
format=serialization.PublicFormat.SubjectPublicKeyInfo,
6670
)
6771
)
72+
73+
74+
def to_object_ssh_public(verification_key: VerificationKey) -> dict:
75+
if verification_key.original_content_type != CONTENT_TYPE:
76+
return
77+
78+
return to_object_jwk(
79+
dataclasses.replace(
80+
verification_key,
81+
original=transform_key_instance_cryptography_ecc_public_to_jwcrypto_jwk(
82+
verification_key.original,
83+
)
84+
)
85+
)

scitt_emulator/verify_statement.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def verify_statement(
6464
# TODO Logging
6565
continue
6666
msg.key = verification_key.cose
67+
verify_signature = False
6768
with contextlib.suppress(Exception):
6869
verify_signature = msg.verify_signature()
6970
if verify_signature:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'transform_key_instance_cryptography_ecc_public_to_jwcrypto_jwk=scitt_emulator:key_loader_format_url_referencing_ssh_authorized_keys.transform_key_instance_cryptography_ecc_public_to_jwcrypto_jwk',
2323
],
2424
'scitt_emulator.key_helpers.verification_key_to_object': [
25-
'to_object_oidc_issuer=scitt_emulator.key_loader_format_url_referencing_oidc_issuer:to_object_oidc_issuer',
25+
'to_object_jwk=scitt_emulator.key_loader_format_did_jwk:to_object_jwk',
26+
'to_object_ssh_public=scitt_emulator.key_loader_format_url_referencing_ssh_authorized_keys:to_object_ssh_public',
2627
],
2728
},
2829
python_requires=">=3.8",

tests/test_cli.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,12 @@ def test_client_cli(use_lro: bool, tmp_path):
156156
assert receipt == receipt_2
157157

158158

159-
def create_flask_app_oidc_server(config):
160-
app = Flask("oidc_server")
159+
def create_flask_app_ssh_authorized_keys_server(config):
160+
app = Flask("ssh_authorized_keys_server")
161161

162162
app.config.update(dict(DEBUG=True))
163163
app.config.update(config)
164164

165-
# TODO For testing ssh key style issuers, not OIDC related needs to be moved
166165
@app.route("/", methods=["GET"])
167166
def ssh_public_keys():
168167
from cryptography.hazmat.primitives import serialization
@@ -178,6 +177,15 @@ def ssh_public_keys():
178177
mimetype="text/plain",
179178
)
180179

180+
return app
181+
182+
183+
def create_flask_app_oidc_server(config):
184+
app = Flask("oidc_server")
185+
186+
app.config.update(dict(DEBUG=True))
187+
app.config.update(config)
188+
181189
@app.route("/.well-known/openid-configuration", methods=["GET"])
182190
def openid_configuration():
183191
return jsonify(

tests/test_docs.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import subprocess
1515
import urllib.parse
1616

17+
import pytest
1718
import myst_parser.parsers.docutils_
1819
import docutils.nodes
1920
import docutils.utils
@@ -28,6 +29,7 @@
2829
payload,
2930
execute_cli,
3031
create_flask_app_oidc_server,
32+
create_flask_app_ssh_authorized_keys_server,
3133
)
3234

3335

@@ -162,7 +164,13 @@ def url_to_did_web(url_string):
162164
]
163165
)
164166

165-
def test_docs_registration_policies(tmp_path):
167+
@pytest.mark.parametrize(
168+
"create_flask_app_notary_identity", [
169+
create_flask_app_oidc_server,
170+
create_flask_app_ssh_authorized_keys_server,
171+
],
172+
)
173+
def test_docs_registration_policies(create_flask_app_notary_identity, tmp_path):
166174
workspace_path = tmp_path / "workspace"
167175

168176
claim_path = tmp_path / "claim.cose"
@@ -195,7 +203,7 @@ def test_docs_registration_policies(tmp_path):
195203

196204
with Service(
197205
{"key": key, "algorithms": [algorithm]},
198-
create_flask_app=create_flask_app_oidc_server,
206+
create_flask_app=create_flask_app_notary_identity,
199207
) as oidc_service, Service(
200208
{
201209
"tree_alg": "CCF",
@@ -238,7 +246,7 @@ def test_docs_registration_policies(tmp_path):
238246
assert os.path.exists(claim_path)
239247

240248
# replace example issuer with test OIDC service issuer (URL) in error
241-
claim_denied_error_blocked = CLAIM_DENIED_ERROR_BLOCKED
249+
claim_denied_error_blocked = copy.deepcopy(CLAIM_DENIED_ERROR_BLOCKED)
242250
claim_denied_error_blocked["detail"] = claim_denied_error_blocked["detail"].replace(
243251
"did:web:denied.example.com", issuer,
244252
)
@@ -276,27 +284,7 @@ def test_docs_registration_policies(tmp_path):
276284
)
277285
)
278286

279-
# submit accepted claim using SSH authorized_keys lookup
280-
command = [
281-
"client",
282-
"submit-claim",
283-
"--claim",
284-
claim_path,
285-
"--out",
286-
receipt_path,
287-
"--out-entry-id",
288-
entry_id_path,
289-
"--url",
290-
service.url
291-
]
292-
execute_cli(command)
293-
assert os.path.exists(receipt_path)
294-
receipt_path.unlink()
295-
assert os.path.exists(entry_id_path)
296-
receipt_path.unlink(entry_id_path)
297-
298-
# TODO Switch back on the OIDC routes
299-
# submit accepted claim using OIDC -> jwks lookup
287+
# submit accepted claim
300288
command = [
301289
"client",
302290
"submit-claim",

0 commit comments

Comments
 (0)