Lua
Lua
Get the Server Certificate from a TLS Connection
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetServerCert, which copies the certificate presented by the remote TLS server into a Cert object for inspection.
Background. The method returns false when the socket is not connected, is not using TLS, or no server certificate is available. Inspecting the certificate lets an application validate the server's identity.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local socket = chilkat.Socket.new()
-- Connect to the server using TLS.
local bTls = true
local maxWaitMs = 5000
local success = socket:connect("example.com", 5000, bTls, maxWaitMs)
if not success then
print(socket.last_error_text)
return
end
-- Copy the certificate presented by the remote TLS server, then inspect it. This can be used to
-- validate the server's identity.
local cert = chilkat.Cert.new()
success = socket:get_server_cert(cert)
if not success then
print(socket.last_error_text)
return
end
print("Server certificate subject: " .. cert.subject_cn)
print("Issued by: " .. cert.issuer_cn)