-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathversion.js
325 lines (269 loc) · 10.7 KB
/
version.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
function convert_existing_addresses_to_canonical_form() {
var vpfvi = pii_vault.aggregate_data.pi_field_value_identifiers;
var name_regexes = [
/address([0-9]+)/g,
/real-address([0-9]+)/g,
];
for (var pi_values in vpfvi) {
var identifier = vpfvi[pi_values];
if (typeof(identifier) != "string") {
continue;
}
for (var j = 0; j < name_regexes.length; j++) {
if (identifier.match(name_regexes[j])) {
var address = pi_values;
(function(address, identifier) {
get_address_components(address, function(result) {
var latitude = result["latitude"];
var longitude = result["longitude"];
pa = parse_address(result["address-components"]);
canonical_address_attributes = [
"street_number",
"street",
"city",
"state",
"zipcode",
"country",
];
for (var p = 0; p < canonical_address_attributes.length; p++) {
if (!(canonical_address_attributes[p] in pa)) {
console.log("APPU ERROR: Address cannot be converted to canonical form: " +
JSON.stringify(address));
if (address in pii_vault.aggregate_data.pi_field_value_identifiers) {
delete pii_vault.aggregate_data.pi_field_value_identifiers[address];
}
return;
}
}
canonical_address = "street-number: " + pa["street_number"]["long_name"];
canonical_address += ", street: " + pa["street"]["long_name"];
canonical_address += ", city: " + pa["city"]["long_name"];
canonical_address += ", state: " + pa["state"]["long_name"];
canonical_address += ", zipcode: " + pa["zipcode"]["long_name"];
canonical_address += ", country: " + pa["country"]["long_name"];
if (address in pii_vault.aggregate_data.pi_field_value_identifiers) {
delete pii_vault.aggregate_data.pi_field_value_identifiers[address];
}
pii_vault.aggregate_data.pi_field_value_identifiers[canonical_address] = {
'identifier': identifier,
'verified': 'no',
'latitude': latitude,
'longitude': longitude,
'full-address': pa,
'sites': [],
}
});
})(address, identifier);
break;
}
}
}
}
function convert_pi_field_values_to_canonical_form() {
var vpfvi = pii_vault.aggregate_data.pi_field_value_identifiers;
for (var pi_values in vpfvi) {
var identifier = vpfvi[pi_values];
if (typeof(identifier) == "string") {
if (pi_values in pii_vault.aggregate_data.pi_field_value_identifiers) {
delete pii_vault.aggregate_data.pi_field_value_identifiers[pi_values];
}
pii_vault.aggregate_data.pi_field_value_identifiers[pi_values] = {
'identifier': identifier,
'type' : "",
'verified': 'no',
'sites': [],
'additional-notes' : {},
'additional-values' : {},
}
}
}
}
function remove_redundant_pi_identifiers() {
var new_pfvi = {};
var pfvi = pii_vault.aggregate_data.pi_field_value_identifiers;
for (var id in pfvi) {
if (!(pfvi[id] in new_pfvi)) {
new_pfvi[pfvi[id]] = id;
}
else {
if (id < new_pfvi[pfvi[id]]) {
new_pfvi[pfvi[id]] = id;
}
}
}
pii_vault.aggregate_data.pi_field_value_identifiers = new_pfvi;
flush_selective_entries("aggregate_data", ["pi_field_value_identifiers"]);
}
function update_specific_changes(last_version) {
if (last_version < '0.3.92') {
console.log("APPU DEBUG: Update specific changes(<0.3.92). Deleting existing password hashes." +
" This is for added security. " +
"Also deleting existing pwd groups as they are inconsistent form report to report");
pii_vault.password_hashes = {};
vault_write("password_hashes", pii_vault.password_hashes);
pii_vault.current_report.pwd_groups = {};
flush_selective_entries("current_report", ["pwd_groups"]);
pii_vault.aggregate_data.non_user_account_sites = {};
flush_selective_entries("aggregate_data", ["non_user_account_sites"]);
remove_redundant_pi_identifiers();
}
if (last_version < '0.3.97') {
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding pwd_group " +
"to pii_vault.password_hashes");
var pvapg = pii_vault.aggregate_data.pwd_groups;
for (var pwdgrp in pvapg) {
for (var i = 0; i < pvapg[pwdgrp].sites.length; i++) {
var hk = ":" + pvapg[pwdgrp].sites[i];
if (pii_vault.password_hashes[hk]) {
pii_vault.password_hashes[hk].my_pwd_group = pwdgrp;
}
}
}
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding session_cookie_store " +
"to pii_vault.aggregate_date");
pii_vault.aggregate_data.session_cookie_store = {};
flush_aggregate_data();
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding new field 'am_i_logged_in' to " +
" user_account_sites in both current_report and aggregate_data");
var cr = pii_vault.current_report;
var ad = pii_vault.aggregate_data;
for (d in cr.user_account_sites) {
cr.user_account_sites[d].am_i_logged_in = 'maybe';
}
for (d in ad.user_account_sites) {
ad.user_account_sites[d].am_i_logged_in = 'maybe';
}
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding new field 'username' to " +
" user_account_sites in both current_report and aggregate_data");
var cr = pii_vault.current_report;
var ad = pii_vault.aggregate_data;
for (d in cr.user_account_sites) {
cr.user_account_sites[d].username = '';
}
for (d in ad.user_account_sites) {
ad.user_account_sites[d].username = '';
}
flush_aggregate_data();
flush_current_report();
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding new field 'lottery_setting' to " +
" current_report");
pii_vault.current_report.lottery_setting = "not-participating";
flush_aggregate_data();
flush_current_report();
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding new field 'lottery_setting' to " +
" options");
pii_vault.options.lottery_setting = "not-participating";
vault_write("options:lottery_setting", pii_vault.options.lottery_setting);
console.log("APPU DEBUG: Update specific changes(<0.3.97). Adding new field 'initialized' to " +
" pii_vault");
//Adding to current user
pii_vault.initialized = true;
vault_write("initialized", pii_vault.initialized);
//Adding to default user
var dug = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
var read_key = dug + ":" + "initialized";
localStorage[read_key] = JSON.stringify(pii_vault.initialized);
}
if (last_version < '0.4.7') {
var per_site_pi = pii_vault.aggregate_data.per_site_pi;
var sym_tab = pii_vault.aggregate_data.pi_field_value_identifiers;
console.log("APPU DEBUG: Update specific changes(<0.4.7). Sanitizing phone numbers.");
for (var value in sym_tab) {
var identifier = sym_tab[value];
if (identifier.match(/^phone([0-9]+)$/)) {
var phone_array = [];
phone_array.push(value);
sanitize_phone(phone_array);
sym_tab[phone_array[0]] = identifier;
}
}
console.log("APPU DEBUG: Update specific changes(<0.4.7). Sanitizing ccn numbers.");
for (var value in sym_tab) {
var identifier = sym_tab[value];
if (identifier.match(/^ccn([0-9]+)$/)) {
var ccn_array = [];
ccn_array.push(value);
sanitize_ccn(ccn_array);
sym_tab[ccn_array[0]] = identifier;
}
}
console.log("APPU DEBUG: Update specific changes(<0.4.7). Sanitizing already downloaded " +
"phones/ccns in per_site_pi.");
for (var s in per_site_pi) {
if (per_site_pi[s].ccn) {
sanitize_ccn(per_site_pi[s].ccn.values);
}
if (per_site_pi[s].phone) {
sanitize_phone(per_site_pi[s].phone.values);
}
}
flush_selective_entries("aggregate_data", ["pi_field_value_identifiers"]);
}
if (last_version < '0.5.11') {
console.log("APPU DEBUG: Update specific changes(<0.5.11). Creating a null identifier");
var vpfvi = pii_vault.aggregate_data.pi_field_value_identifiers;
var vcr = pii_vault.current_report;
var vad = pii_vault.aggregate_data;
vpfvi[''] = 'null_identifier';
flush_selective_entries("aggregate_data", ["pi_field_value_identifiers"]);
console.log("APPU DEBUG: Update specific changes(<0.5.11). Zeroing out user_account_sites (CR & AD)");
vad.num_user_account_sites = 0;
vad.user_account_sites = {};
vcr.num_user_account_sites = 0;
vcr.user_account_sites = {};
console.log("APPU DEBUG: Update specific changes(<0.5.11). Deleting sites from pwd_groups (AD)");
for (var pg in vad.pwd_groups) {
vad.pwd_groups[pg].sites = [];
}
console.log("APPU DEBUG: Update specific changes(<0.5.11). Zeroing out pwd_groups (CR)");
vcr.pwd_groups = {};
console.log("APPU DEBUG: Update specific changes(<0.5.11). Adding a new field, current_loggedin_state to AD");
pii_vault.aggregate_data.current_loggedin_state = {};
flush_aggregate_data();
flush_current_report();
console.log("APPU DEBUG: Update specific changes(<0.5.11). Zeroing out password_hashes");
pii_vault.password_hashes = {};
vault_write("password_hashes", pii_vault.password_hashes);
}
if (last_version < '0.5.18') {
// console.log("APPU DEBUG: Update specific changes(<0.5.18). Creating 'files_uploaded' entries");
// pii_vault.current_report.files_uploaded = {};
// flush_selective_entries("current_report", ["files_uploaded"]);
// pii_vault.aggregate_data.files_uploaded = {};
// flush_selective_entries("aggregate_data", ["files_uploaded"]);
}
if (last_version < '0.5.20') {
// console.log("APPU DEBUG: Update specific changes(<0.5.20). Converting 'pi_field_value_identifiers' to new form");
// convert_existing_addresses_to_canonical_form();
// convert_pi_field_values_to_canonical_form();
// flush_aggregate_data();
}
if (last_version < '0.5.24') {
console.log("APPU DEBUG: Update specific changes(<0.5.24). Adding username_similarity");
pii_vault.aggregate_data.username_similarity = {};
pii_vault.current_report.username_similarity = {};
flush_current_report();
flush_aggregate_data();
}
}
function make_version_check() {
//Detect if there has been an update.
var am_i_updated = false;
var last_version = pii_vault.config.current_version ? pii_vault.config.current_version : '0.0.0';
response_text = read_file('manifest.json');
var manifest = JSON.parse(response_text);
console.log("APPU DEBUG: Current version: " + manifest.version);
if ((!pii_vault.config.current_version) || (manifest.version > pii_vault.config.current_version)) {
if (manifest.version > pii_vault.config.current_version) {
pii_vault.config.current_version = manifest.version;
flush_selective_entries("config", ["current_version"]);
}
am_i_updated = true;
if (pii_vault.current_report) {
pii_vault.current_report.extension_updated = true;
pii_vault.current_report.extension_version = pii_vault.config.current_version;
flush_selective_entries("current_report", ["extension_updated", "extension_version"]);
}
}
return [am_i_updated, last_version];
}