2016-05-31 84 views

回答

1

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

你主要有两种可能性:

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

这是一个Firefox扩展,你可以用它来定制在Firefox中很多东西(包括添加CA证书)。它会生成一个在Firefox安装目录上部署的zip文件(类似于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开头的文本文件-----)。

相关问题