Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/security/manager/ssl/tests/unit/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 3 kB image not shown  

Quelle  test_ocsp_timeout.js   Sprache: JAVA

 
// -*- 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/.
"use strict";

// This test connects to ocsp-stapling-none.example.com to test that OCSP
// requests are cancelled if they're taking too long.
// ocsp-stapling-none.example.com doesn't staple an OCSP response, so
// connecting to it will cause a request to the OCSP responder. As with all of
// these tests, the OCSP AIA (i.e. the url of the responder) in the certificate
// is http://localhost:8888. Since this test opens a TCP socket listening on
// port 8888 that just accepts connections and then ignores them (with
// connect/read/write timeouts of 30 seconds), the OCSP requests should cancel
// themselves. When OCSP hard-fail is enabled, connections will be terminated.
// Otherwise, they will succeed.

var gSocketListener = {
  onSocketAccepted(serverSocket, socketTransport) {
    socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 30);
    socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, 30);
  },

  onStopListening() {},
};

function run_test() {
  do_get_profile();
  Services.prefs.setIntPref("security.OCSP.enabled", 1);

  add_tls_server_setup("OCSPStaplingServer""ocsp_certs");

  let socket = Cc["@mozilla.org/network/server-socket;1"].createInstance(
    Ci.nsIServerSocket
  );
  socket.init(8888, true, -1);
  socket.asyncListen(gSocketListener);

  add_one_test(false"security.OCSP.timeoutMilliseconds.soft", 1000);
  add_one_test(false"security.OCSP.timeoutMilliseconds.soft", 2000);
  add_one_test(false"security.OCSP.timeoutMilliseconds.soft", 4000);

  add_one_test(true"security.OCSP.timeoutMilliseconds.hard", 3000);
  add_one_test(true"security.OCSP.timeoutMilliseconds.hard", 10000);
  add_one_test(true"security.OCSP.timeoutMilliseconds.hard", 15000);

  add_test(function () {
    socket.close();
    run_next_test();
  });
  run_next_test();
}

function add_one_test(useHardFail, timeoutPrefName, timeoutMilliseconds) {
  let startTime;
  add_test(function () {
    Services.prefs.setBoolPref("security.OCSP.require", useHardFail);
    Services.prefs.setIntPref(timeoutPrefName, timeoutMilliseconds);
    startTime = new Date();
    run_next_test();
  });

  add_connection_test(
    "ocsp-stapling-none.example.com",
    useHardFail ? SEC_ERROR_OCSP_SERVER_ERROR : PRErrorCodeSuccess,
    clearSessionCache
  );

  add_test(function () {
    let endTime = new Date();
    let timeDifference = endTime - startTime;
    info(`useHardFail = ${useHardFail}`);
    info(`startTime = ${startTime.getTime()} (${startTime})`);
    info(`endTime = ${endTime.getTime()} (${endTime})`);
    info(`timeDifference = ${timeDifference}ms`);
    // Date() is not guaranteed to be monotonic, so add extra fuzz time to
    // prevent intermittent failures (this only appeared to be a problem on
    // Windows XP). See Bug 1121117.
    const FUZZ_MS = 300;
    Assert.greater(
      timeDifference + FUZZ_MS,
      timeoutMilliseconds,
      `OCSP timeout should be ~${timeoutMilliseconds}s for ` +
        `${useHardFail ? "hard" : "soft"}-fail`
    );
    // Make sure we didn't wait too long.
    // (Unfortunately, we probably can't have a tight upper bound on
    // how long is too long for this test, because we might be running
    // on slow hardware.)
    Assert.less(
      timeDifference,
      60000,
      "Automatic OCSP timeout shouldn't be more than 60s"
    );

    // Reset state
    clearOCSPCache();
    Services.prefs.clearUserPref("security.OCSP.require");
    Services.prefs.clearUserPref(timeoutPrefName);
    run_next_test();
  });
}

Messung V0.5
C=94 H=83 G=88

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.