1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-23 05:10:27 +01:00
CanvasBlocker/test/settingsLoading.php

78 lines
2.5 KiB
PHP
Raw Normal View History

2017-12-12 21:56:22 +01:00
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
2019-02-20 08:13:37 +01:00
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="testIcon.svg" type="image/png" rel="icon">
<link href="testIcon.svg" type="image/png" rel="shortcut icon">
2017-12-12 21:56:22 +01:00
<script>
console.log(new Date(), "starting first fingerprint", window.name);
2017-12-13 20:08:53 +01:00
function fingerPrint(){
"use strict";var canvas = document.createElement("canvas");
canvas.setAttribute("width", 220);
canvas.setAttribute("height", 30);
var fp_text = "BrowserLeaks,com <canvas> 10";
var ctx = canvas.getContext("2d");
ctx.textBaseline = "top";
ctx.font = "14px 'Arial'";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#f60";
ctx.fillRect(125, 1, 62, 20);
ctx.fillStyle = "#069";
ctx.fillText(fp_text, 2, 15);
ctx.fillStyle = "rgba(102, 204, 0, 07)";
ctx.fillText(fp_text, 4, 17);
return canvas.toDataURL();
}
function hash(url){
var buffer = new TextEncoder("utf-8").encode(url);
return crypto.subtle.digest("SHA-256", buffer).then(function(hash){
var chunks = [];
(new Uint32Array(hash)).forEach(function(num){
chunks.push(num.toString(16));
});
return chunks.map(function(chunk){
return "0".repeat(8 - chunk.length) + chunk;
}).join("");
});
}
2017-12-12 21:56:22 +01:00
try {
2017-12-13 20:08:53 +01:00
var firstFingerprint = fingerPrint();
2017-12-12 21:56:22 +01:00
}
catch (e){
2017-12-13 20:08:53 +01:00
console.log(new Date(), e);
var firstFingerprint = false;
2017-12-12 21:56:22 +01:00
}
</script>
</head>
<body>
<script>
2017-12-13 20:08:53 +01:00
if (firstFingerprint){
document.body.textContent = "context API not blocked";
window.setTimeout(function(){
console.log(new Date(), "starting second fingerprint", window.name);
2017-12-13 20:08:53 +01:00
document.body.appendChild(document.createElement("br"));
2017-12-18 23:17:55 +01:00
var secondFingerprint = fingerPrint();
2017-12-13 20:08:53 +01:00
if (firstFingerprint === secondFingerprint){
hash(firstFingerprint).then(function(hash){
document.body.appendChild(document.createTextNode("fingerprint consistent (" + hash + ") -> good!"));
document.body.style.backgroundColor = "green";
2017-12-13 20:08:53 +01:00
});
}
else {
Promise.all([hash(firstFingerprint), hash(secondFingerprint)]).then(function(hashes){
document.body.appendChild(document.createTextNode("fingerprint not consistent (" + hashes[0] + " != " + hashes[1] + ") -> very bad! (potential fingerprint leak)"));
document.body.style.backgroundColor = "red";
});
}
}, 500);
}
else {
document.body.textContent = "context API blocked";
document.body.style.backgroundColor = "orange";
2017-12-13 20:08:53 +01:00
}
2017-12-12 21:56:22 +01:00
</script>
</body></html>