From 13bdfefa9d36b299b1852b475f85793f007dfaef Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Fri, 1 Oct 2021 18:44:32 +0800 Subject: [PATCH 1/3] Feat: Improve Certificaet Info Display --- server/prometheus.js | 2 +- server/util-server.js | 56 ++++++------ src/components/CertificateInfo.vue | 30 +++++++ src/components/CertificateInfoRow.vue | 106 +++++++++++++++++++++++ src/icon.js | 4 + src/mixins/socket.js | 4 +- src/pages/Details.vue | 118 ++++++++++---------------- 7 files changed, 216 insertions(+), 104 deletions(-) create mode 100644 src/components/CertificateInfo.vue create mode 100644 src/components/CertificateInfoRow.vue diff --git a/server/prometheus.js b/server/prometheus.js index 3e4767b3..c27f87f0 100644 --- a/server/prometheus.js +++ b/server/prometheus.js @@ -59,7 +59,7 @@ class Prometheus { } try { - monitor_cert_days_remaining.set(this.monitorLabelValues, tlsInfo.daysRemaining) + monitor_cert_days_remaining.set(this.monitorLabelValues, tlsInfo.certInfo.daysRemaining) } catch (e) { console.error(e) } diff --git a/server/util-server.js b/server/util-server.js index 29e4b11f..66c50d8c 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -185,38 +185,42 @@ const getDaysRemaining = (validFrom, validTo) => { return daysRemaining; }; -exports.checkCertificate = function (res) { - const { - valid_from, - valid_to, - subjectaltname, - issuer, - fingerprint, - } = res.request.res.socket.getPeerCertificate(false); - - if (!valid_from || !valid_to || !subjectaltname) { - throw { - message: "No TLS certificate in response", - }; +// Fix certificate Info for display +// param: info - the chain obtained from getPeerCertificate() +const parseCertificateInfo = function (info) { + let link = info; + + while (link) { + if (!link.valid_from || !link.valid_to) { + break; + } + link.validTo = new Date(link.valid_to); + link.validFor = link.subjectaltname?.replace(/DNS:|IP Address:/g, "").split(", "); + link.daysRemaining = getDaysRemaining(new Date(), link.validTo); + + // Move up the chain until loop is encountered + if (link.issuerCertificate == null) { + break; + } else if (link.fingerprint == link.issuerCertificate.fingerprint) { + link.issuerCertificate = null; + break; + } else { + link = link.issuerCertificate; + } } - const valid = res.request.res.socket.authorized || false; - - const validTo = new Date(valid_to); + return info; +}; - const validFor = subjectaltname - .replace(/DNS:|IP Address:/g, "") - .split(", "); +exports.checkCertificate = function (res) { + const info = res.request.res.socket.getPeerCertificate(true); + const valid = res.request.res.socket.authorized || false; - const daysRemaining = getDaysRemaining(new Date(), validTo); + const parsedInfo = parseCertificateInfo(info); return { - valid, - validFor, - validTo, - daysRemaining, - issuer, - fingerprint, + valid: valid, + certInfo: parsedInfo }; }; diff --git a/src/components/CertificateInfo.vue b/src/components/CertificateInfo.vue new file mode 100644 index 00000000..0b23c952 --- /dev/null +++ b/src/components/CertificateInfo.vue @@ -0,0 +1,30 @@ + + + + + diff --git a/src/components/CertificateInfoRow.vue b/src/components/CertificateInfoRow.vue new file mode 100644 index 00000000..2b37d6e1 --- /dev/null +++ b/src/components/CertificateInfoRow.vue @@ -0,0 +1,106 @@ + + + + + diff --git a/src/icon.js b/src/icon.js index 6fb91498..5ac3511e 100644 --- a/src/icon.js +++ b/src/icon.js @@ -30,6 +30,8 @@ import { faUpload, faCopy, faCheck, + faFileContract, + faLink, } from "@fortawesome/free-solid-svg-icons"; library.add( @@ -59,6 +61,8 @@ library.add( faUpload, faCopy, faCheck, + faFileContract, + faLink, ); export { FontAwesomeIcon }; diff --git a/src/mixins/socket.js b/src/mixins/socket.js index a14771c3..8a12ae4b 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -30,7 +30,7 @@ export default { importantHeartbeatList: { }, avgPingList: { }, uptimeList: { }, - certInfoList: {}, + tlsInfoList: {}, notificationList: [], connectionErrorMsg: "Cannot connect to the socket server. Reconnecting...", }; @@ -154,7 +154,7 @@ export default { }); socket.on("certInfo", (monitorID, data) => { - this.certInfoList[monitorID] = JSON.parse(data); + this.tlsInfoList[monitorID] = JSON.parse(data); }); socket.on("importantHeartbeatList", (monitorID, data, overwrite) => { diff --git a/src/pages/Details.vue b/src/pages/Details.vue index e4aeb28d..ee0c4948 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -73,11 +73,11 @@ -
+
@@ -87,41 +87,7 @@
-

{{ $t("Certificate Info") }}

- - - - - - - - - - - - - - - - - - - - - - - -
- Valid: - {{ certInfo.valid }}
- Valid To: -
- Days Remaining: - {{ certInfo.daysRemaining }}
- Issuer: - {{ certInfo.issuer }}
- Fingerprint: - {{ certInfo.fingerprint }}
+
@@ -207,8 +173,8 @@ +