Bug 1571710 - Adds link to download certificate. r=johannh,fluent-reviewers,flod
☠☠ backed out by 738ec8b07581 ☠ ☠
authordleblanccyr <danielleleb12@gmail.com>
Thu, 15 Aug 2019 15:20:44 +0000
changeset 488464 36d75347441bbeaf2f9f3e321f6318d7643ccec2
parent 488463 983ff93a11ad7c08fd65a507dedf01526e4ae682
child 488465 83efa3e53a72a21fe1048f20a3a5054681fc2f69
push id92762
push userarchaeopteryx@coole-files.de
push dateFri, 16 Aug 2019 08:30:33 +0000
treeherderautoland@83efa3e53a72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, fluent-reviewers, flod
bugs1571710
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1571710 - Adds link to download certificate. r=johannh,fluent-reviewers,flod Differential Revision: https://phabricator.services.mozilla.com/D41078
toolkit/components/certviewer/content/certviewer.ftl
toolkit/components/certviewer/content/components/info-group.js
toolkit/components/certviewer/content/components/info-item.css
toolkit/components/certviewer/content/components/info-item.js
--- a/toolkit/components/certviewer/content/certviewer.ftl
+++ b/toolkit/components/certviewer/content/certviewer.ftl
@@ -55,8 +55,16 @@ certificate-viewer-sha-256 = SHA-256
 certificate-viewer-serial-number = Serial Number
 certificate-viewer-signature-algorithm = Signature Algorithm
 certificate-viewer-signaturealgorithm = Signature Algorithm
 certificate-viewer-signature-scheme = Signature Scheme 
 certificate-viewer-timestamp = Timestamp
 certificate-viewer-value = Value
 certificate-viewer-version = Version
 certificate-viewer-business-category = Business Category
+
+## Variables
+##   $domain (String) - The common name from the certificate being displayed.
+
+certificate-viewer-download-pem = PEM (cert)
+.download = { $domain }.pem
+certificate-viewer-download-pem-chain = PEM (chain)
+.download = { $domain }-chain.pem
--- a/toolkit/components/certviewer/content/components/info-group.js
+++ b/toolkit/components/certviewer/content/components/info-group.js
@@ -23,15 +23,19 @@ export class InfoGroup extends HTMLEleme
     title.textContent = this.item.sectionTitle;
 
     // Adds a class with the section title's name, to make
     // it easier to find when highlighting errors.
     this.classList.add(
       this.item.sectionTitle.replace(/\s+/g, "-").toLowerCase()
     );
 
+    this.classList.add(
+      this.item.sectionTitle.replace(/\s+/g, "-").toLowerCase()
+    );
+
     for (let i = 0; i < this.item.sectionItems.length; i++) {
       this.shadowRoot.append(new InfoItem(this.item.sectionItems[i]));
     }
   }
 }
 
 customElements.define("info-group", InfoGroup);
--- a/toolkit/components/certviewer/content/components/info-item.css
+++ b/toolkit/components/certviewer/content/components/info-item.css
@@ -22,13 +22,17 @@ label:dir(rtl) {
 .long-hex {
   max-width: 100%;
   overflow: hidden;
   word-break: break-all;
   text-overflow: ellipsis;
   white-space: nowrap;
 }
 
+.download-link-chain {
+  margin: 0 5px;
+}
+
 :host(.value) *,
 :host(.method) *,
 :host(.padding) * {
   padding-bottom: 10px;
 }
--- a/toolkit/components/certviewer/content/components/info-item.js
+++ b/toolkit/components/certviewer/content/components/info-item.js
@@ -28,19 +28,72 @@ export class InfoItem extends HTMLElemen
       .replace(/\./g, "")
       .replace(/\//g, "")
       .replace(/--/g, "-")
       .toLowerCase();
     label.setAttribute("data-l10n-id", "certificate-viewer-" + labelText);
 
     this.classList.add(labelText);
 
+    this.classList.add(labelText);
+
     let info = this.shadowRoot.querySelector(".info");
     info.textContent = this.item.info;
 
     // TODO: Use Fluent-friendly condition.
     if (this.item.label === "Modulus") {
       info.classList.add("long-hex");
     }
+
+    if (labelText === "download") {
+      this.setDownloadLinkInformation(info);
+    }
+  }
+
+  setDownloadLinkInformation(info) {
+    let link = document.createElement("a");
+    link.setAttribute("href", "data:," + this.item.info);
+    link.classList.add("download-link");
+
+    let url = new URL(document.URL);
+    let certArray = url.searchParams.getAll("cert");
+    let encodedCertArray = [];
+    for (let i = 0; i < certArray.length; i++) {
+      encodedCertArray.push(
+        encodeURI(
+          `-----BEGIN CERTIFICATE-----\r\n${
+            certArray[i]
+          }\r\n-----END CERTIFICATE-----\r\n`
+        )
+      );
+    }
+    encodedCertArray = encodedCertArray.join("");
+
+    let chainLink = document.createElement("a");
+    chainLink.setAttribute("href", "data:," + encodedCertArray);
+    chainLink.classList.add("download-link");
+    chainLink.classList.add("download-link-chain");
+
+    info.textContent = "";
+    info.appendChild(link);
+    info.appendChild(chainLink);
+
+    let commonName = document
+      .querySelector("certificate-section")
+      .shadowRoot.querySelector(".subject-name")
+      .shadowRoot.querySelector(".common-name")
+      .shadowRoot.querySelector(".info");
+
+    document.l10n.setAttributes(link, "certificate-viewer-download-pem", {
+      domain: commonName.textContent,
+    });
+
+    document.l10n.setAttributes(
+      chainLink,
+      "certificate-viewer-download-pem-chain",
+      {
+        domain: commonName.textContent,
+      }
+    );
   }
 }
 
 customElements.define("info-item", InfoItem);