tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

downloadcert.js (2850B)


      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 const { setText, viewCertHelper } = ChromeUtils.importESModule(
      8  "resource://gre/modules/psm/pippki.sys.mjs"
      9 );
     10 
     11 /**
     12 * @file Implements the functionality of downloadcert.xhtml: a dialog that allows
     13 *       a user to confirm whether to import a certificate, and if so what trust
     14 *       to give it.
     15 * @param {nsISupports} window.arguments.0
     16 *           Certificate to confirm import of, queryable to nsIX509Cert.
     17 * @param {nsISupports} window.arguments.1
     18 *           Object to set the return values of calling the dialog on, queryable
     19 *           to the underlying type of DownloadCertReturnValues.
     20 */
     21 
     22 /**
     23 * @typedef DownloadCertReturnValues
     24 * @type {nsIWritablePropertyBag2}
     25 * @property {boolean} importConfirmed
     26 *           Set to true if the user confirmed import of the cert and accepted
     27 *           the dialog, false otherwise.
     28 * @property {boolean} trustForSSL
     29 *           Set to true if the cert should be trusted for SSL, false otherwise.
     30 *           Undefined value if |importConfirmed| is not true.
     31 * @property {boolean} trustForEmail
     32 *           Set to true if the cert should be trusted for e-mail, false
     33 *           otherwise. Undefined value if |importConfirmed| is not true.
     34 */
     35 
     36 /**
     37 * The cert to potentially import.
     38 *
     39 * @type {nsIX509Cert}
     40 */
     41 var gCert;
     42 
     43 /**
     44 * onload() handler.
     45 */
     46 function onLoad() {
     47  gCert = window.arguments[0].QueryInterface(Ci.nsIX509Cert);
     48 
     49  document.addEventListener("dialogaccept", onDialogAccept);
     50  document.addEventListener("dialogcancel", onDialogCancel);
     51 
     52  let bundle = document.getElementById("pippki_bundle");
     53  let caName = gCert.commonName;
     54  if (!caName.length) {
     55    caName = bundle.getString("unnamedCA");
     56  }
     57 
     58  setText(
     59    document,
     60    "trustHeader",
     61    bundle.getFormattedString("newCAMessage1", [caName])
     62  );
     63 
     64  document.getElementById("viewC-button").addEventListener("command", () => {
     65    viewCertHelper(window, gCert, "window");
     66  });
     67 }
     68 
     69 /**
     70 * ondialogaccept() handler.
     71 */
     72 function onDialogAccept() {
     73  let checkSSL = document.getElementById("trustSSL");
     74  let checkEmail = document.getElementById("trustEmail");
     75 
     76  let retVals = window.arguments[1].QueryInterface(Ci.nsIWritablePropertyBag2);
     77  retVals.setPropertyAsBool("importConfirmed", true);
     78  retVals.setPropertyAsBool("trustForSSL", checkSSL.checked);
     79  retVals.setPropertyAsBool("trustForEmail", checkEmail.checked);
     80 }
     81 
     82 /**
     83 * ondialogcancel() handler.
     84 */
     85 function onDialogCancel() {
     86  let retVals = window.arguments[1].QueryInterface(Ci.nsIWritablePropertyBag2);
     87  retVals.setPropertyAsBool("importConfirmed", false);
     88 }
     89 
     90 window.addEventListener("load", () => onLoad());