tor-browser

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

browser_aboutCertError_untrustedIssuer.js (3346B)


      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_PAGE = "https://expired.example.com/";
      7 const BAD_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 add_setup(async function () {
     18  await SpecialPowers.pushPrefEnv({
     19    set: [
     20      ["test.wait300msAfterTabSwitch", true],
     21      ["security.certerrors.felt-privacy-v1", true],
     22    ],
     23  });
     24 });
     25 
     26 add_task(async function checkUntrustedCertIssuerCopy() {
     27  const pem = await IOUtils.readUTF8(getTestFilePath(BAD_CERT_PATH));
     28  const certBase64 = pemToBase64(pem);
     29  const tab = await openErrorPage(BAD_CERT_PAGE);
     30  const browser = tab.linkedBrowser;
     31 
     32  await SpecialPowers.spawn(browser, [certBase64], async cert => {
     33    const mockErrorInfo = {
     34      errorCodeString: "SEC_ERROR_UNTRUSTED_ISSUER",
     35      errorIsOverridable: false,
     36      channelStatus: 0,
     37      overridableErrorCategory: "trust-error",
     38      validNotBefore: Date.now() - 1000 * 1000,
     39      validNotAfter: Date.now() + 1000 * 1000,
     40      certValidityRangeNotBefore: Date.now() - 1000 * 1000,
     41      certValidityRangeNotAfter: Date.now() + 1000 * 2000,
     42      issuerCommonName: "Untrusted CA",
     43      errorMessage: "Peer’s Certificate issuer is not recognized.",
     44      hasHSTS: false,
     45      hasHPKP: false,
     46      certChainStrings: [cert],
     47    };
     48    content.document.getFailedCertSecurityInfo = () => mockErrorInfo;
     49 
     50    const netErrorCard =
     51      content.document.querySelector("net-error-card").wrappedJSObject;
     52    const info = Cu.cloneInto(mockErrorInfo, netErrorCard);
     53    netErrorCard.errorInfo = info;
     54    netErrorCard.hideExceptionButton = netErrorCard.shouldHideExceptionButton();
     55    await netErrorCard.getUpdateComplete();
     56 
     57    netErrorCard.advancedButton.scrollIntoView();
     58    EventUtils.synthesizeMouseAtCenter(
     59      netErrorCard.advancedButton,
     60      {},
     61      content
     62    );
     63 
     64    await ContentTaskUtils.waitForCondition(
     65      () => ContentTaskUtils.isVisible(netErrorCard.advancedContainer),
     66      "Advanced container is visible"
     67    );
     68 
     69    Assert.ok(
     70      netErrorCard.advancedShowing,
     71      "Advanced details are shown for certificates from untrusted issuers."
     72    );
     73 
     74    Assert.ok(
     75      !netErrorCard.exceptionButton,
     76      "Proceed button should be shown for certificates from untrusted issuers."
     77    );
     78    Assert.equal(
     79      netErrorCard.certErrorIntro.dataset.l10nId,
     80      "fp-certerror-intro",
     81      "Using the 'certificate error' intro."
     82    );
     83    Assert.equal(
     84      netErrorCard.whyDangerous.dataset.l10nId,
     85      "fp-certerror-untrusted-issuer-why-dangerous-body",
     86      "Using the 'untrusted issuer' variant of the 'Why Dangerous' copy."
     87    );
     88    Assert.equal(
     89      netErrorCard.whatCanYouDo.dataset.l10nId,
     90      "fp-certerror-untrusted-issuer-what-can-you-do-body",
     91      "Using the 'untrusted issuer' variant of the 'What can you do' copy."
     92    );
     93    Assert.equal(
     94      netErrorCard.learnMoreLink.getAttribute("support-page"),
     95      "connection-not-secure",
     96      "'Learn more' link points to the insecure connection errors support page."
     97    );
     98  });
     99 
    100  await BrowserTestUtils.removeTab(tab);
    101 });