From 7d56c9e7e69a8ed095635262d987c727ab3d1515 Mon Sep 17 00:00:00 2001 From: Cykesiopka Date: Mon, 10 Oct 2016 16:08:36 +0800 Subject: [PATCH] Bug 332442 - Stop abusing window name to pass cert ref to editcerts.js. r=mgoodwin editcacert.xul/editcerts.js currently requires the |dbKey| attribute of an nsIX509Cert to be passed to it via the window name so it can get a handle to the nsIX509Cert. This has two problems: 1. This used to trigger warnings, and is unwise to do in any case. 2. It's unnecessary complexity - the nsIX509Cert can be passed directly. This patch: 1. Addresses the two problems. 2. Adds a test to ensure the functionality of editcerts.js actually works. 3. Rewrites editcerts.js to better fit modern PSM style. 4. Updates the name of editcerts.js so it's more consistent with the general convention under security/pki/resources/content MozReview-Commit-ID: ECxziXq5TmL --HG-- rename : security/manager/pki/resources/content/editcerts.js => security/manager/pki/resources/content/editcacert.js extra : rebase_source : 46a6b2ff2ee90aded61a27b21ce3d5c1a8bed5c2 --- .../pki/resources/content/certManager.js | 8 +- .../pki/resources/content/editcacert.js | 58 +++++++++ .../pki/resources/content/editcacert.xul | 9 +- .../pki/resources/content/editcerts.js | 71 ----------- security/manager/pki/resources/jar.mn | 2 +- .../ssl/tests/mochitest/browser/browser.ini | 1 + .../browser/browser_editCACertTrust.js | 119 ++++++++++++++++++ 7 files changed, 190 insertions(+), 78 deletions(-) create mode 100644 security/manager/pki/resources/content/editcacert.js delete mode 100644 security/manager/pki/resources/content/editcerts.js create mode 100644 security/manager/ssl/tests/mochitest/browser/browser_editCACertTrust.js diff --git a/security/manager/pki/resources/content/certManager.js b/security/manager/pki/resources/content/certManager.js index 36b257cd2e88..0b4de12b2143 100644 --- a/security/manager/pki/resources/content/certManager.js +++ b/security/manager/pki/resources/content/certManager.js @@ -23,6 +23,10 @@ var { Services } = Components.utils.import("resource://gre/modules/Services.jsm" var key; +/** + * List of certs currently selected in the active tab. + * @type nsIX509Cert[] + */ var selected_certs = []; var selected_tree_items = []; var selected_index = []; @@ -329,8 +333,8 @@ function editCerts() getSelectedCerts(); for (let cert of selected_certs) { - window.openDialog("chrome://pippki/content/editcacert.xul", cert.dbKey, - "chrome,centerscreen,modal"); + window.openDialog("chrome://pippki/content/editcacert.xul", "", + "chrome,centerscreen,modal", cert); } } diff --git a/security/manager/pki/resources/content/editcacert.js b/security/manager/pki/resources/content/editcacert.js new file mode 100644 index 000000000000..405d5281a42c --- /dev/null +++ b/security/manager/pki/resources/content/editcacert.js @@ -0,0 +1,58 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* import-globals-from pippki.js */ +"use strict"; + +const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +var gCertDB = Cc["@mozilla.org/security/x509certdb;1"] + .getService(Ci.nsIX509CertDB); +/** + * Cert to edit the trust of. + * @type nsIX509Cert + */ +var gCert; + +/** + * onload() handler. + */ +function onLoad() { + gCert = window.arguments[0]; + + let bundle = document.getElementById("pippki_bundle"); + setText("certmsg", + bundle.getFormattedString("editTrustCA", [gCert.commonName])); + + let sslCheckbox = document.getElementById("trustSSL"); + sslCheckbox.checked = gCertDB.isCertTrusted(gCert, Ci.nsIX509Cert.CA_CERT, + Ci.nsIX509CertDB.TRUSTED_SSL); + + let emailCheckbox = document.getElementById("trustEmail"); + emailCheckbox.checked = gCertDB.isCertTrusted(gCert, Ci.nsIX509Cert.CA_CERT, + Ci.nsIX509CertDB.TRUSTED_EMAIL); + + let objSignCheckbox = document.getElementById("trustObjSign"); + objSignCheckbox.checked = + gCertDB.isCertTrusted(gCert, Ci.nsIX509Cert.CA_CERT, + Ci.nsIX509CertDB.TRUSTED_OBJSIGN); +} + +/** + * ondialogaccept() handler. + * + * @returns {Boolean} true to make the dialog close, false otherwise. + */ +function onDialogAccept() { + let sslCheckbox = document.getElementById("trustSSL"); + let emailCheckbox = document.getElementById("trustEmail"); + let objSignCheckbox = document.getElementById("trustObjSign"); + let trustSSL = sslCheckbox.checked ? Ci.nsIX509CertDB.TRUSTED_SSL : 0; + let trustEmail = emailCheckbox.checked ? Ci.nsIX509CertDB.TRUSTED_EMAIL : 0; + let trustObjSign = objSignCheckbox.checked ? Ci.nsIX509CertDB.TRUSTED_OBJSIGN + : 0; + + gCertDB.setCertTrust(gCert, Ci.nsIX509Cert.CA_CERT, + trustSSL | trustEmail | trustObjSign); + return true; +} diff --git a/security/manager/pki/resources/content/editcacert.xul b/security/manager/pki/resources/content/editcacert.xul index b3f295e40379..46ea4f1f928d 100644 --- a/security/manager/pki/resources/content/editcacert.xul +++ b/security/manager/pki/resources/content/editcacert.xul @@ -7,18 +7,19 @@ -