From ef1c71016aef612afd0f57c48868de9890254142 Mon Sep 17 00:00:00 2001 From: Fatih Date: Wed, 18 Sep 2024 19:41:08 +0000 Subject: [PATCH] Bug 1919090: Flatten ICE foundations info. r=tjr Differential Revision: https://phabricator.services.mozilla.com/D222345 --- .../UserCharacteristicsPageService.sys.mjs | 3 +- .../content/usercharacteristics.js | 67 +++++++------------ .../resistfingerprinting/metrics.yaml | 36 ++++++++++ 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs b/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs index a39292916682..3c47672e97bc 100644 --- a/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs +++ b/toolkit/components/resistfingerprinting/UserCharacteristicsPageService.sys.mjs @@ -338,7 +338,8 @@ export class UserCharacteristicsPageService { "jsErrors", "pointerType", "anyPointerType", - "iceFoundations", + "iceSd", + "iceOrder", "motionDecimals", "orientationDecimals", "orientationabsDecimals", diff --git a/toolkit/components/resistfingerprinting/content/usercharacteristics.js b/toolkit/components/resistfingerprinting/content/usercharacteristics.js index d00bb46d76b3..2f78aa8281b7 100644 --- a/toolkit/components/resistfingerprinting/content/usercharacteristics.js +++ b/toolkit/components/resistfingerprinting/content/usercharacteristics.js @@ -1017,12 +1017,11 @@ async function populateICEFoundations() { // With no other peers, we wouldn't get prflx candidates. // Relay type of candidates require a turn server. - // So, we'll only get host and srflx candidates. + // srflx candidates require a stun server. + // So, we'll only get host candidates. const result = { - hostLatencies: [], - hostFoundations: [], - srflxLatencies: [], - srflxFoundations: [], + latencies: [], + foundations: [], }; let lastTime; @@ -1033,14 +1032,12 @@ async function populateICEFoundations() { return latency; } - const pc = new RTCPeerConnection({ - iceServers: [{ urls: ["stun:stun.l.google.com:19302"] }], - }); + const pc = new RTCPeerConnection(); pc.onicecandidate = e => { const latency = calculateLatency(); if (e.candidate && e.candidate.candidate !== "") { - result[e.candidate.type + "Latencies"].push(latency); - result[e.candidate.type + "Foundations"].push(e.candidate.foundation); + result.latencies.push(latency); + result.foundations.push(e.candidate.foundation); } }; pc.onicegatheringstatechange = () => { @@ -1063,51 +1060,33 @@ async function populateICEFoundations() { // Run get candidates multiple times to see if foundation order changes // and calculate standard deviation of latencies - const allLatencies = { - srflx: [], - host: [], - }; - const allFoundations = { - srflx: {}, - host: {}, - }; + const latencies = []; + const foundations = {}; for (let i = 0; i < 10; i++) { const result = await getFoundationsAndLatencies(); - const hostFoundations = result.hostFoundations.join(""); - const srflxFoundations = result.srflxFoundations.join(""); - allLatencies.host.push(result.hostLatencies); - allLatencies.srflx.push(result.srflxLatencies); + latencies.push(result.latencies); + const hostFoundations = result.foundations.join(""); if (hostFoundations) { - allFoundations.host[hostFoundations] = - (allFoundations.host[hostFoundations] ?? 0) + 1; - } - if (srflxFoundations) { - allFoundations.srflx[srflxFoundations] = - (allFoundations.srflx[srflxFoundations] ?? 0) + 1; + foundations[hostFoundations] = (foundations[hostFoundations] ?? 0) + 1; } } - const sdLatencies = { - host: [], - srflx: [], - }; - for (let i = 0; i < (allLatencies.host?.[0]?.length ?? 0); i++) { - sdLatencies.host.push(standardDeviation(allLatencies.host.map(a => a[i]))); - } - for (let i = 0; i < (allLatencies.srflx?.[0]?.length ?? 0); i++) { - sdLatencies.srflx.push( - standardDeviation(allLatencies.srflx.map(a => a[i])) - ); + const sdLatencies = []; + for (let i = 0; i < (latencies?.[0]?.length ?? 0); i++) { + sdLatencies.push(standardDeviation(latencies.map(a => a[i]))); } + const sd = + sdLatencies.length > 1 + ? (sdLatencies.reduce((acc, val) => acc + val, 0) / sdLatencies.length) * + 1000 + : 0; + return { - iceFoundations: JSON.stringify({ - uniqueHostOrder: Object.keys(allFoundations.host).length, - uniqueSrflxOrder: Object.keys(allFoundations.srflx).length, - sdLatencies, - }), + iceSd: sd, + iceOrder: Object.keys(foundations).length, }; } diff --git a/toolkit/components/resistfingerprinting/metrics.yaml b/toolkit/components/resistfingerprinting/metrics.yaml index 38669dde39d3..1c8d9885f2d3 100644 --- a/toolkit/components/resistfingerprinting/metrics.yaml +++ b/toolkit/components/resistfingerprinting/metrics.yaml @@ -2667,6 +2667,42 @@ characteristics: # is more like 'technical' (per the Data Review), I'm marking highly sensitive. - highly_sensitive + ice_order: + type: quantity + unit: int + description: > + Unique ICE foundations occurrence count + lifetime: application + send_in_pings: + - user-characteristics + notification_emails: + - tom@mozilla.com + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1919090 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1919090#c4 + expires: never + data_sensitivity: + - technical + + ice_sd: + type: quantity + unit: int + description: > + ICE foundation discovery latency standard deviation sum multiplied by 1000 + lifetime: application + send_in_pings: + - user-characteristics + notification_emails: + - tom@mozilla.com + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1919090 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1919090#c4 + expires: never + data_sensitivity: + - technical + pointer_height: type: quantity unit: int