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

Added option to store data for persistent rng.

Fixes #102.
This commit is contained in:
kkapsner 2017-02-10 17:37:35 +01:00
parent 3b14e56537
commit a8611230b1
7 changed files with 99 additions and 8 deletions

View File

@ -1,3 +1,21 @@
setting[pref-name="rng"] {
border-bottom: 0px transparent none;
padding-top: 0.5em;
}
setting[pref-name="storePersistentRnd"]{
border-top: 0px transparent none;
border-bottom: 0px transparent none;
}
setting[pref-name="persistentRndStorage"]{
border-top: 0px transparent none;
border-bottom: 0px transparent none;
display: none;
}
setting[pref-name="clearPersistentRnd"]{
border-top: 0px transparent none;
border-bottom: 0px transparent none;
}
setting[pref-name="showNotifications"] { setting[pref-name="showNotifications"] {
border-bottom: 0px transparent none; border-bottom: 0px transparent none;
padding-top: 0.5em; padding-top: 0.5em;

View File

@ -39,18 +39,49 @@
}); });
// persistent rng // persistent rng
const persistentRnd = Object.create(null); var persistentRnd = Object.create(null);
try {
let storedData = JSON.parse(prefs.persistentRndStorage);
for (var domain in storedData){
var value = storedData[domain];
if (
Array.isArray(value) &&
value.length === 128 &&
value.every(function(value){return typeof value === "number" && value >= 0 && value < 256;})
){
persistentRnd[domain] = value;
}
}
}
catch(e){}
processes.port.on("canvasBlocker-new-domain-rnd", function(process, data){ processes.port.on("canvasBlocker-new-domain-rnd", function(process, data){
processes.port.emit("canvasBlocker-set-domain-rnd", data); processes.port.emit("canvasBlocker-set-domain-rnd", data);
persistentRnd[data.domain] = data.rnd; persistentRnd[data.domain] = data.rnd;
if (prefs.storePersistentRnd){
prefs.persistentRndStorage = JSON.stringify(persistentRnd);
}
}); });
processes.on("attach", function(process){ processes.forEvery(function(process){
if (process.isRemote){ if (process.isRemote){
for (var name in persistentRnd){ for (var domain in persistentRnd){
process.port.emit("canvasBlocker-set-domain-rnd", {domain: name, rnd: persistentRnd[name]}); process.port.emit("canvasBlocker-set-domain-rnd", {domain, rnd: persistentRnd[domain]});
} }
} }
}); });
preferences.on("storePersistentRnd", function(){
if (prefs.storePersistentRnd){
prefs.persistentRndStorage = JSON.stringify(persistentRnd);
}
else {
prefs.persistentRndStorage = "";
}
});
preferences.on("clearPersistentRnd", function(){
persistentRnd = Object.create(null);
prefs.persistentRndStorage = "";
processes.port.emit("canvasBlocker-clear-domain-rnd");
});
// show release notes // show release notes
var data = require("sdk/self").data; var data = require("sdk/self").data;

View File

@ -17,19 +17,23 @@
return window.location.host; return window.location.host;
} }
const getPersistentRnd = (function(){ const getPersistentRnd = (function(){
var persistentRnd = Object.create(null);
const {process} = require("sdk/remote/child"); const {process} = require("sdk/remote/child");
process.port.on("canvasBlocker-set-domain-rnd", function(process, {domain, rnd}){ process.port.on("canvasBlocker-set-domain-rnd", function(process, {domain, rnd}){
persistentRnd[domain] = new Uint8Array(rnd); persistentRnd[domain] = new Uint8Array(rnd);
}); });
process.port.on("canvasBlocker-clear-domain-rnd", function(){
persistentRnd = Object.create(null);
});
const persistentRnd = Object.create(null);
return function getPersistentRnd(window){ return function getPersistentRnd(window){
var domain = getDomain(window); var domain = getDomain(window);
if (!persistentRnd[domain]){ if (!persistentRnd[domain]){
// create the (sub-)domains random numbers if not existing // create the (sub-)domains random numbers if not existing
persistentRnd[domain] = new Uint8Array(128); persistentRnd[domain] = new Uint8Array(128);
window.crypto.getRandomValues(persistentRnd[domain]); window.crypto.getRandomValues(persistentRnd[domain]);
process.port.emit("canvasBlocker-new-domain-rnd", {domain, rnd: persistentRnd[domain]}); process.port.emit("canvasBlocker-new-domain-rnd", {domain, rnd: Array.from(persistentRnd[domain])});
} }
return persistentRnd[domain]; return persistentRnd[domain];
} }

View File

@ -32,6 +32,16 @@
"rng_options.non persistent": "nicht persistent", "rng_options.non persistent": "nicht persistent",
"rng_title": "Zufallszahlengenerator", "rng_title": "Zufallszahlengenerator",
"persistentRndStorage_title": "Persistenter Speicher",
"persistentRndStorage_description": "Speichert die Informationen für den persistenten Zufallszahlengenerator über einen Neustart hinweg.",
"storePersistentRnd_title": "Persistente Daten speichern",
"storePersistentRnd_description": "Ob Daten für den persistenten Zufallszahlengenerator gespeichert werden sollen.",
"clearPersistentRnd_title": "Persistenten Speicher leeren",
"clearPersistentRnd_description": "Löscht alle Daten für den persistenten Zufallszahlengenerator.",
"clearPersistentRnd_label": "Leeren",
"disableNotifications": "Benachrichtigungen deaktivieren", "disableNotifications": "Benachrichtigungen deaktivieren",
"displayCallingStack": "Aufrufestack anzeigen", "displayCallingStack": "Aufrufestack anzeigen",
"displayFullURL": "URL anzeigen", "displayFullURL": "URL anzeigen",

View File

@ -29,9 +29,19 @@
"rng_description": "", "rng_description": "",
"rng_options.persistent": "persistent", "rng_options.persistent": "persistent",
"rng.non persistent": "non persistent", "rng_options.non persistent": "non persistent",
"rng_title": "Random number generator", "rng_title": "Random number generator",
"persistentRndStorage_title": "Persistent storage",
"persistentRndStorage_description": "Stores the data for the persistent random number generator for usage after restart.",
"storePersistentRnd_title": "Store persistent data",
"storePersistentRnd_description": "If data for the persistent random number generator should be stored.",
"clearPersistentRnd_title": "Clear persistent random storage",
"clearPersistentRnd_description": "Deletes all data for the persistent random number generator.",
"clearPersistentRnd_label": "Clear",
"disableNotifications": "disable notifications", "disableNotifications": "disable notifications",
"displayCallingStack": "display calling stack", "displayCallingStack": "display calling stack",
"displayFullURL": "display full URL", "displayFullURL": "display full URL",

View File

@ -94,6 +94,24 @@
} }
] ]
}, },
{
"name": "persistentRndStorage",
"title": "Persistent storage",
"type": "string",
"value": ""
},
{
"name": "storePersistentRnd",
"title": "Store persistent data",
"type": "bool",
"value": false
},
{
"name": "clearPersistentRnd",
"title": "Clear persistent random storage",
"type": "control",
"label": "Clear"
},
{ {
"name": "askOnlyOnce", "name": "askOnlyOnce",
"title": "Ask only once", "title": "Ask only once",

View File

@ -3,7 +3,7 @@ Version 0.3.7:
- -
new features: new features:
- - data for persistent random number generator can be stored
fixes: fixes:
- fake at input was broken - fake at input was broken