I tried writing some simple code to do the random overwriting, but for some reason Firefox doesn't overwrite the file, instead it creates "File-1" and writes the random data to it, but doesn't seem to overwrite the original file. Here's what I did:
function removeFile(path) {
var fileobj = Components.classes[NS_LOCALEFILE_CONTRACTID].
createInstance(Components.interfaces.nsILocalFile);
fileobj.initWithPath(path);
var stream = Components.classes["@mozilla.org/network/safe-file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
stream.init(fileobj, WRITE_MODE, WRITE_PERMISSION, 0); // write, no creation or truncation because it should overwrite the existing data
var randombytes;
// Create a string of 4096 bytes for speed, Math.random + multiply +
// floor is almost certainly too slow for large files. Overwriting
// with repeating random data is sufficient to prevent most data
// recovery
for(var i=0;i<4096;i++) randombytes += String.fromCharCode(Math.floor(Math.random()*256));
var filesize = fileobj.fileSize;
alert(fileobj.path);
for(i=0;i<filesize;i+=4096) {
stream.write(randombytes, randombytes.length);
}
stream.close();
alert("wait");
try {
fileobj.remove(path);
}
catch (e) {
alert(path);
// If file dosen't exist
}
}
I don't write javascript very much, and this is the first time I've done anything with the Mozilla file and stream libraries, so it may just be a problem with how I wrote it. The alert(fileobj.path) and alert("wait") are in there for debugging. When alert(fileobj.path) runs, it prints /tmp/1182238476247fgpg_tmpFile, but if I look in /tmp I also see /tmp/1182238476247fgpg_tmpFile-1 which actually gets the random bytes written to it, and the original file stays the same. At the alert("wait") line, the -1 file is gone but the original file still has the original data and is not random.
I've tried a couple combinations of values for WRITE_MODE including just 0x02 to open the file write only, since truncating it may deallocate the sectors and the random bytes might get allocated to different ones. I suppose I could write a shell script and batch file that do the secure wiping, but it would require a special utility for Windows and would rely on having dd and /dev/urandom on Linux, which isn't very cross platform. I could also write a C program that would compile on Windows and Linux to do a simple wipe, but I don't know if the project wants to start collecting stuff written in other languages.