From 2f36d0b968c9b73887f2588076d38cd581887f51 Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 13 Sep 2012 20:23:07 +0000 Subject: [PATCH] Fix date handling in ssl-cert Was crashing on unparseable dates (example: "2147483647Z"). Now the exact string is placed in structured output when it cannot be normalized. Also, the structured-format timestamp is used for Normal output for consistency; no timezone offset was previously displayed. --- scripts/ssl-cert.nse | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/ssl-cert.nse b/scripts/ssl-cert.nse index eb23cd3dd..33dc625c9 100644 --- a/scripts/ssl-cert.nse +++ b/scripts/ssl-cert.nse @@ -137,7 +137,7 @@ function date_to_string(date) if type(date) == "string" then return string.format("Can't parse; string is \"%s\"", date) else - return os.date("%Y-%m-%d %H:%M:%S", os.time(date)) + return stdnse.format_timestamp(stdnse.date_to_timestamp(date, 0), 0) end end @@ -190,7 +190,11 @@ local function output_tab(cert) o.pubkey = cert.pubkey o.validity = {} for k, v in pairs(cert.validity) do - o.validity[k] = stdnse.format_timestamp(stdnse.date_to_timestamp(v, 0), 0) + if type(v)=="string" then + o.validity[k] = v + else + o.validity[k] = stdnse.format_timestamp(stdnse.date_to_timestamp(v, 0), 0) + end end o.md5 = stdnse.tohex(cert:digest("md5")) o.sha1 = stdnse.tohex(cert:digest("sha1"))