home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Minami 83
/
MINAMI83.iso
/
Extra
/
DivXInstaller.exe
/
$PLUGINSDIR
/
GoogleToolbarFirefox.msi
/
xpi
/
amulet-jslib
/
phishing-warden.js
< prev
next >
Wrap
Text File
|
2006-08-07
|
7KB
|
223 lines
function PROT_PhishingWarden(listManager, opt_testing) {
PROT_ListWarden.call(this, listManager);
this.debugZone = "phishwarden";
this.testing_ = !!opt_testing;
this.browserViews_ = [];
this.prefs_ = new G_Preferences();
this.displayers_ = {
"afterload": PROT_PhishMsgDisplayer,
};
this.fetcher_ = new PROT_TRFetcher();
if (!this.testing_) {
this.navWatcher_ = new G_NavWatcher(true /* filter spurious navs */);
this.navWatcher_.registerListener("docnavstart",
BindToObject(this.onDocNavStart,
this));
}
var checkRemotePrefName = PROT_globalStore.getServerCheckEnabledPrefName();
this.checkRemote_ = this.prefs_.getPref(checkRemotePrefName, null);
var checkRemotePrefObserver = BindToObject(this.onCheckRemotePrefChanged,
this);
this.prefs_.addObserver(checkRemotePrefName, checkRemotePrefObserver);
var phishWardenPrefName = PROT_globalStore.getPhishWardenEnabledPrefName();
this.phishWardenEnabled_ = this.prefs_.getPref(phishWardenPrefName, null);
var phishWardenPrefObserver =
BindToObject(this.onPhishWardenEnabledPrefChanged, this);
this.prefs_.addObserver(phishWardenPrefName, phishWardenPrefObserver);
this.testURLs_ = PROT_globalStore.getTestURLs();
this.registerWhiteTable("goog-white-domain");
this.registerWhiteTable("goog-white-url");
this.registerBlackTable("goog-black-url");
this.registerBlackTable("goog-black-enchash");
this.maybeToggleUpdateChecking();
}
PROT_PhishingWarden.inherits(PROT_ListWarden);
PROT_PhishingWarden.prototype.maybeToggleUpdateChecking = function() {
if (this.testing_)
return;
var checkRemotePrefName = PROT_globalStore.getServerCheckEnabledPrefName();
this.checkRemote_ = this.prefs_.getPref(checkRemotePrefName, null);
var phishWardenPrefName = PROT_globalStore.getPhishWardenEnabledPrefName();
var phishWardenEnabled = this.prefs_.getPref(phishWardenPrefName, null);
G_Debug(this, "Maybe toggling update checking. " +
"Check remote? " + this.checkRemote_ + " " +
"Warden enabled? " + phishWardenEnabled);
if (phishWardenEnabled === null || this.checkRemote_ === null)
return;
if (phishWardenEnabled === true) {
this.enableWhitelistTableUpdates();
if (this.checkRemote_ === true) {
this.disableBlacklistTableUpdates();
} else if (this.checkRemote_ === false) {
this.enableBlacklistTableUpdates();
}
} else if (phishWardenEnabled === false) {
this.disableBlacklistTableUpdates();
this.disableWhitelistTableUpdates();
}
}
PROT_PhishingWarden.prototype.addBrowserView = function(view) {
G_Debug(this, "New browser view registered.");
this.browserViews_.push(view);
}
PROT_PhishingWarden.prototype.removeBrowserView = function(view) {
for (var i = 0; i < this.browserViews_.length; i++)
if (this.browserViews_[i] === view) {
G_Debug(this, "Browser view unregistered.");
this.browserViews_.splice(i, 1);
return;
}
G_Assert(this, false, "Tried to unregister non-existent browser view!");
}
PROT_PhishingWarden.prototype.onCheckRemotePrefChanged = function(prefName) {
this.checkRemote_ = this.prefs_.getBoolPrefOrDefault(prefName,
this.checkRemote_);
this.maybeToggleUpdateChecking();
}
PROT_PhishingWarden.prototype.onPhishWardenEnabledPrefChanged = function(
prefName) {
this.phishWardenEnabled_ =
this.prefs_.getBoolPrefOrDefault(prefName, this.phishWardenEnabled_);
this.maybeToggleUpdateChecking();
}
PROT_PhishingWarden.prototype.onDocNavStart = function(e) {
var url = e.url;
var request = e.request;
G_Debug(this, "phishWarden: " +
(this.phishWardenEnabled_ ? "enabled" : "disabled"));
G_Debug(this, "checkRemote: " +
(this.checkRemote_ ? "yes" : "no"));
if (this.phishWardenEnabled_ === false)
return;
if (this.isBlacklistTestURL(url)) {
this.houstonWeHaveAProblem_(request);
}
if (this.phishWardenEnabled_ === null)
return;
if (this.checkRemote_) {
var maybeRemoteCheck = BindToObject(this.maybeMakeRemoteCheck_,
this,
url,
request);
this.isWhiteURL(url, maybeRemoteCheck);
} else {
var maybeEvilCallback = BindToObject(this.localBlacklistMatch_,
this,
url,
request);
this.isEvilURL(url, maybeEvilCallback);
}
}
PROT_PhishingWarden.prototype.maybeMakeRemoteCheck_ = function(url, request, status) {
if (PROT_ListWarden.IN_WHITELIST == status)
return;
G_Debug(this, "Local whitelist lookup failed");
this.fetcher_.get(url,
BindToObject(this.onTRFetchComplete,
this,
request));
}
PROT_PhishingWarden.prototype.onTRFetchComplete = function(request,
trValues) {
var callback = BindToObject(this.houstonWeHaveAProblem_, this, request);
this.checkRemoteData(callback, trValues);
}
PROT_PhishingWarden.prototype.houstonWeHaveAProblem_ = function(request) {
if (this.maybeLocateProblem_(request)) // Cases 1 and 2 (see below)
return;
if (request.isPending()) { // Case 3
G_Debug(this, "Can't find problem Doc; Req pending. Retrying.");
new G_Alarm(BindToObject(this.houstonWeHaveAProblem_,
this,
request),
200 /*ms*/);
} else { // Case 4
G_Debug(this,
"Can't find problem Doc; Req completed. Retrying at most twice.");
new G_ConditionalAlarm(BindToObject(this.maybeLocateProblem_,
this,
request),
0 /* next event loop */,
true /* repeat */,
2 /* at most twice */);
}
}
PROT_PhishingWarden.prototype.maybeLocateProblem_ = function(request) {
G_Debug(this, "Trying to find the problem.");
for (var i = 0; i < this.browserViews_.length; i++)
if (this.browserViews_[i].tryToHandleProblemRequest(this, request)) {
G_Debug(this, "Found browser view willing to handle problem!");
return true;
}
return false;
}
PROT_PhishingWarden.prototype.isBlacklistTestURL = function(url) {
for (var i = 0, testURL = null; testURL = this.testURLs_[i]; ++i) {
if (testURL === url) {
return true;
}
}
return false;
}
PROT_PhishingWarden.prototype.localBlacklistMatch_ = function(url, request, status) {
if (PROT_ListWarden.IN_BLACKLIST != status)
return;
G_Debug(this, "Local blacklist hit");
(new PROT_Reporter).report("phishblhit", url);
this.houstonWeHaveAProblem_(request);
}
PROT_PhishingWarden.prototype.checkRemoteData = function(callback,
trValues) {
if (!trValues) {
G_Debug(this, "Didn't get TR values from the server.");
return;
}
G_Debug(this, "Page has phishiness " + trValues["phishy"]);
if (trValues["phishy"] == 1) { // It's on our blacklist
G_Debug(this, "Remote blacklist hit");
callback(this);
} else {
G_Debug(this, "Remote blacklist miss");
}
}
function TEST_PROT_PhishingWarden() {
if (G_GDEBUG) {
var z = "phishwarden UNITTEST";
G_debugService.enableZone(z);
G_Debug(z, "Starting");
var listManager = new PROT_ListManager(true /* testing */);
var warden = new PROT_PhishingWarden(listManager, true /* testing */);
warden.registerBlackTable("test-black-url");
var dbservice = Cc["@google.com/dbupdateservice;1"]
.getService(Ci.GTBIDbUpdateService);
var blackURLs = [
"http://foo.com/1",
"http://foo.com/2",
"http://foo.com/3",
"http://foo.com/4",
];
var data = "[test-black-url 1.1]\n";
for (var i = 0; i < blackURLs.length; i++)
data += "+" + blackURLs[i] + "\t1\n";
function checkTables(tableVersion) {
if (tableVersion != "[test-black-url 1.1]")
G_Error(z, "incorrect table version");
G_Debug(z, "checking tables");
function isNotEvil(status) {
G_Assert(z, PROT_ListWarden.IN_BLACKLIST != status,
"should not be in black list");
}
var count = 0;
function isEvil(status) {
G_Assert(z, PROT_ListWarden.IN_BLACKLIST == status,
"should be in black list");
}
warden.isEvilURL("http://bar.com/", isNotEvil);
for (var i = 0; i < blackURLs.length; i++) {
warden.isEvilURL(blackURLs[i], isEvil);
}
}
dbservice.updateTables(data, checkTables);
}
}