From 40acf751a8a610e247a743dfc91511caa5b1c3b3 Mon Sep 17 00:00:00 2001 From: Edward Wall <33730573+edwardwall@users.noreply.github.com> Date: Sun, 30 Dec 2018 16:46:18 +0000 Subject: [PATCH] Update to understand Generalized / UTC Time Future proofing for when certificates with dates after 2049 begin being issued. These certificates' dates will be in Generalized Time not UTC Time as per RFC 5280 --- src/core/operations/ParseX509Certificate.mjs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/operations/ParseX509Certificate.mjs b/src/core/operations/ParseX509Certificate.mjs index 0b6da703..31e5e359 100644 --- a/src/core/operations/ParseX509Certificate.mjs +++ b/src/core/operations/ParseX509Certificate.mjs @@ -206,13 +206,19 @@ ${extensions}`; * @returns {string} */ function formatDate (dateStr) { - return dateStr[4] + dateStr[5] + "/" + - dateStr[2] + dateStr[3] + "/" + - (dateStr[0] < "5" ? "20" : "19") + - dateStr[0] + dateStr[1] + " " + - dateStr[6] + dateStr[7] + ":" + + if (dateStr.length === 13) { // UTC Time + if (dateStr[0] < "5") { + dateStr = "20" + dateStr; + } else { + dateStr = "19" + dateStr; + } + } + return dateStr[6] + dateStr[7] + "/" + + dateStr[4] + dateStr[5] + "/" + + dateStr[0] + dateStr[1] + dateStr[2] + dateStr[3] + " " + dateStr[8] + dateStr[9] + ":" + - dateStr[10] + dateStr[11]; + dateStr[10] + dateStr[11] + ":" + + dateStr[12] + dateStr[13]; } export default ParseX509Certificate;