1 | |
---|
2 | // The CSS property is in FF from the version 0.8. |
---|
3 | var CSS_PROPERTY = 'MozBoxSizing' |
---|
4 | , BROWSER_NAME = 'Firefox' |
---|
5 | , OPERATIVE_SYSTEM = 'Win32' |
---|
6 | , TOR_BROWSER_VERSION = 10 |
---|
7 | , MIN_AMOUNT_PLUGINS = 0 |
---|
8 | , MAX_AMOUNT_PLUGINS = 1 |
---|
9 | , ALLOWED_PLUGIN_NAMES = ['Shockwave Flash'] |
---|
10 | , SECURITY_EXCEPTION_MSG = 'Permission denied' |
---|
11 | , NUMBER_ALLOWED_MIME_TYPES_LISTED = 0; |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | // It tests if the browser is Firefox. |
---|
16 | function isFirefox () { |
---|
17 | |
---|
18 | var isF = false |
---|
19 | |
---|
20 | // It tests if the browser has CSS_PROP as a CSS property. |
---|
21 | , cssTest = function () { |
---|
22 | |
---|
23 | var testOk = false; |
---|
24 | |
---|
25 | if ( document.documentElement && document.documentElement.style && (CSS_PROPERTY in document.documentElement.style)) |
---|
26 | testOk=true; |
---|
27 | |
---|
28 | return testOk; |
---|
29 | } |
---|
30 | |
---|
31 | // It tests if the 'userAgent' string contains BROWSER_NAME. |
---|
32 | , userAgentTest = function () { |
---|
33 | |
---|
34 | var testOk = false; |
---|
35 | |
---|
36 | if ( navigator.userAgent && (navigator.userAgent.indexOf(BROWSER_NAME) != -1) ) |
---|
37 | testOk=true; |
---|
38 | |
---|
39 | return testOk; |
---|
40 | |
---|
41 | }; |
---|
42 | |
---|
43 | // Unlikely, but .. |
---|
44 | if ( (typeof document !== 'undefined') && (typeof navigator !== 'undefined') ) { |
---|
45 | |
---|
46 | if (cssTest() && userAgentTest()) |
---|
47 | isF = true; |
---|
48 | } |
---|
49 | |
---|
50 | return isF; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | // It tests if the browser declared operative system matches with OPERATIVE_SYSTEM. |
---|
55 | function isOS () { |
---|
56 | |
---|
57 | var isOs = false |
---|
58 | |
---|
59 | // It tests if the 'platform' string contains OPERATIVE_SYSTEM. |
---|
60 | , platformTest = function () { |
---|
61 | |
---|
62 | var testOk = false; |
---|
63 | |
---|
64 | if ( navigator.platform && (navigator.platform.indexOf(OPERATIVE_SYSTEM) != -1)) |
---|
65 | testOk=true; |
---|
66 | |
---|
67 | return testOk; |
---|
68 | |
---|
69 | }; |
---|
70 | |
---|
71 | // Unlikely, but .. |
---|
72 | if ( typeof navigator !== 'undefined' ) { |
---|
73 | |
---|
74 | if (platformTest()) |
---|
75 | isOs = true; |
---|
76 | } |
---|
77 | |
---|
78 | return isOs; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | // It tests if the Browser version matches with the TOR_BROWSER_VERSION version. |
---|
83 | function isTBVersion () { |
---|
84 | |
---|
85 | var isTBV = false |
---|
86 | |
---|
87 | // It tests if the 'userAgent' string contains TOR_BROWSER_VERSION. |
---|
88 | , versionTest = function () { |
---|
89 | |
---|
90 | var testOk = false |
---|
91 | , indexName= -1; |
---|
92 | |
---|
93 | if ( navigator.userAgent ) |
---|
94 | indexName = navigator.userAgent.indexOf(BROWSER_NAME); |
---|
95 | |
---|
96 | if ( indexName != -1 ) |
---|
97 | testOk = (TOR_BROWSER_VERSION == parseFloat(navigator.userAgent.substring(indexName + BROWSER_NAME.length + 1))); |
---|
98 | |
---|
99 | return testOk; |
---|
100 | |
---|
101 | }; |
---|
102 | |
---|
103 | // Unlikely, but .. |
---|
104 | if ( typeof navigator !== 'undefined' ) { |
---|
105 | |
---|
106 | if (versionTest()) |
---|
107 | isTBV = true; |
---|
108 | } |
---|
109 | |
---|
110 | return isTBV; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | // It tests if the Browser has installed as most MAX_AMOUNT_PLUGINS plugins and the installed ones are in ALLOWED_PLUGIN_NAMES. |
---|
115 | function hasAllowedPlugins () { |
---|
116 | |
---|
117 | var hasAP = false |
---|
118 | |
---|
119 | // It tests if the 'plugins' array has a length less than the length MAX_AMOUNT_PLUGINS allowed, |
---|
120 | // and that the 'plugins' array is containing only the plugins in ALLOWED_PLUGIN_NAMES. |
---|
121 | , pluginsTest = function () { |
---|
122 | |
---|
123 | var testOk = false |
---|
124 | , found; |
---|
125 | |
---|
126 | if ( navigator.plugins && (navigator.plugins.length <= MAX_AMOUNT_PLUGINS) ) { |
---|
127 | |
---|
128 | if (navigator.plugins.length == MIN_AMOUNT_PLUGINS) { |
---|
129 | |
---|
130 | testOk = true; |
---|
131 | |
---|
132 | } else { |
---|
133 | |
---|
134 | for(var i=0, len=navigator.plugins.length; i < len; i++){ |
---|
135 | |
---|
136 | found = false; |
---|
137 | |
---|
138 | for(var i2=0, len2=ALLOWED_PLUGIN_NAMES.length; i2 < len2; i2++){ |
---|
139 | |
---|
140 | if ( navigator.plugins[i].name == ALLOWED_PLUGIN_NAMES[i2] ) { |
---|
141 | |
---|
142 | found = true; |
---|
143 | |
---|
144 | break; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | if ( !found ) |
---|
149 | break; |
---|
150 | } |
---|
151 | |
---|
152 | if ( found ) |
---|
153 | testOk = true; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | return testOk; |
---|
159 | |
---|
160 | }; |
---|
161 | |
---|
162 | // Unlikely, but .. |
---|
163 | if ( typeof navigator !== 'undefined' ) { |
---|
164 | |
---|
165 | if (pluginsTest()) |
---|
166 | hasAP = true; |
---|
167 | } |
---|
168 | |
---|
169 | return hasAP; |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | // It tests if it is allowed the access to the Firefox 's Components.lookupMethod function. |
---|
174 | function isNotAllowedComponentsLookup () { |
---|
175 | |
---|
176 | var isNAC = false |
---|
177 | |
---|
178 | // It tests the access to the function 'lookupMethod'. |
---|
179 | , componentsLookupTest = function () { |
---|
180 | |
---|
181 | var testOk = false |
---|
182 | , resFunction; |
---|
183 | |
---|
184 | if ( typeof Components !== 'undefined' ) { |
---|
185 | |
---|
186 | try { |
---|
187 | resFunction = Components.lookupMethod(this, 'window'); |
---|
188 | |
---|
189 | } catch (err) { |
---|
190 | |
---|
191 | if( err.message.indexOf(SECURITY_EXCEPTION_MSG) != -1 ) |
---|
192 | testOk = true; |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | return testOk; |
---|
198 | |
---|
199 | }; |
---|
200 | |
---|
201 | if (componentsLookupTest()) |
---|
202 | isNAC = true; |
---|
203 | |
---|
204 | return isNAC; |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | // It tests if it is allowed the access to Firefox 's Components.interfaces. |
---|
209 | function isNotAllowedComponentsInterfaces () { |
---|
210 | |
---|
211 | var isNAC = false |
---|
212 | |
---|
213 | // It tests the access to 'interfaces'. |
---|
214 | , componentsInterfacesTest = function () { |
---|
215 | |
---|
216 | var testOk = false |
---|
217 | , resObject; |
---|
218 | |
---|
219 | if ( typeof Components !== 'undefined' ) { |
---|
220 | |
---|
221 | try { |
---|
222 | resObject = Components.interfaces.nsITimer; |
---|
223 | |
---|
224 | } catch (err) { |
---|
225 | |
---|
226 | if( err.message.indexOf(SECURITY_EXCEPTION_MSG) != -1 ) |
---|
227 | testOk = true; |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | return testOk; |
---|
233 | |
---|
234 | }; |
---|
235 | |
---|
236 | if (componentsInterfacesTest()) |
---|
237 | isNAC = true; |
---|
238 | |
---|
239 | return isNAC; |
---|
240 | } |
---|
241 | |
---|
242 | |
---|
243 | // It tests if the Browser has disabled DOM Storage. |
---|
244 | function hasDisabledDOMStorage () { |
---|
245 | |
---|
246 | var hasDDS = false |
---|
247 | |
---|
248 | // It tests if the 'sessionStorage' is NULL. |
---|
249 | , domStorageTest = function () { |
---|
250 | |
---|
251 | var testOk = false; |
---|
252 | |
---|
253 | if ( sessionStorage === null ) |
---|
254 | testOk = true; |
---|
255 | |
---|
256 | |
---|
257 | return testOk; |
---|
258 | |
---|
259 | }; |
---|
260 | |
---|
261 | if (domStorageTest()) |
---|
262 | hasDDS = true; |
---|
263 | |
---|
264 | return hasDDS; |
---|
265 | } |
---|
266 | |
---|
267 | |
---|
268 | // It tests if the Browser is not listing the supported MIME Types. |
---|
269 | function isNotListingMimeTypes () { |
---|
270 | |
---|
271 | var isNLMT = false |
---|
272 | |
---|
273 | // It tests if the 'sessionStorage' is NULL. |
---|
274 | , mimeTypesTest = function () { |
---|
275 | |
---|
276 | var testOk = false; |
---|
277 | |
---|
278 | if ( navigator.mimeTypes && (navigator.mimeTypes.length == NUMBER_ALLOWED_MIME_TYPES_LISTED) ) |
---|
279 | testOk = true; |
---|
280 | |
---|
281 | |
---|
282 | return testOk; |
---|
283 | |
---|
284 | }; |
---|
285 | |
---|
286 | // Unlikely, but .. |
---|
287 | if ( typeof navigator !== 'undefined' ) { |
---|
288 | |
---|
289 | if (mimeTypesTest()) |
---|
290 | isNLMT = true; |
---|
291 | } |
---|
292 | |
---|
293 | return isNLMT; |
---|
294 | } |
---|
295 | |
---|
296 | |
---|
297 | // It tests if the browser is a Tor Browser. |
---|
298 | function tb_fingerprint() { |
---|
299 | |
---|
300 | var isTorBrowser = false; |
---|
301 | |
---|
302 | console.debug("Is Firefox?: " + isFirefox()); |
---|
303 | console.debug("Is Win32?: " + isOS()); |
---|
304 | console.debug("Is TB Version?: " + isTBVersion()); |
---|
305 | console.debug("Has allowed plugins?: " + hasAllowedPlugins()); |
---|
306 | console.debug("Is not allowed Components Lookup?: " + isNotAllowedComponentsLookup()); |
---|
307 | console.debug("Is not allowed Components Interfaces?: " + isNotAllowedComponentsInterfaces()); |
---|
308 | console.debug("Has disabled DOM Storage?: " + hasDisabledDOMStorage()); |
---|
309 | console.debug("Is not listing the supported MIME Types?: " + isNotListingMimeTypes()); |
---|
310 | |
---|
311 | //The test continues only if the browser is Firefox |
---|
312 | if ( isFirefox() ) { |
---|
313 | |
---|
314 | if ( isOS() && isTBVersion() && hasAllowedPlugins() && isNotAllowedComponentsLookup && isNotAllowedComponentsInterfaces() && hasDisabledDOMStorage() && isNotListingMimeTypes() ) { |
---|
315 | |
---|
316 | console.debug('The browser seems to be a TOR BROWSER!!!'); |
---|
317 | |
---|
318 | isTorBrowser = true; |
---|
319 | } |
---|
320 | |
---|
321 | } |
---|
322 | |
---|
323 | return isTorBrowser; |
---|
324 | } |
---|