Commit c2ae1d62 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame Committed by Richard Pospesel
Browse files

Bug 40035: Added a fonts fingerprinting test

Added a test to check that fingerprinting can only detect the fonts we
bundle with Tor Browser.
The code is readapted from TorZilla Print:
https://arkenfox.github.io/TZP/tests/fontlists.html
The list should be updated to match the bundled fonts. Also, we ship
different fonts in different platforms, so the test is enabled only for
Linux.

Added also a test to detect which glyph the browser can render and
their size. The code was originally developed by David Fifield and
Serge Egelman:
https://www.bamsoftware.com/talks/fc15-fontfp/fontfp.html#demo
The expected result of the test comes directly from a run on Tor
Browser, and we want it to be persistent, rather than having some
deisred metrics to match.
parent 9052ce21
......@@ -374,6 +374,13 @@ our @tests = (
type => 'marionette',
descr => 'Check that navigator properties are as expected',
},
{
name => 'fp_fonts',
type => 'marionette',
use_net => 1,
descr => 'Check that we are using only bundled fonts',
enable => sub { $OSNAME eq 'linux' },
},
{
name => 'play_videos',
type => 'marionette',
......
import hashlib
import json
from marionette_harness import MarionetteTestCase
class Test(MarionetteTestCase):
def test_fp_fonts(self):
m = self.marionette
with m.using_context('content'):
m.set_pref("network.proxy.allow_hijacking_localhost", False)
m.navigate(self.marionette.absolute_url("fonts/fonts.html"))
fonts = m.find_element('id', 'fonts-list').text.strip()
glyphs = m.find_element('id', 'glyphs').text.strip()
font_list = set(json.loads(fonts))
bundled_fonts = set([
"Arimo",
"Cousine",
"Noto Emoji",
"Noto Naskh Arabic",
"Noto Sans Armenian",
"Noto Sans Bengali",
"Noto Sans Buginese",
"Noto Sans Canadian Aboriginal",
"Noto Sans Cherokee",
"Noto Sans Devanagari",
"Noto Sans Ethiopic",
"Noto Sans Georgian",
"Noto Sans Gujarati",
"Noto Sans Gurmukhi",
"Noto Sans Hebrew",
"Noto Sans JP Regular",
"Noto Sans Kannada",
"Noto Sans Khmer",
"Noto Sans KR Regular",
"Noto Sans Lao",
"Noto Sans Malayalam",
"Noto Sans Mongolian",
"Noto Sans Myanmar",
"Noto Sans Oriya",
"Noto Sans SC Regular",
"Noto Sans Sinhala",
"Noto Sans Tamil",
"Noto Sans TC Regular",
"Noto Sans Telugu",
"Noto Sans Thaana",
"Noto Sans Thai",
"Noto Sans Tibetan",
"Noto Sans Yi",
"Noto Serif Armenian",
"Noto Serif Khmer",
"Noto Serif Lao",
"Noto Serif Thai",
"STIX Math",
"Tinos",
"Twemoji Mozilla",
])
self.assertEqual(font_list, bundled_fonts)
glyphs_hash = hashlib.sha256(glyphs.encode('utf-8')).hexdigest()
expected_hash = "5e185a7bd097ecf482fd6a4d8228a9e25974cfbb4bc5f07751b9d09bdebc0f67"
self.assertEqual(glyphs_hash, expected_hash)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Font fingerprinting test</title>
<style type="text/css">
#stage-div {
text-align: center;
}
#stage-span {
font-size: 500%;
}
</style>
</head>
<body>
<div id="stage-div">
<span id="stage-span">
<span id="stage-slot"></span>
</span>
</div>
<div id="fonts-list"></div>
<div id="glyphs"></div>
<script src="fonts.js"></script>
<script>
const fonts = JSON.stringify(getFonts());
const glyphs = JSON.stringify(getUnicode());
document.querySelector('#fonts-list').textContent = fonts;
document.querySelector('#glyphs').textContent = glyphs;
</script>
</body>
</html>
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment