editcacert.js (1481B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 var gCertDB = Cc["@mozilla.org/security/x509certdb;1"].getService( 8 Ci.nsIX509CertDB 9 ); 10 /** 11 * Cert to edit the trust of. 12 * 13 * @type {nsIX509Cert} 14 */ 15 var gCert = window.arguments[0]; 16 17 document.addEventListener("DOMContentLoaded", init); 18 19 function init() { 20 document.addEventListener("dialogaccept", onDialogAccept); 21 22 let sslCheckbox = document.getElementById("trustSSL"); 23 sslCheckbox.checked = gCertDB.isCertTrusted( 24 gCert, 25 Ci.nsIX509Cert.CA_CERT, 26 Ci.nsIX509CertDB.TRUSTED_SSL 27 ); 28 29 let emailCheckbox = document.getElementById("trustEmail"); 30 emailCheckbox.checked = gCertDB.isCertTrusted( 31 gCert, 32 Ci.nsIX509Cert.CA_CERT, 33 Ci.nsIX509CertDB.TRUSTED_EMAIL 34 ); 35 36 let certMsg = document.getElementById("certmsg"); 37 document.l10n.setAttributes(certMsg, "edit-trust-ca", { 38 certName: gCert.commonName, 39 }); 40 } 41 42 /** 43 * ondialogaccept() handler. 44 */ 45 function onDialogAccept() { 46 let sslCheckbox = document.getElementById("trustSSL"); 47 let emailCheckbox = document.getElementById("trustEmail"); 48 let trustSSL = sslCheckbox.checked ? Ci.nsIX509CertDB.TRUSTED_SSL : 0; 49 let trustEmail = emailCheckbox.checked ? Ci.nsIX509CertDB.TRUSTED_EMAIL : 0; 50 51 gCertDB.setCertTrust(gCert, Ci.nsIX509Cert.CA_CERT, trustSSL | trustEmail); 52 }