-
Notifications
You must be signed in to change notification settings - Fork 0
/
compatibility.py
337 lines (242 loc) · 9.72 KB
/
compatibility.py
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
# ----------------------------------------------
# ------------Compatability Study---------------
# ----------------------------------------------
# {URL: # of CSP violations (broken scripts)}
import json
import ast
from collections import defaultdict
domains = []
# open file and read the content in a list
with open('alexa50-200.txt', 'r') as filehandle:
for line in filehandle:
# remove linebreak which is the last character of the string
currentPlace = line[:-1]
# add item to the list
domains.append(currentPlace)
domino_violationMap = defaultdict(int)
plusPlus_violationMap = defaultdict(int)
count = 0
# allFiles = ["DOMinoRun.txt", "plusPlusRun.txt"]
nonceFinder = defaultdict(int)
allFiles = ["secondControl.txt", "secondDisableDynamic.txt"]
for fileName in allFiles:
# Using readlines()
file1 = open(fileName, 'r')
Lines = file1.readlines()
for line in Lines:
# [11788:14032:1112/042852.933:INFO:CONSOLE(102)] "Conversion time: 6.584999999176944", source: https://www.google.com/ (102)
unreachableDomainErrors = ["ERROR PRINTING OCCURED FOR THIS DOMAIN", "*NEEDS TO TRY HTTP*", "^FAILURE, SITE NOT REACHABLE^"]
if line.strip() in domains:
# This is printing the current domain of interest
# print(line)
continue
if line.strip() in unreachableDomainErrors:
continue
trimmed = line.strip()
try:
jsonObj = ast.literal_eval(trimmed)
except:
continue
# print(jsonObj)
if "nonce" in jsonObj['message']:
nonceFinder[fileName] += 1
# print('here')
forDomain = jsonObj['message'].split(' ')
# print(forDomain[0])
domainName = forDomain[0].lower()
# print(jsonObj['message'])
# Search to determine if domain belongs to domain found in webpage
belongs = False
for element in domains:
websiteName = element
if ".com" in element:
# websiteName = splitWebsiteName[0].lower()
websiteName = websiteName.lower()
if websiteName in domainName:
belongs = True
break
# Check for a count <
if count < 5:
print(belongs)
print(domainName)
count += 1
if belongs:
if "DisableDynamic" in fileName:
plusPlus_violationMap[domainName] += 1
else:
domino_violationMap[domainName] += 1
print("-----------------------")
print("DOMINO")
print("-----------------------")
print(domino_violationMap)
domino_scriptVioloations = sum(domino_violationMap.values())
print("\n")
print("Number of DOMino script violations: " + str(domino_scriptVioloations))
print("\n")
print("-----------------------")
print("PLUSPLUS")
print("-----------------------")
print(plusPlus_violationMap)
plusPlus_scriptVioloations = sum(plusPlus_violationMap.values())
print("\n")
print("Number of DOMino++ script violations: " + str(plusPlus_scriptVioloations))
dominoScriptDomains = len(domino_violationMap.keys())
dominoPlusPlusDomains = len(plusPlus_violationMap.keys())
print("\n")
print("Number of DOMino script violation domains: " + str(dominoScriptDomains))
print("\n")
print("Number of DOMino++ script violation domains: " + str(dominoPlusPlusDomains))
domino_domainMap = defaultdict(int)
plusplus_domainMap = defaultdict(int)
print(nonceFinder)
# Adjusting for five refreshes --------------
adjustedDominoMap = defaultdict(float)
adjustedpluPlusMap = defaultdict(float)
for element in domino_violationMap.keys():
adjustedVal = domino_violationMap[element] * 0.2
adjustedDominoMap[element] += adjustedVal
for element in plusPlus_violationMap.keys():
adjustedVal = plusPlus_violationMap[element] * 0.2
adjustedpluPlusMap[element] += adjustedVal
print(adjustedDominoMap)
# Adjusting for five refreshes --------------
# Keys for pdf default dictionaries are number of script errors, freqency is the value
pdfDomino = {}
pdfPlusPlus = {}
pdfDomino[1] = 0
pdfPlusPlus[1] = 0
for element in adjustedDominoMap.keys():
if adjustedDominoMap[element] <= 1:
pdfDomino[1] += 1
else:
formattedInt = round(adjustedDominoMap[element])
if formattedInt not in pdfDomino.keys():
pdfDomino[formattedInt] = 0
pdfDomino[formattedInt] += 1
for element in adjustedpluPlusMap.keys():
if adjustedpluPlusMap[element] <= 1:
pdfPlusPlus[1] += 1
else:
formattedInt = round(adjustedpluPlusMap[element])
if formattedInt not in pdfPlusPlus.keys():
pdfPlusPlus[formattedInt] = 0
pdfPlusPlus[formattedInt] += 1
# 200 is total number of tested websites
pdfDomino[0] = 200 - len(adjustedDominoMap.keys())
pdfPlusPlus[0] = 200 - len(adjustedpluPlusMap.keys())
# Be sure all keys have a value
scriptErrorNumber = 100 + 1
for i in range(scriptErrorNumber):
if i not in pdfDomino.keys():
pdfDomino[i] = 0
if i not in pdfPlusPlus.keys():
pdfPlusPlus[i] = 0
numberOfDomains = []
for i in range(scriptErrorNumber):
numberOfDomains.append(i)
dominoIncompatible = [0]
plusIncompatible = [0]
for i in range(scriptErrorNumber):
lastDomino = dominoIncompatible[len(dominoIncompatible) - 1]
dominoIncompatible.append(lastDomino + pdfDomino[i]*1/200)
lastPlus = plusIncompatible[len(plusIncompatible) - 1]
plusIncompatible.append(lastPlus + pdfPlusPlus[i]*1/200)
import matplotlib
import matplotlib.pyplot as plt
# Data for plotting
t = []
for i in range(scriptErrorNumber):
t.append(i)
# Ignore value of 0 to begin with
dominoGraph = dominoIncompatible[1:]
plusGraph = plusIncompatible[1:]
plt.plot(t, dominoGraph, label = "DOMino")
plt.plot(t, plusGraph, label = "DOMino++")
plt.xlabel("Number of incompatible scripts (0 -" + str(scriptErrorNumber - 1) + ")")
plt.ylabel("Density of websites (%)")
plt.title("CDF of script compatibility for DOMino and DOMino++ over Alexa top 200 domains")
plt.legend()
plt.show()
# def checkURL(domainList, fullURL):
# for element in domainList:
# if element.lower() in fullURL:
# return True, element
# return False, ""
# dominoTotalDomains = 0
# dominoScriptMap = {}
# for element in domino_violationMap:
# dominoTotalDomains += 1
# shouldAdd, urlToAdd = checkURL(domains, element)
# domino_domainMap[urlToAdd] += domino_violationMap[element]
# if domino_violationMap[element] not in dominoScriptMap.keys():
# dominoScriptMap[domino_violationMap[element]] = 0
# dominoScriptMap[domino_violationMap[element]] += 1
# plusTotalDomains = 0
# plusScriptMap = {}
# for element in plusPlus_violationMap:
# plusTotalDomains += 1
# shouldAdd, urlToAdd = checkURL(domains, element)
# plusplus_domainMap[urlToAdd] += plusPlus_violationMap[element]
# if plusPlus_violationMap[element] not in plusScriptMap.keys():
# plusScriptMap[plusPlus_violationMap[element]] = 0
# plusScriptMap[plusPlus_violationMap[element]] += 1
# print(domino_domainMap)
# print(len(domino_domainMap.keys()))
# print("\n")
# print("total Domino domains: " + str(dominoTotalDomains))
# # for element in domino_domainMap
# print(plusplus_domainMap)
# print(len(plusplus_domainMap.keys()))
# print("total Plus domains: " + str(plusTotalDomains))
# dominoScriptMap[0] = 0
# dominoScriptMap[0] += 150 - len(domino_domainMap.keys())
# curr = 150 - len(domino_domainMap.keys())
# sortedKeys = list(domino_domainMap.keys())
# sortedKeys.sort()
# print(sortedKeys)
# print(dominoScriptMap)
# # while curr < 150:
# plusScriptMap[0] = 0
# plusScriptMap[0] += 150 - len(plusScriptMap.keys())
# print(plusScriptMap)
##############################################################################
# import matplotlib
# import matplotlib.pyplot as plt
# # Data for plotting
# t = []
# for i in range(150):
# t.append(i + 1)
# s = 1 + np.sin(2 * np.pi * t)
# fig, ax = plt.subplots()
# ax.plot(t, s)
# ax.set(xlabel='time (s)', ylabel='voltage (mV)',
# title='About as simple as it gets, folks')
# ax.grid()
# fig.savefig("test.png")
# plt.show()
# dominoKeys = len(domino_violationMap.keys())
# print("\n")
# print("CONTROL MAP: ")
# for url in control_domainMap.keys():
# print("Time to DOMContentLoaded: " + url + " " + str(sum(control_domainMap[url][0])/len(control_domainMap[url][0])))
# print("\n")
# print("CONVERSION MAP: ")
# for url in conversionMap.keys():
# print("Conversion Time: "+ url + " " + str(sum(conversionMap[url])/len(conversionMap[url])))
# # Add to averages map
# for url in conversionMap.keys():
# averageOverhead = sum(conversionMap[url])/len(conversionMap[url]) / sum(test_domainMap[url][0])/len(test_domainMap[url][0])
# averages[url] = str(averageOverhead * 100)
# timedValues.append(float(savedVal))
# print(savedVal)
# # print("Line{}: {}".format(count, line.strip()))
# print("average: " + str(sum(timedValues)/len(timedValues)))
# summedAverages = []
# print("\n")
# for key in averages:
# print("AVERAGE: " + averages[key] + " URL: " + key)
# summedAverages.append(float(averages[key]))
# print("\n")
# print(summedAverages)
# print('\n')
# print("TOTAL AVERAGE: " + str(sum(summedAverages)/len(summedAverages)))