tor-browser

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

browser_aboutCertError_revoked.js (3728B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const BAD_CERT = "https://expired.example.com/";
      7 const REVOKED_CERT_PATH =
      8  "../../../../../security/manager/ssl/tests/mochitest/browser/revoked.pem";
      9 
     10 function pemToBase64(pem) {
     11  return pem
     12    .replace(/-----BEGIN CERTIFICATE-----/, "")
     13    .replace(/-----END CERTIFICATE-----/, "")
     14    .replace(/\s+/g, "");
     15 }
     16 
     17 // The revoked certificate page should not offer a proceed button.
     18 add_task(async function checkRevokedCertificateAdvancedCopy() {
     19  await setSecurityCertErrorsFeltPrivacyToTrue();
     20 
     21  const revokedPem = await IOUtils.readUTF8(getTestFilePath(REVOKED_CERT_PATH));
     22  const revokedCertBase64 = pemToBase64(revokedPem);
     23 
     24  const tab = await openErrorPage(BAD_CERT);
     25  const browser = tab.linkedBrowser;
     26 
     27  await SpecialPowers.spawn(
     28    browser,
     29    [revokedCertBase64],
     30    async function (revokedCert_Base64) {
     31      const mockErrorInfo = {
     32        errorCodeString: "SEC_ERROR_REVOKED_CERTIFICATE",
     33        errorIsOverridable: false,
     34        channelStatus: 0,
     35        overridableErrorCategory: "trust-error",
     36        validNotBefore: Date.now() - 1000,
     37        validNotAfter: Date.now() + 1000,
     38        certValidityRangeNotAfter: Date.now() + 1000,
     39        certValidityRangeNotBefore: Date.now() - 1000,
     40        issuerCommonName: "ca",
     41        errorMessage: "Peer's Certificate has been revoked.",
     42        hasHSTS: false,
     43        hasHPKP: false,
     44        certChainStrings: [revokedCert_Base64],
     45      };
     46 
     47      content.document.getFailedCertSecurityInfo = () => mockErrorInfo;
     48 
     49      const netErrorCard =
     50        content.document.querySelector("net-error-card").wrappedJSObject;
     51      const info = Cu.cloneInto(mockErrorInfo, netErrorCard);
     52      netErrorCard.errorInfo = info;
     53      netErrorCard.hostname = "revoked.example.com";
     54      netErrorCard.domainMismatchNames = null;
     55      netErrorCard.domainMismatchNamesPromise = null;
     56      netErrorCard.certificateErrorText = null;
     57      netErrorCard.certificateErrorTextPromise = null;
     58      netErrorCard.hideExceptionButton = netErrorCard.shouldHideExceptionButton(
     59        info.errorCodeString
     60      );
     61      netErrorCard.requestUpdate();
     62      await netErrorCard.getUpdateComplete();
     63 
     64      const advancedButton = netErrorCard.advancedButton;
     65      advancedButton.scrollIntoView(true);
     66      EventUtils.synthesizeMouseAtCenter(advancedButton, {}, content);
     67 
     68      await ContentTaskUtils.waitForCondition(
     69        () => netErrorCard.advancedContainer,
     70        "Advanced section should be rendered for revoked certificate"
     71      );
     72      await ContentTaskUtils.waitForCondition(
     73        () => netErrorCard.whyDangerous && netErrorCard.whatCanYouDo,
     74        "Revoked copy should be rendered"
     75      );
     76 
     77      Assert.ok(
     78        netErrorCard.advancedShowing,
     79        "Advanced details are shown for revoked certificates."
     80      );
     81      Assert.ok(
     82        !netErrorCard.exceptionButton,
     83        "Proceed button should not be shown for revoked certificates."
     84      );
     85      Assert.equal(
     86        netErrorCard.whyDangerous.dataset.l10nId,
     87        "fp-certerror-revoked-why-dangerous-body",
     88        "Using the 'revoked' variant of the 'Why Dangerous' copy."
     89      );
     90      Assert.equal(
     91        netErrorCard.whatCanYouDo.dataset.l10nId,
     92        "fp-certerror-revoked-what-can-you-do-body",
     93        "Using the 'revoked' variant of the 'What can you do' copy."
     94      );
     95      Assert.equal(
     96        netErrorCard.learnMoreLink.getAttribute("support-page"),
     97        "connection-not-secure",
     98        "'Learn more' link points to the standard support page."
     99      );
    100    }
    101  );
    102 
    103  BrowserTestUtils.removeTab(tab);
    104  await SpecialPowers.popPrefEnv();
    105 });