如何禁用Firefox附加组件的签名检查?

cze*_*rny 41 javascript firefox signing add-on firefox-addon

从版本42开始,Firefox默认拒绝安装未签名的附加组件.如何禁用此验证?

cze*_*rny 36

只能在NightlyDeveloper频道中禁用插件验证.换句话说,在Beta版本和标准版本中不可能的.

  1. 转到about:config(将其输入地址栏)
  2. 设置xpinstall.signatures.requiredfalse.

更多信息,访问https://wiki.mozilla.org/Addons/Extension_Signing

  • Chrome之后,Firefox是第二个需要我安装开发人员版本以进行正常浏览或将我的扩展调整为TamperMonkey脚本的浏览器.顺便问一下,这是一种眼镜蛇效应问题吗? (6认同)
  • 为了清楚起见,可以在Firefox的标准版本中切换选项`xpinstall.signatures.required`(至少在51.01上),但它没有任何效果.插件仍然需要签名. (3认同)

Mak*_*yen 18

在Firefox的发行(所有)版本中禁用附加签名检查

Firefox 65+版本(左右)

以下说明将禁用Firefox中针对安装文件的Firefox配置文件的签名检查。您将在Firefox Profile目录下的chrome目录中添加一些文件。

如果javascript.enabled设置为Falsein,则此代码将不起作用about:config。该选项需要设置为True,这是默认设置。

从Firefox 69+开始,除了下面的说明之外,您还需要toolkit.legacyUserProfileCustomizations.stylesheetstruein 设置为about:config。如果它不存在,那么您将需要创建它(在右键单击上下文菜单中为“新”)作为布尔选项。有关添加此选项的更多详细信息,请参见Bugzilla 1541233

我已经在Firefox 66.0.3+上进行了测试。

升级版本的过程似乎是在未激活这些更改的情况下短暂运行浏览器代码。因此,首次运行新版本的Firefox时,将禁用所有已安装的依赖于禁用附加组件签名的扩展。升级到新的Firefox版本后,您可以立即重新安装这些扩展名,并且这些扩展名应恢复工作。

IIRC,Firefox 65需要一些稍微不同的代码,我相信当我为Firefox 66修改该代码时,我将该代码保留在disable-add-on-signing.js中,但是我不确定。

我们将使用一种技术,该技术允许您从Firefox配置文件目录中存储的文件在浏览器上下文中运行任意JavaScript代码。我从Haggai Nuchi的GitHub存储库(与Firefox Quantum兼容的userChrome.js)中找到了实现方法

在Windows上,您的Firefox配置文件目录将为%appdata%\Mozilla\Firefox\Profiles\[profileID]。如果只有一个配置文件,则[profileID]它将是目录中的唯一%appdata%\Mozilla\Firefox\Profiles目录。如果您有多个配置文件,则需要选择要将此hack安装到的配置文件。

进入个人资料目录后,您将需要创建一个名为的目录(chrome如果尚不存在)。您将以下3个文件添加到该目录:

  • userChrome.css
  • userChrome.xml
  • disable-add-on-signing.js

然后,您需要中的以下代码userChrome.css,可从Haggai Nuchi的GitHub存储库中获得以下代码:

/*Enable userChrome.js */
/* Copyright (c) 2017 Haggai Nuchi
Available for use under the MIT License:
https://opensource.org/licenses/MIT
*/

@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);

toolbarbutton#alltabs-button {
    -moz-binding: url("userChrome.xml#js");
}
Run Code Online (Sandbox Code Playgroud)

您将需要userChrome.xml(从Haggai Nuchi的GitHub存储库中可用版本进行了稍微修改):

<?xml version="1.0"?>
<!-- Copyright (c) 2017 Haggai Nuchi
Available for use under the MIT License:
https://opensource.org/licenses/MIT
 -->
<!-- This has been slightly modified from the version available from
https://github.com/nuchi/firefox-quantum-userchromejs/blob/master/userChrome.xml
by Makyen. The modified version is released under both the MIT and CC BY-SA 3.0 licenses.
 -->

<bindings id="generalBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="js" extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton-badged">
    <implementation>
        <constructor><![CDATA[
            function makeRelativePathURI(name) {
              let absolutePath = Components.stack.filename;
              return absolutePath.substring(0, absolutePath.lastIndexOf("/") + 1) + name;
            }
            // The following code executes in the browser context,
            // i.e. chrome://browser/content/browser.xul
            try {
                Services.scriptloader.loadSubScript(makeRelativePathURI("disable-add-on-signing.js"), window);
            } catch(e) {
                console.error(e);
            }
        ]]></constructor>
    </implementation>
  </binding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

您还需要disable-add-on-signing.js

//This should be installed as the file disable-add-on-signing.js in
//  your profile's "chrome" directory.

//Earlier versions of Firefox
try {
    Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {}).eval("SIGNED_TYPES.clear()");
} catch(ex) {}
try {
    Components.utils.import("resource://gre/modules/addons/XPIInstall.jsm", {}).eval("SIGNED_TYPES.clear()");
} catch(ex) {}
try {
    Components.utils.import("resource://gre/modules/addons/XPIDatabase.jsm", {}).eval("SIGNED_TYPES.clear()");
} catch(ex) {}

//Tested on Firefox 66
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
    XPIDatabase: "resource://gre/modules/addons/XPIDatabase.jsm",
});
XPIDatabase.SIGNED_TYPES.clear();

console.log('Add-on signing disabled.');
Run Code Online (Sandbox Code Playgroud)

将这些文件添加到个人资料的chrome目录中后,您将需要重新启动Firefox。您可以通过查找“禁用附加签名”来验证代码是否正在运行。在浏览器控制台中

被Firefox禁用或删除的加载项将不会自动启用。您将需要重新安装它们。您可以通过将* .xpi文件拖放到Firefox窗口并确认要安装来安装它们。

如果要从Mozilla附加组件获取任何扩展名的* .xpi文件,可以通过右键单击“安装”按钮并选择“另存为”或“删除”来下载该文件。

Firefox 57或更早版本(左右)

不幸的是,我不记得此方法在哪个版本的Firefox上停止了工作。我知道我在Firefox 54,55,52ESR和FF56。*上使用它。

我最初在此博客文章中找到了用于禁用强制加载项签名检查的解决方案,这是此答案中(经过某种程度修改的)代码的原始来源。进行这些更改将使您可以使用修改的Firefox发行版将未签名的加载项安装到配置文件中。对于大多数人来说,这将是您的主要Firefox安装。但是,如果已安装多个版本,则需要在每次安装中进行此修改。但是,一旦您进行了修改,它们将通过正常的Firefox更新保留。

您将需要在Firefox安装目录中添加几个文件。您可以在mozillaZine上找到Windows,Linux和Mac OS的安装目录示例列表。最常见的安装目录是:

  • 视窗
    • C:\ Program Files \ Mozilla Firefox \
    • C:\ Program Files(x86)\ Mozilla Firefox \
  • 的Linux
    • / usr / lib / firefox- <版本>
  • OSX
    • /Applications/Firefox.app

添加第一个文件

然后,您需要在下面添加代码作为文件<Install directory>/defaults/pref/disable-add-on-signing-prefs.js(Windows:)<Install directory>\defaults\pref\disable-add-on-signing-prefs.js

//This file should be placed in the defaults/pref directory (folder)
//within the Firefox installation directory with the with the name:
//  disable-add-on-signing-prefs.js
pref("general.config.obscure_value", 0);
pref("general.config.filename", "disable-add-on-signing.js");
Run Code Online (Sandbox Code Playgroud)

添加第二个文件

您还需要将以下代码添加为文件<Install directory>/disable-add-on-signing.js(Windows:)<Install directory>\disable-add-on-signing.js1

//This file should be placed in the Firefox installation directory
//(folder) with the with the name:
//  disable-add-on-signing.js
try {
    Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm", {})
              .eval("SIGNED_TYPES.clear()");
} catch(ex) {}
try {
    Components.utils.import("resource://gre/modules/addons/XPIInstall.jsm", {})
              .eval("SIGNED_TYPES.clear()");
} catch(ex) {}
Run Code Online (Sandbox Code Playgroud)

结果

我一直在使用这些解决方案多年,现在有我为我安装了自己用了一些扩展,并测试我的工作(扩展的新版本时,我想测试的发行版本,而不是Firefox的开发版每晚)。

注意:about:addonsFirefox中,(在某些情况下)可能显示该附件为启用状态(未变灰),但有文字指出该附件“无法验证且已被禁用”。文字不正确!加载项已启用且正在运行。

怎么运行的

resource://gre/modules/addons/XPIProvider.jsmconst SIGNED_TYPES被定义为一个Set。为了使附件需要签名,其类型必须是该成员Set。该Set.prototype.clear()方法用于清除中的所有条目Set。这样就不会产生需要签名的加载项类型(代码1代码2)。

如果你愿意,你可以单独为任何类型的禁用签名检查"webextension""extension""experiment",或"apiextension"

从任何修改的扩展名中删除META-INF目录

上面各节中的其他文件关闭了必须对扩展名进行签名的要求。如果签名文件存在,则签名仍将被验证。因此,如果您修改了一个已扩展的扩展名,但尚未删除签名文件,则该扩展名将无法通过签名验证。换句话说,实际上检查任何现有签名是与必须存在签名的要求分开的步骤。

如果您修改了已签名的扩展名(可以通过扩展名的根目录中存在META-INF目录来告诉它已签名),则需要删除签名文件。您可以通过删除META-INF目录以及该目录中包含的所有文件来执行此操作。


1.博客中的代码将此调用置于一个try{}catch(){}块中。确实没有必要这样做。这样做确实是唯一有效的就是阻止任何错误从被报道的浏览器控制台Ctrl- Shift- JCmd- Shift- J在OSX)。如果失败,则不需要运行其他代码。另外,如果此操作失败,我希望能够在浏览器控制台中看到该错误,以便知道它实际上已经失败了。如果没有,try{}catch(){}则没有任何负面影响,并且如果在某些将来的Firefox版本中,由于未签名而开始禁用加载项,则可以跟踪问题。


Irr*_*ich 5

为了完成上述答案,我发现了firefox-autoconfig,其中包括安装一个autoconfig.js文件<FIREFOX INSTALLATION DIR>/default/prefs和一个ci.clg文件,<FIREFOX INSTALLATION DIR>这种方法可以xpinstall.signatures.required在打开Firefox(经过Firefox 45.0.1测试)后确定并自动禁用(以及其他选项)。

您将在autoconfig.js以下位置看到这些内容:

//
pref("general.config.filename", "ci.cfg");
pref("general.config.obscure_value", 0);
Run Code Online (Sandbox Code Playgroud)

这些内容在ci.cfg

// Disable checking if firefox is default browser
lockPref('browser.shell.checkDefaultBrowser', false);

// Disable restoring session
lockPref('browser.sessionstore.resume_from_crash', false);

// Disable extension signature check
lockPref('xpinstall.signatures.required', false);

// Allow extensions to be installed without user prompt
pref("extensions.autoDisableScopes", 0);
pref("extensions.enabledScopes", 15);

// Disable updater
lockPref("app.update.enabled", false);
// make absolutely sure it is really off
lockPref("app.update.auto", false);
lockPref("app.update.mode", 0);
lockPref("app.update.service.enabled", false);

// Prevent closing dialogs
lockPref("browser.showQuitWarning", false);
lockPref("browser.warnOnQuit", false);
lockPref("browser.tabs.warnOnClose", false);
lockPref("browser.tabs.warnOnCloseOtherTabs", false);

// Disable Add-ons compatibility checking
clearPref("extensions.lastAppVersion");

// Don't show 'know your rights' on first run
pref("browser.rights.3.shown", true);

//Disable plugin checking
lockPref("plugins.hide_infobar_for_outdated_plugin", true);
clearPref("plugins.update.url");

// Disable health reporter
lockPref("datareporting.healthreport.service.enabled", false);

// Disable all data upload (Telemetry and FHR)
lockPref("datareporting.policy.dataSubmissionEnabled", false);

// Disable crash reporter
lockPref("toolkit.crashreporter.enabled", false);
Components.classes["@mozilla.org/toolkit/crash-reporter;1"].getService(Components.interfaces.nsICrashReporter).submitReports = false;

// Browser Console command line
pref("devtools.chrome.enabled", true);
Run Code Online (Sandbox Code Playgroud)