-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
392 lines (344 loc) · 20.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
const { default: base64url } = require('base64url');
const jose = require('node-jose');
async function main() {
const iaca_cert_pem =
"-----BEGIN CERTIFICATE-----\n" +
"MIICGjCCAb+gAwIBAgIKfqh/NIWv9JsIdDAKBggqhkjOPQQDAjBFMQswCQYDVQQG\n" +
"EwJVUzEpMCcGA1UEAwwgSVNPMTgwMTMtNSBUZXN0IENlcnRpZmljYXRlIElBQ0Ex\n" +
"CzAJBgNVBAgMAk5ZMB4XDTI0MDQyODIxMDIyM1oXDTM0MDQyODIxMDIyNFowRTEL\n" +
"MAkGA1UEBhMCVVMxKTAnBgNVBAMMIElTTzE4MDEzLTUgVGVzdCBDZXJ0aWZpY2F0\n" +
"ZSBJQUNBMQswCQYDVQQIDAJOWTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABC8v\n" +
"9/5utIwwLrN/qe54sga0FSNIJGO/NO9YKWGSUWylElRskOUD7WAK9UKplzQNck3k\n" +
"FeJSKUAyliG4RSIbgnyjgZYwgZMwEgYDVR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8B\n" +
"Af8EBAMCAQYwHQYDVR0OBBYEFEz/lSXgZZtQ7BxDClpyjcQbTTrPMB0GA1UdEgQW\n" +
"MBSBEmV4YW1wbGVAaXNvbWRsLmNvbTAvBgNVHR8EKDAmMCSgIqAghh5odHRwczov\n" +
"L2V4YW1wbGUuY29tL0lTT21ETC5jcmwwCgYIKoZIzj0EAwIDSQAwRgIhAMu3vC2e\n" +
"eEW6r+Naqcd6NMxD1NQsA8ipV4QOe4Zl0xAzAiEA6l1vXXBXfcSULjOzw+PIrZop\n" +
"gJGXXkNfK5h7jN9NVKY=\n" +
"-----END CERTIFICATE-----";
const static_wallet_metadata = {
"issuer":"https://self-issued.me/v2",
"authorization_endpoint":"mdoc-openid4vp://",
"response_types_supported":[
"vp_token"
],
"vp_formats_supported":{
"mso_mdoc":{}
},
"client_id_schemes_supported":[
"x509_san_dns"
],
"authorization_encryption_alg_values_supported":[ "ECDH-ES" ],
"authorization_encryption_enc_values_supported":[ "A256GCM" ]
};
const presentation_definition = {
"id":"mDL-sample-req",
"input_descriptors":[
{
"id":"org.iso.18013.5.1.mDL ",
"format":{
"mso_mdoc":{
"alg":[
"ES256",
"ES384",
"ES512",
"EdDSA",
"ESB256",
"ESB320",
"ESB384",
"ESB512"
]
}
},
"constraints":{
"fields":[
{
"path":[
"$['org.iso.18013.5.1']['birth_date']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['document_number']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['driving_privileges']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['expiry_date']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['family_name']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['given_name']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['issue_date']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['issuing_authority']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['issuing_country']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['portrait']"
],
"intent_to_retain":false
},
{
"path":[
"$['org.iso.18013.5.1']['un_distinguishing_sign']"
],
"intent_to_retain":false
}
],
"limit_disclosure":"required"
}
}
]
};
const ephemeral_private_key_reader = {
"kty":"EC",
"d":"_Hc7lRd1Zt8sDAb1-pCgI9qS3oobKNa-mjRDhaKjH90",
"use":"enc",
"crv":"P-256",
"x":"xVLtZaPPK-xvruh1fEClNVTR6RCZBsQai2-DrnyKkxg",
"y":"-5-QtFqJqGwOjEL3Ut89nrE0MeaUp5RozksKHpBiyw0",
"alg":"ECDH-ES",
"kid":"P8p0virRlh6fAkh5-YSeHt4EIv-hFGneYk14d8DF51w"
};
const ephemeral_public_key_reader = {
"kty":"EC",
"use":"enc",
"crv":"P-256",
"x":"xVLtZaPPK-xvruh1fEClNVTR6RCZBsQai2-DrnyKkxg",
"y":"-5-QtFqJqGwOjEL3Ut89nrE0MeaUp5RozksKHpBiyw0",
"alg":"ECDH-ES",
"kid":"P8p0virRlh6fAkh5-YSeHt4EIv-hFGneYk14d8DF51w"
};
const nonce = "abcdefgh1234567890";
const state = "34asfd34_34$34";
const authz_request_parameters = {
"aud":"https://self-issued.me/v2",
"response_type":"vp_token",
presentation_definition,
"client_metadata":{
"jwks":{
"keys":[
ephemeral_public_key_reader
]
},
"authorization_encrypted_response_alg":"ECDH-ES",
"authorization_encrypted_response_enc":"A256GCM",
"vp_formats":{
"mso_mdoc":{
"alg":[ "ES256", "ES384", "ES512", "EdDSA", "ESB256", "ESB320", "ESB384", "ESB512" ]
}
},
"require_signed_request_object":true
},
state,
nonce,
"client_id":"example.com",
"client_id_scheme":"x509_san_dns",
"response_mode":"direct_post.jwt",
"response_uri":"https://example.com/12345/response"
};
const authz_request_jwt_header = {
"x5c":[
"MIICPzCCAeWgAwIBAgIUDmBXx7+19KhwjltDbBW4BE0CRREwCgYIKoZIzj0EAwIwaTELMAkGA1UEBhMCVVQxDzANBgNVBAgMBlV0b3BpYTENMAsGA1UEBwwEQ2l0eTESMBAGA1UECgwJQUNNRSBDb3JwMRAwDgYDVQQLDAdJVCBEZXB0MRQwEgYDVQQDDAtleGFtcGxlLmNvbTAeFw0yMzEwMDMxNDQ5MzhaFw0yNDA5MjMxNDQ5MzhaMGkxCzAJBgNVBAYTAlVUMQ8wDQYDVQQIDAZVdG9waWExDTALBgNVBAcMBENpdHkxEjAQBgNVBAoMCUFDTUUgQ29ycDEQMA4GA1UECwwHSVQgRGVwdDEUMBIGA1UEAwwLZXhhbXBsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARfLh+cWXq5fWRf9Cwo8VRkp9AAOOLaP3UCi3YY1VDHHEx7lAn9MCXo/vniqL88VFEi1PtT9ODaINVIXZFFjOrYo2swaTAdBgNVHQ4EFgQUxv6HtRQk9q7ASQCUqOqEun5S8QQwHwYDVR0jBBgwFoAUxv6HtRQk9q7ASQCUqOqEun5S8QQwDwYDVR0TAQH/BAUwAwEB/zAWBgNVHREEDzANggtleGFtcGxlLmNvbTAKBggqhkjOPQQDAgNIADBFAiBt5/maixJyaWNKG8W9dAePhvhh5OHjswJaEjcyYiqoogIhANwTGTdg12REzQMfQSXTSVtNp1jjJMPsipqR7kIK1JdT"
],
"typ":"JWT",
"alg":"ES256"
};
const static_private_key_reader_auth = {
"kty":"EC",
"kid":"Cv_aKIPqB8mkHqcJGUFq7zawf5vAyA6xv3PdJpJY1V8",
"crv":"P-256",
"x":"Xy4fnFl6uX1kX_QsKPFUZKfQADji2j91Aot2GNVQxxw",
"y":"THuUCf0wJej--eKovzxUUSLU-1P04Nog1UhdkUWM6tg",
"d":"5SOi-q3lIENTg-pyKeh3Vxhvu7IgYRm-IHPis2vfP8c"
};
const authz_request_object_jwt = await generate_authz_request_object_jwt(
static_private_key_reader_auth, authz_request_jwt_header, authz_request_parameters);
const presentation_submission = {
"definition_id":"mDL-sample-req",
"id":"mDL-sample-res",
"descriptor_map":[
{
"id":"org.iso.18013.5.1.mDL",
"format":"mso_mdoc",
"path":"$"
}
]
};
// contains the base64url-encoded DeviceResponse
const vp_token = "o2ZzdGF0dXMAZ3ZlcnNpb25jMS4waWRvY3VtZW50c4GjZ2RvY1R5cGV1b3JnLmlzby4xODAxMy41LjEubURMbGRldmljZVNpZ25lZKJqZGV2aWNlQXV0aKFvZGV2aWNlU2lnbmF0dXJlhEOhASag9lhAZIIUI8retZS5btJ9TGyaMt7j1nQm1DUy5FyG_98yKOOWNOtizwY41CipQOMGZ5d7Plh722-YQrSCpZTNBIYjxmpuYW1lU3BhY2Vz2BhBoGxpc3N1ZXJTaWduZWSiamlzc3VlckF1dGiEQ6EBJqEYIVkCYDCCAlwwggIBoAMCAQICCkdSCck8KAChX_8wCgYIKoZIzj0EAwIwRTELMAkGA1UEBhMCVVMxKTAnBgNVBAMMIElTTzE4MDEzLTUgVGVzdCBDZXJ0aWZpY2F0ZSBJQUNBMQswCQYDVQQIDAJOWTAeFw0yNDA0MjgyMTAyMjNaFw0yNTA3MjkyMTAyMjNaMEQxCzAJBgNVBAYTAlVTMSgwJgYDVQQDDB9JU08xODAxMy01IFRlc3QgQ2VydGlmaWNhdGUgRFNDMQswCQYDVQQIDAJOWTBZMBMGByqGSM49Ag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GFjvpGhkaWdlc3RJRAJmcmFuZG9tUFoPu1Ae76m2ftDBo8H1DU9xZWxlbWVudElkZW50aWZpZXJyZHJpdmluZ19wcml2aWxlZ2VzbGVsZW1lbnRWYWx1ZYKjamlzc3VlX2RhdGXZA-xqMjAyMC0wMS0wMWtleHBpcnlfZGF0ZdkD7GoyMDI1LTAxLTAxdXZlaGljbGVfY2F0ZWdvcnlfY29kZWFCo2ppc3N1ZV9kYXRl2QPsajIwMjAtMDEtMDFrZXhwaXJ5X2RhdGXZA-xqMjAyNS0wMS0wMXV2ZWhpY2xlX2NhdGVnb3J5X2NvZGViQkXYGFhdpGhkaWdlc3RJRANmcmFuZG9tUADrjtIGo37dMzctfKHT9J1xZWxlbWVudElkZW50aWZpZXJ2dW5fZGlzdGluZ3Vpc2hpbmdfc2lnbmxlbGVtZW50VmFsdWVjVVNB";
const authz_response_parameters = {
presentation_submission,
vp_token
};
const mdoc_generated_nonce = "1234567890abcdefgh";
const authz_response_object_jwt = await generate_authz_response_object_jwt(
authz_response_parameters, mdoc_generated_nonce, nonce, ephemeral_public_key_reader);
const authz_response_jwt_header = JSON.parse(base64url.decode(authz_response_object_jwt.split('.')[0]));
const ephemeral_private_key_mdoc = {
// In node-jose:encrypt.js: line 196: in the debug console, do console.log(JSON.stringify(epk.toJSON(true, ["kid"]), null, 2))
};
const ephemeral_public_key_mdoc = authz_response_jwt_header.epk;
// -------
// OID4VPHandover and SessionTranscriopt using the following params:
// mdoc_generated_nonce = "1234567890abcdefgh"
// client_id = "example.com".
// response_uri = "https://example.com/12345/response"
// nonce = "abcdefgh1234567890"
const oid4vp_handover_hex = "835820DA25C527E5FB75BC2DD31267C02237C4462BA0C1BF37071F692E7DD93B10AD0B5820F6ED8E3220D3C59A5F17EB45F48AB70AEECF9EE21744B1014982350BD96AC0C572616263646566676831323334353637383930";
const session_transcript_hex = "83F6F6835820DA25C527E5FB75BC2DD31267C02237C4462BA0C1BF37071F692E7DD93B10AD0B5820F6ED8E3220D3C59A5F17EB45F48AB70AEECF9EE21744B1014982350BD96AC0C572616263646566676831323334353637383930";
// -------
console.log("----------------");
console.log("Annex B Examples");
console.log("----------------");
console.log("-------------------------");
console.log("Example: IACA Certificate");
console.log("-------------------------");
console.log(iaca_cert_pem);
console.log("-------------------------------");
console.log("Example: Static Wallet Metadata");
console.log("-------------------------------");
console.log(JSON.stringify(static_wallet_metadata, null, 2));
console.log("--------------------------------");
console.log("Example: Presentation Definition");
console.log("--------------------------------");
console.log(JSON.stringify(presentation_definition, null, 2));
console.log("-----------------------------------------");
console.log("Example: Ephemeral Private Reader Key JWK");
console.log("-----------------------------------------");
console.log(JSON.stringify(ephemeral_private_key_reader, null, 2));
console.log("----------------------------------------");
console.log("Example: Ephemeral Public Reader Key JWK");
console.log("----------------------------------------");
console.log(JSON.stringify(ephemeral_public_key_reader, null, 2));
console.log("------------------------------------------------");
console.log("Example: Authorization Request Object parameters");
console.log("------------------------------------------------");
console.log(JSON.stringify(authz_request_parameters, null, 2));
console.log("------------------------------------------------------");
console.log("Example: Authorization Request Object JWT (JAR) Header");
console.log("------------------------------------------------------");
console.log(JSON.stringify(authz_request_jwt_header, null, 2));
console.log("------------------------------------------------------------------------");
console.log("Example: Static Private Reader Key JWK corresponding to 'x5c' JWT Header");
console.log("------------------------------------------------------------------------");
console.log(JSON.stringify(static_private_key_reader_auth, null, 2));
console.log("----------------------------------------------------------");
console.log("Example: Authorization Request Object encoded as JWT (JAR)");
console.log("----------------------------------------------------------");
console.log(authz_request_object_jwt);
console.log("--------------------------------");
console.log("Example: Presentation Submission");
console.log("--------------------------------");
console.log(JSON.stringify(presentation_submission, null, 2));
console.log("-----------------");
console.log("Example: VP Token");
console.log("-----------------");
console.log(vp_token);
console.log("-------------------------------------------------");
console.log("Example: Authorization Response Object parameters");
console.log("-------------------------------------------------");
console.log(JSON.stringify(authz_response_parameters, null, 2));
console.log("-----------------------------------------------------------");
console.log("Example: Authorization Response Object encoded as JWT (JARM)");
console.log("-----------------------------------------------------------");
console.log(authz_response_object_jwt);
console.log("--------------------------------------------------------");
console.log("Example: Authorization Response Object JWT (JARM) Header");
console.log("--------------------------------------------------------");
console.log(JSON.stringify(authz_response_jwt_header, null, 2));
console.log("--------------------------------------");
console.log("Example: Ephemeral Public MDOC Key JWK");
console.log("--------------------------------------");
console.log(JSON.stringify(ephemeral_public_key_mdoc, null, 2));
console.log("--------------------------------------");
console.log("Example: Ephemeral Private MDOC Key JWK");
console.log("--------------------------------------");
console.log("In node-jose:encrypt.js: line 196: in the debug console, do console.log(JSON.stringify(epk.toJSON(true, [\"kid\"]), null, 2))");
console.log("-----------------------------------------------------------");
console.log("Example: OID4VPHandover CBOR Hex");
console.log("-----------------------------------------------------------");
console.log(oid4vp_handover_hex);
console.log("-----------------------------------------------------------");
console.log("Example: SessionTranscipt CBOR Hex");
console.log("-----------------------------------------------------------");
console.log(session_transcript_hex);
}
async function generate_authz_request_object_jwt(static_private_key_reader_auth, authz_request_jwt_header, authz_request_parameters) {
const key = await jose.JWK.asKey(static_private_key_reader_auth);
const jwt = await jose.JWS.createSign({ format: 'compact', fields: authz_request_jwt_header }, key).
update(JSON.stringify(authz_request_parameters)).
final();
return jwt;
}
async function generate_authz_response_object_jwt(
authz_response_parameters, mdoc_generated_nonce, nonce, ephemeral_public_key_reader) {
const encKey = await jose.JWK.asKey(ephemeral_public_key_reader);
const apu = base64url(mdoc_generated_nonce);
const apv = base64url(nonce);
const jwe = await jose.JWE.createEncrypt({
format: 'compact',
fields: {
alg: 'ECDH-ES',
enc: 'A256GCM',
apu: apu,
apv: apv,
kid: ephemeral_public_key_reader.kid
},
}, {
key: encKey,
}).update(JSON.stringify(authz_response_parameters)).final();
return jwe;
}
// async function decrypt_authz_response_jwt_headers(authz_response_object_jwt, ephemeral_private_key_reader) {
// const decKey = await jose.JWK.asKey(ephemeral_private_key_reader);
// const decrypted = await jose.JWE.createDecrypt(decKey).decrypt(authz_response_object_jwt);
// console.log('decrypted: ', JSON.parse(decrypted.payload.toString('utf8')));
// }
// async function extract() {
// const args = process.argv.slice(2);
// const key = fs.readFileSync(args[0]);
// const keystore = jose.JWK.createKeyStore();
// var DUMP_PRIVATE_KEY = ('true' == args[1]);
// keystore
// .add(key, 'pem')
// .then(function(_) {
// const jwks = keystore.toJSON(DUMP_PRIVATE_KEY);
// console.log(JSON.stringify(jwks, null, 4));
// });
// }
main()