Lua Requires Chilkat v9.5.0.77+
Lua
Load .crl, Convert to XML, Get Revoked Serial Numbers and Dates
See more Certificates Examples
Load a binary .crl file (Certificate Revocation List), converts to XML, and then gets the revoked certificate serial numbers and revocation dates.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- Load a binary .crl file.
local bdCrl = chilkat.BinData.new()
local success = bdCrl:load_file("qa_data/crl/ca1.crl")
if not success then
print("Failed to load CRL file.")
return
end
local asn = chilkat.Asn.new()
success = asn:load_bd(bdCrl)
if not success then
print(asn.last_error_text)
return
end
-- Convert ASN.1 to XML and load into xml and re-emit for pretty printing..
local xml = chilkat.Xml.new()
xml:load_xml(asn:asn_to_xml())
success = xml:save_xml("qa_output/crl.xml")
-- Use this online tool to generate parsing code from CRL XML:
-- Generate Parsing Code from XML
-- Here's code to parse the XML. This code was generated by the above tool,
-- and then we modified it by removing unneeded code and changing some names
local tagPath = ""
local j = 0
local count_j = 0
local k = 0
local count_k = 0
local revokedCertSerialHex = ""
local dateRevoked = ""
local dt = chilkat.DateTime.new()
local i = 0
local count_i = xml:num_children_having_tag("sequence")
while i < count_i do
xml.i = i
j = 0
count_j = xml:num_children_having_tag("sequence[i]|sequence")
while j < count_j do
xml.j = j
k = 0
count_k = xml:num_children_having_tag("sequence[i]|sequence[j]|sequence")
while k < count_k do
xml.k = k
-- Get the revoked certificate's serial number in uppercase hex.
revokedCertSerialHex = xml:get_child_content("sequence[i]|sequence[j]|sequence[k]|int")
print("serial number: " .. revokedCertSerialHex)
-- Get the date/time revoked. It will be a string formatted as "YYMMDDhhmmssZ", such as "181023093028Z"
dateRevoked = xml:get_child_content("sequence[i]|sequence[j]|sequence[k]|utctime")
-- Date/time strings formatted as YYMMDDhhmmssZ can be parsed as follows:
dt:set_from_timestamp(dateRevoked)
print("date revoked: " .. dt:get_as_rfc822(false))
k = k + 1
end
j = j + 1
end
i = i + 1
end