home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Minami 80
/
MINAMI80.iso
/
Extra
/
DivXInstaller.exe
/
$PLUGINSDIR
/
GoogleToolbarFirefox.msi
/
xpi
/
amulet-jslib
/
phishing-warden.js
< prev
next >
Wrap
Text File
|
2006-05-15
|
7KB
|
207 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"));
G_Debug(this, "isTestURL: " +
(this.isBlacklistTestURL(url) ? "yes" : "no"));
if (this.isBlacklistTestURL(url) &&
(this.phishWardenEnabled_ === true ||
this.phishWardenEnabled_ === null)) {
this.houstonWeHaveAProblem_(request);
} else if (this.phishWardenEnabled_ === true) {
if (this.checkRemote_) {
if (!this.isWhiteURL_(url)) {
G_Debug(this, "Local whitelist lookup failed");
this.fetcher_.get(url,
BindToObject(this.onTRFetchComplete,
this,
request));
} else {
G_Debug(this, "WL suppressing BL lookup for " + url);
}
} else {
if (this.checkUrl(url)) {
this.houstonWeHaveAProblem_(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.checkUrl = function(url) {
G_Debug(this, "Checking URL for " + url);
if (this.isEvilURL_(url) || this.isBlacklistTestURL(url)) {
G_Debug(this, "Local blacklist hit");
(new PROT_Reporter).report("phishblhit", url);
return true;
}
G_Debug(this, "Local blacklist miss");
return false;
}
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 blackURLs = [
"http://foo.com/1",
"http://foo.com/2",
"http://foo.com/3",
"http://foo.com/4",
];
for (var i = 0; i < blackURLs.length; i++)
listManager.safeInsert("test-black-url", blackURLs[i], "1");
G_Assert(z, !warden.checkUrl("http://bar.com/"),
"bar.com should not be found");
for (var i = 0; i < blackURLs.length; i++) {
G_Assert(z, warden.checkUrl(blackURLs[i]),
blackURLs[i] + " not found");
}
for (var i = 0; i < blackURLs.length; i++)
listManager.safeErase("test-black-url", blackURLs[i]);
G_Debug(z, "PASSED");
}
}