gpt4 book ai didi

javascript - 是否可以在 Firefox 中自动导入证书?

转载 作者:行者123 更新时间:2023-11-30 00:08:22 26 4
gpt4 key购买 nike

在 Linux 上部署 Firefox 时,是否可以使用类似于自动配置的方式自动导入证书?

我四处搜索了一下,找到了一些相关说明,但它们似乎都已过时。

最佳答案

这是可能的,并且在任何支持的平台(包括 Linux)上都一样。

你主要有两种可能:

使用https://mike.kaply.com/cck2/

这是一个 Firefox 扩展,您可以使用它来自定义 Firefox 中的许多内容(包括添加 CA 证书)。它会生成一个 zip 文件,您可以将其部署在 Firefox 安装目录(类似于 Linux 上的/usr/lib/firefox)之上。这可能是最简单的方法。

使用自动配置

我用它在公司环境中部署 CA 证书(未使用其他类型的证书进行测试)。它还允许进行您需要的任何自定义。

首先,您需要配置一个自动配置文件,参见https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment#Configuration了解如何做到这一点。

然后,您需要将您的证书文件放入 defaults/pref 子目录(例如:/usr/lib/firefox/defaults/pref),将下面的函数放入您的自动配置文件中,并调用它:

// This imports a root certificate into Firefox
// The certificate has to be in defaults/pref directory of Firefox
// Source : http://xulfr.org/forums/read.php?1,8256
function importCert(certFileName) {
var BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
var END_CERT = "-----END CERTIFICATE-----";

var x509certdb = Components.classes["@mozilla.org/security/x509certdb;1"];
var certDB ;
try {
// For Firefox <=32
certDB = x509certdb.getService(Components.interfaces.nsIX509CertDB2);
}
catch (exc) {
// For Firefox >=33
certDB = x509certdb.getService(Components.interfaces.nsIX509CertDB);
}

var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);

var scriptableStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
.getService(Components.interfaces.nsIScriptableInputStream);


// https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Getting_special_files
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var certFile = FileUtils.getFile("PrfDef", [certFileName]);

// http://www.mozilla.org/projects/security/pki/nss/tools/certutil.html
var trustFlags = "C,C,C";

var channel = ioService.newChannelFromURI(ioService.newFileURI(certFile));
var input = channel.open();
scriptableStream.init(input);
var certfile = scriptableStream.read(input.available());
scriptableStream.close();
input.close();

certfile = certfile.replace(/[\r\n]/g, "");
begin = certfile.indexOf(BEGIN_CERT);
end = certfile.indexOf(END_CERT);
cert = certfile.substring(begin + BEGIN_CERT.length, end);

certDB.addCertFromBase64(cert, trustFlags, "");
}
importCert("myCert.pem");

您的证书需要采用 ASCII Base64 X509 格式(以 -----BEGIN CERTIFICATE----- 开头的文本文件)。

关于javascript - 是否可以在 Firefox 中自动导入证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37553127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com