Repository navigation
Expand file tree
/
Copy pathvault.js
More file actions
499 lines (443 loc) · 15.4 KB
/
Copy pathvault.js
File metadata and controls
499 lines (443 loc) · 15.4 KB
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
var on_disk_values = {
"top_level" : [
"current_user",
"sign_in_status",
"salt_table",
"initialized",
"total_site_list",
"password_hashes",
"initial_survey",
"past_reports",
],
"config" : [
"deviceid",
"current_version",
"status",
"disable_period",
"disable_start",
"enable_timer",
"reporting_hour",
"next_reporting_time",
"reporting_interval",
"report_reminder_time",
"reportid",
],
"options" : [
"blacklist",
"dontbuglist",
"report_setting",
"monitor_icon_setting",
"lottery_setting",
],
"current_report" : [
"initialize_time",
"files_uploaded",
"reportid",
"deviceid",
"report_modified",
"guid",
"num_report_visits",
"report_time_spent",
"appu_errors",
"num_myfootprint_visits",
"myfootprint_time_spent",
"report_reviewed",
"user_approved",
"input_fields",
"send_attempts",
"extension_version",
"extension_updated",
"scheduled_report_time",
"actual_report_send_time",
"report_setting",
"lottery_setting",
"send_report_postponed",
"num_total_sites",
"total_time_spent",
"total_time_spent_logged_in",
"total_time_spent_wo_logged_in",
"num_user_account_sites",
"user_account_sites",
"num_non_user_account_sites",
"appu_disabled",
"dontbuglist",
"num_pwds",
"pwd_groups",
"pwd_similarity",
"username_similarity",
"downloaded_pi",
"common_fields",
"pwd_reuse_warnings",
"browser",
"browser_version",
"os",
"os_version",
"layout_engine",
"layout_engine_version",
],
"aggregate_data" : [
"session_cookie_store",
"files_uploaded",
"current_loggedin_state",
"initialized_time",
"num_viewed",
"total_time_spent",
"num_total_sites",
"all_sites_total_time_spent",
"all_sites_stats_start",
"num_user_account_sites",
"user_account_sites",
"num_non_user_account_sites",
"non_user_account_sites",
"num_pwds",
"pwd_groups",
"pwd_similarity",
"username_similarity",
"per_site_pi",
"pi_field_value_identifiers",
"pi_passively_identified",
],
}
//Initializing each property.
//TODO: Perhaps a better way is to write a generic function
//that accepts property_name and property initializer for that property.
//It will test if property exists. If not, then call the initializer function on that property.
//It will shorten the code and make it decent.
function vault_init() {
var vault_modified = false;
console.log("vault_init(): Initializing missing properties from last release");
// All top level values
if (!pii_vault.guid) {
//Verifying that no such user-id exists is taken care by
//Create Account or Sign-in.
//However, if there is a duplicate GUID then we are in trouble.
//Need to take care of that somehow.
// pii_vault.guid = generate_random_id();
// console.log("vault_init(): Updated GUID in vault: " + pii_vault.guid);
// vault_write("guid", pii_vault.guid);
// pii_vault.current_user = current_user;
// vault_write("current_user", pii_vault.current_user);
// pii_vault.sign_in_status = sign_in_status;
// vault_write("sign_in_status", pii_vault.sign_in_status);
pii_vault = { "options" : {}, "config": {}};
current_user = "default";
pii_vault.guid = default_user_guid;
sign_in_status = 'not-signed-in';
console.log("vault_init(): Updated GUID in vault: " + pii_vault.guid);
vault_write("guid", pii_vault.guid);
pii_vault.current_user = current_user;
console.log("vault_init(): Updated CURRENT_USER in vault: " + pii_vault.current_user);
vault_write("current_user", pii_vault.current_user);
pii_vault.sign_in_status = sign_in_status;
console.log("vault_init(): Updated SIGN_IN_STATUS in vault: " + pii_vault.sign_in_status);
vault_write("sign_in_status", pii_vault.sign_in_status);
}
if (!pii_vault.salt_table) {
var salt_table = {};
//current_ip for current input, not ip address
var current_ip = pii_vault.guid;
for(var i = 0; i < 1000; i++) {
salt_table[i] = CryptoJS.SHA1(current_ip).toString();
current_ip = salt_table[i];
}
pii_vault.salt_table = salt_table;
console.log("vault_init(): Updated SALT TABLE in vault");
vault_write("salt_table", pii_vault.salt_table);
}
if (!pii_vault.initialized) {
if (current_user != "default") {
var dug = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
var read_key = dug + ":" + "initialized";
if (read_key in localStorage) {
var val = JSON.parse(localStorage[read_key]);
pii_vault.initialized = val;
}
else {
pii_vault.initialized = false;
}
}
else {
pii_vault.initialized = false;
}
console.log("vault_init(): Updated INITIALIZED in vault");
vault_write("initialized", pii_vault.initialized);
}
if (!pii_vault.total_site_list) {
// This is maintained only to calculate total number of DIFFERENT sites visited
// from time to time. Its reset after every new current_report is created.
pii_vault.total_site_list = [];
console.log("vault_init(): Updated TOTAL_SITE_LIST in vault");
vault_write("total_site_list", pii_vault.total_site_list);
}
if (!pii_vault.password_hashes) {
// This is maintained separarely from current_report as it should not
// be sent to the server.
// Structure is: Key: 'username:etld'
// Value: {
// 'pwd_full_hash':'xyz',
// 'pwd_short_hash':'a',
// 'salt' : 'zz',
// 'pwd_group' : '',
// 'initialized': Date }
pii_vault.password_hashes = {};
console.log("vault_init(): Updated PASSWORD_HASHES in vault");
vault_write("password_hashes", pii_vault.password_hashes);
}
if (!pii_vault.initial_survey) {
pii_vault.initial_survey = {};
console.log("vault_init(): Updated INITIAL_SURVEY in vault");
vault_write("initial_survey", pii_vault.initial_survey);
}
if (!pii_vault.past_reports) {
pii_vault.past_reports = [];
console.log("vault_init(): Updated PAST_REPORTS in vault");
vault_write("past_reports", pii_vault.past_reports);
}
// All config values
if (!pii_vault.config.deviceid) {
//A device id is only used to identify all reports originating from a
//specific Appu install point. It serves no other purpose.
pii_vault.config.deviceid = generate_random_id();
console.log("vault_init(): Updated DEVICEID in vault: " + pii_vault.config.deviceid);
flush_selective_entries("config", ["deviceid"]);
}
if (!pii_vault.config.current_version) {
response_text = read_file('manifest.json');
var manifest = JSON.parse(response_text);
pii_vault.config.current_version = manifest.version;
console.log("vault_init(): Updated CURRENT_VERSION in vault: " + pii_vault.config.current_version);
flush_selective_entries("config", ["current_version"]);
}
if (!pii_vault.config.status) {
pii_vault.config.status = "active";
console.log("vault_init(): Updated STATUS in vault");
vault_write("config:status", pii_vault.config.status);
}
if (!pii_vault.config.disable_period) {
pii_vault.config.disable_period = -1;
console.log("vault_init(): Updated DISABLE_PERIOD in vault");
vault_write("config:disable_period", pii_vault.config.disable_period);
}
if (!pii_vault.config.reporting_hour) {
pii_vault.config.reporting_hour = 0;
//Random time between 5 pm to 8 pm. Do we need to adjust according to local time?
var rand_minutes = 1020 + Math.floor(Math.random() * 1000)%180;
pii_vault.config.reporting_hour = rand_minutes;
console.log("vault_init(): Updated REPORTING_HOUR in vault");
vault_write("config:reporting_hour", pii_vault.config.reporting_hour);
}
if (!pii_vault.config.reporting_interval) {
//3 days in minutes
pii_vault.config.reporting_interval = 4320;
console.log("vault_init(): Updated REPORTING_INTERVAL in vault");
vault_write("config:reporting_interval", pii_vault.config.reporting_interval);
}
if (!pii_vault.config.next_reporting_time) {
var curr_time = new Date();
//Advance by 3 days.
curr_time.setMinutes( curr_time.getMinutes() + pii_vault.config.reporting_interval);
//Third day's 0:0:0 am
curr_time.setSeconds(0);
curr_time.setMinutes(0);
curr_time.setHours(0);
curr_time.setMinutes( curr_time.getMinutes() + pii_vault.config.reporting_hour);
//Start reporting next day
pii_vault.config.next_reporting_time = curr_time.toString();
console.log("Report will be sent everyday at "+ Math.floor(rand_minutes/60) + ":" + (rand_minutes%60));
console.log("Next scheduled reporting is: " + curr_time);
console.log("vault_init(): Updated NEXT_REPORTING_TIME in vault");
vault_write("config:next_reporting_time", pii_vault.config.next_reporting_time);
}
if (!pii_vault.config.report_reminder_time) {
pii_vault.config.report_reminder_time = -1;
console.log("vault_init(): Updated REPORT_REMINDER_TIME in vault");
vault_write("config:report_reminder_time", pii_vault.config.report_reminder_time);
}
if (!pii_vault.config.reportid) {
pii_vault.config.reportid = 1;
console.log("vault_init(): Updated REPORTID in vault");
vault_write("config:reportid", pii_vault.config.reportid);
}
// All options values
if (!pii_vault.options.blacklist) {
pii_vault.options.blacklist = [];
console.log("vault_init(): Updated BLACKLIST in vault");
vault_write("options:blacklist", pii_vault.options.blacklist);
}
if (!pii_vault.options.dontbuglist) {
pii_vault.options.dontbuglist = [];
console.log("vault_init(): Updated DONTBUGLIST in vault");
vault_write("options:dontbuglist", pii_vault.options.dontbuglist);
}
//Three different types of reporting.
//Manual: If reporting time of the day and if report ready, interrupt user and ask
// him to review, modify and then send report.
//Auto: Send report automatically when ready.
//Differential: Interrupt user to manually review report only if current report
// entries are different from what he reviewed in the past.
// (How many past reports should be stored? lets settle on 10 for now?).
// Highlight the different entries with different color background.
if (!pii_vault.options.report_setting) {
pii_vault.options.report_setting = "manual";
console.log("vault_init(): Updated REPORT_SETTING in vault");
vault_write("options:report_setting", pii_vault.options.report_setting);
}
if (!pii_vault.options.monitor_icon_setting) {
pii_vault.options.monitor_icon_setting = "no";
console.log("vault_init(): Updated MONITOR_ICON_SETTING in vault");
vault_write("options:monitor_icon_setting", pii_vault.options.monitor_icon_setting);
}
if (!pii_vault.options.lottery_setting) {
//By default, not-participating
//User can update it to "participating"
if (current_user != "default") {
var dug = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
var read_key = dug + ":" + "options" + ":" + "lottery_setting";
if (read_key in localStorage) {
var val = JSON.parse(localStorage[read_key]);
pii_vault.options.lottery_setting = val;
}
else {
pii_vault.options.lottery_setting = "not-participating";
}
}
else {
pii_vault.options.lottery_setting = "not-participating";
}
console.log("vault_init(): Updated LOTTERY_SETTING in vault");
vault_write("options:lottery_setting", pii_vault.options.lottery_setting);
}
// All current report values
if (!pii_vault.current_report) {
pii_vault.current_report = initialize_report();
console.log("vault_init(): Updated CURRENT_REPORT in vault");
flush_current_report();
}
// All aggregate data values
if (!pii_vault.aggregate_data) {
pii_vault.aggregate_data = initialize_aggregate_data();
console.log("vault_init(): Updated AGGREGATE_DATA in vault");
flush_aggregate_data();
}
if (!pii_vault.aggregate_data.session_cookie_store) {
pii_vault.aggregate_data.session_cookie_store = {};
flush_aggregate_data();
}
}
function vault_read() {
try {
pii_vault.guid = JSON.parse(localStorage.guid);
if (pii_vault.guid) {
for (k in on_disk_values) {
if (on_disk_values.hasOwnProperty(k)) {
var read_key_prefix = pii_vault.guid + ":";
if (k != 'top_level') {
read_key_prefix += (k + ":");
}
var all_properties = on_disk_values[k];
for (var i = 0; i < all_properties.length; i++) {
var read_key = read_key_prefix + all_properties[i];
try {
var val = JSON.parse(localStorage[read_key]);
if (k === 'top_level') {
pii_vault[all_properties[i]] = val;
if (all_properties[i] == 'current_user') {
current_user = val;
}
if (all_properties[i] == 'sign_in_status') {
sign_in_status = val;
}
}
else {
if (!pii_vault[k]) {
pii_vault[k] = {};
}
pii_vault[k][all_properties[i]] = val;
}
}
catch (e) {
}
}
}
}
if(pii_vault.guid) {
console.log("User Id: " + pii_vault.guid);
}
if("salt_table" in pii_vault) {
//console.log("salt_table length: " + Object.size(pii_vault.salt_table));
}
}
else {
pii_vault = { "options" : {}, "config": {}};
}
}
catch (e) {
console.log("Loading extension for the first time. Initializing extension data");
pii_vault = { "options" : {}, "config": {}};
}
}
//Since this function is getting called async from many different points,
//ideally it should have a lock to avoid race conditions (and possibly corruption).
//However, apparently JS is threadless and JS engine takes care of this issue
//under the hood. So we are safe.
function vault_write(key, value) {
if (value !== undefined) {
if (key && key == "guid") {
//console.log("APPU DEBUG: vault_write(), key: " + key + ", " + value);
localStorage[key] = JSON.stringify(value);
}
else if (key !== undefined) {
var write_key = pii_vault.guid + ":" + key;
//console.log("APPU DEBUG: vault_write(), key: " + write_key + ", " + value);
localStorage[write_key] = JSON.stringify(value);
if (key.split(':').length == 2 && key.split(':')[0] === 'current_report') {
//This is so that if the reports tab queries for current_report,
//we can send it an updated one. There is no need to flush this to disk.
pii_vault.current_report.report_updated = true;
}
}
}
else {
print_appu_error("Appu Error: vault_write(), Value is empty for key: " + key);
}
}
function flush_current_report() {
for (var j = 0; j < on_disk_values.current_report.length; j++) {
var write_key = "current_report:" + on_disk_values.current_report[j];
vault_write(write_key, pii_vault.current_report[on_disk_values.current_report[j]]);
}
}
function flush_aggregate_data() {
for (var j = 0; j < on_disk_values.aggregate_data.length; j++) {
var write_key = "aggregate_data:" + on_disk_values.aggregate_data[j];
vault_write(write_key, pii_vault.aggregate_data[on_disk_values.aggregate_data[j]]);
}
}
function flush_selective_entries(struct_name, entry_list) {
for (var j = 0; j < entry_list.length; j++) {
var write_key = struct_name + ":" + entry_list[j];
vault_write(write_key, pii_vault[struct_name][entry_list[j]]);
}
}
function flush_session_cookie_store() {
flush_selective_entries("aggregate_data", ["session_cookie_store"]);
}
function flush_version(version) {
if (version) {
pii_vault.config.current_version = version;
}
flush_selective_entries("config", ["current_version"]);
}
function update_reporting_interval(interval, hour) {
console.log("Here here: ");
if (interval) {
console.log("Here here: ");
pii_vault.config.reporting_interval = interval;
vault_write("config:reporting_interval", pii_vault.config.reporting_interval);
}
if (hour) {
console.log("Here here: ");
pii_vault.config.reporting_hour = hour;
vault_write("config:reporting_hour", pii_vault.config.reporting_hour);
}
}