/* 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/. */ /* eslint-disable import/no-unassigned-import */ /* eslint-env mozilla/remote-page */ import { getCSSClass, getHostName, getSubjectAltNames, getFailedCertificatesAsPEMString, recordSecurityUITelemetry, } from "chrome://global/content/aboutNetErrorHelpers.mjs"; import { html } from "chrome://global/content/vendor/lit.all.mjs"; import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; import "chrome://global/content/elements/moz-button-group.mjs"; import "chrome://global/content/elements/moz-button.mjs"; import "chrome://global/content/elements/moz-support-link.mjs"; const HOST_NAME = getHostName(); export class NetErrorCard extends MozLitElement { static properties = { hostname: { type: String }, domainMismatchNames: { type: String }, advancedShowing: { type: Boolean, reflect: true }, certErrorDebugInfoShowing: { type: Boolean, reflect: true }, certificateErrorText: { type: String }, }; static queries = { copyButtonTop: "#copyToClipboardTop", exceptionButton: "#exception-button", errorCode: "#errorCode", advancedContainer: ".advanced-container", advancedButton: "#advanced-button", }; static ERROR_CODES = new Set([ "SEC_ERROR_UNKNOWN_ISSUER", "SSL_ERROR_BAD_CERT_DOMAIN", "MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT", "SEC_ERROR_EXPIRED_CERTIFICATE", "SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE", ]); constructor() { super(); this.domainMismatchNames = null; this.advancedShowing = false; this.certErrorDebugInfoShowing = false; this.certificateErrorText = null; this.domainMismatchNamesPromise = null; this.certificateErrorTextPromise = null; } async getUpdateComplete() { const result = await super.getUpdateComplete(); if (this.domainMismatchNames && this.certificateErrorText) { return result; } await Promise.all([ this.getDomainMismatchNames(), this.getCertificateErrorText(), ]); await Promise.all([ this.domainMismatchNamesPromise, this.certificateErrorTextPromise, ]); return result; } connectedCallback() { super.connectedCallback(); this.init(); } firstUpdated() { // Dispatch this event so tests can detect that we finished loading the error page. document.dispatchEvent( new CustomEvent("AboutNetErrorLoad", { bubbles: true }) ); } init() { document.l10n.setAttributes( document.querySelector("title"), "fp-certerror-page-title" ); this.failedCertInfo = document.getFailedCertSecurityInfo(); this.hostname = HOST_NAME; const { port } = document.location; if (port && port != 443) { this.hostname += ":" + port; } if (getCSSClass() == "expertBadCert") { this.toggleAdvancedShowing(); } } introContentTemplate() { switch (this.failedCertInfo.errorCodeString) { case "SEC_ERROR_UNKNOWN_ISSUER": case "SSL_ERROR_BAD_CERT_DOMAIN": case "SEC_ERROR_EXPIRED_CERTIFICATE": case "MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT": return html`
`; case "SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE": return html``; } return null; } advancedContainerTemplate() { if (!this.advancedShowing) { return null; } let content; switch (this.failedCertInfo.errorCodeString) { case "SEC_ERROR_UNKNOWN_ISSUER": { content = this.advancedSectionTemplate({ whyDangerousL10nId: "fp-certerror-unknown-issuer-why-dangerous-body", whatCanYouDoL10nId: "fp-certerror-unknown-issuer-what-can-you-do-body", learnMoreL10nId: "fp-learn-more-about-cert-issues", learnMoreSupportPage: "connection-not-secure", viewCert: true, viewDateTime: true, }); break; } case "SSL_ERROR_BAD_CERT_DOMAIN": { if (!this.domainMismatchNames) { this.getDomainMismatchNames(); return null; } content = this.advancedSectionTemplate({ whyDangerousL10nId: "fp-certerror-bad-domain-why-dangerous-body", whyDangerousL10nArgs: { hostname: this.hostname, validHosts: this.domainMismatchNames ?? "", }, whatCanYouDoL10nId: "fp-certerror-bad-domain-what-can-you-do-body", learnMoreL10nId: "fp-learn-more-about-secure-connection-failures", learnMoreSupportPage: "connection-not-secure", viewCert: true, viewDateTime: true, }); break; } case "SEC_ERROR_EXPIRED_CERTIFICATE": { const notBefore = this.failedCertInfo.validNotBefore; const notAfter = this.failedCertInfo.validNotAfter; if (notBefore && Date.now() < notAfter) { content = this.advancedSectionTemplate({ whyDangerousL10nId: "fp-certerror-not-yet-valid-why-dangerous-body", whyDangerousL10nArgs: { date: notBefore, }, whatCanYouDoL10nId: "fp-certerror-expired-what-can-you-do-body", whatCanYouDoL10nArgs: { date: Date.now(), }, learnMoreL10nId: "fp-learn-more-about-time-related-errors", learnMoreSupportPage: "time-errors", viewCert: true, viewDateTime: true, }); } else { content = this.advancedSectionTemplate({ whyDangerousL10nId: "fp-certerror-expired-why-dangerous-body", whyDangerousL10nArgs: { date: notAfter, }, whatCanYouDoL10nId: "fp-certerror-expired-what-can-you-do-body", whatCanYouDoL10nArgs: { date: Date.now(), }, learnMoreL10nId: "fp-learn-more-about-time-related-errors", learnMoreSupportPage: "time-errors", viewCert: true, viewDateTime: true, }); } break; } case "MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT": { content = this.advancedSectionTemplate({ whyDangerousL10nId: "fp-certerror-self-signed-why-dangerous-body", whatCanYouDoL10nId: "fp-certerror-self-signed-what-can-you-do-body", importantNote: "fp-certerror-self-signed-important-note", viewCert: true, viewDateTime: true, }); break; } case "SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE": { const notAfter = this.failedCertInfo.validNotAfter; content = this.advancedSectionTemplate({ whyDangerousL10nId: "fp-certerror-expired-why-dangerous-body", whyDangerousL10nArgs: { date: notAfter, }, whatCanYouDoL10nId: "fp-certerror-expired-what-can-you-do-body", whatCanYouDoL10nArgs: { date: Date.now(), }, learnMoreL10nId: "fp-learn-more-about-time-related-errors", learnMoreSupportPage: "time-errors", viewCert: true, viewDateTime: true, }); break; } } return html`${whyDangerousL10nId ? html` ` : null}
${whatCanYouDoL10nId ? html`` : null} ${importantNote ? html`` : null} ${learnMoreL10nId ? html`` : null} ${viewCert ? html`` : null} ${viewDateTime ? html`` : null}