-
Notifications
You must be signed in to change notification settings - Fork 25
/
demo.html
435 lines (405 loc) · 17.8 KB
/
demo.html
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HCERT Validation Demo</title>
<style>
textarea, button, input {
display: block;
}
</style>
<script src="build/distributions/hcert-kotlin.js"></script>
<script>
var debug = false;
var verifier;
var dateString=null;
document.onload = function () {
let tQR = document.getElementById("tQR");
let tCert = document.getElementById("tCert");
let atTCert = document.getElementById("atTCert");
let tGenCert = document.getElementById("tGenCert");
let tGenKey = document.getElementById("tGenKey");
let tRes = document.getElementById("tRes");
let tGenRes = document.getElementById("tGenRes");
let tValid = document.getElementById("tValid");
let tError = document.getElementById("tError");
let tMeta = document.getElementById("tMeta");
let tEgc = document.getElementById("tEgc");
tRes.value = "";
tGenRes.value = "";
tValid.value = "";
tError.value = "";
tMeta.value = "";
tEgc.value = "";
}
function generateRandom() {
let input = tGenInput.value.trim();
tGenRes.value = "Generating ...";
let generator = new hcert.GeneratorEcRandom(256);
let result = generator.encode(input);
console.info(result);
tGenRes.value = result.step5Prefixed;
document.getElementById("tGenQr").src = generator.encodeToQrCode(input, 4, 2);
}
function generateFixed() {
let input = tGenInput.value.trim();
let key = tGenKey.value.trim();
let cert = tGenCert.value.trim();
tGenRes.value = "Generating ...";
let generator = new hcert.GeneratorFixed(key, cert);
let result = generator.encode(input);
console.info(result);
tGenRes.value = result.step5Prefixed;
document.getElementById("tGenQr").src = generator.encodeToQrCode(input, 4, 2);
}
function validate(showDataClass) {
let qr = tQR.value.trim();
let pemCert = tCert.value.trim();
let atPemCert = atTCert.value.trim();
tRes.value = "Verifying ...";
verifier = new hcert.VerifierDirect([pemCert], [atPemCert], dateString, debug);
let result = callVerifier(showDataClass, qr);
console.info(result);
tRes.value = JSON.stringify(result, null, 2);
tValid.value = JSON.stringify(result.isValid, null, 2);
tError.value = JSON.stringify(result.error, null, 2);
tMeta.value = JSON.stringify(result.metaInformation, null, 2);
tEgc.value = JSON.stringify(result.greenCertificate, null, 2);
return result
}
function downloadBinary(requestUrl, callback) {
console.log("Downloading " + requestUrl + " ...")
var xhr = new XMLHttpRequest();
xhr.open("GET", requestUrl);
xhr.responseType = "arraybuffer";
xhr.onload = function () {
if (this.status === 200) {
callback(xhr.response);
} else {
console.warn(this);
}
};
xhr.send();
}
function validateTrustList(showDataClass) {
let qr = tQR.value.trim();
let pemCert = tTrustListRoot.value.trim();
tRes.value = "Verifying ...";
let contentUrl = document.getElementById("tTrustListContentUrl").value.trim();
let signatureUrl = document.getElementById("tTrustListSignatureUrl").value.trim();
downloadBinary(contentUrl, function (resultContent) {
downloadBinary(signatureUrl, function (resultSignature) {
try {
verifier = new hcert.VerifierTrustList(pemCert, resultContent, resultSignature, debug);
let result = callVerifier(showDataClass, qr);
console.info(result);
tRes.value = JSON.stringify(result, null, 2);
tValid.value = JSON.stringify(result.isValid, null, 2);
tError.value = JSON.stringify(result.error, null, 2);
tMeta.value = JSON.stringify(result.metaInformation, null, 2);
tEgc.value = JSON.stringify(result.greenCertificate, null, 2);
} catch (error) {
tRes.value = error.name + ": " + JSON.stringify(error, null, 2);
}
})
});
}
function updateTrustList() {
let pemCert = tTrustListRoot.value.trim();
tRes.value = "Updating TrustList ...";
let contentUrl = document.getElementById("tTrustListContentUrl").value.trim();
let signatureUrl = document.getElementById("tTrustListSignatureUrl").value.trim();
downloadBinary(contentUrl, function (resultContent) {
downloadBinary(signatureUrl, function (resultSignature) {
try {
verifier.updateTrustList(pemCert, resultContent, resultSignature, document.getElementById("tlAT").checked);
tRes.value = "Updated TrustList!";
} catch (error) {
tRes.value = error.name + ": " + JSON.stringify(error, null, 2);
}
})
});
}
function callVerifier(showDataClass, qr) {
if (showDataClass)
return verifier.verifyDataClass(qr);
else
return verifier.verify(qr);
}
function loadTrustList() {
let pemCert = document.getElementById("tSignedDataRoot").value.trim();
document.getElementById("tSignedData").value = "Loading ...";
let contentUrl = document.getElementById("tTrustListBinUrl").value.trim();
let signatureUrl = document.getElementById("tTrustListSigUrl").value.trim();
downloadBinary(contentUrl, function (resultContent) {
downloadBinary(signatureUrl, function (resultSignature) {
try {
let result = hcert.SignedDataDownloader.loadTrustList(pemCert, resultContent, resultSignature);
console.info(result);
document.getElementById("tSignedData").value = JSON.stringify(result.first, ["validFrom", "validUntil"], 2);
} catch (error) {
console.error(error);
document.getElementById("tSignedData").value = error.name + ": " + JSON.stringify(error, null, 2);
}
})
});
}
function loadBusinessRules() {
let pemCert = document.getElementById("tSignedDataRoot").value.trim();
document.getElementById("tSignedData").value = "Loading ...";
let contentUrl = document.getElementById("tBusinessRulesBinUrl").value.trim();
let signatureUrl = document.getElementById("tBusinessRulesSigUrl").value.trim();
downloadBinary(contentUrl, function (resultContent) {
downloadBinary(signatureUrl, function (resultSignature) {
try {
let result = hcert.SignedDataDownloader.loadBusinessRules(pemCert, resultContent, resultSignature);
console.info(result);
document.getElementById("tSignedData").value = JSON.stringify(result.first, ["validFrom", "validUntil"], 2);
} catch (error) {
console.error(error);
document.getElementById("tSignedData").value = error.name + ": " + JSON.stringify(error, null, 2);
}
})
});
}
function loadValueSets() {
let pemCert = document.getElementById("tSignedDataRoot").value.trim();
document.getElementById("tSignedData").value = "Loading ...";
let contentUrl = document.getElementById("tValueSetsBinUrl").value.trim();
let signatureUrl = document.getElementById("tValueSetsSigUrl").value.trim();
downloadBinary(contentUrl, function (resultContent) {
downloadBinary(signatureUrl, function (resultSignature) {
try {
let result = hcert.SignedDataDownloader.loadValueSets(pemCert, resultContent, resultSignature);
console.info(result);
document.getElementById("tSignedData").value = JSON.stringify(result.first, ["validFrom", "validUntil"], 2);
} catch (error) {
console.error(error);
document.getElementById("tSignedData").value = error.name + ": " + JSON.stringify(error, null, 2);
}
})
});
}
</script>
</head>
<body>
<h1>Verification</h1>
<h2>Input</h2>
<p>
<label for="tQR">QR Code Contents</label>
<textarea rows="10" cols="100" id="tQR">HC1:NCFTW2H:7*I06R3W/J:O6:P4QB3+7RKFVJWV66UBCE//UXDT:*ML-4D.NBXR+SRHMNIY6EB8I595+6UY9-+0DPIO6C5%0SBHN-OWKCJ6BLC2M.M/NPKZ4F3WNHEIE6IO26LB8:F4:JVUGVY8*EKCLQ..QCSTS+F$:0PON:.MND4Z0I9:GU.LBJQ7/2IJPR:PAJFO80NN0TRO1IB:44:N2336-:KC6M*2N*41C42CA5KCD555O/A46F6ST1JJ9D0:.MMLH2/G9A7ZX4DCL*010LGDFI$MUD82QXSVH6R.CLIL:T4Q3129HXB8WZI8RASDE1LL9:9NQDC/O3X3G+A:2U5VP:IE+EMG40R53CG9J3JE1KB KJA5*$4GW54%LJBIWKE*HBX+4MNEIAD$3NR E228Z9SS4E R3HUMH3J%-B6DRO3T7GJBU6O URY858P0TR8MDJ$6VL8+7B5$G CIKIPS2CPVDK%K6+N0GUG+TG+RB5JGOU55HXDR.TL-N75Y0NHQTZ3XNQMTF/ZHYBQ$8IR9MIQHOSV%9K5-7%ZQ/.15I0*-J8AVD0N0/0USH.3</textarea>
</p>
<h3>Direct Verifier</h3>
<p>
<label for="tCert">PEM-encoded DSC</label>
<textarea rows="10" cols="100" id="tCert">
-----BEGIN CERTIFICATE-----
MIIBvTCCAWOgAwIBAgIKAXk8i88OleLsuTAKBggqhkjOPQQDAjA2MRYwFAYDVQQD
DA1BVCBER0MgQ1NDQSAxMQswCQYDVQQGEwJBVDEPMA0GA1UECgwGQk1TR1BLMB4X
DTIxMDUwNTEyNDEwNloXDTIzMDUwNTEyNDEwNlowPTERMA8GA1UEAwwIQVQgRFND
IDExCzAJBgNVBAYTAkFUMQ8wDQYDVQQKDAZCTVNHUEsxCjAIBgNVBAUTATEwWTAT
BgcqhkjOPQIBBggqhkjOPQMBBwNCAASt1Vz1rRuW1HqObUE9MDe7RzIk1gq4XW5G
TyHuHTj5cFEn2Rge37+hINfCZZcozpwQKdyaporPUP1TE7UWl0F3o1IwUDAOBgNV
HQ8BAf8EBAMCB4AwHQYDVR0OBBYEFO49y1ISb6cvXshLcp8UUp9VoGLQMB8GA1Ud
IwQYMBaAFP7JKEOflGEvef2iMdtopsetwGGeMAoGCCqGSM49BAMCA0gAMEUCIQDG
2opotWG8tJXN84ZZqT6wUBz9KF8D+z9NukYvnUEQ3QIgdBLFSTSiDt0UJaDF6St2
bkUQuVHW6fQbONd731/M4nc=
-----END CERTIFICATE-----
</textarea>
<label for="atTCert">AT PEM-encoded DSC</label>
<textarea rows="10" cols="100" id="atTCert">
-----BEGIN CERTIFICATE-----
MIIBvTCCAWOgAwIBAgIKAXk8i88OleLsuTAKBggqhkjOPQQDAjA2MRYwFAYDVQQD
DA1BVCBER0MgQ1NDQSAxMQswCQYDVQQGEwJBVDEPMA0GA1UECgwGQk1TR1BLMB4X
DTIxMDUwNTEyNDEwNloXDTIzMDUwNTEyNDEwNlowPTERMA8GA1UEAwwIQVQgRFND
IDExCzAJBgNVBAYTAkFUMQ8wDQYDVQQKDAZCTVNHUEsxCjAIBgNVBAUTATEwWTAT
BgcqhkjOPQIBBggqhkjOPQMBBwNCAASt1Vz1rRuW1HqObUE9MDe7RzIk1gq4XW5G
TyHuHTj5cFEn2Rge37+hINfCZZcozpwQKdyaporPUP1TE7UWl0F3o1IwUDAOBgNV
HQ8BAf8EBAMCB4AwHQYDVR0OBBYEFO49y1ISb6cvXshLcp8UUp9VoGLQMB8GA1Ud
IwQYMBaAFP7JKEOflGEvef2iMdtopsetwGGeMAoGCCqGSM49BAMCA0gAMEUCIQDG
2opotWG8tJXN84ZZqT6wUBz9KF8D+z9NukYvnUEQ3QIgdBLFSTSiDt0UJaDF6St2
bkUQuVHW6fQbONd731/M4nc=
-----END CERTIFICATE-----
</textarea>
</p>
<p>
<button onClick="validate(false)">Validate</button>
</p>
<p>
<button onClick="validate(true)">Validate, show Data Class</button>
</p>
<h3>TrustList Verifier</h3>
<p>
<label for="tTrustListRoot">PEM-encoded Root of TrustList</label>
<textarea rows="10" cols="100" id="tTrustListRoot">
-----BEGIN CERTIFICATE-----
MIIBJTCBy6ADAgECAgUAwvEVkzAKBggqhkjOPQQDAjAQMQ4wDAYDVQQDDAVFQy1N
ZTAeFw0yMTA0MjMxMTI3NDhaFw0yMTA1MjMxMTI3NDhaMBAxDjAMBgNVBAMMBUVD
LU1lMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/OV5UfYrtE140ztF9jOgnux1
oyNO8Bss4377E/kDhp9EzFZdsgaztfT+wvA29b7rSb2EsHJrr8aQdn3/1ynte6MS
MBAwDgYDVR0PAQH/BAQDAgWgMAoGCCqGSM49BAMCA0kAMEYCIQC51XwstjIBH10S
N701EnxWGK3gIgPaUgBN+ljZAs76zQIhAODq4TJ2qAPpFc1FIUOvvlycGJ6QVxNX
EkhRcgdlVfUb
-----END CERTIFICATE-----
</textarea>
</p>
<p>
<label for="tTrustListContentUrl">URL of TrustList Content File</label>
<textarea rows="1" cols="100" id="tTrustListContentUrl">https://dgc.a-sit.at/ehn/cert/listv2</textarea>
</p>
<p>
<label for="tTrustListSignatureUrl">URL of TrustList Signature File</label>
<textarea rows="1" cols="100" id="tTrustListSignatureUrl">https://dgc.a-sit.at/ehn/cert/sigv2</textarea>
</p>
<p>
<button onClick="validateTrustList(false)">Validate with TrustList</button>
</p>
<p>
<button onClick="validateTrustList(true)">Validate with TrustList, show Data Class</button>
</p>
<p>
<button style="display: inline" onClick="updateTrustList()">Update TrustList</button>
<label style="display:inline-block; white-space: nowrap" for="tlAT">AT-Specific Trustlist</label> <input
style="display: inline" type="checkbox" id="tlAT" name="tlAT">
</p>
<h2>Result</h2>
<p>
<label for="tRes">Overall Structure</label><textarea rows="50" cols="100" id="tRes" disabled></textarea>
</p>
<p>
<label for="tValid">IsValid</label><textarea rows="2" cols="100" id="tValid" disabled></textarea>
</p>
<p>
<label for="tError">Error</label><textarea rows="2" cols="100" id="tError" disabled></textarea>
</p>
<p>
<label for="tMeta">Meta Information</label><textarea rows="20" cols="100" id="tMeta" disabled></textarea>
</p>
<p>
<label for="tEgc">Green Certificate</label><textarea rows="30" cols="100" id="tEgc" disabled></textarea>
</p>
<h1>Generation</h1>
<h2>Input</h2>
<p>
<label for="tGenInput">Digital Covid Certificate</label><textarea rows="30" cols="100" id="tGenInput">
{
"ver": "1.2.1",
"nam": {
"fn": "Musterfrau-G\u00f6\u00dfinger",
"gn": "Gabriele",
"fnt": "MUSTERFRAU<GOESSINGER",
"gnt": "GABRIELE"
},
"dob": "1998-02-26",
"t": [
{
"tg": "840539006",
"tt": "LP6464-4",
"nm": "Roche LightCycler qPCR",
"sc": "2021-02-20T12:34:56+00:00",
"tr": "260415000",
"tc": "Testing center Vienna 1",
"co": "AT",
"is": "Ministry of Health, Austria",
"ci": "URN:UVCI:01:AT:B5921A35D6A0D696421B3E2462178297#I"
}
]
}
</textarea>
</p>
<h3>Random Generator</h3>
<p>
<button onClick="generateRandom()">Generate with Random EC Key</button>
</p>
<h3>Fixed Generator</h3>
<p>
<label for="tGenKey">PEM-encoded Private Key</label>
<textarea rows="5" cols="100" id="tGenKey">
-----BEGIN PRIVATE KEY-----
ME0CAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEMzAxAgEBBCCOpgFH1YNIU9vzJWH0
DkR7lDM2LZWvzlfsTi3t5yjXA6AKBggqhkjOPQMBBw==
-----END PRIVATE KEY-----</textarea>
</p>
<p>
<label for="tGenCert">PEM-encoded Certificate</label>
<textarea rows="12" cols="100" id="tGenCert">
-----BEGIN CERTIFICATE-----
MIIBWTCCAQCgAwIBAgIFAI2jlhowCgYIKoZIzj0EAwIwEDEOMAwGA1UEAwwFRUMt
TWUwHhcNMjEwNTMxMTUzNzExWhcNMjEwNjMwMTUzNzExWjAQMQ4wDAYDVQQDDAVF
Qy1NZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABH1hRvgNXdbX5RVHXyuKIjn0
BNYRsK3cySMWV+m1BZ9nlhDqMXTFibjBFOVLDYKoL3bZNEfCKw9sn6cdhE4nuu+j
RzBFMA4GA1UdDwEB/wQEAwIFoDAzBgNVHSUELDAqBgwrBgEEAQCON49lAQEGDCsG
AQQBAI43j2UBAgYMKwYBBAEAjjePZQEDMAoGCCqGSM49BAMCA0cAMEQCIBrfOypj
4mKnqQJfmeRnASBqMWIq7M8vGE0U0wRHv3o7AiBoD69F7gzdMgZ31uzTFpxdkKoS
zT4F0Pw48h7dfUeW6A==
-----END CERTIFICATE-----</textarea>
</p>
<p>
<button onClick="generateFixed()">Generate with Fixed Key</button>
</p>
<h2>Result</h2>
<p>
<label for="tGenRes">QR Code Contents</label><textarea rows="10" cols="100" id="tGenRes" disabled></textarea>
</p>
<p>
QR Code Picture:
</p>
<p>
<img id="tGenQr"/>
</p>
<h1>SignedData Download</h1>
<h2>Input</h2>
<p>
<label for="tSignedDataRoot">PEM-encoded Root of SignedData</label>
<textarea rows="10" cols="100" id="tSignedDataRoot">
-----BEGIN CERTIFICATE-----
MIIBJTCBy6ADAgECAgUAwvEVkzAKBggqhkjOPQQDAjAQMQ4wDAYDVQQDDAVFQy1N
ZTAeFw0yMTA0MjMxMTI3NDhaFw0yMTA1MjMxMTI3NDhaMBAxDjAMBgNVBAMMBUVD
LU1lMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/OV5UfYrtE140ztF9jOgnux1
oyNO8Bss4377E/kDhp9EzFZdsgaztfT+wvA29b7rSb2EsHJrr8aQdn3/1ynte6MS
MBAwDgYDVR0PAQH/BAQDAgWgMAoGCCqGSM49BAMCA0kAMEYCIQC51XwstjIBH10S
N701EnxWGK3gIgPaUgBN+ljZAs76zQIhAODq4TJ2qAPpFc1FIUOvvlycGJ6QVxNX
EkhRcgdlVfUb
-----END CERTIFICATE-----
</textarea>
</p>
<p>
<label for="tTrustListBinUrl">URL of TrustList Content File</label>
<textarea rows="1" cols="100" id="tTrustListBinUrl">https://dgc.a-sit.at/ehn/cert/listv2</textarea>
</p>
<p>
<label for="tTrustListSigUrl">URL of TrustList Signature File</label>
<textarea rows="1" cols="100" id="tTrustListSigUrl">https://dgc.a-sit.at/ehn/cert/sigv2</textarea>
</p>
<p>
<button onClick="loadTrustList()">Load TrustList</button>
</p>
<p>
<label for="tBusinessRulesBinUrl">URL of BusinessRules Content File</label>
<textarea rows="1" cols="100" id="tBusinessRulesBinUrl">https://dgc.a-sit.at/ehn/rules/v1/bin</textarea>
</p>
<p>
<label for="tBusinessRulesSigUrl">URL of BusinessRules Signature File</label>
<textarea rows="1" cols="100" id="tBusinessRulesSigUrl">https://dgc.a-sit.at/ehn/rules/v1/sig</textarea>
</p>
<p>
<button onClick="loadBusinessRules()">Load BusinessRules</button>
</p>
<p>
<label for="tValueSetsBinUrl">URL of ValueSets Content File</label>
<textarea rows="1" cols="100" id="tValueSetsBinUrl">https://dgc.a-sit.at/ehn/values/v1/bin</textarea>
</p>
<p>
<label for="tValueSetsSigUrl">URL of ValueSets Signature File</label>
<textarea rows="1" cols="100" id="tValueSetsSigUrl">https://dgc.a-sit.at/ehn/values/v1/sig</textarea>
</p>
<p>
<button onClick="loadValueSets()">Load ValueSets</button>
</p>
<h2>Result</h2>
<p>
<label for="tSignedData">Meta Information</label><textarea rows="5" cols="100" id="tSignedData" disabled></textarea>
</p>
<p>See Console for more output</p>
</body>
</html>