@@ -142,14 +142,16 @@ if unverified_issuer.startswith("did:web:"):
142
142
143
143
# Load keys from issuer
144
144
jwk_keys = []
145
+ cryptography_ssh_keys = []
146
+ cwt_cose_keys = []
147
+ pycose_cose_keys = []
145
148
146
149
import urllib.request
147
150
import urllib.parse
148
151
149
152
# TODO did:web: -> URL
150
153
from cryptography.hazmat.primitives import serialization
151
154
152
- cryptography_ssh_keys = []
153
155
if " ://" in unverified_issuer and not unverified_issuer.startswith(" file://" ):
154
156
# TODO Logging for URLErrors
155
157
# Check if OIDC issuer
@@ -166,10 +168,16 @@ if "://" in unverified_issuer and not unverified_issuer.startswith("file://"):
166
168
if response.status == 200 :
167
169
jwks = json.loads(response.read())
168
170
for jwk_key_as_dict in jwks[" keys" ]:
171
+ """
169
172
jwk_key_as_string = json.dumps(jwk_key_as_dict)
170
173
jwk_keys.append(
171
174
jwcrypto.jwk.JWK.from_json(jwk_key_as_string),
172
175
)
176
+ """
177
+ cwt_cose_key = cwt.COSEKey.from_jwk(
178
+ jwk_key_as_dict
179
+ )
180
+ cwt_cose_keys.append(cwt_cose_key)
173
181
174
182
# Try loading ssh keys. Example: https://github.com/username.keys
175
183
with contextlib.suppress(urllib.request.URLError):
@@ -194,17 +202,37 @@ for cryptography_ssh_key in cryptography_ssh_keys:
194
202
)
195
203
)
196
204
197
- cwt_cose_keys = []
198
- pycose_cose_keys = []
199
-
200
205
for jwk_key in jwk_keys:
206
+ print (jwk_key, " kid=" , jwk_key.thumbprint())
201
207
cwt_cose_key = cwt.COSEKey.from_pem(
202
208
jwk_key.export_to_pem(),
203
209
kid = jwk_key.thumbprint(),
204
210
)
205
211
cwt_cose_keys.append(cwt_cose_key)
212
+
213
+ for cwt_cose_key in cwt_cose_keys:
206
214
cwt_ec2_key_as_dict = cwt_cose_key.to_dict()
215
+ import pprint
216
+ import inspect
217
+ cose_tags = {
218
+ member.identifier: member.fullname
219
+ for _member_name, member in inspect.getmembers(pycose.headers)
220
+ if (
221
+ hasattr (member, " identifier" )
222
+ and hasattr (member, " fullname" )
223
+ )
224
+ }
225
+ pprint.pprint(cose_tags)
226
+ cwt_ec2_key_as_dict_labeled = {
227
+ cose_tags.get(key, key): value
228
+ for key, value in cwt_ec2_key_as_dict.items()
229
+ }
230
+ print (" cwt_ec2_key_as_dict_labeled['STATIC_KEY_ID']" , cwt_ec2_key_as_dict_labeled[' CRITICAL' ])
231
+ pprint.pprint(cwt_ec2_key_as_dict)
232
+ pprint.pprint(cwt_ec2_key_as_dict_labeled)
207
233
pycose_cose_key = pycose.keys.ec2.EC2Key.from_dict(cwt_ec2_key_as_dict)
234
+ pycose_cose_key.kid = cwt_ec2_key_as_dict_labeled[' CRITICAL' ]
235
+ # cwt_cose_key.kid = cwt_ec2_key_as_dict_labeled['CRITICAL']
208
236
pycose_cose_keys.append(pycose_cose_key)
209
237
210
238
verify_signature = False
@@ -214,6 +242,7 @@ for pycose_cose_key in pycose_cose_keys:
214
242
verify_signature = msg.verify_signature()
215
243
if verify_signature:
216
244
break
245
+ msg.kid = pycose_cose_key.kid
217
246
218
247
unittest.TestCase().assertTrue(
219
248
verify_signature,
@@ -270,14 +299,17 @@ $ scitt-emulator server --workspace workspace/ --tree-alg CCF --use-lro
270
299
```
271
300
272
301
The current emulator notary (create-statement) implementation will sign
273
- statements using a generated key or a key we provide via the ` --private-key-pem `
274
- argument. If we provide the ` --private-key-pem ` argument but the key at the
275
- given path does not exist, the generated key will be written out to that path.
302
+ statements using a generated ephemeral key or a key we provide via the
303
+ ` --private-key-pem ` argument.
304
+
305
+ Since we need to export the key for verification by the policy engine, we will
306
+ first generate it using ` ssh-keygen ` .
276
307
277
308
``` console
278
- $ export ISSUER_PORT=" 9000" && \
279
- export ISSUER_URL="http://localhost:${ISSUER_PORT}"
280
- $ scitt-emulator client create-claim \
309
+ $ export ISSUER_PORT=" 9000" \
310
+ && export ISSUER_URL="http://localhost:${ISSUER_PORT}" \
311
+ && ssh-keygen -q -f /dev/stdout -t ecdsa -b 384 -N '' -I $RANDOM <<<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 \
312
+ && scitt-emulator client create-claim \
281
313
--private-key-pem private-key.pem \
282
314
--issuer "${ISSUER_URL}" \
283
315
--subject "solar" \
0 commit comments