-
Notifications
You must be signed in to change notification settings - Fork 8
/
index_trust.html
305 lines (262 loc) · 12.1 KB
/
index_trust.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
<!doctype html>
<html lang="en" data-fr-scheme="light">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="static/dsfr.min.css">
<meta name="theme-color" content="#000091">
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
</style>
<title>Trusted third party</title>
</head>
<body>
<div class="fr-container" role="main">
<h1 style="text-align: center;background-color: yellow;">Trusted third party website</h1>
<div class="fr-highlight" style="margin-bottom: 2.5rem;">
<p> This page simulates one or many trusted third parties that can be used to verify the actual age of
users.</p>
</div>
<h2>Ask for the signature of a challenge</h2>
<p>
Select a user which is already registered on the platform and a trusted third party. The signature can only
occured if the selected user has the required age.
</p>
<form onsubmit="upload_and_sign(); return false;">
<p style="max-width: 400px;">
<label class="fr-label" for="trustedId">Select a trusted party identification number</label>
<select class="fr-input" type="number" id="trustedId" required>
</select>
</p>
<p style="max-width: 400px;">
<label class="fr-label" for="IndividualSignId">Select a registered user</label>
<select class="fr-input" id="IndividualSignId" required>
</select>
</p>
<div class="fr-upload-group">
<p>
<label class="fr-label" for="fileUploaded">Select JSON challenge provided by the website</label>
<input class="fr-upload" type="file" id="fileUploaded" accept=".json" required>
</p>
</div>
<p>
<input class="fr-btn" type="submit" value="Sign the challenge" />
</p>
</form>
<h2>Register users</h2>
<div class="fr-highlight" style="margin-bottom: 2.5rem;">
<p>This section allows to simulate users registered in trusted third parties.</p>
</div>
<form onsubmit="registerAge(); return false;">
<p style="max-width: 400px;">
<label class="fr-label" for="IndividualId">Name of the user</label>
<input class="fr-input" id="IndividualId" value="Eve" required />
<span class="fr-hint-text">
This name will be used to check the age. It will erase previously registered users
if the same name is used twice.
</span>
</p>
<p style="max-width: 400px;">
<label class="fr-label" for="AgeId">Age of the user</label>
<input class="fr-input" type="number" id="AgeId" required />
</p>
<p>
<input class="fr-btn" type="submit" value="Register this user" />
</form>
<h2>List of existing users</h2>
<div class="fr-highlight" style="margin-bottom: 2.5rem;">
<p>This section list all users that are registered on the platforms.</p>
</div>
<table id="user_list"
style="font-family: arial, sans-serif;border-collapse: collapse;width: 20%;border: 1px solid black;">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</table>
<div class="fr-highlight" style="margin-bottom: 2.5rem;">
<p>Please note that users are currently registered on all trusted third party (which should not be the case
in real-life scenarios), and that registration is currently very basic and declarative.</p>
</div>
<h2>List of existing trusted third parties</h2>
<div class="fr-highlight" style="margin-bottom: 2.5rem;">
<p>This section list all third parties that has been registered.New trusted third parties can be created
from the <a href="" id="authority_link"> certification authority website</a>.</p>
</div>
<table id="thirdparty_list"
style="font-family: arial, sans-serif;border-collapse: collapse;width: 20%;border: 1px solid black;">
<tr>
<th>id</th>
</tr>
</table>
<br>
<input class="fr-btn" type="button" value="Refresh list" onclick="refresh_values()" />
</div>
<!-- Script en version es6 module et nomodule pour les navigateurs le ne supportant pas -->
<script type="module" src="static/dsfr.module.min.js"></script>
<script type="text/javascript" nomodule src="static/dsfr.nomodule.min.js"></script>
<script type="text/javascript">
// Port and hosts of the sites
var authority_url = "{{urls['authority']['url']}}";
var age_verifier_url = "{{urls['trust']['url']}}";
authority_link = document.getElementById("authority_link");
authority_link.setAttribute("href", authority_url);
function refresh_values() {
function removeOptions(selectElement) {
var i, L = selectElement.options.length - 1;
for (i = L; i >= 0; i--) {
selectElement.remove(i);
}
}
function removeRows(tableElement) {
var i, L = tableElement.rows.length - 1;
for (i = L; i >= 1; i--) {
tableElement.deleteRow(-1);
}
}
fetch(authority_url + "number_certificates")
.then((response) => response.json())
.then((number_certificates) => {
let trustedId = document.getElementById("trustedId");
let thirdparty_list = document.getElementById("thirdparty_list");
removeOptions(trustedId);
removeRows(thirdparty_list);
for (let i = 1; i < number_certificates.number+1; i++) {
let option = document.createElement("option");
option.value = i;
option.text = i;
trustedId.add(option);
let newRow = thirdparty_list.insertRow(-1);
let newCellid = newRow.insertCell(0);
let newTextCelldid = document.createTextNode(i);
newCellid.appendChild(newTextCelldid);
}
}
);
fetch(age_verifier_url + "list_users")
.then((response) => response.json())
.then((number_users) => {
let IndividualSignId = document.getElementById("IndividualSignId");
let user_list = document.getElementById("user_list");
removeOptions(IndividualSignId);
removeRows(user_list);
for (const [key, value] of Object.entries(number_users)) {
let option = document.createElement("option");
option.value = key;
option.text = key + " (" + value+ " years old)";
IndividualSignId.add(option);
let newRow = user_list.insertRow(-1);
let newCellid = newRow.insertCell(0);
let newTextCelldid = document.createTextNode(key);
let newCellage = newRow.insertCell(1);
let newTextCelldage = document.createTextNode(value);
newCellid.appendChild(newTextCelldid);
newCellage.appendChild(newTextCelldage);
}
}
);
}
refresh_values();
function sign(data, trusted, id) {
fetch(age_verifier_url + "sign?trusted=" + trusted + "&id=" + id, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data_from_trust) => {
if (data_from_trust.majeur && data_from_trust.user) {
var dataStr =
"data:text/json;charset=utf-8," +
encodeURIComponent(JSON.stringify(data_from_trust));
var downloadAnchorNode = document.createElement("a");
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", "signature" + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
} else {
if (data_from_trust.user) {
alert("User does not match the required age");
} else {
alert("User doesn't exist");
}
}
});
}
// retrieves the crypto parameters
function get_params() {
console.log("Retrieving crypto parameters");
return fetch(authority_url + "crypto_parameters").then(
(response) => response.json()
);
}
// Retrieves the number of parties
function count_parties() {
console.log("Counting the trusted parties");
return fetch(authority_url + "number_certificates").then(
(response) => response.json()
);
}
// checks the existence of a given trusted party
function checkingExistence(trusted) {
console.log("Checking existence of the trusted party");
return count_parties().then(
(number_certificates) =>
trusted < number_certificates.number + 1 &&
trusted > 0 &&
Number.isInteger(trusted)
);
}
function upload_and_sign() {
let id = document.getElementById("IndividualSignId").value;
let file = document.getElementById("fileUploaded").files[0];
let trusted = parseInt(document.getElementById("trustedId").value);
if (file) {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) {
challenge = JSON.parse(evt.target.result);
checkingExistence(trusted).then((exists) => {
if (exists) {
get_params().then((crypto_params) =>
sign(Object.assign(challenge, crypto_params), trusted, id)
);
} else {
console.log("This trusted party doesn't exist.");
}
});
};
reader.onerror = function (evt) {
console.log("Error reading file");
};
} else {
console.log("No file selected");
}
}
function registerAge(number_certificates) {
let registered_age = document.getElementById("AgeId").valueAsNumber;
let id = document.getElementById("IndividualId").value;
fetch(age_verifier_url +
"registerAge?registered_age=" +
registered_age +
"&id=" +
id,
{ method: "POST" }
);
document.getElementById("AgeId").value = "";
document.getElementById("IndividualId").value = "";
alert(`Registration done: age=${registered_age}, id=${id}.`);
refresh_values();
}
</script>
</body>
</html>