Lua
Lua
Subject Alternative Name
See more Certificates Examples
Demonstrates the usage of the SubjectAlternativeName property to get the certificate SAN (subject alternative name) as XML.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Note: Not all certificates contain a Subject Alternative Name.
-- If it does not, the SubjectAlternativeName property will contain the empty string.
local cert = chilkat.Cert.new()
local success = cert:load_from_file("qa_data/certs/testIcpBrasil.cer")
if not success then
print(cert.last_error_text)
return
end
local subjectAltNameXml = cert.subject_alternative_name
print(subjectAltNameXml)
-- Here's a sample of the subjectAltNameXml:
-- <?xml version="1.0" encoding="utf-8"?>
-- <SubjectAltName>
-- <name type="oid" oid="2.16.76.1.3.4">...</name>
-- <name type="oid" oid="2.16.76.1.3.2">...</name>
-- <name type="oid" oid="2.16.76.1.3.3">...</name>
-- <name type="oid" oid="2.16.76.1.3.7">...</name>
-- <rfc822Name>...</rfc822Name>
-- </SubjectAltName>
-- The XML can be parsed like this:
local xml = chilkat.Xml.new()
xml:load_xml(subjectAltNameXml)
local oid = ""
local name = ""
local i = 0
local count_i = xml:num_children_having_tag("name")
while i < count_i do
xml.i = i
oid = xml:chilkat_path("name[i]|(oid)")
name = xml:get_child_content("name[i]")
i = i + 1
end
local rfc822Name = xml:get_child_content("rfc822Name")