Skip to content

Commit

Permalink
feat: add font loading to panopticon (#16)
Browse files Browse the repository at this point in the history
* feat: add font loading to panopticon

* fix: types

* feat: extra records

* fix: types
  • Loading branch information
fouwels authored Dec 30, 2023
1 parent e92e200 commit 43f667f
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions lib/exp/panopticon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,52 @@ export interface fingerprint {
legacyAppVersion: string | undefined
legacyProductSub: string | undefined
legacyVendor: string | undefined
mediaDevices: string[] | undefined
mediaDevices: MediaDeviceInfo[] | undefined
networkInfo: NetworkInformation | undefined
fontData: FontData[] | undefined
}
}

// https://wicg.github.io/netinfo/#-dfn-networkinformation-dfn-interface
interface NetworkInformation {
type: string
effectiveType: string
downlinkMax: string
downlink: string
rtt: string
};

// https://wicg.github.io/netinfo/#-dfn-networkinformation-dfn-interface
interface FontData {
postscriptName: string
fullName: string
family: string
style: string
}

// Get user's fingerprint
export async function Inspect (): Promise<fingerprint> {
const gl = document.createElement('canvas').getContext('webgl')
const ext = gl?.getExtension('WEBGL_debug_renderer_info')

let fontData: FontData[] | undefined
try {
// https://wicg.github.io/local-font-access/
const localFonts = await (window as any).queryLocalFonts()
fontData = localFonts !== undefined ? localFonts as FontData[] : undefined
} catch (e: any) {
console.debug('exp::Inspect: failed to grab local fonts:' + String(e))
}

let networkInfo: NetworkInformation | undefined
try {
// https://wicg.github.io/netinfo/#-dfn-networkinformation-dfn-interface
const connection = (navigator as any).connection
networkInfo = connection !== undefined ? connection as NetworkInformation : undefined
} catch (e: any) {
console.debug('exp::Inspect: failed to get NetworkInformation:' + JSON.stringify(e))
}

const records = {
userAgent: navigator.userAgent,
timeIANA: Intl.DateTimeFormat().resolvedOptions().timeZone,
Expand All @@ -58,14 +95,16 @@ export async function Inspect (): Promise<fingerprint> {
webGLRenderer: gl?.getParameter(WebGLRenderingContext.RENDERER),
webGLHwVendor: ext !== undefined && ext !== null ? gl?.getParameter(ext.UNMASKED_VENDOR_WEBGL) : undefined,
webGLHwRender: ext !== undefined && ext !== null ? gl?.getParameter(ext.UNMASKED_RENDERER_WEBGL) : undefined,
webGLExtensions: gl?.getSupportedExtensions()?.join(' '),
webGLExtensions: gl?.getSupportedExtensions() !== undefined ? 'sha256-' + Buffer.from(await crypto.subtle.digest('SHA-256', (new TextEncoder()).encode(gl?.getSupportedExtensions()?.join(' ')))).toString('base64') : undefined,
featurePDF: navigator.pdfViewerEnabled,
featureDoNotTrack: navigator.doNotTrack !== null ? navigator.doNotTrack : undefined,
featureCookies: navigator.cookieEnabled,
legacyAppVersion: navigator.appVersion !== '' ? navigator.appVersion : undefined,
legacyProductSub: navigator.productSub !== '' ? navigator.productSub : undefined,
legacyVendor: navigator.vendor !== '' ? navigator.vendor : undefined,
mediaDevices: (await navigator.mediaDevices.enumerateDevices()).map((x) => `${x.deviceId} ${x.groupId} ${x.kind} ${x.label}`)
mediaDevices: (await navigator.mediaDevices.enumerateDevices()).filter(x => x.deviceId !== '' || x.groupId !== '' || x.label !== ''),
networkInfo,
fontData
}

const values = Object.values(records).toString()
Expand Down

0 comments on commit 43f667f

Please sign in to comment.