-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagtreq.html
293 lines (280 loc) · 16.6 KB
/
agtreq.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
<!DOCTYPE html>
<html>
<head>
<title>VISS Web Client - AGT Request</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="images/favicon.ico">
<link rel="stylesheet" href="styles/menu.css" type="text/css">
<link rel="stylesheet" href="styles/general.css" type="text/css">
<script src="scripts/js/logger.js"></script>
<script src="scripts/js/clientcrypto.js"></script>
<script src = "scripts/js/encoding.js"></script>
<script src = "scripts/js/clientscripts.js"></script>
<script src = "scripts/js/tokenhandler.js"></script>
</head>
<body>
<script src = "scripts/js/menu.js"></script>
<h2>Access Grant Token Client</h2><br>
<div class = "mid_div">
<div id = left_col class = "mid_col">
<div id = gt_opts class="vert_select_list">
<p class="subject">Grant Token Request</p>
<div class = "row">
<div class = "column">
<label for="vin">Vehicle Number</label>
<br><input id="vin" type="text" placeholder="GEO001"/>
<br><label for="proof">Proof:</label>
<br><input id="proof" type="text" value = "ABC" placeholder="ABC (not yet implemented)"/>
<br><label for="sign_type" name>Signature Type</label>
<br><select id = "sign_type" name = "sign_type">
<option value = "None">None</option>
<option value = "RS256">RS256</option>
<option value = "ES256">ES256</option>
</select>
</div>
<div class = "column">
<label for="user_role">User Role</label>
<br><select id = "user_role" name = "user_role">
<option value = "Dealer">Dealer</option>
<option value = "OEM">OEM</option>
<option value = "Independent">Independent</option>
<option value = "Owner">Owner</option>
<option value = "Driver">Driver</option>
<option value = "Passenger">Passenger</option>
</select>
<br> <label for="app_role">App Role</label>
<br><select id="app_role" name = "app_role">
<option value = "OEM">OEM</option>
<option value = "Third party">Third Party</option>
</select>
<br><label for="dev_role">Device Role</label>
<br><select id="dev_role" name = "dev_role">
<option value = "Vehicle">Vehicle</option>
<option value = "Nomadic">Nomadic</option>
<option value = "Cloud">Cloud</option>
</select>
</div>
<div class="column">
<div id = pop_opts style="display:none">
<label for="pop_jti">JTI</label>
<br><input id = "pop_jti" type = "text" value = "auto" placeholder = "default: auto">
<br><label for="pop_aud">AUD</label>
<br><input id = "pop_aud" type = "text" value = "vissv2/agts" placeholder = "default: vissv2/agts">
<br><label for = "pop_iat">IAT</label>
<br><input id = "pop_iat" type = "text" value = "auto" placeholder = "auto, +1, -1, 123">
<br><label for = "jwk_thumb" style="display:none;"><b>Public Key</b></label>
<br><output id = "jwk_thumb" type = "text" style="display: none;"></output>
</div>
</div>
</div>
</div>
<div class="horiz_click_list">
<br><button onclick="sendAgtReq()" class="arrow_button"><span>Send</span></button>
<input type="checkbox" id="log_switch" checked>
<span>Logs</span>
</div>
<div class="data_box" id="logs">
<p class="subject">Logs<br></p>
<p id="log_data" class="data"></p>
<button onclick="logReset()">Reset</button>
</div>
</div>
<div id = "right_col" class = "mid_col">
<button onclick="togPrettyRaw()" class="gen_button" style="margin-left: 30px;">TOGGLE</button>
<button onclick="saveAgToken()" class="gen_button">SAVE TOKEN</button>
<input id = "tokenID" class="gen_input" placeholder="Token ID">
<p id ="saveStatus" style="margin-left: 30px;"></p>
<div id = "raw" style="display: block;">
<div class="data_box_bordered">
<p class="subject">Request</p>
<p id="Req" class="data"></p>
</div>
<div class="data_box_bordered">
<p class="subject">Response</p>
<p id = "Resp" class="data"></p>
</div>
<div class="data_box_bordered">
<p class="subject">POP<br></p>
<p id="Pop" class="data"></p>
</div>
</div>
<div id = "pretty" style="display: none;">
<div class="data_box_bordered">
<p class="subject">Request</p>
<pre id="ReqPretty" class="data"></pre>
</div>
<div class="data_box_bordered">
<p class="subject" id = "RespTypPretty">Response</p>
<div id = "RespOK" style="display:block;">
<h5>Header</h5>
<pre id = "RespPretty_head" class = "data"></pre>
<h5>Payload</h5>
<pre id = "RespPretty_payl" class="data"></pre>
</div>
<div id = "RespFail" style="display:none;">
<p class="data" id="RespErr"></p>
</div>
</div>
<div class="data_box_bordered">
<p class="subject">POP<br></p>
<h5>Header</h5>
<pre id="PopPretty_head" class="data"></pre>
<h5>Payload</h5>
<pre id="PopPretty_payl" class="data"></pre>
</div>
</div>
</div>
</div>
<!-- Script for style changes and logs-->
<script src = "scripts/js/logger.js"></script>
<script src = "scripts/js/encoding.js"></script>
<script>
document.getElementById("sign_type").addEventListener("change", showPopOpts)
function showPopOpts() {
if (document.getElementById("sign_type").value == "" || document.getElementById("sign_type").value == "None"){
document.getElementById("pop_opts").style.display = "none"
} else{
document.getElementById("pop_opts").style.display = "block"
}
}
function togPrettyRaw(){
if (document.getElementById("raw").style.display == "none"){
document.getElementById("raw").style.display = "block"
document.getElementById("pretty").style.display = "none"
} else{
document.getElementById("raw").style.display = "none"
document.getElementById("pretty").style.display = "block"
}
}
</script>
<!-- Request maker-->
<script>
var receivedToken; // Stores the token received
//var Req = document.getElementById("Req");
var Pop = document.getElementById("Pop");
var Resp = document.getElementById("Resp");
var RespTypPretty = document.getElementById("RespTypPretty");
var RespPretty_head = document.getElementById("RespPretty_head");
var RespPretty_payl = document.getElementById("RespPretty_payl");
var key_thumb;
function genAgtReq() {
let req;
req = jsonRecursiveEncoding("vin", document.getElementById("vin").value, "");
req = jsonRecursiveEncoding("context",document.getElementById("user_role").value + "+"
+ document.getElementById("app_role").value + "+" + document.getElementById("dev_role").value, req);
req = jsonRecursiveEncoding("proof", document.getElementById("proof").value, req);
return req;
}
//Generates the URL for the AGT
const AgtUrl = (urlMap.tls ? "https://": "http://") + urlMap.AgtIp + ":" + urlMap.AgtPort + "/agts";
async function sendAgtReq(){
try {
//async function sendAgtReq(){
RespTypPretty.innerHTML = "Response";
RespPretty_head.innerHTML = "";
RespPretty_payl.innerHTML = "";
Resp.innerHTML = "";
// XML Request
let xhttpreq = new XMLHttpRequest();
xhttpreq.onreadystatechange = function(){ // State Change method
if(this.readyState == 4){
if (this.status != 200){
logStatus("Error", "HTTP Request status: "+this.status+",data: "+this.statusText + ". Response: " + this.responseText);
let response = this.responseText;
Resp.innerHTML = response;
document.getElementById("RespErr").innerHTML = response;
document.getElementById("RespOK").style.display = "none";
document.getElementById("RespFail").style.display = "block";
document.getElementById("RespTypPretty").innerHTML = "Response: Error "+this.status;
Resp.innerHTML = response
} else{
if (this.responseText.length > 55){
logStatus("Info", "HTTP Response received: "+this.responseText.slice(0, 55)+ "...");
} else{
logStatus("Info", "HTTP Response received: "+this.responseText);
}
let response = this.responseText;
let json_resp = JSON.parse(response);
if (json_resp.error !== undefined){ // Error
Resp.innerHTML = response;
document.getElementById("RespErr").innerHTML = json_resp.error;
document.getElementById("RespOK").style.display = "none";
document.getElementById("RespFail").style.display = "block";
document.getElementById("RespTypPretty").innerHTML = "Response: error";
} else if (json_resp.token !== undefined){
Resp.innerHTML = response;
receivedToken = json_resp.token;
document.getElementById("saveStatus").innerHTML = "";
let agTk = jwtPretty(json_resp.token);
document.getElementById("RespPretty_head").innerHTML = agTk[0]
document.getElementById("RespPretty_payl").innerHTML = agTk[1]
document.getElementById("RespOK").style.display = "block";
document.getElementById("RespFail").style.display = "none";
document.getElementById("RespTypPretty").innerHTML = "Response: token";
} else {
Resp.innerHTML = response;
}
}
}
}
xhttpreq.open("POST", AgtUrl, true);
//xhttpreq.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
let req = genAgtReq();
logStatus("Info", "Request Body Generated")
// If a signing algorithm is selected, a POP must be generated
if ((document.getElementById("sign_type").value == "RS256")
|| ((document.getElementById("sign_type").value == "ES256"))){
logStatus("Info", "Generating POP");
if ((document.getElementById("sign_type").value == "RS256") && (! await checkKeyAsync("RSA"))){
window.alert("RSA Key Not Avaliable");
return;
}
if ((document.getElementById("sign_type").value == "ES256") && (! await checkKeyAsync("ECDSA"))){
window.alert("ECDSA Key Not Avaliable");
return;
}
let pop = await generatePop();
if (pop != ""){
xhttpreq.setRequestHeader("PoP", pop);
req = jsonRecursiveEncoding("key", await getPublicThumbprint(document.getElementById("sign_type").value) , req);
logStatus("Info", "POP generated correctly");
document.getElementById("Pop").innerHTML = pop;
let popPretty = jwtPretty(pop);
document.getElementById("PopPretty_head").innerHTML = popPretty[0];
document.getElementById("PopPretty_payl").innerHTML = popPretty[1];
} else {
logStatus("Error", "POP could not be generated");
document.getElementById("PopPretty_head").innerHTML = pop;
document.getElementById("PopPretty_payl").innerHTML = "";
return
}
} else {
logStatus("Info", "POP not used, expecting not long term token");
Pop.innerHTML = "";
document.getElementById("PopPretty_head").innerHTML = "";
document.getElementById("PopPretty_payl").innerHTML = "";
}
document.getElementById("Req").textContent = req;
document.getElementById("ReqPretty").innerHTML = jsonPrettify(req);
logStatus("Info", "Sending AGT Request");
receivedToken = null; // Sets received token to null before sending request
xhttpreq.send(req);
} catch(err){
logStatus("Error", err.message)
}
}
</script>
<!-- Token saver-->
<script>
function saveAgToken(){
if (receivedToken == null){ // If no token has been received
document.getElementById("saveStatus").innerHTML = "Can not save token: no AGT Received";
} else {
document.getElementById("saveStatus").innerHTML = "Token Saved";
storeAgt(document.getElementById("sign_type").value, receivedToken, document.getElementById("tokenID").value);
}
}
</script>
</body>
</html>