2007-08-09 15:11:22 -07:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is Google Safe Browsing.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Google Inc.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Dave Camp <dcamp@mozilla.com>
|
|
|
|
# Fritz Schneider <fritz@google.com> (original phishing-warden.js author)
|
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
|
|
|
// This warden manages updates to the malware list
|
|
|
|
|
|
|
|
const kMalwareWardenEnabledPref = "browser.safebrowsing.malware.enabled";
|
|
|
|
|
|
|
|
function PROT_MalwareWarden() {
|
|
|
|
PROT_ListWarden.call(this);
|
|
|
|
|
|
|
|
this.debugZone = "malwarewarden";
|
|
|
|
|
|
|
|
// Use this to query preferences
|
|
|
|
this.prefs_ = new G_Preferences();
|
|
|
|
|
|
|
|
// Global preference to enable the malware warden
|
|
|
|
this.malwareWardenEnabled_ =
|
|
|
|
this.prefs_.getPref(kMalwareWardenEnabledPref, null);
|
|
|
|
|
|
|
|
// Get notifications when the malware warden enabled pref changes
|
|
|
|
var malwareWardenPrefObserver =
|
|
|
|
BindToObject(this.onMalwareWardenEnabledPrefChanged, this);
|
|
|
|
this.prefs_.addObserver(kMalwareWardenEnabledPref, malwareWardenPrefObserver);
|
|
|
|
|
|
|
|
// Add a test chunk to the database
|
|
|
|
var testData = "mozilla.com/firefox/its-an-attack.html";
|
|
|
|
|
|
|
|
var testUpdate =
|
|
|
|
"n:1000\ni:test-malware-simple\nad:1\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:1:32:" + testData.length + "\n" +
|
|
|
|
testData;
|
2007-10-29 11:29:14 -07:00
|
|
|
|
|
|
|
testData = "mozilla.com/firefox/its-a-trap.html";
|
|
|
|
testUpdate +=
|
|
|
|
"n:1000\ni:test-phish-simple\nad:1\n" +
|
2008-01-29 12:57:18 -08:00
|
|
|
"a:1:32:" + testData.length + "\n" +
|
|
|
|
testData;
|
2007-08-09 15:11:22 -07:00
|
|
|
|
|
|
|
var dbService_ = Cc["@mozilla.org/url-classifier/dbservice;1"]
|
|
|
|
.getService(Ci.nsIUrlClassifierDBService);
|
|
|
|
|
2008-01-12 14:22:03 -08:00
|
|
|
var listener = {
|
|
|
|
QueryInterface: function(iid)
|
|
|
|
{
|
|
|
|
if (iid.equals(Ci.nsISupports) ||
|
|
|
|
iid.equals(Ci.nsIUrlClassifierUpdateObserver))
|
|
|
|
return this;
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
updateUrlRequested: function(url) { },
|
2008-04-11 10:26:03 -07:00
|
|
|
streamFinished: function(status) { },
|
2008-01-12 14:22:03 -08:00
|
|
|
updateError: function(errorCode) { },
|
|
|
|
updateSuccess: function(requestedTimeout) { }
|
|
|
|
};
|
|
|
|
|
2008-01-23 11:30:54 -08:00
|
|
|
try {
|
2008-04-15 15:39:44 -07:00
|
|
|
dbService_.beginUpdate(listener,
|
|
|
|
"test-malware-simple,test-phish-simple", "");
|
2008-02-27 00:51:02 -08:00
|
|
|
dbService_.beginStream("", "");
|
2008-01-23 11:30:54 -08:00
|
|
|
dbService_.updateStream(testUpdate);
|
|
|
|
dbService_.finishStream();
|
|
|
|
dbService_.finishUpdate();
|
|
|
|
} catch(ex) {
|
|
|
|
// beginUpdate will throw harmlessly if there's an existing update
|
|
|
|
// in progress, ignore failures.
|
|
|
|
}
|
2007-08-09 15:11:22 -07:00
|
|
|
G_Debug(this, "malwareWarden initialized");
|
|
|
|
}
|
|
|
|
|
|
|
|
PROT_MalwareWarden.inherits(PROT_ListWarden);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup on shutdown.
|
|
|
|
*/
|
|
|
|
PROT_MalwareWarden.prototype.shutdown = function() {
|
|
|
|
this.prefs_.removeAllObservers();
|
|
|
|
|
|
|
|
this.listManager_ = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When a preference changes, we might have to start or stop asking for
|
|
|
|
* updates.
|
|
|
|
*/
|
|
|
|
PROT_MalwareWarden.prototype.maybeToggleUpdateChecking = function() {
|
|
|
|
var malwareWardenEnabled = this.prefs_.getPref(kMalwareWardenEnabledPref,
|
|
|
|
null);
|
|
|
|
|
|
|
|
G_Debug(this, "Maybe toggling update checking. " +
|
|
|
|
"Warden enabled? " + malwareWardenEnabled);
|
|
|
|
|
|
|
|
// Do nothing unless thre pref is set
|
|
|
|
if (malwareWardenEnabled === null)
|
|
|
|
return;
|
|
|
|
|
2008-02-08 20:50:16 -08:00
|
|
|
// We update and save to disk all tables
|
2007-08-09 15:11:22 -07:00
|
|
|
if (malwareWardenEnabled === true) {
|
|
|
|
this.enableBlacklistTableUpdates();
|
|
|
|
} else {
|
|
|
|
// Anti-malware is off, disable table updates
|
|
|
|
this.disableBlacklistTableUpdates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deal with a user changing the pref that says whether we should
|
|
|
|
* enable the malware warden.
|
|
|
|
*
|
|
|
|
* @param prefName Name of the pref holding the value indicating whether
|
|
|
|
* we should enable the malware warden
|
|
|
|
*/
|
|
|
|
PROT_MalwareWarden.prototype.onMalwareWardenEnabledPrefChanged = function(
|
|
|
|
prefName) {
|
|
|
|
// Just to be safe, ignore changes to sub prefs.
|
|
|
|
if (prefName != kMalwareWardenEnabledPref)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.malwareWardenEnabled_ =
|
|
|
|
this.prefs_.getPref(prefName, this.malwareWardenEnabled_);
|
|
|
|
this.maybeToggleUpdateChecking();
|
|
|
|
}
|