DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* 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/. */


const { XPCOMUtils } = ChromeUtils.import(
  "resource://gre/modules/XPCOMUtils.jsm"
);
const protocolHandler = Cc[
  "@mozilla.org/network/protocol;1?name=http"
  "@mozilla.org/network/protocol;1?name=http"
].getService(Ci.nsIHttpProtocolHandler);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);

const TLS_ERROR_REPORT_TELEMETRY_SUCCESS = 6;
const TLS_ERROR_REPORT_TELEMETRY_SUCCESS = 6;
const TLS_ERROR_REPORT_TELEMETRY_FAILURE = 7;
const HISTOGRAM_ID = "TLS_ERROR_REPORT_UI";

ChromeUtils.defineModuleGetter(
  this,
  this,
  "UpdateUtils",
  "resource://gre/modules/UpdateUtils.jsm"
);

function SecurityReporter() {}
function SecurityReporter() {}

SecurityReporter.prototype = {
  QueryInterface: ChromeUtils.generateQI([Ci.nsISecurityReporter]),
  reportTLSError(transportSecurityInfo, hostname, port) {
    // don't send if there's no transportSecurityInfo (since the report cannot
    // contain anything of interest)
    if (!transportSecurityInfo) {
    if (!transportSecurityInfo) {
      return;
    }

    // don't send a report if the pref is not enabled
    if (!Services.prefs.getBoolPref("security.ssl.errorReporting.enabled")) {
    if (!Services.prefs.getBoolPref("security.ssl.errorReporting.enabled")) {
      return;
    }

    // Don't send a report if the host we're connecting to is the report
    // server (otherwise we'll get loops when this fails)
    // server (otherwise we'll get loops when this fails)
    let endpoint = Services.prefs.getCharPref(
      "security.ssl.errorReporting.url"
    );
    let reportURI = Services.io.newURI(endpoint);

    if (reportURI.host == hostname) {
      return;
    }
    }

    // Convert the array of nsIX509Cert into a format that can be parsed into
    // JSON
    let asciiCertChain = [];


    if (transportSecurityInfo.failedCertChain) {
      for (let cert of transportSecurityInfo.failedCertChain) {
        asciiCertChain.push(cert.getBase64DERString());
      }
    }

    let report = {
    let report = {
      hostname,
      port,
      timestamp: Math.round(Date.now() / 1000),
      errorCode: transportSecurityInfo.errorCode,
      failedCertChain: asciiCertChain,
      failedCertChain: asciiCertChain,
      userAgent: protocolHandler.userAgent,
      version: 1,
      build: Services.appinfo.appBuildID,
      product: Services.appinfo.name,
      channel: UpdateUtils.UpdateChannel,
    };
    };

    fetch(endpoint, {
      method: "POST",
      body: JSON.stringify(report),
      credentials: "omit",
      credentials: "omit",
      headers: {
        "Content-Type": "application/json",
      },
    })
      .then(function(aResponse) {
      .then(function(aResponse) {
        if (!aResponse.ok) {
          // request returned non-success status
          Services.telemetry
            .getHistogramById(HISTOGRAM_ID)
            .add(TLS_ERROR_REPORT_TELEMETRY_FAILURE);
            .add(TLS_ERROR_REPORT_TELEMETRY_FAILURE);
        } else {
          Services.telemetry
            .getHistogramById(HISTOGRAM_ID)
            .add(TLS_ERROR_REPORT_TELEMETRY_SUCCESS);
        }
        }
      })
      .catch(function(e) {
        // error making request to reportURL
        Services.telemetry
          .getHistogramById(HISTOGRAM_ID)
          .getHistogramById(HISTOGRAM_ID)
          .add(TLS_ERROR_REPORT_TELEMETRY_FAILURE);
      });
  },
};


var EXPORTED_SYMBOLS = ["SecurityReporter"];