Bug 1484873 - Add a "View Certificate" link to all cert error pages. r=nhnt11
☠☠ backed out by 3c175c006e65 ☠ ☠
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 17 Oct 2018 13:09:27 +0000
changeset 490058 868c99ece921edeec1b06259ee4060d35adeceea
parent 490057 00562394d243152bc7a729be27ee97efd47b7183
child 490059 8ec57c7e30579ee2bb53f8332968177b165c822b
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersnhnt11
bugs1484873
milestone64.0a1
Bug 1484873 - Add a "View Certificate" link to all cert error pages. r=nhnt11 Differential Revision: https://phabricator.services.mozilla.com/D8966
browser/base/content/aboutNetError-new.xhtml
browser/base/content/browser.js
browser/base/content/test/about/browser_aboutCertError.js
browser/locales/en-US/chrome/overrides/netError.dtd
browser/themes/shared/aboutNetError-new.css
--- a/browser/base/content/aboutNetError-new.xhtml
+++ b/browser/base/content/aboutNetError-new.xhtml
@@ -193,16 +193,17 @@
 
       <div id="netErrorButtonContainer" class="button-container">
         <button id="errorTryAgain" class="primary" autocomplete="off">&retry.label;</button>
       </div>
 
       <div id="advancedPanelContainer">
         <div id="badCertAdvancedPanel" class="advanced-panel">
           <p id="badCertTechnicalInfo"/>
+          <a id="viewCertificate" href="javascript:void(0)">&viewCertificate.label;</a>
           <div id="advancedPanelButtonContainer" class="button-container">
             <button id="advancedPanelReturnButton" class="primary" autocomplete="off" data-telemetry-id="return_button_adv">&returnToPreviousPage1.label;</button>
             <button id="advancedPanelErrorTryAgain" class="primary" autocomplete="off">&retry.label;</button>
             <div class="exceptionDialogButtonContainer">
               <button id="exceptionDialogButton" data-telemetry-id="exception_button">&securityOverride.exceptionButton1Label;</button>
             </div>
           </div>
         </div>
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -3036,16 +3036,22 @@ var BrowserOnClick = {
       break;
     }
   },
 
   onCertError(browser, elementId, isTopFrame, location, securityInfoAsString, frameId) {
     let securityInfo;
 
     switch (elementId) {
+      case "viewCertificate":
+        securityInfo = getSecurityInfo(securityInfoAsString);
+        let cert = securityInfo.serverCert;
+        Services.ww.openWindow(window, "chrome://pippki/content/certViewer.xul",
+                               "_blank", "centerscreen,chrome", cert);
+        break;
       case "exceptionDialogButton":
         securityInfo = getSecurityInfo(securityInfoAsString);
         let params = { exceptionAdded: false,
                        securityInfo };
         if (Services.prefs.getBoolPref("browser.security.newcerterrorpage.enabled", false)) {
           let overrideService = Cc["@mozilla.org/security/certoverride;1"]
                                   .getService(Ci.nsICertOverrideService);
           let flags = 0;
--- a/browser/base/content/test/about/browser_aboutCertError.js
+++ b/browser/base/content/test/about/browser_aboutCertError.js
@@ -477,16 +477,42 @@ add_task(async function checkCautionClas
       let doc = frame ? content.document.querySelector("iframe").contentDocument : content.document;
       ok(!doc.body.classList.contains("caution"), "Cert error body has no caution class");
     });
 
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
   }
 });
 
+add_task(async function checkViewCertificate() {
+  info("Loading a cert error and checking that the certificate can be shown.");
+  for (let useFrame of [false, true]) {
+    let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
+    let browser = tab.linkedBrowser;
+
+    let dialogOpened = BrowserTestUtils.domWindowOpened();
+
+    await ContentTask.spawn(browser, {frame: useFrame}, async function({frame}) {
+      let doc = frame ? content.document.querySelector("iframe").contentDocument : content.document;
+      let viewCertificate = doc.getElementById("viewCertificate");
+      viewCertificate.click();
+    });
+
+    let win = await dialogOpened;
+    await BrowserTestUtils.waitForEvent(win, "load");
+    is(win.document.documentURI, "chrome://pippki/content/certViewer.xul",
+      "Opened the cert viewer dialog");
+    is(win.document.getElementById("commonname").value, "self-signed.example.com",
+      "Shows the correct certificate in the dialog");
+    win.close();
+
+    BrowserTestUtils.removeTab(gBrowser.selectedTab);
+  }
+});
+
 function getCertChain(securityInfoAsString) {
   let certChain = "";
   const serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
                        .getService(Ci.nsISerializationHelper);
   let securityInfo = serhelper.deserializeObject(securityInfoAsString);
   securityInfo.QueryInterface(Ci.nsITransportSecurityInfo);
   for (let cert of securityInfo.failedCertChain.getEnumerator()) {
     certChain += getPEMString(cert);
--- a/browser/locales/en-US/chrome/overrides/netError.dtd
+++ b/browser/locales/en-US/chrome/overrides/netError.dtd
@@ -7,16 +7,17 @@
 
 <!ENTITY loadError.label "Problem loading page">
 <!ENTITY retry.label "Try Again">
 <!ENTITY returnToPreviousPage.label "Go Back">
 <!ENTITY returnToPreviousPage1.label "Go Back (Recommended)">
 <!ENTITY advanced.label "Advanced">
 <!ENTITY continue2.label "Moreā€¦">
 <!ENTITY moreInformation.label "More Information">
+<!ENTITY viewCertificate.label "View Certificate">
 
 <!-- Specific error messages -->
 
 <!ENTITY connectionFailure.title "Unable to connect">
 <!ENTITY connectionFailure.longDesc "&sharedLongDesc;">
 
 <!ENTITY deniedPortAccess.title "This address is restricted">
 <!ENTITY deniedPortAccess.longDesc "">
--- a/browser/themes/shared/aboutNetError-new.css
+++ b/browser/themes/shared/aboutNetError-new.css
@@ -59,16 +59,17 @@ button:disabled {
   display: none;
 }
 
 #advancedPanelButtonContainer {
   background-color: var(--exception-button-container-background);
   display: flex;
   justify-content: end;
   padding: 5px;
+  margin-top: 2em;
 }
 
 body:not(.neterror) #certErrorAndCaptivePortalButtonContainer {
   display: flex;
 }
 
 body:not(.neterror) #netErrorButtonContainer {
   display: none;
@@ -153,18 +154,22 @@ span#hostname {
   cursor: text;
   text-decoration: none;
 }
 
 #errorCode[href] {
   white-space: nowrap;
 }
 
+#viewCertificate {
+  margin: 0 3em;
+}
+
 #badCertTechnicalInfo {
-  margin: 3em;
+  margin: 3em 3em 1em;
   overflow: auto;
   white-space: pre-wrap;
 }
 
 #certificateErrorReporting {
   display: none;
 }