Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Fix blank cert page on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Dec 22, 2015
1 parent 4cbe61d commit 2fef8bb
Showing 1 changed file with 81 additions and 73 deletions.
154 changes: 81 additions & 73 deletions ant/firefox/firefox-config.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,87 +7,95 @@
//# For questions please visit ${vendor.website}/support #
//##############################################################################

// Get NSS certdb object
var certdb = getCertDB();

if (needsUninstall()) {
deleteCertificate();
} else if (needsCert()) {
deleteCertificate();
installCertificate();
}
var observer = {
observe: function observe(aSubject, aTopic, aData) {
// Get NSS certdb object
var certdb = getCertDB();

// Compares the timestamp embedded in this script against that stored in the browser's about:config
function needsCert() {
try {
return getPref("${build.socket.name}.installer.timestamp") != getInstallerTimestamp();
} catch (notfound) {}
return true;
}
if (needsUninstall()) {
deleteCertificate();
} else if (needsCert()) {
deleteCertificate();
installCertificate();
}

// Installs the embedded base64 certificate into the browser
function installCertificate() {
certdb.addCertFromBase64(getCertData(), "C,C,C", "${commonName} - ${vendor.company}");
pref("${build.socket.name}.installer.timestamp", getInstallerTimestamp());
}
// Compares the timestamp embedded in this script against that stored in the browser's about:config
function needsCert() {
try {
return getPref("${build.socket.name}.installer.timestamp") != getInstallerTimestamp();
} catch (notfound) {}
return true;
}

// Deletes the certificate, if it exists
function deleteCertificate() {
var nick1 = "${commonName} - ${vendor.company}";
var nick2 = "${commonName} - ${vendor.company} #2";
if (certExists(nick1)) {
certdb.deleteCertificate(certdb.findCertByNickname(null, nick1));
}
if (certExists(nick2)) {
certdb.deleteCertificate(certdb.findCertByNickname(null, nick2));
}

// Mark as removed
if (!certExists(nick1) && !certExists(nick2)) {
pref("${build.socket.name}.installer.timestamp", "-1");
}
}
// Installs the embedded base64 certificate into the browser
function installCertificate() {
certdb.addCertFromBase64(getCertData(), "C,C,C", "${commonName} - ${vendor.company}");
pref("${build.socket.name}.installer.timestamp", getInstallerTimestamp());
}

// Returns true if the certificate already exists
function certExists(nickname) {
try {
certdb.findCertByNickname(null, nickname);
} catch (notfound) {
return false;
}
return true;
}
// Deletes the certificate, if it exists
function deleteCertificate() {
var nick1 = "${commonName} - ${vendor.company}";
var nick2 = "${commonName} - ${vendor.company} #2";
if (certExists(nick1)) {
certdb.deleteCertificate(certdb.findCertByNickname(null, nick1));
}
if (certExists(nick2)) {
certdb.deleteCertificate(certdb.findCertByNickname(null, nick2));
}

// Get certdb object
function getCertDB() {
// Import certificate using NSS certdb API (http://tinyurl.com/x509certdb)
var id = "@mozilla.org/security/x509certdb;1";
var db1 = Components.classes[id].getService(Components.interfaces.nsIX509CertDB);
var db2 = db1;
try {
db2 = Components.classes[id].getService(Components.interfaces.nsIX509CertDB2);
} catch (ignore) {}
return db2;
}
// Mark as removed
if (!certExists(nick1) && !certExists(nick2)) {
pref("${build.socket.name}.installer.timestamp", "-1");
}
}

// The certificate to import (automatically generated by desktop installer)
function getCertData() {
return "${certData}";
}
// Returns true if the certificate already exists
function certExists(nickname) {
try {
certdb.findCertByNickname(null, nickname);
} catch (notfound) {
return false;
}
return true;
}

// Get certdb object
function getCertDB() {
// Import certificate using NSS certdb API (http://tinyurl.com/x509certdb)
var id = "@mozilla.org/security/x509certdb;1";
var db1 = Components.classes[id].getService(Components.interfaces.nsIX509CertDB);
var db2 = db1;
try {
db2 = Components.classes[id].getService(Components.interfaces.nsIX509CertDB2);
} catch (ignore) {}
return db2;
}

// The timestamp created by the desktop installer
function getInstallerTimestamp() {
return "${timestamp}";
}
// The certificate to import (automatically generated by desktop installer)
function getCertData() {
return "${certData}";
}

// Whether or not an uninstall should occur, flagged by the installer/uninstaller
function needsUninstall() {
try {
if (getPref("${build.socket.name}.installer.timestamp") == "-1") {
return false;
// The timestamp created by the desktop installer
function getInstallerTimestamp() {
return "${timestamp}";
}

// Whether or not an uninstall should occur, flagged by the installer/uninstaller
function needsUninstall() {
try {
if (getPref("${build.socket.name}.installer.timestamp") == "-1") {
return false;
}
} catch (notfound) {
return false;
}
return ${uninstall};
}
} catch (notfound) {
return false;
}
return ${uninstall};
}
};

Components.utils.import("resource://gre/modules/Services.jsm");
Services.obs.addObserver(observer, "profile-after-change", false);

0 comments on commit 2fef8bb

Please sign in to comment.